| Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 1 | """ |
| 2 | Use lldb Python API to make sure the dynamic checkers are doing their jobs. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import re |
| 7 | import unittest2 |
| 8 | import lldb, lldbutil |
| 9 | from lldbtest import * |
| 10 | |
| Johnny Chen | 2c684f0 | 2011-12-20 02:11:37 +0000 | [diff] [blame] | 11 | class ObjCCheckerTestCase(TestBase): |
| Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 12 | |
| Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 13 | mydir = TestBase.compute_mydir(__file__) |
| Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 14 | |
| Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 15 | def setUp(self): |
| 16 | # Call super's setUp(). |
| 17 | TestBase.setUp(self) |
| 18 | |
| 19 | # Find the line number to break for main.c. |
| Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 20 | self.source_name = 'main.m' |
| 21 | |
| Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame^] | 22 | @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 Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 30 | 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 Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 46 | process = target.LaunchSimple (None, None, self.get_process_working_directory()) |
| Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 47 | |
| 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 | |
| 73 | if __name__ == '__main__': |
| 74 | import atexit |
| 75 | lldb.SBDebugger.Initialize() |
| 76 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 77 | unittest2.main() |