-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtest_util_symbols.py
More file actions
241 lines (194 loc) · 7.15 KB
/
test_util_symbols.py
File metadata and controls
241 lines (194 loc) · 7.15 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# -*- coding: utf-8 -*- # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
import unittest
import gdb
from crash.exceptions import DelayedAttributeError
from crash.util.symbols import MinimalSymbols, Symbols, Symvals, Types
from crash.util.symbols import TypeCallbacks, SymbolCallbacks
from crash.util.symbols import MinimalSymbolCallbacks
class TestDelayedContainers(unittest.TestCase):
def setUp(self):
gdb.execute("file")
def load_file(self):
gdb.execute("file tests/test-util")
def msymbol_test(self):
class Test(object):
msymbols = MinimalSymbols([ 'test_struct' ])
return Test
def test_bad_msymbol_name(self):
test = self.msymbol_test()
x = test.msymbols
with self.assertRaises(AttributeError):
y = x.bad_symbol_name
def test_msymbol_unavailable_at_start(self):
test = self.msymbol_test()
x = test().msymbols
with self.assertRaises(DelayedAttributeError):
y = x.test_struct
def test_msymbol_available_on_load(self):
test = self.msymbol_test()
x = test().msymbols
with self.assertRaises(DelayedAttributeError):
y = x.test_struct
self.load_file()
self.assertTrue(isinstance(x.test_struct, gdb.MinSymbol))
def test_msymbol_available_at_start(self):
test = self.msymbol_test()
x = test().msymbols
self.load_file()
self.assertTrue(isinstance(x.test_struct, gdb.MinSymbol))
def symbol_test(self):
class Test(object):
symbols = Symbols([ 'test_struct' ])
return Test
def test_bad_symbol_name(self):
test = self.symbol_test()
x = test.symbols
with self.assertRaises(AttributeError):
y = x.bad_symbol_name
def test_symbol_unavailable_at_start(self):
test = self.symbol_test()
x = test().symbols
with self.assertRaises(DelayedAttributeError):
y = x.test_struct
def test_symbol_available_on_load(self):
test = self.symbol_test()
x = test().symbols
with self.assertRaises(DelayedAttributeError):
y = x.test_struct
self.load_file()
self.assertTrue(isinstance(x.test_struct, gdb.Symbol))
def test_symbol_available_at_start(self):
test = self.symbol_test()
self.load_file()
x = test().symbols
self.assertTrue(isinstance(x.test_struct, gdb.Symbol))
def symval_test(self):
class Test(object):
symvals = Symvals( [ 'test_struct' ] )
return Test
def test_bad_symval_name(self):
test = self.symval_test()
x = test.symvals
with self.assertRaises(AttributeError):
y = x.bad_symval_name
def test_symval_unavailable_at_start(self):
test = self.symval_test()
x = test().symvals
with self.assertRaises(DelayedAttributeError):
y = x.test_struct
def test_symval_available_on_load(self):
test = self.symval_test()
x = test().symvals
with self.assertRaises(DelayedAttributeError):
y = x.test_struct
self.load_file()
self.assertTrue(isinstance(x.test_struct, gdb.Value))
def test_symval_available_at_start(self):
test = self.symval_test()
self.load_file()
x = test().symvals
self.assertTrue(isinstance(x.test_struct, gdb.Value))
def type_test(self):
class Test(object):
types = Types( [ 'struct test' ] )
return Test
def test_bad_type_name(self):
test = self.type_test()
x = test.types
with self.assertRaises(AttributeError):
y = x.bad_type_name
def test_type_unavailable_at_start(self):
test = self.type_test()
x = test().types
with self.assertRaises(DelayedAttributeError):
y = x.test_type
def test_type_available_on_load(self):
test = self.type_test()
x = test().types
with self.assertRaises(DelayedAttributeError):
y = x.test_type
self.load_file()
y = x.test_type
self.assertTrue(isinstance(y, gdb.Type))
def test_type_available_at_start(self):
test = self.type_test()
self.load_file()
x = test().types
y = x.test_type
self.assertTrue(isinstance(y, gdb.Type))
def ptype_test(self):
class Test(object):
types = Types( [ 'struct test *' ])
return Test
def test_bad_ptype_name(self):
test = self.ptype_test()
x = test.types
with self.assertRaises(AttributeError):
y = x.bad_ptype_name
def test_p_type_unavailable_at_start(self):
test = self.ptype_test()
x = test().types
with self.assertRaises(DelayedAttributeError):
y = x.test_p_type
def test_p_type_available_on_load(self):
test = self.ptype_test()
x = test().types
with self.assertRaises(DelayedAttributeError):
y = x.test_p_type
self.load_file()
y = x.test_p_type
self.assertTrue(isinstance(y, gdb.Type))
def test_p_type_available_at_start(self):
test = self.ptype_test()
self.load_file()
x = test().types
y = x.test_p_type
self.assertTrue(isinstance(y, gdb.Type))
def type_callback_test(self):
class Test(object):
class nested(object):
ulong_valid = False
@classmethod
def check_ulong(cls, gdbtype):
cls.ulong_valid = True
type_cbs = TypeCallbacks( [ ('unsigned long',
nested.check_ulong) ] )
return Test
def test_type_callback_nofile(self):
test = self.type_callback_test()
x = test().nested
self.assertFalse(x.ulong_valid)
with self.assertRaises(AttributeError):
y = x.unsigned_long_type
def test_type_callback(self):
test = self.type_callback_test()
x = test().nested
self.load_file()
self.assertTrue(x.ulong_valid)
with self.assertRaises(AttributeError):
y = x.unsigned_long_type
def type_callback_test_multi(self):
class Test(object):
class nested(object):
types = Types( [ 'unsigned long' ] )
ulong_valid = False
@classmethod
def check_ulong(cls, gdbtype):
cls.ulong_valid = True
type_cbs = TypeCallbacks( [ ('unsigned long',
nested.check_ulong) ] )
return Test
def test_type_callback_nofile_multi(self):
test = self.type_callback_test_multi()
x = test().nested
self.assertFalse(x.ulong_valid)
with self.assertRaises(DelayedAttributeError):
y = x.types.unsigned_long_type
def test_type_callback_multi(self):
test = self.type_callback_test_multi()
x = test().nested
self.load_file()
self.assertTrue(x.ulong_valid)
y = x.types.unsigned_long_type
self.assertTrue(isinstance(y, gdb.Type))
self.assertTrue(y.sizeof > 4)