blob: 8f816c516f1deb7079cb3b4adabfe5fd9461fc95 [file] [log] [blame]
Jim Inghamce553d82011-11-01 02:46:54 +00001"""
2Use lldb Python API to make sure the dynamic checkers are doing their jobs.
3"""
4
5import os, time
6import re
7import unittest2
8import lldb, lldbutil
9from lldbtest import *
10
Johnny Chen2c684f02011-12-20 02:11:37 +000011class ObjCCheckerTestCase(TestBase):
Jim Inghamce553d82011-11-01 02:46:54 +000012
Greg Clayton4570d3e2013-12-10 23:19:29 +000013 mydir = TestBase.compute_mydir(__file__)
Jim Inghamce553d82011-11-01 02:46:54 +000014
Jim Inghamce553d82011-11-01 02:46:54 +000015 def setUp(self):
16 # Call super's setUp().
17 TestBase.setUp(self)
18
19 # Find the line number to break for main.c.
Jim Inghamce553d82011-11-01 02:46:54 +000020 self.source_name = 'main.m'
21
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000022 @skipUnlessDarwin
23 @python_api_test
24 def test_objc_checker(self):
25 """Test that checkers catch unrecognized selectors"""
26 if self.getArchitecture() == 'i386':
27 self.skipTest("requires Objective-C 2.0 runtime")
28
29 self.build()
Jim Inghamce553d82011-11-01 02:46:54 +000030 exe = os.path.join(os.getcwd(), "a.out")
31
32 # Create a target from the debugger.
33
34 target = self.dbg.CreateTarget (exe)
35 self.assertTrue(target, VALID_TARGET)
36
37 # Set up our breakpoints:
38
39
40 main_bkpt = target.BreakpointCreateBySourceRegex ("Set a breakpoint here.", lldb.SBFileSpec (self.source_name))
41 self.assertTrue(main_bkpt and
42 main_bkpt.GetNumLocations() == 1,
43 VALID_BREAKPOINT)
44
45 # Now launch the process, and do not stop at the entry point.
Greg Claytonc6947512013-12-13 19:18:59 +000046 process = target.LaunchSimple (None, None, self.get_process_working_directory())
Jim Inghamce553d82011-11-01 02:46:54 +000047
48 self.assertTrue(process.GetState() == lldb.eStateStopped,
49 PROCESS_STOPPED)
50
51 threads = lldbutil.get_threads_stopped_at_breakpoint (process, main_bkpt)
52 self.assertTrue (len(threads) == 1)
53 thread = threads[0]
54
55 #
56 # The class Simple doesn't have a count method. Make sure that we don't
57 # actually try to send count but catch it as an unrecognized selector.
58
59 frame = thread.GetFrameAtIndex(0)
60 expr_value = frame.EvaluateExpression("(int) [my_simple count]", False)
61 expr_error = expr_value.GetError()
62
63 self.assertTrue (expr_error.Fail())
64
65 # Make sure the call produced no NSLog stdout.
66 stdout = process.GetSTDOUT(100)
67 self.assertTrue (len(stdout) == 0)
68
69 # Make sure the error is helpful:
70 err_string = expr_error.GetCString()
71 self.assertTrue ("selector" in err_string)
72
73if __name__ == '__main__':
74 import atexit
75 lldb.SBDebugger.Initialize()
76 atexit.register(lambda: lldb.SBDebugger.Terminate())
77 unittest2.main()