1"""Test the integrity of the lldb public api directory containing SB*.h headers.
2
3There should be nothing unwanted there and a simpe main.cpp which includes SB*.h
4should compile and link with the LLDB framework."""
5
6from __future__ import print_function
7
8
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13
14class SBDirCheckerCase(TestBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17    NO_DEBUG_INFO_TESTCASE = True
18
19    def setUp(self):
20        TestBase.setUp(self)
21        self.source = 'main.cpp'
22        self.generateSource(self.source)
23
24    @skipIfNoSBHeaders
25    def test_sb_api_directory(self):
26        """Test the SB API directory and make sure there's no unwanted stuff."""
27
28        # Only proceed if this is an Apple OS, "x86_64", and local platform.
29        if not (self.platformIsDarwin() and self.getArchitecture() == "x86_64"):
30            self.skipTest("This test is only for LLDB.framework built 64-bit")
31        if self.getArchitecture() == "i386":
32            self.skipTest(
33                "LLDB is 64-bit and cannot be linked to 32-bit test program.")
34
35        exe_name = self.getBuildArtifact("a.out")
36        self.buildDriver(self.source, exe_name)
37        self.sanity_check_executable(exe_name)
38
39    def sanity_check_executable(self, exe_name):
40        """Sanity check executable compiled from the auto-generated program."""
41        exe_name = self.getBuildArtifact("a.out")
42        exe = self.getBuildArtifact(exe_name)
43        self.runCmd("file %s" % exe, CURRENT_EXECUTABLE_SET)
44
45        # This test uses a generated source file, so it's in the build directory.
46        self.line_to_break = line_number(
47            self.getBuildArtifact(self.source), '// Set breakpoint here.')
48
49        env_cmd = "settings set target.env-vars %s=%s" % (
50            self.dylibPath, self.getLLDBLibraryEnvVal())
51        if self.TraceOn():
52            print("Set environment to: ", env_cmd)
53        self.runCmd(env_cmd)
54        self.addTearDownHook(
55            lambda: self.dbg.HandleCommand(
56                "settings remove target.env-vars %s" %
57                self.dylibPath))
58
59        lldbutil.run_break_set_by_file_and_line(
60            self, self.source, self.line_to_break, num_expected_locations=-1)
61
62        self.runCmd("run", RUN_SUCCEEDED)
63
64        # The stop reason of the thread should be breakpoint.
65        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
66                    substrs=['stopped',
67                             'stop reason = breakpoint'])
68
69        self.runCmd('frame variable')
70