diff options
-rw-r--r-- | lldb/test/function_types/TestFunctionTypes.py | 55 | ||||
-rw-r--r-- | lldb/test/lldbtest.py | 20 |
2 files changed, 32 insertions, 43 deletions
diff --git a/lldb/test/function_types/TestFunctionTypes.py b/lldb/test/function_types/TestFunctionTypes.py index 8eafe7d1859..b9190d7d307 100644 --- a/lldb/test/function_types/TestFunctionTypes.py +++ b/lldb/test/function_types/TestFunctionTypes.py @@ -11,58 +11,37 @@ class TestFunctionTypes(TestBase): def test_function_types(self): """Test 'callback' has function ptr type, then break on the function.""" - res = self.res exe = os.path.join(os.getcwd(), "a.out") - self.ci.HandleCommand("file " + exe, res) - self.assertTrue(res.Succeeded(), CURRENT_EXECUTABLE_SET) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Break inside the main. - self.ci.HandleCommand("breakpoint set -f main.c -l 21", res) - self.assertTrue(res.Succeeded(), CMD_MSG('breakpoint set')) - self.assertTrue(res.GetOutput().startswith( - "Breakpoint created: 1: file ='main.c', line = 21, locations = 1"), - BREAKPOINT_CREATED) + self.expect("breakpoint set -f main.c -l 21", BREAKPOINT_CREATED, + startstr = "Breakpoint created: 1: file ='main.c', line = 21, locations = 1") - self.ci.HandleCommand("run", res) - self.runStarted = True - self.assertTrue(res.Succeeded(), RUN_STOPPED) + self.runCmd("run", RUN_STOPPED) # The stop reason of the thread should be breakpoint. - self.ci.HandleCommand("thread list", res) - #print "thread list ->", res.GetOutput() - self.assertTrue(res.Succeeded(), CMD_MSG('thread list')) - self.assertTrue(res.GetOutput().find('state is Stopped') > 0 and - res.GetOutput().find('stop reason = breakpoint') > 0, - STOPPED_DUE_TO_BREAKPOINT) + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['state is Stopped', + 'stop reason = breakpoint']) # The breakpoint should have a hit count of 1. - self.ci.HandleCommand("breakpoint list", res) - self.assertTrue(res.Succeeded(), CMD_MSG('breakpoint list')) - self.assertTrue(res.GetOutput().find(' resolved, hit count = 1') > 0, - BREAKPOINT_HIT_ONCE) + self.expect("breakpoint list", BREAKPOINT_HIT_ONCE, + substrs = [' resolved, hit count = 1']) # Check that the 'callback' variable display properly. - self.ci.HandleCommand("variable list callback", res); - self.assertTrue(res.Succeeded(), CMD_MSG('variable list ...')) - output = res.GetOutput() - self.assertTrue(output.startswith('(int (*)(char const *)) callback ='), - VARIABLES_DISPLAYED_CORRECTLY) + self.expect("variable list callback", VARIABLES_DISPLAYED_CORRECTLY, + startstr = '(int (*)(char const *)) callback =') # And that we can break on the callback function. - self.ci.HandleCommand("breakpoint set -n string_not_empty", res); - self.assertTrue(res.Succeeded(), BREAKPOINT_CREATED) - self.ci.HandleCommand("continue", res) - self.assertTrue(res.Succeeded(), CMD_MSG('continue')) + self.runCmd("breakpoint set -n string_not_empty", BREAKPOINT_CREATED) + self.runCmd("continue") # Check that we do indeed stop on the string_not_empty function. - self.ci.HandleCommand("process status", res) - self.assertTrue(res.Succeeded(), CMD_MSG('process status')) - output = res.GetOutput() - #print "process status =", output - self.assertTrue(output.find('where = a.out`string_not_empty') > 0 and - output.find('main.c:12') > 0 and - output.find('stop reason = breakpoint') > 0, - STOPPED_DUE_TO_BREAKPOINT) + self.expect("process status", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['where = a.out`string_not_empty', + 'main.c:12', + 'stop reason = breakpoint']) if __name__ == '__main__': diff --git a/lldb/test/lldbtest.py b/lldb/test/lldbtest.py index 1588cbf0df2..3a1c6fde950 100644 --- a/lldb/test/lldbtest.py +++ b/lldb/test/lldbtest.py @@ -114,7 +114,7 @@ class TestBase(unittest2.TestCase): # Restore old working directory. os.chdir(self.oldcwd) - def runCmd(self, cmd, msg=None, check=True): + def runCmd(self, cmd, msg=None, check=True, verbose=False): """ Ask the command interpreter to handle the command and then check its return status. @@ -122,16 +122,26 @@ class TestBase(unittest2.TestCase): # Fail fast if 'cmd' is not meaningful. if not cmd or len(cmd) == 0: raise Exception("Bad 'cmd' parameter encountered") + + if verbose: + print "runCmd:", cmd + self.ci.HandleCommand(cmd, self.res) + if cmd.startswith("run"): self.runStarted = True + + if not self.res.Succeeded(): + print self.res.GetError() + + if verbose: + print "output:", self.res.GetOutput() + if check: - if (not self.res.Succeeded()): - print self.res.GetError() self.assertTrue(self.res.Succeeded(), msg if msg else CMD_MSG(cmd)) - def expect(self, cmd, msg, startstr=None, substrs=None): + def expect(self, cmd, msg, startstr=None, substrs=None, verbose=False): """ Similar to runCmd; with additional expect style output matching ability. @@ -143,7 +153,7 @@ class TestBase(unittest2.TestCase): # Fail fast if 'msg' is not meaningful. if not msg or len(msg) == 0: raise Exception("Bad 'msg' parameter encountered") - self.runCmd(cmd) + self.runCmd(cmd, verbose = (True if verbose else False)) output = self.res.GetOutput() matched = output.startswith(startstr) if startstr else True |