From b2a27481c178c101c7c843db30a814cff24cd6a6 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Tue, 3 May 2011 17:38:06 +0000 Subject: [PATCH] A more robust pexpect-based test case for testing against the firing of stop hooks. Change one test sequence to detect the '** End Stop Hooks **' marker emitted by the stop hooks mechanism and check for whether the 'expr ptr' stop-hook has been run. Also, change the TestBase.tearDown() to wait for 2 seocnds before forcefully kill the pexpect-spawned child lldb process. llvm-svn: 130767 --- lldb/test/lldbtest.py | 3 +++ lldb/test/stop-hook/TestStopHook.py | 42 +++++++++++++++-------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lldb/test/lldbtest.py b/lldb/test/lldbtest.py index 583cf14a3261..a0cb3cdaf609 100644 --- a/lldb/test/lldbtest.py +++ b/lldb/test/lldbtest.py @@ -679,7 +679,10 @@ class TestBase(unittest2.TestCase): # This is for the case of directly spawning 'lldb' and interacting with it # using pexpect. if self.child and self.child.isalive(): + with recording(self, traceAlways) as sbuf: + print >> sbuf, "tearing down the child process...." self.child.sendline('quit') + time.sleep(2) self.child.close() # Terminate the current process being debugged, if any. diff --git a/lldb/test/stop-hook/TestStopHook.py b/lldb/test/stop-hook/TestStopHook.py index a15ec3a3e84e..b05f25d96911 100644 --- a/lldb/test/stop-hook/TestStopHook.py +++ b/lldb/test/stop-hook/TestStopHook.py @@ -34,51 +34,53 @@ class StopHookTestCase(TestBase): def stop_hook_command_sequence(self): """Test a sequence of target stop-hook commands.""" exe = os.path.join(os.getcwd(), "a.out") - prompt = "\r\n\(lldb\) " - add_prompt = "Enter your stop hook command\(s\). Type 'DONE' to end.\r\n> " + prompt = "(lldb) " + add_prompt = "Enter your stop hook command(s). Type 'DONE' to end.\r\n> " add_prompt1 = "\r\n> " - child = pexpect.spawn('%s %s' % (self.lldbExec, exe)) + # So that the child gets torn down after the test. + self.child = pexpect.spawn('%s %s' % (self.lldbExec, exe)) + child = self.child # Turn on logging for what the child sends back. if self.TraceOn(): child.logfile_read = sys.stdout # Set the breakpoint, followed by the target stop-hook commands. - child.expect(prompt) + child.expect_exact(prompt) child.sendline('breakpoint set -f main.cpp -l %d' % self.begl) - child.expect(prompt) + child.expect_exact(prompt) child.sendline('breakpoint set -f main.cpp -l %d' % self.line) - child.expect(prompt) + child.expect_exact(prompt) child.sendline('target stop-hook add -f main.cpp -l %d -e %d' % (self.begl, self.endl)) - child.expect(add_prompt) + child.expect_exact(add_prompt) child.sendline('expr ptr') - child.expect(add_prompt1) + child.expect_exact(add_prompt1) child.sendline('DONE') - child.expect(prompt) + child.expect_exact(prompt) child.sendline('target stop-hook list') # Now run the program, expect to stop at the the first breakpoint which is within the stop-hook range. - child.expect(prompt) + child.expect_exact(prompt) child.sendline('run') - child.expect(prompt) - self.DebugPExpect(child) + child.expect_exact(prompt) child.sendline('thread step-over') - child.expect(prompt) - self.DebugPExpect(child) + #self.DebugPExpect(child) + child.expect_exact('** End Stop Hooks **') + #self.DebugPExpect(child) # Verify that the 'Stop Hooks' mechanism is fired off. self.expect(child.before, exe=False, - substrs = ['Stop Hooks']) + substrs = ['(void *) $0 = 0x']) # Now continue the inferior, we'll stop at another breakpoint which is outside the stop-hook range. child.sendline('process continue') - child.expect(prompt) - self.DebugPExpect(child) + child.expect_exact(prompt) + #self.DebugPExpect(child) child.sendline('thread step-over') - child.expect(prompt) - self.DebugPExpect(child) + child.expect_exact(prompt) + #self.DebugPExpect(child) # Verify that the 'Stop Hooks' mechanism is NOT BEING fired off. self.expect(child.before, exe=False, matching=False, - substrs = ['Stop Hooks']) + substrs = ['(void *) $0 = 0x']) if __name__ == '__main__':