e00206587eddae1884a217cd9b2ab2a4b1e44837
[openbsd] /
1 """
2 Test lldb Python API object's default constructor and make sure it is invalid
3 after initial construction.
4
5 There are also some cases of boundary condition testings sprinkled throughout
6 the tests where None is passed to SB API which expects (const char *) in the
7 C++ API counterpart.  Passing None should not crash lldb!
8
9 There are three exceptions to the above general rules, though; API objects
10 SBCommadnReturnObject, SBStream, and SBSymbolContextList, are all valid objects
11 after default construction.
12 """
13
14 from __future__ import print_function
15
16
17 import lldb
18 from lldbsuite.test.decorators import *
19 from lldbsuite.test.lldbtest import *
20 from lldbsuite.test import lldbutil
21
22
23 class APIDefaultConstructorTestCase(TestBase):
24
25     mydir = TestBase.compute_mydir(__file__)
26     NO_DEBUG_INFO_TESTCASE = True
27
28     @add_test_categories(['pyapi'])
29     def test_SBAddress(self):
30         obj = lldb.SBAddress()
31         if self.TraceOn():
32             print(obj)
33         self.assertFalse(obj)
34         # Do fuzz testing on the invalid obj, it should not crash lldb.
35         import sb_address
36         sb_address.fuzz_obj(obj)
37
38     @add_test_categories(['pyapi'])
39     def test_SBBlock(self):
40         obj = lldb.SBBlock()
41         if self.TraceOn():
42             print(obj)
43         self.assertFalse(obj)
44         # Do fuzz testing on the invalid obj, it should not crash lldb.
45         import sb_block
46         sb_block.fuzz_obj(obj)
47
48     @add_test_categories(['pyapi'])
49     def test_SBBreakpoint(self):
50         obj = lldb.SBBreakpoint()
51         if self.TraceOn():
52             print(obj)
53         self.assertFalse(obj)
54         # Do fuzz testing on the invalid obj, it should not crash lldb.
55         import sb_breakpoint
56         sb_breakpoint.fuzz_obj(obj)
57
58     @add_test_categories(['pyapi'])
59     def test_SBBreakpointLocation(self):
60         obj = lldb.SBBreakpointLocation()
61         if self.TraceOn():
62             print(obj)
63         self.assertFalse(obj)
64         # Do fuzz testing on the invalid obj, it should not crash lldb.
65         import sb_breakpointlocation
66         sb_breakpointlocation.fuzz_obj(obj)
67
68     @add_test_categories(['pyapi'])
69     def test_SBBreakpointName(self):
70         obj = lldb.SBBreakpointName()
71         if self.TraceOn():
72             print(obj)
73         self.assertFalse(obj)
74         # Do fuzz testing on the invalid obj, it should not crash lldb.
75         import sb_breakpointname
76         sb_breakpointname.fuzz_obj(obj)
77
78     @add_test_categories(['pyapi'])
79     def test_SBBroadcaster(self):
80         obj = lldb.SBBroadcaster()
81         if self.TraceOn():
82             print(obj)
83         self.assertFalse(obj)
84         # Do fuzz testing on the invalid obj, it should not crash lldb.
85         import sb_broadcaster
86         sb_broadcaster.fuzz_obj(obj)
87
88     @add_test_categories(['pyapi'])
89     def test_SBCommandReturnObject(self):
90         """SBCommandReturnObject object is valid after default construction."""
91         obj = lldb.SBCommandReturnObject()
92         if self.TraceOn():
93             print(obj)
94         self.assertTrue(obj)
95
96     @add_test_categories(['pyapi'])
97     def test_SBCommunication(self):
98         obj = lldb.SBCommunication()
99         if self.TraceOn():
100             print(obj)
101         self.assertFalse(obj)
102         # Do fuzz testing on the invalid obj, it should not crash lldb.
103         import sb_communication
104         sb_communication.fuzz_obj(obj)
105
106     @add_test_categories(['pyapi'])
107     def test_SBCompileUnit(self):
108         obj = lldb.SBCompileUnit()
109         if self.TraceOn():
110             print(obj)
111         self.assertFalse(obj)
112         # Do fuzz testing on the invalid obj, it should not crash lldb.
113         import sb_compileunit
114         sb_compileunit.fuzz_obj(obj)
115
116     @add_test_categories(['pyapi'])
117     def test_SBDebugger(self):
118         obj = lldb.SBDebugger()
119         if self.TraceOn():
120             print(obj)
121         self.assertFalse(obj)
122         # Do fuzz testing on the invalid obj, it should not crash lldb.
123         import sb_debugger
124         sb_debugger.fuzz_obj(obj)
125
126     @add_test_categories(['pyapi'])
127     # darwin: This test passes with swig 3.0.2, fails w/3.0.5 other tests fail
128     # with 2.0.12 http://llvm.org/pr23488
129     def test_SBError(self):
130         obj = lldb.SBError()
131         if self.TraceOn():
132             print(obj)
133         self.assertFalse(obj)
134         # Do fuzz testing on the invalid obj, it should not crash lldb.
135         import sb_error
136         sb_error.fuzz_obj(obj)
137
138     @add_test_categories(['pyapi'])
139     def test_SBEvent(self):
140         obj = lldb.SBEvent()
141         # This is just to test that typemap, as defined in lldb.swig, works.
142         obj2 = lldb.SBEvent(0, "abc")
143         if self.TraceOn():
144             print(obj)
145         self.assertFalse(obj)
146         # Do fuzz testing on the invalid obj, it should not crash lldb.
147         import sb_event
148         sb_event.fuzz_obj(obj)
149
150     @add_test_categories(['pyapi'])
151     def test_SBFileSpec(self):
152         obj = lldb.SBFileSpec()
153         # This is just to test that FileSpec(None) does not crash.
154         obj2 = lldb.SBFileSpec(None, True)
155         if self.TraceOn():
156             print(obj)
157         self.assertFalse(obj)
158         # Do fuzz testing on the invalid obj, it should not crash lldb.
159         import sb_filespec
160         sb_filespec.fuzz_obj(obj)
161
162     @add_test_categories(['pyapi'])
163     def test_SBFrame(self):
164         obj = lldb.SBFrame()
165         if self.TraceOn():
166             print(obj)
167         self.assertFalse(obj)
168         # Do fuzz testing on the invalid obj, it should not crash lldb.
169         import sb_frame
170         sb_frame.fuzz_obj(obj)
171
172     @add_test_categories(['pyapi'])
173     def test_SBFunction(self):
174         obj = lldb.SBFunction()
175         if self.TraceOn():
176             print(obj)
177         self.assertFalse(obj)
178         # Do fuzz testing on the invalid obj, it should not crash lldb.
179         import sb_function
180         sb_function.fuzz_obj(obj)
181
182     @add_test_categories(['pyapi'])
183     def test_SBFile(self):
184         sbf = lldb.SBFile()
185         self.assertFalse(sbf.IsValid())
186         self.assertFalse(bool(sbf))
187         e, n = sbf.Write(b'foo')
188         self.assertTrue(e.Fail())
189         self.assertEqual(n, 0)
190         buffer = bytearray(100)
191         e, n = sbf.Read(buffer)
192         self.assertEqual(n, 0)
193         self.assertTrue(e.Fail())
194
195     @add_test_categories(['pyapi'])
196     def test_SBInstruction(self):
197         obj = lldb.SBInstruction()
198         if self.TraceOn():
199             print(obj)
200         self.assertFalse(obj)
201         # Do fuzz testing on the invalid obj, it should not crash lldb.
202         import sb_instruction
203         sb_instruction.fuzz_obj(obj)
204
205     @add_test_categories(['pyapi'])
206     def test_SBInstructionList(self):
207         obj = lldb.SBInstructionList()
208         if self.TraceOn():
209             print(obj)
210         self.assertFalse(obj)
211         # Do fuzz testing on the invalid obj, it should not crash lldb.
212         import sb_instructionlist
213         sb_instructionlist.fuzz_obj(obj)
214
215     @add_test_categories(['pyapi'])
216     def test_SBLineEntry(self):
217         obj = lldb.SBLineEntry()
218         if self.TraceOn():
219             print(obj)
220         self.assertFalse(obj)
221         # Do fuzz testing on the invalid obj, it should not crash lldb.
222         import sb_lineentry
223         sb_lineentry.fuzz_obj(obj)
224
225     @add_test_categories(['pyapi'])
226     def test_SBListener(self):
227         obj = lldb.SBListener()
228         if self.TraceOn():
229             print(obj)
230         self.assertFalse(obj)
231         # Do fuzz testing on the invalid obj, it should not crash lldb.
232         import sb_listener
233         sb_listener.fuzz_obj(obj)
234
235     @add_test_categories(['pyapi'])
236     # Py3 asserts due to a bug in SWIG.  Trying to upstream a patch to fix
237     # this in 3.0.8
238     @skipIf(py_version=['>=', (3, 0)], swig_version=['<', (3, 0, 8)])
239     def test_SBModule(self):
240         obj = lldb.SBModule()
241         if self.TraceOn():
242             print(obj)
243         self.assertFalse(obj)
244         # Do fuzz testing on the invalid obj, it should not crash lldb.
245         import sb_module
246         sb_module.fuzz_obj(obj)
247
248     @add_test_categories(['pyapi'])
249     def test_SBProcess(self):
250         obj = lldb.SBProcess()
251         if self.TraceOn():
252             print(obj)
253         self.assertFalse(obj)
254         # Do fuzz testing on the invalid obj, it should not crash lldb.
255         import sb_process
256         sb_process.fuzz_obj(obj)
257
258     @add_test_categories(['pyapi'])
259     def test_SBProcessInfo(self):
260         obj = lldb.SBProcessInfo()
261         if self.TraceOn():
262             print(obj)
263         self.assertFalse(obj)
264         # Do fuzz testing on the invalid obj, it should not crash lldb.
265         import sb_process_info
266         sb_process_info.fuzz_obj(obj)
267
268     @add_test_categories(['pyapi'])
269     def test_SBSection(self):
270         obj = lldb.SBSection()
271         if self.TraceOn():
272             print(obj)
273         self.assertFalse(obj)
274         # Do fuzz testing on the invalid obj, it should not crash lldb.
275         import sb_section
276         sb_section.fuzz_obj(obj)
277
278     @add_test_categories(['pyapi'])
279     def test_SBStream(self):
280         """SBStream object is valid after default construction."""
281         obj = lldb.SBStream()
282         if self.TraceOn():
283             print(obj)
284         self.assertTrue(obj)
285
286     @add_test_categories(['pyapi'])
287     def test_SBStringList(self):
288         obj = lldb.SBStringList()
289         if self.TraceOn():
290             print(obj)
291         self.assertFalse(obj)
292         # Do fuzz testing on the invalid obj, it should not crash lldb.
293         import sb_stringlist
294         sb_stringlist.fuzz_obj(obj)
295
296     @add_test_categories(['pyapi'])
297     def test_SBSymbol(self):
298         obj = lldb.SBSymbol()
299         if self.TraceOn():
300             print(obj)
301         self.assertFalse(obj)
302         # Do fuzz testing on the invalid obj, it should not crash lldb.
303         import sb_symbol
304         sb_symbol.fuzz_obj(obj)
305
306     @add_test_categories(['pyapi'])
307     def test_SBSymbolContext(self):
308         obj = lldb.SBSymbolContext()
309         if self.TraceOn():
310             print(obj)
311         self.assertFalse(obj)
312         # Do fuzz testing on the invalid obj, it should not crash lldb.
313         import sb_symbolcontext
314         sb_symbolcontext.fuzz_obj(obj)
315
316     @add_test_categories(['pyapi'])
317     def test_SBSymbolContextList(self):
318         """SBSymbolContextList object is valid after default construction."""
319         obj = lldb.SBSymbolContextList()
320         if self.TraceOn():
321             print(obj)
322         self.assertTrue(obj)
323
324     @add_test_categories(['pyapi'])
325     def test_SBTarget(self):
326         obj = lldb.SBTarget()
327         if self.TraceOn():
328             print(obj)
329         self.assertFalse(obj)
330         # Do fuzz testing on the invalid obj, it should not crash lldb.
331         import sb_target
332         sb_target.fuzz_obj(obj)
333
334     @add_test_categories(['pyapi'])
335     def test_SBThread(self):
336         obj = lldb.SBThread()
337         if self.TraceOn():
338             print(obj)
339         self.assertFalse(obj)
340         # Do fuzz testing on the invalid obj, it should not crash lldb.
341         import sb_thread
342         sb_thread.fuzz_obj(obj)
343
344     @add_test_categories(['pyapi'])
345     def test_SBType(self):
346         try:
347             obj = lldb.SBType()
348             if self.TraceOn():
349                 print(obj)
350             self.assertFalse(obj)
351             # If we reach here, the test fails.
352             self.fail("lldb.SBType() should fail, not succeed!")
353         except:
354             # Exception is expected.
355             return
356
357         # Unreachable code because lldb.SBType() should fail.
358         # Do fuzz testing on the invalid obj, it should not crash lldb.
359         import sb_type
360         sb_type.fuzz_obj(obj)
361
362     @add_test_categories(['pyapi'])
363     def test_SBTypeList(self):
364         """SBTypeList object is valid after default construction."""
365         obj = lldb.SBTypeList()
366         if self.TraceOn():
367             print(obj)
368         self.assertTrue(obj)
369
370     @add_test_categories(['pyapi'])
371     def test_SBValue(self):
372         obj = lldb.SBValue()
373         if self.TraceOn():
374             print(obj)
375         self.assertFalse(obj)
376         # Do fuzz testing on the invalid obj, it should not crash lldb.
377         import sb_value
378         sb_value.fuzz_obj(obj)
379
380     @add_test_categories(['pyapi'])
381     def test_SBValueList(self):
382         obj = lldb.SBValueList()
383         if self.TraceOn():
384             print(obj)
385         self.assertFalse(obj)
386         # Do fuzz testing on the invalid obj, it should not crash lldb.
387         import sb_valuelist
388         sb_valuelist.fuzz_obj(obj)
389
390     @add_test_categories(['pyapi'])
391     def test_SBWatchpoint(self):
392         obj = lldb.SBWatchpoint()
393         if self.TraceOn():
394             print(obj)
395         self.assertFalse(obj)
396         # Do fuzz testing on the invalid obj, it should not crash lldb.
397         import sb_watchpoint
398         sb_watchpoint.fuzz_obj(obj)