Added a subtest to exercise the capability of lldb Python objects to print

themselves.  Right now, it tests a breakpoint both before and after it has been
resolved.

Updated lldbtest.TestBase.expect() with an additional keyword argument 'exe' (
default to True), which if set to False, will treat the mandatory first argument
as just the string to be matched/or not-matched against the golden input.

llvm-svn: 114501
This commit is contained in:
Johnny Chen 2010-09-21 23:33:30 +00:00
parent d64f9b8381
commit 9c48b8d79c
2 changed files with 52 additions and 13 deletions

View File

@ -84,6 +84,14 @@ class ArrayTypesTestCase(TestBase):
breakpoint = target.BreakpointCreateByLocation("main.c", 42)
self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
bp = repr(breakpoint)
self.expect(bp, msg="Breakpoint looks good", exe=False,
substrs = ["file ='main.c'",
"line = 42",
"locations = 1"])
self.expect(bp, msg="Breakpoint is not resolved as yet", exe=False, matching=False,
substrs = ["resolved = 1"])
self.runCmd("run", RUN_SUCCEEDED, setCookie=False)
# This does not work, and results in the process stopped at dyld_start?
#process = target.LaunchProcess([''], [''], os.ctermid(), False)
@ -91,17 +99,34 @@ class ArrayTypesTestCase(TestBase):
self.process = target.GetProcess()
self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID)
#procRepr = repr(self.process)
#print "procRepr:", procRepr
# The stop reason of the thread should be breakpoint.
thread = self.process.GetThreadAtIndex(0)
self.assertTrue(thread.GetStopReason() == StopReasonEnum("Breakpoint"),
STOPPED_DUE_TO_BREAKPOINT)
#threadRepr = repr(thread)
#print "threadRepr:", threadRepr
# The breakpoint should have a hit count of 1.
self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)
bp = repr(breakpoint)
self.expect(bp, "Breakpoint looks good and is resolved", exe=False,
substrs = ["file ='main.c'",
"line = 42",
"locations = 1",
"resolved = 1"])
# Lookup the "strings" string array variable.
frame = thread.GetFrameAtIndex(0)
#frameRepr = repr(frame)
#print "frameRepr:", frameRepr
variable = frame.LookupVar("strings")
#varRepr = repr(variable)
#print "varRepr:", varRepr
self.DebugSBValue(frame, variable)
self.assertTrue(variable.GetNumChildren() == 4,
"Variable 'strings' should have 4 children")

View File

@ -152,8 +152,11 @@ VARIABLES_DISPLAYED_CORRECTLY = "Variable(s) displayed correctly"
#
# And a generic "Command '%s' returns successfully" message generator.
#
def CMD_MSG(command):
return "Command '%s' returns successfully" % (command)
def CMD_MSG(str, exe):
if exe:
return "Command '%s' returns successfully" % str
else:
return "'%s' compares successfully" % str
#
# Returns the enum from the input string.
@ -402,9 +405,9 @@ class TestBase(unittest2.TestCase):
if check:
self.assertTrue(self.res.Succeeded(),
msg if msg else CMD_MSG(cmd))
msg if msg else CMD_MSG(cmd, True))
def expect(self, cmd, msg=None, patterns=None, startstr=None, substrs=None, trace=False, error=False, matching=True):
def expect(self, str, msg=None, patterns=None, startstr=None, substrs=None, trace=False, error=False, matching=True, exe=True):
"""
Similar to runCmd; with additional expect style output matching ability.
@ -422,19 +425,30 @@ class TestBase(unittest2.TestCase):
If the keyword argument matching is set to False, it signifies that the API
client is expecting the output of the command not to match the golden
input.
Finally, the required argument 'str' represents the lldb command to be
sent to the command interpreter. In case the keyword argument 'exe' is
set to False, the 'str' is treated as a string to be matched/not-matched
against the golden input.
"""
trace = (True if traceAlways else trace)
# First run the command. If we are expecting error, set check=False.
self.runCmd(cmd, trace = (True if trace else False), check = not error)
if exe:
# First run the command. If we are expecting error, set check=False.
self.runCmd(str, trace = (True if trace else False), check = not error)
# Then compare the output against expected strings.
output = self.res.GetError() if error else self.res.GetOutput()
# Then compare the output against expected strings.
output = self.res.GetError() if error else self.res.GetOutput()
# If error is True, the API client expects the command to fail!
if error:
self.assertFalse(self.res.Succeeded(),
"Command '" + cmd + "' is expected to fail!")
# If error is True, the API client expects the command to fail!
if error:
self.assertFalse(self.res.Succeeded(),
"Command '" + str + "' is expected to fail!")
else:
# No execution required, just compare str against the golden input.
output = str
if trace:
print >> sys.stderr, "look at:", output
# The heading says either "Expecting" or "Not expecting".
if trace:
@ -479,7 +493,7 @@ class TestBase(unittest2.TestCase):
print >> sys.stderr
self.assertTrue(matched if matching else not matched,
msg if msg else CMD_MSG(cmd))
msg if msg else CMD_MSG(str, exe))
def invoke(self, obj, name, trace=False):
"""Use reflection to call a method dynamically with no argument."""