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    NO_DEBUG_INFO_TESTCASE = True
16
17    def setUp(self):
18        TestBase.setUp(self)
19        self.source = 'main.cpp'
20        self.generateSource(self.source)
21
22    @skipIfNoSBHeaders
23    def test_sb_api_directory(self):
24        """Test the SB API directory and make sure there's no unwanted stuff."""
25
26        # Only proceed if this is an Apple OS, "x86_64", and local platform.
27        if not (self.platformIsDarwin() and self.getArchitecture() == "x86_64"):
28            self.skipTest("This test is only for LLDB.framework built 64-bit")
29        if self.getArchitecture() == "i386":
30            self.skipTest(
31                "LLDB is 64-bit and cannot be linked to 32-bit test program.")
32
33        exe_name = self.getBuildArtifact("a.out")
34        self.buildDriver(self.source, exe_name)
35        self.sanity_check_executable(exe_name)
36
37    def sanity_check_executable(self, exe_name):
38        """Sanity check executable compiled from the auto-generated program."""
39        exe_name = self.getBuildArtifact("a.out")
40        exe = self.getBuildArtifact(exe_name)
41        self.runCmd("file %s" % exe, CURRENT_EXECUTABLE_SET)
42
43        # This test uses a generated source file, so it's in the build directory.
44        self.line_to_break = line_number(
45            self.getBuildArtifact(self.source), '// Set breakpoint here.')
46
47        env_cmd = "settings set target.env-vars %s=%s" % (
48            self.dylibPath, self.getLLDBLibraryEnvVal())
49        if self.TraceOn():
50            print("Set environment to: ", env_cmd)
51        self.runCmd(env_cmd)
52        self.addTearDownHook(
53            lambda: self.dbg.HandleCommand(
54                "settings remove target.env-vars %s" %
55                self.dylibPath))
56
57        lldbutil.run_break_set_by_file_and_line(
58            self, self.source, self.line_to_break, num_expected_locations=-1)
59
60        self.runCmd("run", RUN_SUCCEEDED)
61
62        # The stop reason of the thread should be breakpoint.
63        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
64                    substrs=['stopped',
65                             'stop reason = breakpoint'])
66
67        self.runCmd('frame variable')
68