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 def test_SBError(self): 121 obj = lldb.SBError() 122 if self.TraceOn(): 123 print(obj) 124 self.assertFalse(obj) 125 # Do fuzz testing on the invalid obj, it should not crash lldb. 126 import sb_error 127 128 sb_error.fuzz_obj(obj) 129 130 def test_SBEvent(self): 131 obj = lldb.SBEvent() 132 # This is just to test that typemap, as defined in lldb.swig, works. 133 obj2 = lldb.SBEvent(0, "abc") 134 if self.TraceOn(): 135 print(obj) 136 self.assertFalse(obj) 137 # Do fuzz testing on the invalid obj, it should not crash lldb. 138 import sb_event 139 140 sb_event.fuzz_obj(obj) 141 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) 146 if self.TraceOn(): 147 print(obj) 148 self.assertFalse(obj) 149 # Do fuzz testing on the invalid obj, it should not crash lldb. 150 import sb_filespec 151 152 sb_filespec.fuzz_obj(obj) 153 154 def test_SBFrame(self): 155 obj = lldb.SBFrame() 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_frame 161 162 sb_frame.fuzz_obj(obj) 163 164 def test_SBFunction(self): 165 obj = lldb.SBFunction() 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_function 171 172 sb_function.fuzz_obj(obj) 173 174 def test_SBFile(self): 175 sbf = lldb.SBFile() 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()) 185 186 def test_SBInstruction(self): 187 obj = lldb.SBInstruction() 188 if self.TraceOn(): 189 print(obj) 190 self.assertFalse(obj) 191 # Do fuzz testing on the invalid obj, it should not crash lldb. 192 import sb_instruction 193 194 sb_instruction.fuzz_obj(obj) 195 196 def test_SBInstructionList(self): 197 obj = lldb.SBInstructionList() 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_instructionlist 203 204 sb_instructionlist.fuzz_obj(obj) 205 206 def test_SBLineEntry(self): 207 obj = lldb.SBLineEntry() 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_lineentry 213 214 sb_lineentry.fuzz_obj(obj) 215 216 def test_SBListener(self): 217 obj = lldb.SBListener() 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_listener 223 224 sb_listener.fuzz_obj(obj) 225 226 def test_SBModule(self): 227 obj = lldb.SBModule() 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_module 233 234 sb_module.fuzz_obj(obj) 235 236 def test_SBProcess(self): 237 obj = lldb.SBProcess() 238 if self.TraceOn(): 239 print(obj) 240 self.assertFalse(obj) 241 # Do fuzz testing on the invalid obj, it should not crash lldb. 242 import sb_process 243 244 sb_process.fuzz_obj(obj) 245 246 def test_SBProcessInfo(self): 247 obj = lldb.SBProcessInfo() 248 if self.TraceOn(): 249 print(obj) 250 self.assertFalse(obj) 251 # Do fuzz testing on the invalid obj, it should not crash lldb. 252 import sb_process_info 253 254 sb_process_info.fuzz_obj(obj) 255 256 def test_SBSection(self): 257 obj = lldb.SBSection() 258 if self.TraceOn(): 259 print(obj) 260 self.assertFalse(obj) 261 # Do fuzz testing on the invalid obj, it should not crash lldb. 262 import sb_section 263 264 sb_section.fuzz_obj(obj) 265 266 def test_SBStream(self): 267 """SBStream object is valid after default construction.""" 268 obj = lldb.SBStream() 269 if self.TraceOn(): 270 print(obj) 271 self.assertTrue(obj) 272 273 def test_SBStringList(self): 274 obj = lldb.SBStringList() 275 if self.TraceOn(): 276 print(obj) 277 self.assertFalse(obj) 278 # Do fuzz testing on the invalid obj, it should not crash lldb. 279 import sb_stringlist 280 281 sb_stringlist.fuzz_obj(obj) 282 283 def test_SBSymbol(self): 284 obj = lldb.SBSymbol() 285 if self.TraceOn(): 286 print(obj) 287 self.assertFalse(obj) 288 # Do fuzz testing on the invalid obj, it should not crash lldb. 289 import sb_symbol 290 291 sb_symbol.fuzz_obj(obj) 292 293 def test_SBSymbolContext(self): 294 obj = lldb.SBSymbolContext() 295 if self.TraceOn(): 296 print(obj) 297 self.assertFalse(obj) 298 # Do fuzz testing on the invalid obj, it should not crash lldb. 299 import sb_symbolcontext 300 301 sb_symbolcontext.fuzz_obj(obj) 302 303 def test_SBSymbolContextList(self): 304 """SBSymbolContextList object is valid after default construction.""" 305 obj = lldb.SBSymbolContextList() 306 if self.TraceOn(): 307 print(obj) 308 self.assertTrue(obj) 309 310 def test_SBTarget(self): 311 obj = lldb.SBTarget() 312 if self.TraceOn(): 313 print(obj) 314 self.assertFalse(obj) 315 # Do fuzz testing on the invalid obj, it should not crash lldb. 316 import sb_target 317 318 sb_target.fuzz_obj(obj) 319 320 def test_SBThread(self): 321 obj = lldb.SBThread() 322 if self.TraceOn(): 323 print(obj) 324 self.assertFalse(obj) 325 # Do fuzz testing on the invalid obj, it should not crash lldb. 326 import sb_thread 327 328 sb_thread.fuzz_obj(obj) 329 330 def test_SBType(self): 331 try: 332 obj = lldb.SBType() 333 if self.TraceOn(): 334 print(obj) 335 self.assertFalse(obj) 336 # If we reach here, the test fails. 337 self.fail("lldb.SBType() should fail, not succeed!") 338 except: 339 # Exception is expected. 340 return 341 342 # Unreachable code because lldb.SBType() should fail. 343 # Do fuzz testing on the invalid obj, it should not crash lldb. 344 import sb_type 345 346 sb_type.fuzz_obj(obj) 347 348 def test_SBTypeList(self): 349 """SBTypeList object is valid after default construction.""" 350 obj = lldb.SBTypeList() 351 if self.TraceOn(): 352 print(obj) 353 self.assertTrue(obj) 354 355 def test_SBValue(self): 356 obj = lldb.SBValue() 357 if self.TraceOn(): 358 print(obj) 359 self.assertFalse(obj) 360 # Do fuzz testing on the invalid obj, it should not crash lldb. 361 import sb_value 362 363 sb_value.fuzz_obj(obj) 364 365 def test_SBValueList(self): 366 obj = lldb.SBValueList() 367 if self.TraceOn(): 368 print(obj) 369 self.assertFalse(obj) 370 # Do fuzz testing on the invalid obj, it should not crash lldb. 371 import sb_valuelist 372 373 sb_valuelist.fuzz_obj(obj) 374 375 def test_SBWatchpoint(self): 376 obj = lldb.SBWatchpoint() 377 if self.TraceOn(): 378 print(obj) 379 self.assertFalse(obj) 380 # Do fuzz testing on the invalid obj, it should not crash lldb. 381 import sb_watchpoint 382 383 sb_watchpoint.fuzz_obj(obj) 384