Home | History | Annotate | Download | only in rdar-9973865
      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 Radar9973865DataFormatterTestCase(TestBase):
     12 
     13     # test for rdar://problem/9973865 (If you use "${var}" in the summary string for an aggregate type, the summary doesn't print for a pointer to that type)
     14     mydir = os.path.join("functionalities", "data-formatter", "rdar-9973865")
     15 
     16     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     17     @dsym_test
     18     def test_with_dsym_and_run_command(self):
     19         """Test data formatter commands."""
     20         self.buildDsym()
     21         self.data_formatter_commands()
     22 
     23     @dwarf_test
     24     def test_with_dwarf_and_run_command(self):
     25         """Test data formatter commands."""
     26 
     27         self.buildDwarf()
     28         self.data_formatter_commands()
     29 
     30     def setUp(self):
     31         # Call super's setUp().
     32         TestBase.setUp(self)
     33         # Find the line number to break at.
     34         self.line = line_number('main.cpp', '// Set break point at this line.')
     35 
     36     def data_formatter_commands(self):
     37         """Test that that file and class static variables display correctly."""
     38         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
     39 
     40         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
     41 
     42         self.runCmd("run", RUN_SUCCEEDED)
     43 
     44         # The stop reason of the thread should be breakpoint.
     45         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
     46             substrs = ['stopped',
     47                        'stop reason = breakpoint'])
     48 
     49         # This is the function to remove the custom formats in order to have a
     50         # clean slate for the next test case.
     51         def cleanup():
     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.runCmd("type summary add --summary-string \"SUMMARY SUCCESS ${var}\" Summarize")
     58         
     59         self.expect('frame variable mine_ptr',
     60                 substrs = ['SUMMARY SUCCESS summarize_ptr_t @ '])
     61 
     62         self.expect('frame variable *mine_ptr',
     63                 substrs = ['SUMMARY SUCCESS summarize_t @'])
     64 
     65         self.runCmd("type summary add --summary-string \"SUMMARY SUCCESS ${var.first}\" Summarize")
     66 
     67         self.expect('frame variable mine_ptr',
     68                     substrs = ['SUMMARY SUCCESS 10'])
     69 
     70         self.expect('frame variable *mine_ptr',
     71                     substrs = ['SUMMARY SUCCESS 10'])
     72 
     73 if __name__ == '__main__':
     74     import atexit
     75     lldb.SBDebugger.Initialize()
     76     atexit.register(lambda: lldb.SBDebugger.Terminate())
     77     unittest2.main()
     78