1""" 2Test lldb Python API object's default constructor and make sure it is invalid 3after initial construction. 4 5There are also some cases of boundary condition testings sprinkled throughout 6the tests where None is passed to SB API which expects (const char *) in the 7C++ API counterpart. Passing None should not crash lldb! 8 9There are three exceptions to the above general rules, though; API objects 10SBCommandReturnObject, SBStream, and SBSymbolContextList, are all valid objects 11after default construction. 12""" 13 14from __future__ import print_function 15 16 17import lldb 18from lldbsuite.test.decorators import * 19from lldbsuite.test.lldbtest import * 20from lldbsuite.test import lldbutil 21 22 23class 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 @skipIfReproducer # lldb::FileSP used in typemap cannot be instrumented. 118 def test_SBDebugger(self): 119 obj = lldb.SBDebugger() 120 if self.TraceOn(): 121 print(obj) 122 self.assertFalse(obj) 123 # Do fuzz testing on the invalid obj, it should not crash lldb. 124 import sb_debugger 125 sb_debugger.fuzz_obj(obj) 126 127 @add_test_categories(['pyapi']) 128 # darwin: This test passes with swig 3.0.2, fails w/3.0.5 other tests fail 129 # with 2.0.12 http://llvm.org/pr23488 130 def test_SBError(self): 131 obj = lldb.SBError() 132 if self.TraceOn(): 133 print(obj) 134 self.assertFalse(obj) 135 # Do fuzz testing on the invalid obj, it should not crash lldb. 136 import sb_error 137 sb_error.fuzz_obj(obj) 138 139 @add_test_categories(['pyapi']) 140 def test_SBEvent(self): 141 obj = lldb.SBEvent() 142 # This is just to test that typemap, as defined in lldb.swig, works. 143 obj2 = lldb.SBEvent(0, "abc") 144 if self.TraceOn(): 145 print(obj) 146 self.assertFalse(obj) 147 # Do fuzz testing on the invalid obj, it should not crash lldb. 148 import sb_event 149 sb_event.fuzz_obj(obj) 150 151 @add_test_categories(['pyapi']) 152 def test_SBFileSpec(self): 153 obj = lldb.SBFileSpec() 154 # This is just to test that FileSpec(None) does not crash. 155 obj2 = lldb.SBFileSpec(None, True) 156 if self.TraceOn(): 157 print(obj) 158 self.assertFalse(obj) 159 # Do fuzz testing on the invalid obj, it should not crash lldb. 160 import sb_filespec 161 sb_filespec.fuzz_obj(obj) 162 163 @add_test_categories(['pyapi']) 164 def test_SBFrame(self): 165 obj = lldb.SBFrame() 166 if self.TraceOn(): 167 print(obj) 168 self.assertFalse(obj) 169 # Do fuzz testing on the invalid obj, it should not crash lldb. 170 import sb_frame 171 sb_frame.fuzz_obj(obj) 172 173 @add_test_categories(['pyapi']) 174 def test_SBFunction(self): 175 obj = lldb.SBFunction() 176 if self.TraceOn(): 177 print(obj) 178 self.assertFalse(obj) 179 # Do fuzz testing on the invalid obj, it should not crash lldb. 180 import sb_function 181 sb_function.fuzz_obj(obj) 182 183 @add_test_categories(['pyapi']) 184 @skipIfReproducer # lldb::FileSP used in typemap cannot be instrumented. 185 def test_SBFile(self): 186 sbf = lldb.SBFile() 187 self.assertFalse(sbf.IsValid()) 188 self.assertFalse(bool(sbf)) 189 e, n = sbf.Write(b'foo') 190 self.assertTrue(e.Fail()) 191 self.assertEqual(n, 0) 192 buffer = bytearray(100) 193 e, n = sbf.Read(buffer) 194 self.assertEqual(n, 0) 195 self.assertTrue(e.Fail()) 196 197 @add_test_categories(['pyapi']) 198 def test_SBInstruction(self): 199 obj = lldb.SBInstruction() 200 if self.TraceOn(): 201 print(obj) 202 self.assertFalse(obj) 203 # Do fuzz testing on the invalid obj, it should not crash lldb. 204 import sb_instruction 205 sb_instruction.fuzz_obj(obj) 206 207 @add_test_categories(['pyapi']) 208 def test_SBInstructionList(self): 209 obj = lldb.SBInstructionList() 210 if self.TraceOn(): 211 print(obj) 212 self.assertFalse(obj) 213 # Do fuzz testing on the invalid obj, it should not crash lldb. 214 import sb_instructionlist 215 sb_instructionlist.fuzz_obj(obj) 216 217 @add_test_categories(['pyapi']) 218 def test_SBLineEntry(self): 219 obj = lldb.SBLineEntry() 220 if self.TraceOn(): 221 print(obj) 222 self.assertFalse(obj) 223 # Do fuzz testing on the invalid obj, it should not crash lldb. 224 import sb_lineentry 225 sb_lineentry.fuzz_obj(obj) 226 227 @add_test_categories(['pyapi']) 228 def test_SBListener(self): 229 obj = lldb.SBListener() 230 if self.TraceOn(): 231 print(obj) 232 self.assertFalse(obj) 233 # Do fuzz testing on the invalid obj, it should not crash lldb. 234 import sb_listener 235 sb_listener.fuzz_obj(obj) 236 237 @add_test_categories(['pyapi']) 238 # Py3 asserts due to a bug in SWIG. Trying to upstream a patch to fix 239 # this in 3.0.8 240 @skipIf(py_version=['>=', (3, 0)], swig_version=['<', (3, 0, 8)]) 241 def test_SBModule(self): 242 obj = lldb.SBModule() 243 if self.TraceOn(): 244 print(obj) 245 self.assertFalse(obj) 246 # Do fuzz testing on the invalid obj, it should not crash lldb. 247 import sb_module 248 sb_module.fuzz_obj(obj) 249 250 @add_test_categories(['pyapi']) 251 def test_SBProcess(self): 252 obj = lldb.SBProcess() 253 if self.TraceOn(): 254 print(obj) 255 self.assertFalse(obj) 256 # Do fuzz testing on the invalid obj, it should not crash lldb. 257 import sb_process 258 sb_process.fuzz_obj(obj) 259 260 @add_test_categories(['pyapi']) 261 def test_SBProcessInfo(self): 262 obj = lldb.SBProcessInfo() 263 if self.TraceOn(): 264 print(obj) 265 self.assertFalse(obj) 266 # Do fuzz testing on the invalid obj, it should not crash lldb. 267 import sb_process_info 268 sb_process_info.fuzz_obj(obj) 269 270 @add_test_categories(['pyapi']) 271 def test_SBSection(self): 272 obj = lldb.SBSection() 273 if self.TraceOn(): 274 print(obj) 275 self.assertFalse(obj) 276 # Do fuzz testing on the invalid obj, it should not crash lldb. 277 import sb_section 278 sb_section.fuzz_obj(obj) 279 280 @add_test_categories(['pyapi']) 281 def test_SBStream(self): 282 """SBStream object is valid after default construction.""" 283 obj = lldb.SBStream() 284 if self.TraceOn(): 285 print(obj) 286 self.assertTrue(obj) 287 288 @add_test_categories(['pyapi']) 289 def test_SBStringList(self): 290 obj = lldb.SBStringList() 291 if self.TraceOn(): 292 print(obj) 293 self.assertFalse(obj) 294 # Do fuzz testing on the invalid obj, it should not crash lldb. 295 import sb_stringlist 296 sb_stringlist.fuzz_obj(obj) 297 298 @add_test_categories(['pyapi']) 299 def test_SBSymbol(self): 300 obj = lldb.SBSymbol() 301 if self.TraceOn(): 302 print(obj) 303 self.assertFalse(obj) 304 # Do fuzz testing on the invalid obj, it should not crash lldb. 305 import sb_symbol 306 sb_symbol.fuzz_obj(obj) 307 308 @add_test_categories(['pyapi']) 309 def test_SBSymbolContext(self): 310 obj = lldb.SBSymbolContext() 311 if self.TraceOn(): 312 print(obj) 313 self.assertFalse(obj) 314 # Do fuzz testing on the invalid obj, it should not crash lldb. 315 import sb_symbolcontext 316 sb_symbolcontext.fuzz_obj(obj) 317 318 @add_test_categories(['pyapi']) 319 def test_SBSymbolContextList(self): 320 """SBSymbolContextList object is valid after default construction.""" 321 obj = lldb.SBSymbolContextList() 322 if self.TraceOn(): 323 print(obj) 324 self.assertTrue(obj) 325 326 @add_test_categories(['pyapi']) 327 def test_SBTarget(self): 328 obj = lldb.SBTarget() 329 if self.TraceOn(): 330 print(obj) 331 self.assertFalse(obj) 332 # Do fuzz testing on the invalid obj, it should not crash lldb. 333 import sb_target 334 sb_target.fuzz_obj(obj) 335 336 @add_test_categories(['pyapi']) 337 def test_SBThread(self): 338 obj = lldb.SBThread() 339 if self.TraceOn(): 340 print(obj) 341 self.assertFalse(obj) 342 # Do fuzz testing on the invalid obj, it should not crash lldb. 343 import sb_thread 344 sb_thread.fuzz_obj(obj) 345 346 @add_test_categories(['pyapi']) 347 def test_SBType(self): 348 try: 349 obj = lldb.SBType() 350 if self.TraceOn(): 351 print(obj) 352 self.assertFalse(obj) 353 # If we reach here, the test fails. 354 self.fail("lldb.SBType() should fail, not succeed!") 355 except: 356 # Exception is expected. 357 return 358 359 # Unreachable code because lldb.SBType() should fail. 360 # Do fuzz testing on the invalid obj, it should not crash lldb. 361 import sb_type 362 sb_type.fuzz_obj(obj) 363 364 @add_test_categories(['pyapi']) 365 def test_SBTypeList(self): 366 """SBTypeList object is valid after default construction.""" 367 obj = lldb.SBTypeList() 368 if self.TraceOn(): 369 print(obj) 370 self.assertTrue(obj) 371 372 @add_test_categories(['pyapi']) 373 def test_SBValue(self): 374 obj = lldb.SBValue() 375 if self.TraceOn(): 376 print(obj) 377 self.assertFalse(obj) 378 # Do fuzz testing on the invalid obj, it should not crash lldb. 379 import sb_value 380 sb_value.fuzz_obj(obj) 381 382 @add_test_categories(['pyapi']) 383 def test_SBValueList(self): 384 obj = lldb.SBValueList() 385 if self.TraceOn(): 386 print(obj) 387 self.assertFalse(obj) 388 # Do fuzz testing on the invalid obj, it should not crash lldb. 389 import sb_valuelist 390 sb_valuelist.fuzz_obj(obj) 391 392 @add_test_categories(['pyapi']) 393 def test_SBWatchpoint(self): 394 obj = lldb.SBWatchpoint() 395 if self.TraceOn(): 396 print(obj) 397 self.assertFalse(obj) 398 # Do fuzz testing on the invalid obj, it should not crash lldb. 399 import sb_watchpoint 400 sb_watchpoint.fuzz_obj(obj) 401