Home | History | Annotate | Download | only in enum_types
      1 """Look up enum type information and check for correct display."""
      2 
      3 import os, time
      4 import unittest2
      5 import lldb
      6 from lldbtest import *
      7 import lldbutil
      8 
      9 class CPP11EnumTypesTestCase(TestBase):
     10 
     11     mydir = os.path.join("lang", "cpp", "enum_types")
     12 
     13     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     14     @dsym_test
     15     def test_with_dsym_int8_t(self):
     16         """Test C++11 enumeration class types as int8_t types."""
     17         self.buildDsym(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=int8_t"'})
     18         self.image_lookup_for_enum_type()
     19 
     20     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     21     @dsym_test
     22     def test_with_dsym_int16_t(self):
     23         """Test C++11 enumeration class types as int16_t types."""
     24         self.buildDsym(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=int16_t"'})
     25         self.image_lookup_for_enum_type()
     26 
     27     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     28     @dsym_test
     29     def test_with_dsym_int32_t(self):
     30         """Test C++11 enumeration class types as int32_t types."""
     31         self.buildDsym(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=int32_t"'})
     32         self.image_lookup_for_enum_type()
     33 
     34     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     35     @dsym_test
     36     def test_with_dsym_int64_t(self):
     37         """Test C++11 enumeration class types as int64_t types."""
     38         self.buildDsym(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=int64_t"'})
     39         self.image_lookup_for_enum_type()
     40 
     41     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     42     @dsym_test
     43     def test_with_dsym_uint8_t(self):
     44         """Test C++11 enumeration class types as uint8_t types."""
     45         self.buildDsym(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=uint8_t"'})
     46         self.image_lookup_for_enum_type()
     47 
     48     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     49     @dsym_test
     50     def test_with_dsym_uint16_t(self):
     51         """Test C++11 enumeration class types as uint16_t types."""
     52         self.buildDsym(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=uint16_t"'})
     53         self.image_lookup_for_enum_type()
     54 
     55     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     56     @dsym_test
     57     def test_with_dsym_uint32_t(self):
     58         """Test C++11 enumeration class types as uint32_t types."""
     59         self.buildDsym(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=uint32_t"'})
     60         self.image_lookup_for_enum_type()
     61 
     62     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     63     @dsym_test
     64     def test_with_dsym_uint64_t(self):
     65         """Test C++11 enumeration class types as uint64_t types."""
     66         self.buildDsym(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=uint64_t"'})
     67         self.image_lookup_for_enum_type()
     68 
     69     @dwarf_test
     70     def test_with_dwarf_int8_t(self):
     71         """Test C++11 enumeration class types as int8_t types."""
     72         self.buildDwarf(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=int8_t"'})
     73         self.image_lookup_for_enum_type()
     74 
     75     @dwarf_test
     76     def test_with_dwarf_int16_t(self):
     77         """Test C++11 enumeration class types as int16_t types."""
     78         self.buildDwarf(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=int16_t"'})
     79         self.image_lookup_for_enum_type()
     80 
     81     @dwarf_test
     82     def test_with_dwarf_int32_t(self):
     83         """Test C++11 enumeration class types as int32_t types."""
     84         self.buildDwarf(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=int32_t"'})
     85         self.image_lookup_for_enum_type()
     86 
     87     @dwarf_test
     88     def test_with_dwarf_int64_t(self):
     89         """Test C++11 enumeration class types as int64_t types."""
     90         self.buildDwarf(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=int64_t"'})
     91         self.image_lookup_for_enum_type()
     92 
     93     @dwarf_test
     94     def test_with_dwarf_uint8_t(self):
     95         """Test C++11 enumeration class types as uint8_t types."""
     96         self.buildDwarf(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=uint8_t"'})
     97         self.image_lookup_for_enum_type()
     98 
     99     @dwarf_test
    100     def test_with_dwarf_uint16_t(self):
    101         """Test C++11 enumeration class types as uint16_t types."""
    102         self.buildDwarf(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=uint16_t"'})
    103         self.image_lookup_for_enum_type()
    104 
    105     @dwarf_test
    106     def test_with_dwarf_uint32_t(self):
    107         """Test C++11 enumeration class types as uint32_t types."""
    108         self.buildDwarf(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=uint32_t"'})
    109         self.image_lookup_for_enum_type()
    110 
    111     @dwarf_test
    112     def test_with_dwarf_uint64_t(self):
    113         """Test C++11 enumeration class types as uint64_t types."""
    114         self.buildDwarf(dictionary={'CFLAGS_EXTRAS': '"-DTEST_BLOCK_CAPTURED_VARS=uint64_t"'})
    115         self.image_lookup_for_enum_type()
    116 
    117     def setUp(self):
    118         # Call super's setUp().
    119         TestBase.setUp(self)
    120         # Find the line number to break inside main().
    121         self.line = line_number('main.cpp', '// Set break point at this line.')
    122 
    123     def image_lookup_for_enum_type(self):
    124         """Test C++11 enumeration class types."""
    125         exe = os.path.join(os.getcwd(), "a.out")
    126         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
    127 
    128         # Break inside the main.
    129         bkpt_id = lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
    130 
    131         self.runCmd("run", RUN_SUCCEEDED)
    132 
    133         # The stop reason of the thread should be breakpoint.
    134         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
    135             substrs = ['stopped',
    136                        'stop reason = breakpoint'])
    137 
    138         # The breakpoint should have a hit count of 1.
    139         self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
    140             substrs = [' resolved, hit count = 1'])
    141 
    142         # Look up information about the 'DayType' enum type.
    143         # Check for correct display.
    144         self.expect("image lookup -t DayType", DATA_TYPES_DISPLAYED_CORRECTLY,
    145             substrs = ['enum DayType {',
    146                        'Monday',
    147                        'Tuesday',
    148                        'Wednesday',
    149                        'Thursday',
    150                        'Friday',
    151                        'Saturday',
    152                        'Sunday',
    153                        'kNumDays',
    154                        '}'])
    155 
    156         enum_values = [ '-4', 
    157                         'Monday', 
    158                         'Tuesday', 
    159                         'Wednesday', 
    160                         'Thursday',
    161                         'Friday',
    162                         'Saturday',
    163                         'Sunday',
    164                         'kNumDays',
    165                         '5'];
    166 
    167         bkpt = self.target().FindBreakpointByID(bkpt_id)
    168         for enum_value in enum_values:
    169             self.expect("frame variable day", 'check for valid enumeration value',
    170                 substrs = [enum_value])
    171             lldbutil.continue_to_breakpoint (self.process(), bkpt)
    172 if __name__ == '__main__':
    173     import atexit
    174     lldb.SBDebugger.Initialize()
    175     atexit.register(lambda: lldb.SBDebugger.Terminate())
    176     unittest2.main()
    177