TestOrderFile.py revision 17a1399a7e7fbc4d2adb4186cd472f7e72d8d161
1"""
2Test that debug symbols have the correct order as specified by the order file.
3"""
4
5import os, time
6import re
7import unittest2
8import lldb
9from lldbtest import *
10
11class OrderFileTestCase(TestBase):
12
13    mydir = os.path.join("macosx", "order")
14
15    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
16    def test_with_dsym(self):
17        """Test debug symbols follow the correct order by the order file."""
18        self.buildDsym()
19        self.order_file()
20
21    def test_with_dwarf(self):
22        """Test debug symbols follow the correct order by the order file."""
23        self.buildDwarf()
24        self.order_file()
25
26    def order_file(self):
27        """Test debug symbols follow the correct order by the order file."""
28        exe = os.path.join(os.getcwd(), "a.out")
29        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
30
31        # Test that the debug symbols have Function f3 before Function f1.
32        # Use "-s address" option to sort by address.
33        self.runCmd("image dump symtab -s address a.out")
34        output = self.res.GetOutput()
35        mo_f3 = re.search("Code +.+f3", output)
36        mo_f1 = re.search("Code +.+f1", output)
37
38        # Match objects for f3 and f1 must exist and f3 must come before f1.
39        self.assertTrue(mo_f3 and mo_f1 and mo_f3.start() < mo_f1.start(),
40                        "Symbols have correct order by the order file")
41
42        self.runCmd("run", RUN_COMPLETED)
43
44
45if __name__ == '__main__':
46    import atexit
47    lldb.SBDebugger.Initialize()
48    atexit.register(lambda: lldb.SBDebugger.Terminate())
49    unittest2.main()
50