Home | History | Annotate | Download | only in rdar-12481949
      1 """
      2 Check that SBValue.GetValueAsSigned() does the right thing for a 32-bit -1.
      3 """
      4 
      5 import os, time
      6 import unittest2
      7 import lldb
      8 from lldbtest import *
      9 import lldbutil
     10 
     11 class Radar12481949DataFormatterTestCase(TestBase):
     12 
     13     # test for rdar://problem/12481949
     14     mydir = os.path.join("python_api", "rdar-12481949")
     15 
     16     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     17     @dsym_test
     18     def test_with_dsym_and_run_command(self):
     19         """Check that SBValue.GetValueAsSigned() does the right thing for a 32-bit -1."""
     20         self.buildDsym()
     21         self.rdar12481949_commands()
     22 
     23     @dwarf_test
     24     def test_with_dwarf_and_run_command(self):
     25         """Check that SBValue.GetValueAsSigned() does the right thing for a 32-bit -1."""
     26         self.buildDwarf()
     27         self.rdar12481949_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 rdar12481949_commands(self):
     36         """Check that SBValue.GetValueAsSigned() does the right thing for a 32-bit -1."""
     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.assertTrue(self.frame().FindVariable("myvar").GetValueAsSigned() == -1, "GetValueAsSigned() says -1")
     58         self.assertTrue(self.frame().FindVariable("myvar").GetValueAsSigned() != 0xFFFFFFFF, "GetValueAsSigned() does not say 0xFFFFFFFF")
     59         self.assertTrue(self.frame().FindVariable("myvar").GetValueAsSigned() != 0xFFFFFFFFFFFFFFFF, "GetValueAsSigned() does not say 0xFFFFFFFFFFFFFFFF")
     60 
     61         self.assertTrue(self.frame().FindVariable("myvar").GetValueAsUnsigned() != -1, "GetValueAsUnsigned() does not say -1")
     62         self.assertTrue(self.frame().FindVariable("myvar").GetValueAsUnsigned() == 0xFFFFFFFFFFFFFFFF, "GetValueAsUnsigned() says 0xFFFFFFFFFFFFFFFF")
     63         self.assertTrue(self.frame().FindVariable("myvar").GetValueAsSigned() != 0xFFFFFFFF, "GetValueAsUnsigned() does not say 0xFFFFFFFF")
     64 
     65 if __name__ == '__main__':
     66     import atexit
     67     lldb.SBDebugger.Initialize()
     68     atexit.register(lambda: lldb.SBDebugger.Terminate())
     69     unittest2.main()
     70