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