1"""
2Test lldb data formatter subsystem.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9import lldbutil
10
11class Radar13338477DataFormatterTestCase(TestBase):
12
13    # test for rdar://problem/13338477 ()
14    mydir = os.path.join("functionalities", "data-formatter", "rdar-13338477")
15
16    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
17    @dsym_test
18    def test_with_dsym_and_run_command(self):
19        """Test that LLDB handles the clang typeclass Paren correctly."""
20        self.buildDsym()
21        self.data_formatter_commands()
22
23    @dwarf_test
24    def test_with_dwarf_and_run_command(self):
25        """Test that LLDB handles the clang typeclass Paren correctly."""
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 LLDB handles the clang typeclass Paren correctly."""
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, loc_exact=True)
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 delete hex', check=False)
52            self.runCmd('type summary clear', check=False)
53
54        # Execute the cleanup function during test case tear down.
55        self.addTearDownHook(cleanup)
56
57        self.expect('p *(int (*)[3])foo',
58            substrs = ['(int [3]) $',' = {','[0] = 1','[1] = 2','[2] = 3'])
59
60        self.expect('p *(int (*)[3])foo', matching=False,
61            substrs = ['01 00 00 00 02 00 00 00 03 00 00 00'])
62        self.expect('p *(int (*)[3])foo', matching=False,
63            substrs = ['0x000000030000000200000001'])
64
65
66if __name__ == '__main__':
67    import atexit
68    lldb.SBDebugger.Initialize()
69    atexit.register(lambda: lldb.SBDebugger.Terminate())
70    unittest2.main()
71