TestDefaultConstructorForAPIObjects.py revision b7a9d64b2558ed5b8c15ce37de47fc7dd33004e8
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        if self.TraceOn():
122            print obj
123        self.assertFalse(obj)
124        # Do fuzz testing on the invalid obj, it should not crash lldb.
125        import sb_event
126        sb_event.fuzz_obj(obj)
127
128    @python_api_test
129    def test_SBFileSpec(self):
130        obj = lldb.SBFileSpec()
131        if self.TraceOn():
132            print obj
133        self.assertFalse(obj)
134        # Do fuzz testing on the invalid obj, it should not crash lldb.
135        import sb_filespec
136        sb_filespec.fuzz_obj(obj)
137
138    @python_api_test
139    def test_SBFrame(self):
140        obj = lldb.SBFrame()
141        if self.TraceOn():
142            print obj
143        self.assertFalse(obj)
144        # Do fuzz testing on the invalid obj, it should not crash lldb.
145        import sb_frame
146        sb_frame.fuzz_obj(obj)
147
148    @python_api_test
149    def test_SBFunction(self):
150        obj = lldb.SBFunction()
151        if self.TraceOn():
152            print obj
153        self.assertFalse(obj)
154        # Do fuzz testing on the invalid obj, it should not crash lldb.
155        import sb_function
156        sb_function.fuzz_obj(obj)
157
158    @python_api_test
159    def test_SBInputReader(self):
160        obj = lldb.SBInputReader()
161        if self.TraceOn():
162            print obj
163        self.assertFalse(obj)
164        # Do fuzz testing on the invalid obj, it should not crash lldb.
165        import sb_inputreader
166        sb_inputreader.fuzz_obj(obj)
167
168    @python_api_test
169    def test_SBInstruction(self):
170        obj = lldb.SBInstruction()
171        if self.TraceOn():
172            print obj
173        self.assertFalse(obj)
174        # Do fuzz testing on the invalid obj, it should not crash lldb.
175        import sb_instruction
176        sb_instruction.fuzz_obj(obj)
177
178    @python_api_test
179    def test_SBInstructionList(self):
180        obj = lldb.SBInstructionList()
181        if self.TraceOn():
182            print obj
183        self.assertFalse(obj)
184        # Do fuzz testing on the invalid obj, it should not crash lldb.
185        import sb_instructionlist
186        sb_instructionlist.fuzz_obj(obj)
187
188    @python_api_test
189    def test_SBLineEntry(self):
190        obj = lldb.SBLineEntry()
191        if self.TraceOn():
192            print obj
193        self.assertFalse(obj)
194        # Do fuzz testing on the invalid obj, it should not crash lldb.
195        import sb_lineentry
196        sb_lineentry.fuzz_obj(obj)
197
198    @python_api_test
199    def test_SBListener(self):
200        obj = lldb.SBListener()
201        if self.TraceOn():
202            print obj
203        self.assertFalse(obj)
204        # Do fuzz testing on the invalid obj, it should not crash lldb.
205        import sb_listener
206        sb_listener.fuzz_obj(obj)
207
208    @python_api_test
209    def test_SBModule(self):
210        obj = lldb.SBModule()
211        if self.TraceOn():
212            print obj
213        self.assertFalse(obj)
214        # Do fuzz testing on the invalid obj, it should not crash lldb.
215        import sb_module
216        sb_module.fuzz_obj(obj)
217
218    @python_api_test
219    def test_SBProcess(self):
220        obj = lldb.SBProcess()
221        if self.TraceOn():
222            print obj
223        self.assertFalse(obj)
224        # Do fuzz testing on the invalid obj, it should not crash lldb.
225        import sb_process
226        sb_process.fuzz_obj(obj)
227
228    @python_api_test
229    def test_SBStream(self):
230        """SBStream object is valid after default construction."""
231        obj = lldb.SBStream()
232        if self.TraceOn():
233            print obj
234        self.assertTrue(obj)
235
236    @python_api_test
237    def test_SBStringList(self):
238        obj = lldb.SBStringList()
239        if self.TraceOn():
240            print obj
241        self.assertFalse(obj)
242
243    @python_api_test
244    def test_SBSymbol(self):
245        obj = lldb.SBSymbol()
246        if self.TraceOn():
247            print obj
248        self.assertFalse(obj)
249
250    @python_api_test
251    def test_SBSymbolContext(self):
252        obj = lldb.SBSymbolContext()
253        if self.TraceOn():
254            print obj
255        self.assertFalse(obj)
256
257    @python_api_test
258    def test_SBSymbolContextList(self):
259        """SBSymbolContextList object is valid after default construction."""
260        obj = lldb.SBSymbolContextList()
261        if self.TraceOn():
262            print obj
263        self.assertTrue(obj)
264
265    @python_api_test
266    def test_SBTarget(self):
267        obj = lldb.SBTarget()
268        if self.TraceOn():
269            print obj
270        self.assertFalse(obj)
271
272    @python_api_test
273    def test_SBThread(self):
274        obj = lldb.SBThread()
275        if self.TraceOn():
276            print obj
277        self.assertFalse(obj)
278
279    @python_api_test
280    def test_SBType(self):
281        obj = lldb.SBType()
282        if self.TraceOn():
283            print obj
284        self.assertFalse(obj)
285
286    @python_api_test
287    def test_SBValue(self):
288        obj = lldb.SBValue()
289        if self.TraceOn():
290            print obj
291        self.assertFalse(obj)
292
293    @python_api_test
294    def test_SBValueList(self):
295        obj = lldb.SBValueList()
296        if self.TraceOn():
297            print obj
298        self.assertFalse(obj)
299
300
301if __name__ == '__main__':
302    import atexit
303    lldb.SBDebugger.Initialize()
304    atexit.register(lambda: lldb.SBDebugger.Terminate())
305    unittest2.main()
306