1"""
2Make sure we can find the binary inside an app bundle.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9import lldbsuite.test.lldbutil as lldbutil
10import lldbsuite.test.lldbplatformutil as lldbplatformutil
11from lldbsuite.test.lldbtest import *
12
13@decorators.skipUnlessDarwin
14class FindAppInMacOSAppBundle(TestBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17
18    NO_DEBUG_INFO_TESTCASE = True
19
20    def test_find_app_in_bundle(self):
21        """There can be many tests in a test case - describe this test here."""
22        self.build()
23        self.main_source_file = lldb.SBFileSpec("main.c")
24        self.find_app_in_bundle_test()
25
26    def find_app_in_bundle_test(self):
27        """This reads in the .app, makes sure we get the right binary and can run it."""
28
29        # This function starts a process, "a.out" by default, sets a source
30        # breakpoint, runs to it, and returns the thread, process & target.
31        # It optionally takes an SBLaunchOption argument if you want to pass
32        # arguments or environment variables.
33        exe = self.getBuildArtifact("TestApp.app")
34        error = lldb.SBError()
35        target = self.dbg.CreateTarget(exe, None, None, False, error)
36        self.assertTrue(error.Success(), "Could not create target: %s"%(error.GetCString()))
37        self.assertTrue(target.IsValid(), "Target: TestApp.app is not valid.")
38        exe_module_spec = target.GetExecutable()
39        self.assertTrue(exe_module_spec.GetFilename(), "TestApp")
40
41        bkpt = target.BreakpointCreateBySourceRegex("Set a breakpoint here", self.main_source_file)
42        self.assertEquals(bkpt.GetNumLocations(), 1, "Couldn't set a breakpoint in the main app")
43
44        if lldbplatformutil.getPlatform() == "macosx":
45            launch_info = lldb.SBLaunchInfo(None)
46            launch_info.SetWorkingDirectory(self.get_process_working_directory())
47
48            error = lldb.SBError()
49            process = target.Launch(launch_info, error)
50
51            self.assertTrue(process.IsValid(), "Could not create a valid process for TestApp: %s"%(error.GetCString()))
52
53            # Frame #0 should be at our breakpoint.
54            threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
55
56            self.assertEquals(len(threads), 1, "Expected 1 thread to stop at breakpoint, %d did."%(len(threads)))
57
58
59