Home | History | Annotate | Download | only in const_variables
      1 """Check that compiler-generated constant values work correctly"""
      2 
      3 import os, time
      4 import unittest2
      5 import lldb
      6 from lldbtest import *
      7 import lldbutil
      8 
      9 class ConstVariableTestCase(TestBase):
     10 
     11     mydir = os.path.join("lang", "c", "const_variables")
     12 
     13     @dsym_test
     14     @unittest2.expectedFailure(13314878)
     15     def test_with_dsym_and_run_command(self):
     16         """Test interpreted and JITted expressions on constant values."""
     17         self.buildDsym()
     18         self.const_variable()
     19 
     20     @skipIfLinux # This test works with gcc, but fails with newer version of clang on Linux due to a clang issue. Fails for icc as well. Bug number TDB.
     21     @dwarf_test
     22     @unittest2.expectedFailure(13314878)
     23     def test_with_dwarf_and_run_command(self):
     24         """Test interpreted and JITted expressions on constant values."""
     25         self.buildDwarf()
     26         self.const_variable()
     27 
     28     def setUp(self):
     29         # Call super's setUp().
     30         TestBase.setUp(self)
     31 
     32     def const_variable(self):
     33         """Test interpreted and JITted expressions on constant values."""
     34         exe = os.path.join(os.getcwd(), "a.out")
     35         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
     36 
     37         # Break inside the main.
     38         lldbutil.run_break_set_by_symbol (self, "main", num_expected_locations=1)
     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         # The breakpoint should have a hit count of 1.
     48         self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
     49             substrs = [' resolved, hit count = 1'])
     50 
     51         self.runCmd("next")
     52 
     53         # Try frame variable.
     54         self.expect("frame variable index", VARIABLES_DISPLAYED_CORRECTLY,
     55             substrs = ['(int32_t) index = 512'])
     56 
     57         # Try an interpreted expression.
     58         self.expect("expr (index + 512)", VARIABLES_DISPLAYED_CORRECTLY,
     59             substrs = ['(int) $0 = 1024'])
     60 
     61         # Try a JITted expression.
     62         self.expect("expr (int)getpid(); (index - 256)", VARIABLES_DISPLAYED_CORRECTLY,
     63             substrs = ['(int) $1 = 256'])
     64 
     65         self.runCmd("kill")
     66 
     67 if __name__ == '__main__':
     68     import atexit
     69     lldb.SBDebugger.Initialize()
     70     atexit.register(lambda: lldb.SBDebugger.Terminate())
     71     unittest2.main()
     72