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