1"""
2Test lldb data formatter subsystem.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9import lldbutil
10
11class ValueObjectRecursionTestCase(TestBase):
12
13    mydir = os.path.join("functionalities", "recursion")
14
15    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
16    @dsym_test
17    def test_with_dsym_and_run_command(self):
18        """Test that deeply nested ValueObjects still work."""
19        self.buildDsym()
20        self.recursive_vo_commands()
21
22    @dwarf_test
23    def test_with_dwarf_and_run_command(self):
24        """Test that deeply nested ValueObjects still work."""
25        self.buildDwarf()
26        self.recursive_vo_commands()
27
28    def setUp(self):
29        # Call super's setUp().
30        TestBase.setUp(self)
31        # Find the line number to break at.
32        self.line = line_number('main.cpp', '// Set break point at this line.')
33
34    def recursive_vo_commands(self):
35        """Test that that file and class static variables display correctly."""
36        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
37
38        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
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        root = self.frame().FindVariable("root")
57        child = root.GetChildAtIndex(1)
58        if self.TraceOn():
59             print root
60             print child
61        for i in range(0,24500):
62             child = child.GetChildAtIndex(1)
63        if self.TraceOn():
64             print child
65        self.assertTrue(child.IsValid(),"could not retrieve the deep ValueObject")
66        self.assertTrue(child.GetChildAtIndex(0).IsValid(),"the deep ValueObject has no value")
67        self.assertTrue(child.GetChildAtIndex(0).GetValueAsUnsigned() != 0,"the deep ValueObject has a zero value")
68        self.assertTrue(child.GetChildAtIndex(1).GetValueAsUnsigned() != 0, "the deep ValueObject has no next")
69
70if __name__ == '__main__':
71    import atexit
72    lldb.SBDebugger.Initialize()
73    atexit.register(lambda: lldb.SBDebugger.Terminate())
74    unittest2.main()
75