1"""
2Test that variables of integer basic types are displayed correctly.
3"""
4
5import AbstractBase
6import unittest2
7import sys
8import lldb
9from lldbtest import *
10
11# rdar://problem/9649573
12# Capture the lldb and gdb-remote log files for test failures when run with no "-w" option
13class DebugIntegerTypesFailures(AbstractBase.GenericTester):
14
15    mydir = "types"
16
17    def setUp(self):
18        # Call super's setUp().
19        TestBase.setUp(self)
20        # If we're lucky, test_long_type_with_dsym fails.
21        # Let's turn on logging just for that.
22        try:
23            if "test_long_type_with_dsym" in self.id():
24                self.runCmd(
25                    "log enable -n -f %s lldb commands event process state" %
26                    os.environ["DEBUG_LLDB_LOG"])
27                self.runCmd(
28                    "log enable -n -f %s gdb-remote packets process" %
29                    os.environ["DEBUG_GDB_REMOTE_LOG"])
30        except:
31            pass
32
33    def tearDown(self):
34        # Call super's tearDown().
35        TestBase.tearDown(self)
36        # If we're lucky, test_long_type_with_dsym fails.
37        # Let's turn off logging just for that.
38        if "test_long_type_with_dsym" in self.id():
39            self.runCmd("log disable lldb")
40            self.runCmd("log disable gdb-remote")
41
42    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
43    def test_char_type_with_dsym(self):
44        """Test that char-type variables are displayed correctly."""
45        d = {'CXX_SOURCES': 'char.cpp'}
46        self.buildDsym(dictionary=d)
47        self.setTearDownCleanup(dictionary=d)
48        self.char_type()
49
50    def test_char_type_with_dwarf(self):
51        """Test that char-type variables are displayed correctly."""
52        d = {'CXX_SOURCES': 'char.cpp'}
53        self.buildDwarf(dictionary=d)
54        self.setTearDownCleanup(dictionary=d)
55        self.char_type()
56
57    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
58    def test_short_type_with_dsym(self):
59        """Test that short-type variables are displayed correctly."""
60        d = {'CXX_SOURCES': 'short.cpp'}
61        self.buildDsym(dictionary=d)
62        self.setTearDownCleanup(dictionary=d)
63        self.short_type()
64
65    def test_short_type_with_dwarf(self):
66        """Test that short-type variables are displayed correctly."""
67        d = {'CXX_SOURCES': 'short.cpp'}
68        self.buildDwarf(dictionary=d)
69        self.setTearDownCleanup(dictionary=d)
70        self.short_type()
71
72    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
73    def test_int_type_with_dsym(self):
74        """Test that int-type variables are displayed correctly."""
75        d = {'CXX_SOURCES': 'int.cpp'}
76        self.buildDsym(dictionary=d)
77        self.setTearDownCleanup(dictionary=d)
78        self.int_type()
79
80    def test_int_type_with_dwarf(self):
81        """Test that int-type variables are displayed correctly."""
82        d = {'CXX_SOURCES': 'int.cpp'}
83        self.buildDwarf(dictionary=d)
84        self.setTearDownCleanup(dictionary=d)
85        self.int_type()
86
87    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
88    def test_long_type_with_dsym(self):
89        """Test that long-type variables are displayed correctly."""
90        d = {'CXX_SOURCES': 'long.cpp'}
91        print self.id()
92        self.buildDsym(dictionary=d)
93        self.setTearDownCleanup(dictionary=d)
94        self.long_type()
95
96    def test_long_type_with_dwarf(self):
97        """Test that long-type variables are displayed correctly."""
98        d = {'CXX_SOURCES': 'long.cpp'}
99        self.buildDwarf(dictionary=d)
100        self.setTearDownCleanup(dictionary=d)
101        self.long_type()
102
103    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
104    def test_long_long_type_with_dsym(self):
105        """Test that 'long long'-type variables are displayed correctly."""
106        d = {'CXX_SOURCES': 'long_long.cpp'}
107        self.buildDsym(dictionary=d)
108        self.setTearDownCleanup(dictionary=d)
109        self.long_long_type()
110
111    def test_long_long_type_with_dwarf(self):
112        """Test that 'long long'-type variables are displayed correctly."""
113        d = {'CXX_SOURCES': 'long_long.cpp'}
114        self.buildDwarf(dictionary=d)
115        self.setTearDownCleanup(dictionary=d)
116        self.long_long_type()
117
118    def char_type(self):
119        """Test that char-type variables are displayed correctly."""
120        self.generic_type_tester(set(['char']), quotedDisplay=True)
121
122    def int_type(self):
123        """Test that int-type variables are displayed correctly."""
124        self.generic_type_tester(set(['int']))
125
126    def short_type(self):
127        """Test that short-type variables are displayed correctly."""
128        self.generic_type_tester(set(['short']))
129
130    def long_type(self):
131        """Test that long-type variables are displayed correctly."""
132        self.generic_type_tester(set(['long']))
133
134    def long_long_type(self):
135        """Test that long long-type variables are displayed correctly."""
136        self.generic_type_tester(set(['long long']))
137
138
139if __name__ == '__main__':
140    import atexit
141    lldb.SBDebugger.Initialize()
142    atexit.register(lambda: lldb.SBDebugger.Terminate())
143    unittest2.main()
144