2 Test lldb Python API object's default constructor and make sure it is invalid
3 after initial construction.
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!
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.
14 from __future__ import print_function
18 from lldbsuite.test.decorators import *
19 from lldbsuite.test.lldbtest import *
20 from lldbsuite.test import lldbutil
23 class APIDefaultConstructorTestCase(TestBase):
25 mydir = TestBase.compute_mydir(__file__)
26 NO_DEBUG_INFO_TESTCASE = True
28 @add_test_categories(['pyapi'])
29 def test_SBAddress(self):
30 obj = lldb.SBAddress()
34 # Do fuzz testing on the invalid obj, it should not crash lldb.
36 sb_address.fuzz_obj(obj)
38 @add_test_categories(['pyapi'])
39 def test_SBBlock(self):
44 # Do fuzz testing on the invalid obj, it should not crash lldb.
46 sb_block.fuzz_obj(obj)
48 @add_test_categories(['pyapi'])
49 def test_SBBreakpoint(self):
50 obj = lldb.SBBreakpoint()
54 # Do fuzz testing on the invalid obj, it should not crash lldb.
56 sb_breakpoint.fuzz_obj(obj)
58 @add_test_categories(['pyapi'])
59 def test_SBBreakpointLocation(self):
60 obj = lldb.SBBreakpointLocation()
64 # Do fuzz testing on the invalid obj, it should not crash lldb.
65 import sb_breakpointlocation
66 sb_breakpointlocation.fuzz_obj(obj)
68 @add_test_categories(['pyapi'])
69 def test_SBBreakpointName(self):
70 obj = lldb.SBBreakpointName()
74 # Do fuzz testing on the invalid obj, it should not crash lldb.
75 import sb_breakpointname
76 sb_breakpointname.fuzz_obj(obj)
78 @add_test_categories(['pyapi'])
79 def test_SBBroadcaster(self):
80 obj = lldb.SBBroadcaster()
84 # Do fuzz testing on the invalid obj, it should not crash lldb.
86 sb_broadcaster.fuzz_obj(obj)
88 @add_test_categories(['pyapi'])
89 def test_SBCommandReturnObject(self):
90 """SBCommandReturnObject object is valid after default construction."""
91 obj = lldb.SBCommandReturnObject()
96 @add_test_categories(['pyapi'])
97 def test_SBCommunication(self):
98 obj = lldb.SBCommunication()
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)
106 @add_test_categories(['pyapi'])
107 def test_SBCompileUnit(self):
108 obj = lldb.SBCompileUnit()
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)
116 @add_test_categories(['pyapi'])
117 def test_SBDebugger(self):
118 obj = lldb.SBDebugger()
121 self.assertFalse(obj)
122 # Do fuzz testing on the invalid obj, it should not crash lldb.
124 sb_debugger.fuzz_obj(obj)
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):
133 self.assertFalse(obj)
134 # Do fuzz testing on the invalid obj, it should not crash lldb.
136 sb_error.fuzz_obj(obj)
138 @add_test_categories(['pyapi'])
139 def test_SBEvent(self):
141 # This is just to test that typemap, as defined in lldb.swig, works.
142 obj2 = lldb.SBEvent(0, "abc")
145 self.assertFalse(obj)
146 # Do fuzz testing on the invalid obj, it should not crash lldb.
148 sb_event.fuzz_obj(obj)
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)
157 self.assertFalse(obj)
158 # Do fuzz testing on the invalid obj, it should not crash lldb.
160 sb_filespec.fuzz_obj(obj)
162 @add_test_categories(['pyapi'])
163 def test_SBFrame(self):
167 self.assertFalse(obj)
168 # Do fuzz testing on the invalid obj, it should not crash lldb.
170 sb_frame.fuzz_obj(obj)
172 @add_test_categories(['pyapi'])
173 def test_SBFunction(self):
174 obj = lldb.SBFunction()
177 self.assertFalse(obj)
178 # Do fuzz testing on the invalid obj, it should not crash lldb.
180 sb_function.fuzz_obj(obj)
182 @add_test_categories(['pyapi'])
183 def test_SBFile(self):
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())
195 @add_test_categories(['pyapi'])
196 def test_SBInstruction(self):
197 obj = lldb.SBInstruction()
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)
205 @add_test_categories(['pyapi'])
206 def test_SBInstructionList(self):
207 obj = lldb.SBInstructionList()
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)
215 @add_test_categories(['pyapi'])
216 def test_SBLineEntry(self):
217 obj = lldb.SBLineEntry()
220 self.assertFalse(obj)
221 # Do fuzz testing on the invalid obj, it should not crash lldb.
223 sb_lineentry.fuzz_obj(obj)
225 @add_test_categories(['pyapi'])
226 def test_SBListener(self):
227 obj = lldb.SBListener()
230 self.assertFalse(obj)
231 # Do fuzz testing on the invalid obj, it should not crash lldb.
233 sb_listener.fuzz_obj(obj)
235 @add_test_categories(['pyapi'])
236 # Py3 asserts due to a bug in SWIG. Trying to upstream a patch to fix
238 @skipIf(py_version=['>=', (3, 0)], swig_version=['<', (3, 0, 8)])
239 def test_SBModule(self):
240 obj = lldb.SBModule()
243 self.assertFalse(obj)
244 # Do fuzz testing on the invalid obj, it should not crash lldb.
246 sb_module.fuzz_obj(obj)
248 @add_test_categories(['pyapi'])
249 def test_SBProcess(self):
250 obj = lldb.SBProcess()
253 self.assertFalse(obj)
254 # Do fuzz testing on the invalid obj, it should not crash lldb.
256 sb_process.fuzz_obj(obj)
258 @add_test_categories(['pyapi'])
259 def test_SBProcessInfo(self):
260 obj = lldb.SBProcessInfo()
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)
268 @add_test_categories(['pyapi'])
269 def test_SBSection(self):
270 obj = lldb.SBSection()
273 self.assertFalse(obj)
274 # Do fuzz testing on the invalid obj, it should not crash lldb.
276 sb_section.fuzz_obj(obj)
278 @add_test_categories(['pyapi'])
279 def test_SBStream(self):
280 """SBStream object is valid after default construction."""
281 obj = lldb.SBStream()
286 @add_test_categories(['pyapi'])
287 def test_SBStringList(self):
288 obj = lldb.SBStringList()
291 self.assertFalse(obj)
292 # Do fuzz testing on the invalid obj, it should not crash lldb.
294 sb_stringlist.fuzz_obj(obj)
296 @add_test_categories(['pyapi'])
297 def test_SBSymbol(self):
298 obj = lldb.SBSymbol()
301 self.assertFalse(obj)
302 # Do fuzz testing on the invalid obj, it should not crash lldb.
304 sb_symbol.fuzz_obj(obj)
306 @add_test_categories(['pyapi'])
307 def test_SBSymbolContext(self):
308 obj = lldb.SBSymbolContext()
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)
316 @add_test_categories(['pyapi'])
317 def test_SBSymbolContextList(self):
318 """SBSymbolContextList object is valid after default construction."""
319 obj = lldb.SBSymbolContextList()
324 @add_test_categories(['pyapi'])
325 def test_SBTarget(self):
326 obj = lldb.SBTarget()
329 self.assertFalse(obj)
330 # Do fuzz testing on the invalid obj, it should not crash lldb.
332 sb_target.fuzz_obj(obj)
334 @add_test_categories(['pyapi'])
335 def test_SBThread(self):
336 obj = lldb.SBThread()
339 self.assertFalse(obj)
340 # Do fuzz testing on the invalid obj, it should not crash lldb.
342 sb_thread.fuzz_obj(obj)
344 @add_test_categories(['pyapi'])
345 def test_SBType(self):
350 self.assertFalse(obj)
351 # If we reach here, the test fails.
352 self.fail("lldb.SBType() should fail, not succeed!")
354 # Exception is expected.
357 # Unreachable code because lldb.SBType() should fail.
358 # Do fuzz testing on the invalid obj, it should not crash lldb.
360 sb_type.fuzz_obj(obj)
362 @add_test_categories(['pyapi'])
363 def test_SBTypeList(self):
364 """SBTypeList object is valid after default construction."""
365 obj = lldb.SBTypeList()
370 @add_test_categories(['pyapi'])
371 def test_SBValue(self):
375 self.assertFalse(obj)
376 # Do fuzz testing on the invalid obj, it should not crash lldb.
378 sb_value.fuzz_obj(obj)
380 @add_test_categories(['pyapi'])
381 def test_SBValueList(self):
382 obj = lldb.SBValueList()
385 self.assertFalse(obj)
386 # Do fuzz testing on the invalid obj, it should not crash lldb.
388 sb_valuelist.fuzz_obj(obj)
390 @add_test_categories(['pyapi'])
391 def test_SBWatchpoint(self):
392 obj = lldb.SBWatchpoint()
395 self.assertFalse(obj)
396 # Do fuzz testing on the invalid obj, it should not crash lldb.
398 sb_watchpoint.fuzz_obj(obj)