TestUniversal.py revision c95fe320ae4b923ae0164e4dda4139e202c225a7
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    # rdar://problem/8689814 test failure: test/macosx/universal (the i386 slice does not break?)
19    @unittest2.skipUnless(sys.platform.startswith("darwin") and os.uname()[4]=='i386',
20                          "requires Darwin & i386")
21    def test_process_launch_for_universal(self):
22        """Test process launch of a universal binary."""
23
24        # Invoke the default build rule.
25        self.buildDefault()
26
27        # Note that "testit" is a universal binary.
28        exe = os.path.join(os.getcwd(), "testit")
29
30        # By default, x86_64 is assumed if no architecture is specified.
31        self.expect("file " + exe, CURRENT_EXECUTABLE_SET,
32            startstr = "Current executable set to ",
33            substrs = ["testit' (x86_64)."])
34
35        # Break inside the main.
36        self.expect("breakpoint set -f main.c -l %d" % self.line,
37                    BREAKPOINT_CREATED,
38            startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
39                        self.line)
40
41        # We should be able to launch the x86_64 executable.
42        self.runCmd("run", RUN_SUCCEEDED)
43
44        # Check whether we have a 64-bit process launched.
45        target = self.dbg.GetSelectedTarget()
46        process = target.GetProcess()
47        self.assertTrue(target.IsValid() and process.IsValid() and
48                        self.invoke(process, 'GetAddressByteSize') == 8,
49                        "64-bit process launched")
50
51        self.runCmd("continue")
52
53        # Now specify i386 as the architecture for "testit".
54        self.expect("file " + exe + " -a i386", CURRENT_EXECUTABLE_SET,
55            startstr = "Current executable set to ",
56            substrs = ["testit' (i386)."])
57
58        # Break inside the main.
59        self.expect("breakpoint set -f main.c -l %d" % self.line,
60                    BREAKPOINT_CREATED,
61            startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
62                        self.line)
63
64        # We should be able to launch the i386 executable as well.
65        self.runCmd("run", RUN_SUCCEEDED)
66
67        # Check whether we have a 32-bit process launched.
68        target = self.dbg.GetSelectedTarget()
69        process = target.GetProcess()
70        self.assertTrue(target.IsValid() and process.IsValid() and
71                        self.invoke(process, 'GetAddressByteSize') == 4,
72                        "32-bit process launched")
73
74        self.runCmd("continue")
75
76
77if __name__ == '__main__':
78    import atexit
79    lldb.SBDebugger.Initialize()
80    atexit.register(lambda: lldb.SBDebugger.Terminate())
81    unittest2.main()
82