-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtest_infra_lookup.py
More file actions
224 lines (180 loc) · 7.11 KB
/
test_infra_lookup.py
File metadata and controls
224 lines (180 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# -*- coding: utf-8 -*- # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
import unittest
import gdb
from crash.exceptions import DelayedAttributeError
from crash.infra.callback import ObjfileEventCallback
from crash.infra.lookup import SymbolCallback, TypeCallback
from crash.infra.lookup import MinimalSymbolCallback
from crash.infra.lookup import DelayedType, DelayedSymbol, DelayedSymval
from crash.infra.lookup import DelayedMinimalSymbol, DelayedMinimalSymval
class TestTypeNameResolution(unittest.TestCase):
def test_resolve_struct_normal(self):
spec = 'struct test'
(name, attrname, pointer) = TypeCallback.resolve_type(spec)
self.assertTrue(name == 'struct test')
self.assertTrue(attrname == 'test_type')
self.assertFalse(pointer)
def test_resolve_struct_normal_pointer(self):
spec = 'struct test *'
(name, attrname, pointer) = TypeCallback.resolve_type(spec)
self.assertTrue(name == 'struct test')
self.assertTrue(attrname == 'test_p_type')
self.assertTrue(pointer)
def test_resolve_struct_leading_whitespace(self):
spec = ' struct test'
(name, attrname, pointer) = TypeCallback.resolve_type(spec)
self.assertTrue(name == 'struct test')
self.assertTrue(attrname == 'test_type')
self.assertFalse(pointer)
def test_resolve_struct_trailing_whitespace(self):
spec = 'struct test '
(name, attrname, pointer) = TypeCallback.resolve_type(spec)
self.assertTrue(name == 'struct test')
self.assertTrue(attrname == 'test_type')
self.assertFalse(pointer)
def test_resolve_struct_middle_whitespace(self):
spec = 'struct test'
(name, attrname, pointer) = TypeCallback.resolve_type(spec)
self.assertTrue(name == 'struct test')
self.assertTrue(attrname == 'test_type')
self.assertFalse(pointer)
def test_resolve_char(self):
spec = 'char'
(name, attrname, pointer) = TypeCallback.resolve_type(spec)
self.assertTrue(name == 'char')
self.assertTrue(attrname == 'char_type')
self.assertFalse(pointer)
def test_resolve_char_pointer(self):
spec = 'char *'
(name, attrname, pointer) = TypeCallback.resolve_type(spec)
self.assertTrue(name == 'char')
self.assertTrue(attrname == 'char_p_type')
self.assertTrue(pointer)
class TestMinimalSymbolCallback(unittest.TestCase):
def setUp(self):
gdb.execute("file")
def tearDown(self):
gdb.execute("file")
def load_file(self):
gdb.execute("file tests/test-util")
def get_test_class(self):
class test_class(object):
def __init__(self):
self.found = False
cb = MinimalSymbolCallback('test_struct', self.callback)
def callback(self, result):
self.found = True
self.result = result
return test_class
def test_minsymbol_no_symbol_found(self):
test_class = self.get_test_class()
x = test_class()
self.assertFalse(x.found)
gdb.execute("file tests/test-list")
self.assertFalse(x.found)
def test_minsymbol_found_immediately(self):
test_class = self.get_test_class()
self.load_file()
x = test_class()
self.assertTrue(x.found)
self.assertTrue(isinstance(x.result, gdb.MinSymbol))
def test_minsymbol_found_after_load(self):
test_class = self.get_test_class()
x = test_class()
self.assertFalse(x.found)
self.load_file()
self.assertTrue(x.found)
self.assertTrue(isinstance(x.result, gdb.MinSymbol))
def test_minsymbol_not_found_in_early_load_then_found_after_load(self):
test_class = self.get_test_class()
x = test_class()
self.assertFalse(x.found)
gdb.execute("file tests/test-list")
self.assertFalse(x.found)
self.load_file()
self.assertTrue(x.found)
self.assertTrue(isinstance(x.result, gdb.MinSymbol))
class TestSymbolCallback(unittest.TestCase):
def setUp(self):
gdb.execute("file")
def load_file(self):
gdb.execute("file tests/test-util")
def get_test_class(self):
class test_class(object):
def __init__(self):
self.found = False
cb = SymbolCallback('test_struct', self.callback)
def callback(self, result):
self.found = True
self.result = result
return test_class
def test_symbol_no_symbol_found(self):
test_class = self.get_test_class()
x = test_class()
self.assertFalse(x.found)
gdb.execute("file tests/test-list")
self.assertFalse(x.found)
def test_symbol_found_immediately(self):
test_class = self.get_test_class()
self.load_file()
x = test_class()
self.assertTrue(x.found)
self.assertTrue(isinstance(x.result, gdb.Symbol))
def test_symbol_found_after_load(self):
test_class = self.get_test_class()
x = test_class()
self.assertFalse(x.found)
self.load_file()
self.assertTrue(x.found)
self.assertTrue(isinstance(x.result, gdb.Symbol))
def test_symbol_not_found_in_early_load_then_found_after_load(self):
test_class = self.get_test_class()
x = test_class()
self.assertFalse(x.found)
gdb.execute("file tests/test-list")
self.assertFalse(x.found)
self.load_file()
self.assertTrue(x.found)
self.assertTrue(isinstance(x.result, gdb.Symbol))
class TestTypeCallback(unittest.TestCase):
def setUp(self):
gdb.execute("file")
def load_file(self):
gdb.execute("file tests/test-util")
def get_test_class(self):
class test_class(object):
def __init__(self):
self.found = False
cb = TypeCallback('struct test', self.callback)
def callback(self, result):
self.found = True
self.gdbtype = result
return test_class
def test_type_no_type_found(self):
test_class = self.get_test_class()
x = test_class()
self.assertFalse(x.found)
gdb.execute("file tests/test-list")
self.assertFalse(x.found)
def test_type_found_immediately(self):
test_class = self.get_test_class()
self.load_file()
x = test_class()
self.assertTrue(x.found)
self.assertTrue(isinstance(x.gdbtype, gdb.Type))
def test_type_found_after_load(self):
test_class = self.get_test_class()
x = test_class()
self.assertFalse(x.found)
self.load_file()
self.assertTrue(x.found)
self.assertTrue(isinstance(x.gdbtype, gdb.Type))
def test_type_not_found_in_early_load_then_found_after_load(self):
test_class = self.get_test_class()
x = test_class()
self.assertFalse(x.found)
gdb.execute("file tests/test-list")
self.assertFalse(x.found)
self.load_file()
self.assertTrue(x.found)
self.assertTrue(isinstance(x.gdbtype, gdb.Type))