TestDataFormatterAdv.py revision 9b3117e0365f3a3d59cf9adc073f716cea3bf942
1"""
2Test lldb data formatter subsystem.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10class DataFormatterTestCase(TestBase):
11
12    mydir = os.path.join("functionalities", "data-formatter", "data-formatter-advanced")
13
14    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
15    def test_with_dsym_and_run_command(self):
16        """Test data formatter commands."""
17        self.buildDsym()
18        self.data_formatter_commands()
19
20    def test_with_dwarf_and_run_command(self):
21        """Test data formatter commands."""
22        self.buildDwarf()
23        self.data_formatter_commands()
24
25    def setUp(self):
26        # Call super's setUp().
27        TestBase.setUp(self)
28        # Find the line number to break at.
29        self.line = line_number('main.cpp', '// Set break point at this line.')
30
31    def data_formatter_commands(self):
32        """Test that that file and class static variables display correctly."""
33        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
34
35        self.expect("breakpoint set -f main.cpp -l %d" % self.line,
36                    BREAKPOINT_CREATED,
37            startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" %
38                        self.line)
39
40        self.runCmd("run", RUN_SUCCEEDED)
41
42        # The stop reason of the thread should be breakpoint.
43        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
44            substrs = ['stopped',
45                       'stop reason = breakpoint'])
46
47        # This is the function to remove the custom formats in order to have a
48        # clean slate for the next test case.
49        def cleanup():
50            self.runCmd('type format clear', check=False)
51            self.runCmd('type summary clear', check=False)
52
53        # Execute the cleanup function during test case tear down.
54        self.addTearDownHook(cleanup)
55
56        self.runCmd("type summary add -f \"pippo\" -x \"IUseCharStar\"")
57
58        self.expect("frame variable iEncapsulateCharStar",
59            substrs = ['pippo'])
60
61        self.runCmd("type summary clear")
62
63        self.runCmd("type summary add -f \"pippo\" \"i_am_cool\"")
64
65        self.runCmd("type summary add -f \"pluto\" -x \"i_am_cool[a-z]*\"")
66
67        self.expect("frame variable cool_boy",
68            substrs = ['pippo'])
69
70        self.expect("frame variable cooler_boy",
71            substrs = ['pluto'])
72
73        self.runCmd("type summary delete i_am_cool")
74
75        self.expect("frame variable cool_boy",
76            substrs = ['pluto'])
77
78        self.runCmd("type summary clear")
79
80        self.runCmd("type summary add -f \"${*var[]}\" -x \"int \\[[0-9]\\]")
81
82        self.expect("frame variable int_array",
83            substrs = ['1,2,3,4,5'])
84
85        self.runCmd("type summary add -f \"${*var[].integer}\" -x \"i_am_cool \\[[0-9]\\]")
86
87        self.expect("frame variable cool_array",
88            substrs = ['1,1,1,1,6'])
89
90        self.runCmd("type summary clear")
91
92        self.runCmd("type summary add -f \"${var[1-0]%x}\" \"int\"")
93
94        self.expect("frame variable iAmInt",
95            substrs = ['01'])
96
97        self.runCmd("type summary add -f \"${*var[0-1]%x}\" \"int\"")
98
99        self.expect("frame variable iAmInt", matching=False,
100            substrs = ['01'])
101
102        self.runCmd("type summary add -f \"${var[0-1]%x}\" \"int\"")
103
104        self.expect("frame variable iAmInt",
105            substrs = ['01'])
106
107
108if __name__ == '__main__':
109    import atexit
110    lldb.SBDebugger.Initialize()
111    atexit.register(lambda: lldb.SBDebugger.Terminate())
112    unittest2.main()
113