TestDataFormatterStdIterator.py revision dbd73cf5eb16e733b28e823554e1dacdba1ebd0b
1"""
2Test lldb data formatter subsystem.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9import lldbutil
10
11class StdIteratorDataFormatterTestCase(TestBase):
12
13    mydir = os.path.join("functionalities", "data-formatter", "data-formatter-stl", "libstdcpp", "iterator")
14
15    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
16    @dsym_test
17    def test_with_dsym_and_run_command(self):
18        """Test data formatter commands."""
19        self.buildDsym()
20        self.data_formatter_commands()
21
22    @dwarf_test
23    @expectedFailureGcc # llvm.org/pr15301 LLDB prints incorrect sizes of STL containers
24    def test_with_dwarf_and_run_command(self):
25        """Test data formatter commands."""
26        self.buildDwarf()
27        self.data_formatter_commands()
28
29    def setUp(self):
30        # Call super's setUp().
31        TestBase.setUp(self)
32        # Find the line number to break at.
33        self.line = line_number('main.cpp', '// Set break point at this line.')
34
35    def data_formatter_commands(self):
36        """Test that libstdcpp iterators format properly."""
37        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
38
39        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1)
40
41        self.runCmd("run", RUN_SUCCEEDED)
42
43        # The stop reason of the thread should be breakpoint.
44        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
45            substrs = ['stopped',
46                       'stop reason = breakpoint'])
47
48        # This is the function to remove the custom formats in order to have a
49        # clean slate for the next test case.
50        def cleanup():
51            self.runCmd('type format clear', check=False)
52            self.runCmd('type summary clear', check=False)
53            self.runCmd('type filter clear', check=False)
54            self.runCmd('type synth clear', check=False)
55            self.runCmd("settings set target.max-children-count 256", check=False)
56
57        # Execute the cleanup function during test case tear down.
58        self.addTearDownHook(cleanup)
59
60        self.expect('frame variable ivI', substrs = ['item = 3'])
61        self.expect('expr ivI', substrs = ['item = 3'])
62
63        self.expect('frame variable iimI', substrs = ['first = 0','second = 12'])
64        self.expect('expr iimI', substrs = ['first = 0','second = 12'])
65
66        self.expect('frame variable simI', substrs = ['first = "world"','second = 42'])
67        self.expect('expr simI', substrs = ['first = "world"','second = 42'])
68
69        self.expect('frame variable svI', substrs = ['item = "hello"'])
70        self.expect('expr svI', substrs = ['item = "hello"'])
71
72if __name__ == '__main__':
73    import atexit
74    lldb.SBDebugger.Initialize()
75    atexit.register(lambda: lldb.SBDebugger.Terminate())
76    unittest2.main()
77