Home | History | Annotate | Download | only in data-formatter-disabling
      1 """
      2 Test lldb data formatter subsystem.
      3 """
      4 
      5 import os, time
      6 import unittest2
      7 import lldb
      8 from lldbtest import *
      9 import lldbutil
     10 
     11 class DataFormatterDisablingTestCase(TestBase):
     12 
     13     mydir = os.path.join("functionalities", "data-formatter", "data-formatter-disabling")
     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     def test_with_dwarf_and_run_command(self):
     24         """Test data formatter commands."""
     25         self.buildDwarf()
     26         self.data_formatter_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 data_formatter_commands(self):
     35         """Check that we can properly disable all data formatter categories."""
     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 category enable default', check=False)
     51              self.runCmd('type category enable system', check=False)
     52              self.runCmd('type category enable VectorTypes', check=False)
     53              self.runCmd('type category enable libcxx', check=False)
     54              self.runCmd('type category enable gnu-libstdc++', check=False)
     55              self.runCmd('type category enable CoreGraphics', check=False)
     56              self.runCmd('type category enable CoreServices', check=False)
     57              self.runCmd('type category enable AppKit', check=False)
     58              self.runCmd('type category enable CoreFoundation', check=False)
     59              self.runCmd('type category enable objc', check=False)
     60 
     61         # Execute the cleanup function during test case tear down.
     62         self.addTearDownHook(cleanup)
     63 
     64         #self.runCmd('type category enable system VectorTypes libcxx gnu-libstdc++ CoreGraphics CoreServices AppKit CoreFoundation objc default', check=False)
     65 
     66         self.expect('type category list', substrs = ['system is enabled', 'gnu-libstdc++ is enabled', 'AppKit is enabled'])
     67 
     68         self.expect("frame variable numbers",
     69             substrs = ['[0] = 1', '[3] = 1234'])
     70 
     71         self.expect('frame variable string1', substrs = ['hello world'])
     72 
     73         # now disable them all and check that nothing is formatted
     74         self.runCmd('type category disable *')
     75 
     76         self.expect("frame variable numbers", matching=False,
     77             substrs = ['[0] = 1', '[3] = 1234'])
     78 
     79         self.expect('frame variable string1', matching=False, substrs = ['hello world'])
     80 
     81         self.expect('type category list', substrs = ['system is not enabled', 'gnu-libstdc++ is not enabled', 'AppKit is not enabled'])
     82         
     83         # now enable and check that we are back to normal
     84         self.runCmd("type category enable *")
     85 
     86         self.expect('type category list', substrs = ['system is enabled', 'gnu-libstdc++ is enabled', 'AppKit is enabled'])
     87 
     88         self.expect("frame variable numbers",
     89             substrs = ['[0] = 1', '[3] = 1234'])
     90 
     91         self.expect('frame variable string1', substrs = ['hello world'])
     92 
     93         self.expect('type category list', substrs = ['system is enabled', 'gnu-libstdc++ is enabled', 'AppKit is enabled'])
     94 
     95         # last check - our cleanup will re-enable everything
     96         self.runCmd('type category disable *')
     97         self.expect('type category list', substrs = ['system is not enabled', 'gnu-libstdc++ is not enabled', 'AppKit is not enabled'])
     98 
     99 
    100 if __name__ == '__main__':
    101     import atexit
    102     lldb.SBDebugger.Initialize()
    103     atexit.register(lambda: lldb.SBDebugger.Terminate())
    104     unittest2.main()
    105