From 37286b2440b54265f7dd5f264f16f880ad025bbf Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Tue, 3 May 2011 00:19:01 +0000 Subject: [PATCH] Add a test case to exercise the 'target stop-hook add' command without relying on pexpect to spawn an lldb child command. The test is not "correct" in that the '** Stop Hooks **' message emitted by the Target implementation is invoked asynchronously and is using a separate: CommandReturnObject result; command return object that what the driver passes to the normal command interpreter loop. But it can help test our output serialization work. I need to modify the test case later to maybe only test that "-o 'expr ptr'" option does indeed work. llvm-svn: 130742 --- lldb/test/stop-hook/TestStopHookCmd.py | 71 ++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 lldb/test/stop-hook/TestStopHookCmd.py diff --git a/lldb/test/stop-hook/TestStopHookCmd.py b/lldb/test/stop-hook/TestStopHookCmd.py new file mode 100644 index 000000000000..81b1599d7108 --- /dev/null +++ b/lldb/test/stop-hook/TestStopHookCmd.py @@ -0,0 +1,71 @@ +""" +Test lldb target stop-hook command. +""" + +import os +import unittest2 +import lldb +import pexpect +from lldbtest import * + +class StopHookCmdTestCase(TestBase): + + mydir = "stop-hook" + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + def test_with_dsym(self): + """Test a sequence of target add-hook commands.""" + self.buildDsym() + self.stop_hook_cmd_sequence() + + def test_with_dwarf(self): + """Test a sequence of target add-hook commands.""" + self.buildDwarf() + self.stop_hook_cmd_sequence() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line numbers inside main.cpp. + self.begl = line_number('main.cpp', '// Set breakpoint here to test target stop-hook.') + self.endl = line_number('main.cpp', '// End of the line range for which stop-hook is to be run.') + self.line = line_number('main.cpp', '// Another breakpoint which is outside of the stop-hook range.') + + def stop_hook_cmd_sequence(self): + """Test a sequence of target stop-hook commands.""" + exe = os.path.join(os.getcwd(), "a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + self.expect('breakpoint set -f main.cpp -l %d' % self.begl, + BREAKPOINT_CREATED, + startstr = "Breakpoint created: 1: file ='main.cpp', line = %d" % + self.begl) + self.expect('breakpoint set -f main.cpp -l %d' % self.line, + BREAKPOINT_CREATED, + startstr = "Breakpoint created: 2: file ='main.cpp', line = %d" % + self.line) + + self.runCmd("target stop-hook add -f main.cpp -l %d -e %d -o 'expr ptr'" % (self.begl, self.endl)) + + self.runCmd('target stop-hook list') + + # Now run the program, expect to stop at the the first breakpoint which is within the stop-hook range. + #self.expect('run', 'Stop hook fired', + # substrs = '** Stop Hooks **') + self.runCmd('run') + self.runCmd('thread step-over') + self.expect('thread step-over', 'Stop hook fired again', + substrs = '** Stop Hooks **') + + # Now continue the inferior, we'll stop at another breakpoint which is outside the stop-hook range. + self.runCmd('process continue') + # Verify that the 'Stop Hooks' mechanism is NOT BEING fired off. + self.expect('thread step-over', 'Stop hook should not be fired', matching=False, + substrs = '** Stop Hooks **') + + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() -- GitLab