summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohnny Chen <johnny.chen@apple.com>2010-08-19 23:26:59 +0000
committerJohnny Chen <johnny.chen@apple.com>2010-08-19 23:26:59 +0000
commit27f212d1e69f33e7b66a427cffe0982228a57199 (patch)
tree9a20eb2935104ccd1fef8baf94f15314cbfab6b2
parent43057cd56a0b0a59d37921490b8d7de8fbea4d03 (diff)
downloadbcm5719-llvm-27f212d1e69f33e7b66a427cffe0982228a57199.tar.gz
bcm5719-llvm-27f212d1e69f33e7b66a427cffe0982228a57199.zip
Abstracted the running of command through the command interpreter and checking
its return status into lldbtest.TestBase.runCmd(); and runCmd() in combination with checking the output against matching substrings (including startswith) into lldbtest.TestBase.expect(). TestUnsignedTypes.py is refactored to use the abstracted APIs. Other test cases to be modified later. llvm-svn: 111572
-rw-r--r--lldb/test/lldbtest.py41
-rw-r--r--lldb/test/unsigned_types/TestUnsignedTypes.py57
2 files changed, 55 insertions, 43 deletions
diff --git a/lldb/test/lldbtest.py b/lldb/test/lldbtest.py
index 703f9d03457..e4727be484f 100644
--- a/lldb/test/lldbtest.py
+++ b/lldb/test/lldbtest.py
@@ -104,7 +104,6 @@ class TestBase(unittest2.TestCase):
# And the result object.
self.res = lldb.SBCommandReturnObject()
-
def tearDown(self):
# Finish the inferior process, if it was "run" previously.
if self.runStarted:
@@ -114,3 +113,43 @@ class TestBase(unittest2.TestCase):
# Restore old working directory.
os.chdir(self.oldcwd)
+
+ def runCmd(self, cmd, msg=None, check=True):
+ """
+ Ask the command interpreter to handle the command and then check its
+ return status.
+ """
+ # Fail fast if 'cmd' is not meaningful.
+ if not cmd or len(cmd) == 0:
+ raise Exception("Bad 'cmd' parameter encountered")
+ self.ci.HandleCommand(cmd, self.res)
+ if cmd == "run":
+ self.runStarted = True
+ if check:
+ self.assertTrue(self.res.Succeeded(),
+ msg if msg else CMD_MSG(cmd))
+
+ def expect(self, cmd, msg, startstr=None, substrs=None):
+ """
+ Similar to runCmd; with additional expect style output matching ability.
+
+ Ask the command interpreter to handle the command and then check its
+ return status. The 'msg' parameter specifies an informational assert
+ message. We expect the output from running the command to start with
+ 'startstr' and matches the substrings contained in 'substrs'.
+ """
+ # Fail fast if 'msg' is not meaningful.
+ if not msg or len(msg) == 0:
+ raise Exception("Bad 'msg' parameter encountered")
+ self.runCmd(cmd)
+
+ output = self.res.GetOutput()
+ matched = output.startswith(startstr) if startstr else True
+ if substrs:
+ for str in substrs:
+ matched = output.find(str) > 0
+ if not matched:
+ break
+
+ self.assertTrue(matched, msg)
+
diff --git a/lldb/test/unsigned_types/TestUnsignedTypes.py b/lldb/test/unsigned_types/TestUnsignedTypes.py
index 40a7d58eff1..cadee140922 100644
--- a/lldb/test/unsigned_types/TestUnsignedTypes.py
+++ b/lldb/test/unsigned_types/TestUnsignedTypes.py
@@ -14,58 +14,31 @@ class TestUnsignedTypes(TestBase):
def test_unsigned_types(self):
"""Test that variables with unsigned types display correctly."""
- 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 on line 19 in main() aftre the variables are assigned values.
- self.ci.HandleCommand("breakpoint set -f main.cpp -l 19", res)
- self.assertTrue(res.Succeeded(), CMD_MSG('breakpoint set'))
- self.assertTrue(res.GetOutput().startswith(
- "Breakpoint created: 1: file ='main.cpp', line = 19, locations = 1"
- ),
- BREAKPOINT_CREATED)
+ self.expect("breakpoint set -f main.cpp -l 19", BREAKPOINT_CREATED,
+ startstr = "Breakpoint created: 1: file ='main.cpp', line = 19, 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)
- 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'])
# Test that unsigned types display correctly.
- self.ci.HandleCommand("variable list -a", res)
- #print "variable list -a ->", res.GetOutput()
- self.assertTrue(res.Succeeded(), CMD_MSG('variable list -a'))
- output = res.GetOutput()
- self.assertTrue(
- output.startswith("the_unsigned_char = (unsigned char) 'c'")
- and
- output.find("the_unsigned_short = (short unsigned int) 0x0063") > 0
- and
- output.find("the_unsigned_int = (unsigned int) 0x00000063") > 0
- and
- output.find("the_unsigned_long = (long unsigned int) "
- "0x0000000000000063") > 0
- and
- output.find("the_unsigned_long_long = (long long unsigned int)"
- " 0x0000000000000063") > 0
- and
- output.find("the_uint32 = (uint32_t) 0x00000063"),
-
- VARIABLES_DISPLAYED_CORRECTLY
- )
+ self.expect("variable list -a", VARIABLES_DISPLAYED_CORRECTLY,
+ startstr = "the_unsigned_char = (unsigned char) 'c'",
+ substrs = ["the_unsigned_short = (short unsigned int) 0x0063",
+ "the_unsigned_int = (unsigned int) 0x00000063",
+ "the_unsigned_long = (long unsigned int) 0x0000000000000063",
+ "the_unsigned_long_long = (long long unsigned int) 0x0000000000000063",
+ "the_uint32 = (uint32_t) 0x00000063"])
if __name__ == '__main__':
OpenPOWER on IntegriCloud