TestDefaultConstructorForAPIObjects.py revision 74597b88726aade190d4768062a10a67a07cd059
1""" 2Test lldb Python API object's default constructor and make sure it is invalid 3after initial construction. 4 5There are three exceptions to the above general rules, though; API objects 6SBCommadnReturnObject, SBStream, and SBSymbolContextList, are all valid objects 7after default construction. 8""" 9 10import os, time 11import re 12import unittest2 13import lldb, lldbutil 14from lldbtest import * 15 16class APIDefaultConstructorTestCase(TestBase): 17 18 mydir = os.path.join("python_api", "default-constructor") 19 20 @python_api_test 21 def test_SBAddress(self): 22 obj = lldb.SBAddress() 23 if self.TraceOn(): 24 print obj 25 self.assertFalse(obj) 26 # Do fuzz testing on the invalid obj, it should not crash lldb. 27 import sb_address 28 sb_address.fuzz_obj(obj) 29 30 @python_api_test 31 def test_SBBlock(self): 32 obj = lldb.SBBlock() 33 if self.TraceOn(): 34 print obj 35 self.assertFalse(obj) 36 # Do fuzz testing on the invalid obj, it should not crash lldb. 37 import sb_block 38 sb_block.fuzz_obj(obj) 39 40 @python_api_test 41 def test_SBBreakpoint(self): 42 obj = lldb.SBBreakpoint() 43 if self.TraceOn(): 44 print obj 45 self.assertFalse(obj) 46 # Do fuzz testing on the invalid obj, it should not crash lldb. 47 import sb_breakpoint 48 sb_breakpoint.fuzz_obj(obj) 49 50 @python_api_test 51 def test_SBBreakpointLocation(self): 52 obj = lldb.SBBreakpointLocation() 53 if self.TraceOn(): 54 print obj 55 self.assertFalse(obj) 56 # Do fuzz testing on the invalid obj, it should not crash lldb. 57 import sb_breakpointlocation 58 sb_breakpointlocation.fuzz_obj(obj) 59 60 @python_api_test 61 def test_SBBroadcaster(self): 62 obj = lldb.SBBroadcaster() 63 if self.TraceOn(): 64 print obj 65 self.assertFalse(obj) 66 # Do fuzz testing on the invalid obj, it should not crash lldb. 67 import sb_broadcaster 68 sb_broadcaster.fuzz_obj(obj) 69 70 @python_api_test 71 def test_SBCommandReturnObject(self): 72 """SBCommandReturnObject object is valid after default construction.""" 73 obj = lldb.SBCommandReturnObject() 74 if self.TraceOn(): 75 print obj 76 self.assertTrue(obj) 77 78 @python_api_test 79 def test_SBCommunication(self): 80 obj = lldb.SBCommunication() 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_communication 86 sb_communication.fuzz_obj(obj) 87 88 @python_api_test 89 def test_SBCompileUnit(self): 90 obj = lldb.SBCompileUnit() 91 if self.TraceOn(): 92 print obj 93 self.assertFalse(obj) 94 # Do fuzz testing on the invalid obj, it should not crash lldb. 95 import sb_compileunit 96 sb_compileunit.fuzz_obj(obj) 97 98 @python_api_test 99 def test_SBDebugger(self): 100 obj = lldb.SBDebugger() 101 if self.TraceOn(): 102 print obj 103 self.assertFalse(obj) 104 # Do fuzz testing on the invalid obj, it should not crash lldb. 105 import sb_debugger 106 sb_debugger.fuzz_obj(obj) 107 108 @python_api_test 109 def test_SBError(self): 110 obj = lldb.SBError() 111 if self.TraceOn(): 112 print obj 113 self.assertFalse(obj) 114 # Do fuzz testing on the invalid obj, it should not crash lldb. 115 import sb_error 116 sb_error.fuzz_obj(obj) 117 118 @python_api_test 119 def test_SBEvent(self): 120 obj = lldb.SBEvent() 121 # This is just to test that typemap, as defined in lldb.swig, works. 122 obj2 = lldb.SBEvent(0, "abc") 123 if self.TraceOn(): 124 print obj 125 self.assertFalse(obj) 126 # Do fuzz testing on the invalid obj, it should not crash lldb. 127 import sb_event 128 sb_event.fuzz_obj(obj) 129 130 @python_api_test 131 def test_SBFileSpec(self): 132 obj = lldb.SBFileSpec() 133 if self.TraceOn(): 134 print obj 135 self.assertFalse(obj) 136 # Do fuzz testing on the invalid obj, it should not crash lldb. 137 import sb_filespec 138 sb_filespec.fuzz_obj(obj) 139 140 @python_api_test 141 def test_SBFrame(self): 142 obj = lldb.SBFrame() 143 if self.TraceOn(): 144 print obj 145 self.assertFalse(obj) 146 # Do fuzz testing on the invalid obj, it should not crash lldb. 147 import sb_frame 148 sb_frame.fuzz_obj(obj) 149 150 @python_api_test 151 def test_SBFunction(self): 152 obj = lldb.SBFunction() 153 if self.TraceOn(): 154 print obj 155 self.assertFalse(obj) 156 # Do fuzz testing on the invalid obj, it should not crash lldb. 157 import sb_function 158 sb_function.fuzz_obj(obj) 159 160 @python_api_test 161 def test_SBInputReader(self): 162 obj = lldb.SBInputReader() 163 if self.TraceOn(): 164 print obj 165 self.assertFalse(obj) 166 # Do fuzz testing on the invalid obj, it should not crash lldb. 167 import sb_inputreader 168 sb_inputreader.fuzz_obj(obj) 169 170 @python_api_test 171 def test_SBInstruction(self): 172 obj = lldb.SBInstruction() 173 if self.TraceOn(): 174 print obj 175 self.assertFalse(obj) 176 # Do fuzz testing on the invalid obj, it should not crash lldb. 177 import sb_instruction 178 sb_instruction.fuzz_obj(obj) 179 180 @python_api_test 181 def test_SBInstructionList(self): 182 obj = lldb.SBInstructionList() 183 if self.TraceOn(): 184 print obj 185 self.assertFalse(obj) 186 # Do fuzz testing on the invalid obj, it should not crash lldb. 187 import sb_instructionlist 188 sb_instructionlist.fuzz_obj(obj) 189 190 @python_api_test 191 def test_SBLineEntry(self): 192 obj = lldb.SBLineEntry() 193 if self.TraceOn(): 194 print obj 195 self.assertFalse(obj) 196 # Do fuzz testing on the invalid obj, it should not crash lldb. 197 import sb_lineentry 198 sb_lineentry.fuzz_obj(obj) 199 200 @python_api_test 201 def test_SBListener(self): 202 obj = lldb.SBListener() 203 if self.TraceOn(): 204 print obj 205 self.assertFalse(obj) 206 # Do fuzz testing on the invalid obj, it should not crash lldb. 207 import sb_listener 208 sb_listener.fuzz_obj(obj) 209 210 @python_api_test 211 def test_SBModule(self): 212 obj = lldb.SBModule() 213 if self.TraceOn(): 214 print obj 215 self.assertFalse(obj) 216 # Do fuzz testing on the invalid obj, it should not crash lldb. 217 import sb_module 218 sb_module.fuzz_obj(obj) 219 220 @python_api_test 221 def test_SBProcess(self): 222 obj = lldb.SBProcess() 223 if self.TraceOn(): 224 print obj 225 self.assertFalse(obj) 226 # Do fuzz testing on the invalid obj, it should not crash lldb. 227 import sb_process 228 sb_process.fuzz_obj(obj) 229 230 @python_api_test 231 def test_SBStream(self): 232 """SBStream object is valid after default construction.""" 233 obj = lldb.SBStream() 234 if self.TraceOn(): 235 print obj 236 self.assertTrue(obj) 237 238 @python_api_test 239 def test_SBStringList(self): 240 obj = lldb.SBStringList() 241 if self.TraceOn(): 242 print obj 243 self.assertFalse(obj) 244 # Do fuzz testing on the invalid obj, it should not crash lldb. 245 import sb_stringlist 246 sb_stringlist.fuzz_obj(obj) 247 248 @python_api_test 249 def test_SBSymbol(self): 250 obj = lldb.SBSymbol() 251 if self.TraceOn(): 252 print obj 253 self.assertFalse(obj) 254 # Do fuzz testing on the invalid obj, it should not crash lldb. 255 import sb_symbol 256 sb_symbol.fuzz_obj(obj) 257 258 @python_api_test 259 def test_SBSymbolContext(self): 260 obj = lldb.SBSymbolContext() 261 if self.TraceOn(): 262 print obj 263 self.assertFalse(obj) 264 # Do fuzz testing on the invalid obj, it should not crash lldb. 265 import sb_symbolcontext 266 sb_symbolcontext.fuzz_obj(obj) 267 268 @python_api_test 269 def test_SBSymbolContextList(self): 270 """SBSymbolContextList object is valid after default construction.""" 271 obj = lldb.SBSymbolContextList() 272 if self.TraceOn(): 273 print obj 274 self.assertTrue(obj) 275 276 @python_api_test 277 def test_SBTarget(self): 278 obj = lldb.SBTarget() 279 if self.TraceOn(): 280 print obj 281 self.assertFalse(obj) 282 # Do fuzz testing on the invalid obj, it should not crash lldb. 283 import sb_target 284 sb_target.fuzz_obj(obj) 285 286 @python_api_test 287 def test_SBThread(self): 288 obj = lldb.SBThread() 289 if self.TraceOn(): 290 print obj 291 self.assertFalse(obj) 292 # Do fuzz testing on the invalid obj, it should not crash lldb. 293 import sb_thread 294 sb_thread.fuzz_obj(obj) 295 296 @python_api_test 297 def test_SBType(self): 298 try: 299 obj = lldb.SBType() 300 if self.TraceOn(): 301 print obj 302 self.assertFalse(obj) 303 # If we reach here, the test fails. 304 self.fail("lldb.SBType() should fail, not succeed!") 305 except: 306 # Exception is expected. 307 return 308 309 # Unreachable code because lldb.SBType() should fail. 310 # Do fuzz testing on the invalid obj, it should not crash lldb. 311 import sb_type 312 sb_type.fuzz_obj(obj) 313 314 @python_api_test 315 def test_SBTypeList(self): 316 obj = lldb.SBTypeList() 317 if self.TraceOn(): 318 print obj 319 self.assertTrue(obj) 320 321 @python_api_test 322 def test_SBValue(self): 323 obj = lldb.SBValue() 324 if self.TraceOn(): 325 print obj 326 self.assertFalse(obj) 327 # Do fuzz testing on the invalid obj, it should not crash lldb. 328 import sb_value 329 sb_value.fuzz_obj(obj) 330 331 @python_api_test 332 def test_SBValueList(self): 333 obj = lldb.SBValueList() 334 if self.TraceOn(): 335 print obj 336 self.assertFalse(obj) 337 # Do fuzz testing on the invalid obj, it should not crash lldb. 338 import sb_valuelist 339 sb_valuelist.fuzz_obj(obj) 340 341 342if __name__ == '__main__': 343 import atexit 344 lldb.SBDebugger.Initialize() 345 atexit.register(lambda: lldb.SBDebugger.Terminate()) 346 unittest2.main() 347