forked from OSchip/llvm-project
o lldbtest.py:
Add a keyword argument 'endstr' to TestBase.expect() method to assert that the output will end with 'endstr'. Add TestBase.switch_to_thread_with_stop_reason(stop_reason) to select the thread with the stop reason = 'stop_reason' as the current thread. o TestWatchLocation.py: Modified to switch to the stopped thread with stop reason = watchpoint and to evaluate an expression with expected output for stronger assertion. llvm-svn: 140890
This commit is contained in:
parent
920844c36e
commit
86268e4459
|
@ -62,6 +62,9 @@ class HelloWatchLocationTestCase(TestBase):
|
||||||
# incrmenting the global pool by 2.
|
# incrmenting the global pool by 2.
|
||||||
self.expect("frame variable -w write -x 1 -g g_char_ptr", WATCHPOINT_CREATED,
|
self.expect("frame variable -w write -x 1 -g g_char_ptr", WATCHPOINT_CREATED,
|
||||||
substrs = ['Watchpoint created', 'size = 1', 'type = w'])
|
substrs = ['Watchpoint created', 'size = 1', 'type = w'])
|
||||||
|
self.runCmd("expr unsigned val = *g_char_ptr; val")
|
||||||
|
self.expect(self.res.GetOutput().splitlines()[0], exe=False,
|
||||||
|
endstr = ' = 0')
|
||||||
|
|
||||||
# Use the '-v' option to do verbose listing of the watchpoint.
|
# Use the '-v' option to do verbose listing of the watchpoint.
|
||||||
# The hit count should be 0 initially.
|
# The hit count should be 0 initially.
|
||||||
|
@ -77,6 +80,13 @@ class HelloWatchLocationTestCase(TestBase):
|
||||||
'stop reason = watchpoint',
|
'stop reason = watchpoint',
|
||||||
self.violating_func])
|
self.violating_func])
|
||||||
|
|
||||||
|
# Switch to the thread stopped due to watchpoint and issue some commands.
|
||||||
|
self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint)
|
||||||
|
self.runCmd("thread backtrace")
|
||||||
|
self.runCmd("expr unsigned val = *g_char_ptr; val")
|
||||||
|
self.expect(self.res.GetOutput().splitlines()[0], exe=False,
|
||||||
|
endstr = ' = 1')
|
||||||
|
|
||||||
# Use the '-v' option to do verbose listing of the watchpoint.
|
# Use the '-v' option to do verbose listing of the watchpoint.
|
||||||
# The hit count should now be 1.
|
# The hit count should now be 1.
|
||||||
self.expect("watchpoint list -v",
|
self.expect("watchpoint list -v",
|
||||||
|
|
|
@ -23,6 +23,8 @@ char *g_char_ptr = NULL;
|
||||||
void
|
void
|
||||||
do_bad_thing_with_location(char *char_ptr, char new_val)
|
do_bad_thing_with_location(char *char_ptr, char new_val)
|
||||||
{
|
{
|
||||||
|
unsigned what = new_val;
|
||||||
|
printf("new value written to location(%p) = %u\n", char_ptr, what);
|
||||||
*char_ptr = new_val;
|
*char_ptr = new_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -962,6 +962,21 @@ class TestBase(Base):
|
||||||
|
|
||||||
del self.dbg
|
del self.dbg
|
||||||
|
|
||||||
|
def switch_to_thread_with_stop_reason(self, stop_reason):
|
||||||
|
"""
|
||||||
|
Run the 'thread list' command, and select the thread with stop reason as
|
||||||
|
'stop_reason'. If no such thread exists, no select action is done.
|
||||||
|
"""
|
||||||
|
from lldbutil import stop_reason_to_str
|
||||||
|
self.runCmd('thread list')
|
||||||
|
output = self.res.GetOutput()
|
||||||
|
thread_line_pattern = re.compile("^[ *] thread #([0-9]+):.*stop reason = %s" %
|
||||||
|
stop_reason_to_str(stop_reason))
|
||||||
|
for line in output.splitlines():
|
||||||
|
matched = thread_line_pattern.match(line)
|
||||||
|
if matched:
|
||||||
|
self.runCmd('thread select %s' % matched.group(1))
|
||||||
|
|
||||||
def runCmd(self, cmd, msg=None, check=True, trace=False):
|
def runCmd(self, cmd, msg=None, check=True, trace=False):
|
||||||
"""
|
"""
|
||||||
Ask the command interpreter to handle the command and then check its
|
Ask the command interpreter to handle the command and then check its
|
||||||
|
@ -1000,7 +1015,7 @@ class TestBase(Base):
|
||||||
self.assertTrue(self.res.Succeeded(),
|
self.assertTrue(self.res.Succeeded(),
|
||||||
msg if msg else CMD_MSG(cmd))
|
msg if msg else CMD_MSG(cmd))
|
||||||
|
|
||||||
def expect(self, str, msg=None, patterns=None, startstr=None, substrs=None, trace=False, error=False, matching=True, exe=True):
|
def expect(self, str, msg=None, patterns=None, startstr=None, endstr=None, substrs=None, trace=False, error=False, matching=True, exe=True):
|
||||||
"""
|
"""
|
||||||
Similar to runCmd; with additional expect style output matching ability.
|
Similar to runCmd; with additional expect style output matching ability.
|
||||||
|
|
||||||
|
@ -1056,6 +1071,14 @@ class TestBase(Base):
|
||||||
print >> sbuf, "%s start string: %s" % (heading, startstr)
|
print >> sbuf, "%s start string: %s" % (heading, startstr)
|
||||||
print >> sbuf, "Matched" if matched else "Not matched"
|
print >> sbuf, "Matched" if matched else "Not matched"
|
||||||
|
|
||||||
|
# Look for endstr, if specified.
|
||||||
|
keepgoing = matched if matching else not matched
|
||||||
|
if endstr:
|
||||||
|
matched = output.endswith(endstr)
|
||||||
|
with recording(self, trace) as sbuf:
|
||||||
|
print >> sbuf, "%s end string: %s" % (heading, endstr)
|
||||||
|
print >> sbuf, "Matched" if matched else "Not matched"
|
||||||
|
|
||||||
# Look for sub strings, if specified.
|
# Look for sub strings, if specified.
|
||||||
keepgoing = matched if matching else not matched
|
keepgoing = matched if matching else not matched
|
||||||
if substrs and keepgoing:
|
if substrs and keepgoing:
|
||||||
|
@ -1110,14 +1133,15 @@ class TestBase(Base):
|
||||||
|
|
||||||
err = sys.stderr
|
err = sys.stderr
|
||||||
err.write(val.GetName() + ":\n")
|
err.write(val.GetName() + ":\n")
|
||||||
err.write('\t' + "TypeName -> " + val.GetTypeName() + '\n')
|
err.write('\t' + "TypeName -> " + val.GetTypeName() + '\n')
|
||||||
err.write('\t' + "ByteSize -> " + str(val.GetByteSize()) + '\n')
|
err.write('\t' + "ByteSize -> " + str(val.GetByteSize()) + '\n')
|
||||||
err.write('\t' + "NumChildren -> " + str(val.GetNumChildren()) + '\n')
|
err.write('\t' + "NumChildren -> " + str(val.GetNumChildren()) + '\n')
|
||||||
err.write('\t' + "Value -> " + str(val.GetValue()) + '\n')
|
err.write('\t' + "Value -> " + str(val.GetValue()) + '\n')
|
||||||
err.write('\t' + "ValueType -> " + value_type_to_str(val.GetValueType()) + '\n')
|
err.write('\t' + "ValueAsUnsigned -> " + str(val.GetValueAsUnsigned())+ '\n')
|
||||||
err.write('\t' + "Summary -> " + str(val.GetSummary()) + '\n')
|
err.write('\t' + "ValueType -> " + value_type_to_str(val.GetValueType()) + '\n')
|
||||||
err.write('\t' + "IsPointerType -> " + str(val.TypeIsPointerType()) + '\n')
|
err.write('\t' + "Summary -> " + str(val.GetSummary()) + '\n')
|
||||||
err.write('\t' + "Location -> " + val.GetLocation() + '\n')
|
err.write('\t' + "IsPointerType -> " + str(val.TypeIsPointerType()) + '\n')
|
||||||
|
err.write('\t' + "Location -> " + val.GetLocation() + '\n')
|
||||||
|
|
||||||
def DebugSBType(self, type):
|
def DebugSBType(self, type):
|
||||||
"""Debug print a SBType object, if traceAlways is True."""
|
"""Debug print a SBType object, if traceAlways is True."""
|
||||||
|
|
Loading…
Reference in New Issue