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 SBCommandReturnObject, SBStream, and SBSymbolContextList, are all valid objects
11 after default construction.
15 from lldbsuite
.test
.decorators
import *
16 from lldbsuite
.test
.lldbtest
import *
17 from lldbsuite
.test
import lldbutil
20 class APIDefaultConstructorTestCase(TestBase
):
21 NO_DEBUG_INFO_TESTCASE
= True
23 def test_SBAddress(self
):
24 obj
= lldb
.SBAddress()
28 # Do fuzz testing on the invalid obj, it should not crash lldb.
31 sb_address
.fuzz_obj(obj
)
33 def test_SBBlock(self
):
38 # Do fuzz testing on the invalid obj, it should not crash lldb.
41 sb_block
.fuzz_obj(obj
)
43 def test_SBBreakpoint(self
):
44 obj
= lldb
.SBBreakpoint()
48 # Do fuzz testing on the invalid obj, it should not crash lldb.
51 sb_breakpoint
.fuzz_obj(obj
)
53 def test_SBBreakpointLocation(self
):
54 obj
= lldb
.SBBreakpointLocation()
58 # Do fuzz testing on the invalid obj, it should not crash lldb.
59 import sb_breakpointlocation
61 sb_breakpointlocation
.fuzz_obj(obj
)
63 def test_SBBreakpointName(self
):
64 obj
= lldb
.SBBreakpointName()
68 # Do fuzz testing on the invalid obj, it should not crash lldb.
69 import sb_breakpointname
71 sb_breakpointname
.fuzz_obj(obj
)
73 def test_SBBroadcaster(self
):
74 obj
= lldb
.SBBroadcaster()
78 # Do fuzz testing on the invalid obj, it should not crash lldb.
81 sb_broadcaster
.fuzz_obj(obj
)
83 def test_SBCommandReturnObject(self
):
84 """SBCommandReturnObject object is valid after default construction."""
85 obj
= lldb
.SBCommandReturnObject()
90 def test_SBCommunication(self
):
91 obj
= lldb
.SBCommunication()
95 # Do fuzz testing on the invalid obj, it should not crash lldb.
96 import sb_communication
98 sb_communication
.fuzz_obj(obj
)
100 def test_SBCompileUnit(self
):
101 obj
= lldb
.SBCompileUnit()
104 self
.assertFalse(obj
)
105 # Do fuzz testing on the invalid obj, it should not crash lldb.
106 import sb_compileunit
108 sb_compileunit
.fuzz_obj(obj
)
110 def test_SBDebugger(self
):
111 obj
= lldb
.SBDebugger()
114 self
.assertFalse(obj
)
115 # Do fuzz testing on the invalid obj, it should not crash lldb.
118 sb_debugger
.fuzz_obj(obj
)
120 def test_SBError(self
):
124 self
.assertFalse(obj
)
125 # Do fuzz testing on the invalid obj, it should not crash lldb.
128 sb_error
.fuzz_obj(obj
)
130 def test_SBEvent(self
):
132 # This is just to test that typemap, as defined in lldb.swig, works.
133 obj2
= lldb
.SBEvent(0, "abc")
136 self
.assertFalse(obj
)
137 # Do fuzz testing on the invalid obj, it should not crash lldb.
140 sb_event
.fuzz_obj(obj
)
142 def test_SBFileSpec(self
):
143 obj
= lldb
.SBFileSpec()
144 # This is just to test that FileSpec(None) does not crash.
145 obj2
= lldb
.SBFileSpec(None, True)
148 self
.assertFalse(obj
)
149 # Do fuzz testing on the invalid obj, it should not crash lldb.
152 sb_filespec
.fuzz_obj(obj
)
154 def test_SBFrame(self
):
158 self
.assertFalse(obj
)
159 # Do fuzz testing on the invalid obj, it should not crash lldb.
162 sb_frame
.fuzz_obj(obj
)
164 def test_SBFunction(self
):
165 obj
= lldb
.SBFunction()
168 self
.assertFalse(obj
)
169 # Do fuzz testing on the invalid obj, it should not crash lldb.
172 sb_function
.fuzz_obj(obj
)
174 def test_SBFile(self
):
176 self
.assertFalse(sbf
.IsValid())
177 self
.assertFalse(bool(sbf
))
178 e
, n
= sbf
.Write(b
"foo")
179 self
.assertTrue(e
.Fail())
180 self
.assertEqual(n
, 0)
181 buffer = bytearray(100)
182 e
, n
= sbf
.Read(buffer)
183 self
.assertEqual(n
, 0)
184 self
.assertTrue(e
.Fail())
186 def test_SBInstruction(self
):
187 obj
= lldb
.SBInstruction()
190 self
.assertFalse(obj
)
191 # Do fuzz testing on the invalid obj, it should not crash lldb.
192 import sb_instruction
194 sb_instruction
.fuzz_obj(obj
)
196 def test_SBInstructionList(self
):
197 obj
= lldb
.SBInstructionList()
200 self
.assertFalse(obj
)
201 # Do fuzz testing on the invalid obj, it should not crash lldb.
202 import sb_instructionlist
204 sb_instructionlist
.fuzz_obj(obj
)
206 def test_SBLineEntry(self
):
207 obj
= lldb
.SBLineEntry()
210 self
.assertFalse(obj
)
211 # Do fuzz testing on the invalid obj, it should not crash lldb.
214 sb_lineentry
.fuzz_obj(obj
)
216 def test_SBListener(self
):
217 obj
= lldb
.SBListener()
220 self
.assertFalse(obj
)
221 # Do fuzz testing on the invalid obj, it should not crash lldb.
224 sb_listener
.fuzz_obj(obj
)
226 def test_SBModule(self
):
227 obj
= lldb
.SBModule()
230 self
.assertFalse(obj
)
231 # Do fuzz testing on the invalid obj, it should not crash lldb.
234 sb_module
.fuzz_obj(obj
)
236 def test_SBProcess(self
):
237 obj
= lldb
.SBProcess()
240 self
.assertFalse(obj
)
241 # Do fuzz testing on the invalid obj, it should not crash lldb.
244 sb_process
.fuzz_obj(obj
)
246 def test_SBProcessInfo(self
):
247 obj
= lldb
.SBProcessInfo()
250 self
.assertFalse(obj
)
251 # Do fuzz testing on the invalid obj, it should not crash lldb.
252 import sb_process_info
254 sb_process_info
.fuzz_obj(obj
)
256 def test_SBSection(self
):
257 obj
= lldb
.SBSection()
260 self
.assertFalse(obj
)
261 # Do fuzz testing on the invalid obj, it should not crash lldb.
264 sb_section
.fuzz_obj(obj
)
266 def test_SBStream(self
):
267 """SBStream object is valid after default construction."""
268 obj
= lldb
.SBStream()
273 def test_SBStringList(self
):
274 obj
= lldb
.SBStringList()
277 self
.assertFalse(obj
)
278 # Do fuzz testing on the invalid obj, it should not crash lldb.
281 sb_stringlist
.fuzz_obj(obj
)
283 def test_SBSymbol(self
):
284 obj
= lldb
.SBSymbol()
287 self
.assertFalse(obj
)
288 # Do fuzz testing on the invalid obj, it should not crash lldb.
291 sb_symbol
.fuzz_obj(obj
)
293 def test_SBSymbolContext(self
):
294 obj
= lldb
.SBSymbolContext()
297 self
.assertFalse(obj
)
298 # Do fuzz testing on the invalid obj, it should not crash lldb.
299 import sb_symbolcontext
301 sb_symbolcontext
.fuzz_obj(obj
)
303 def test_SBSymbolContextList(self
):
304 """SBSymbolContextList object is valid after default construction."""
305 obj
= lldb
.SBSymbolContextList()
310 def test_SBTarget(self
):
311 obj
= lldb
.SBTarget()
314 self
.assertFalse(obj
)
315 # Do fuzz testing on the invalid obj, it should not crash lldb.
318 sb_target
.fuzz_obj(obj
)
320 def test_SBThread(self
):
321 obj
= lldb
.SBThread()
324 self
.assertFalse(obj
)
325 # Do fuzz testing on the invalid obj, it should not crash lldb.
328 sb_thread
.fuzz_obj(obj
)
330 def test_SBType(self
):
335 self
.assertFalse(obj
)
336 # If we reach here, the test fails.
337 self
.fail("lldb.SBType() should fail, not succeed!")
339 # Exception is expected.
342 # Unreachable code because lldb.SBType() should fail.
343 # Do fuzz testing on the invalid obj, it should not crash lldb.
346 sb_type
.fuzz_obj(obj
)
348 def test_SBTypeList(self
):
349 """SBTypeList object is valid after default construction."""
350 obj
= lldb
.SBTypeList()
355 def test_SBValue(self
):
359 self
.assertFalse(obj
)
360 # Do fuzz testing on the invalid obj, it should not crash lldb.
363 sb_value
.fuzz_obj(obj
)
365 def test_SBValueList(self
):
366 obj
= lldb
.SBValueList()
369 self
.assertFalse(obj
)
370 # Do fuzz testing on the invalid obj, it should not crash lldb.
373 sb_valuelist
.fuzz_obj(obj
)
375 def test_SBWatchpoint(self
):
376 obj
= lldb
.SBWatchpoint()
379 self
.assertFalse(obj
)
380 # Do fuzz testing on the invalid obj, it should not crash lldb.
383 sb_watchpoint
.fuzz_obj(obj
)