TestUniversal.py revision 4b1c6251c0a829973d466df76ab682bd7ff39fc0
1"""Test aspects of lldb commands on universal binaries."""
2
3import os, time
4import unittest2
5import lldb
6from lldbtest import *
7
8class UniversalTestCase(TestBase):
9
10    mydir = os.path.join("macosx", "universal")
11
12    def setUp(self):
13        # Call super's setUp().
14        TestBase.setUp(self)
15        # Find the line number to break inside main().
16        self.line = line_number('main.c', '// Set break point at this line.')
17
18    @unittest2.skipUnless(sys.platform.startswith("darwin") and os.uname()[4]=='i386',
19                          "requires Darwin & i386")
20    def test_process_launch_for_universal(self):
21        """Test process launch of a universal binary."""
22
23        # Invoke the default build rule.
24        self.buildDefault()
25
26        # Note that "testit" is a universal binary.
27        exe = os.path.join(os.getcwd(), "testit")
28
29        # By default, x86_64 is assumed if no architecture is specified.
30        self.expect("file " + exe, CURRENT_EXECUTABLE_SET,
31            startstr = "Current executable set to ",
32            substrs = ["testit' (x86_64)."])
33
34        # Break inside the main.
35        self.expect("breakpoint set -f main.c -l %d" % self.line,
36                    BREAKPOINT_CREATED,
37            startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
38                        self.line)
39
40        # We should be able to launch the x86_64 executable.
41        self.runCmd("run", RUN_SUCCEEDED)
42
43        # Check whether we have a 64-bit process launched.
44        target = self.dbg.GetSelectedTarget()
45        process = target.GetProcess()
46        self.assertTrue(target.IsValid() and process.IsValid() and
47                        self.invoke(process, 'GetAddressByteSize') == 8,
48                        "64-bit process launched")
49
50        self.runCmd("continue")
51
52        # Now specify i386 as the architecture for "testit".
53        self.expect("file " + exe + " -a i386", CURRENT_EXECUTABLE_SET,
54            startstr = "Current executable set to ",
55            substrs = ["testit' (i386)."])
56
57        # Break inside the main.
58        self.expect("breakpoint set -f main.c -l %d" % self.line,
59                    BREAKPOINT_CREATED,
60            startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
61                        self.line)
62
63        # We should be able to launch the i386 executable as well.
64        self.runCmd("run", RUN_SUCCEEDED)
65
66        # Check whether we have a 32-bit process launched.
67        target = self.dbg.GetSelectedTarget()
68        process = target.GetProcess()
69        self.assertTrue(target.IsValid() and process.IsValid() and
70                        self.invoke(process, 'GetAddressByteSize') == 4,
71                        "32-bit process launched")
72
73        self.runCmd("continue")
74
75
76if __name__ == '__main__':
77    import atexit
78    lldb.SBDebugger.Initialize()
79    atexit.register(lambda: lldb.SBDebugger.Terminate())
80    unittest2.main()
81