Converted some more test cases to use runCmd()/expect().

llvm-svn: 111652
This commit is contained in:
Johnny Chen 2010-08-20 17:04:20 +00:00
parent 8525fe7155
commit 617cca957e
4 changed files with 38 additions and 82 deletions

View File

@ -11,41 +11,27 @@ class TestClassTypes(TestBase):
def test_class_types(self):
"""Test 'variable list this' when stopped on a class constructor."""
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 the ctor function of class C.
self.ci.HandleCommand("breakpoint set -f main.cpp -l 73", res)
self.assertTrue(res.Succeeded(), CMD_MSG('breakpoint list'))
self.assertTrue(res.GetOutput().startswith(
"Breakpoint created: 1: file ='main.cpp', line = 73, locations = 1"),
BREAKPOINT_CREATED)
self.expect("breakpoint set -f main.cpp -l 73", BREAKPOINT_CREATED,
startstr = "Breakpoint created: 1: file ='main.cpp', line = 73, 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'])
# We should be stopped on the ctor function of class C.
self.ci.HandleCommand("variable list this", res);
self.assertTrue(res.Succeeded(), CMD_MSG('variable list ...'))
self.assertTrue(res.GetOutput().startswith('(class C *const) this = '),
VARIABLES_DISPLAYED_CORRECTLY)
self.expect("variable list this", VARIABLES_DISPLAYED_CORRECTLY,
startstr = '(class C *const) this = ')
if __name__ == '__main__':

View File

@ -15,18 +15,13 @@ class TestCommandSource(TestBase):
def test_command_source(self):
"""Test that lldb command "command source" works correctly."""
res = self.res
# Sourcing .lldb in the current working directory, which in turn imports
# the "my" package that defines the date() function.
self.ci.HandleCommand("command source .lldb", res)
self.assertTrue(res.Succeeded(), CMD_MSG('command source .lldb'))
self.runCmd("command source .lldb")
# Python should evaluate "my.date()" successfully.
self.ci.HandleCommand("script my.date()", res)
if (not res.Succeeded()):
print res.GetError()
self.assertTrue(res.Succeeded(), CMD_MSG('script my.date()'))
self.runCmd("script my.date()")
if __name__ == '__main__':

View File

@ -13,73 +13,46 @@ class TestDeadStrip(TestBase):
def test_dead_strip(self):
"""Test breakpoint works correctly with dead-code stripping."""
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 by function name f1 (live code).
self.ci.HandleCommand("breakpoint set -s a.out -n f1", res)
self.assertTrue(res.Succeeded(), CMD_MSG('breakpoint set'))
self.assertTrue(res.GetOutput().startswith(
"Breakpoint created: 1: name = 'f1', module = a.out, locations = 1"
),
BREAKPOINT_CREATED)
self.expect("breakpoint set -s a.out -n f1", BREAKPOINT_CREATED,
startstr = "Breakpoint created: 1: name = 'f1', module = a.out, locations = 1")
# Break by function name f2 (dead code).
self.ci.HandleCommand("breakpoint set -s a.out -n f2", res)
self.assertTrue(res.Succeeded(), CMD_MSG('breakpoint set'))
self.assertTrue(res.GetOutput().startswith(
"Breakpoint created: 2: name = 'f2', module = a.out, locations = 0 "
"(pending)"),
BREAKPOINT_PENDING_CREATED)
self.expect("breakpoint set -s a.out -n f2", BREAKPOINT_PENDING_CREATED,
startstr = "Breakpoint created: 2: name = 'f2', module = a.out, locations = 0 (pending)")
# Break by function name f3 (live code).
self.ci.HandleCommand("breakpoint set -s a.out -n f3", res)
self.assertTrue(res.Succeeded(), CMD_MSG('breakpoint set'))
self.assertTrue(res.GetOutput().startswith(
"Breakpoint created: 3: name = 'f3', module = a.out, locations = 1"
),
BREAKPOINT_CREATED)
self.expect("breakpoint set -s a.out -n f3", BREAKPOINT_CREATED,
startstr = "Breakpoint created: 3: name = 'f3', module = a.out, 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 (breakpoint #1).
self.ci.HandleCommand("thread list", res)
output = res.GetOutput()
self.assertTrue(res.Succeeded(), CMD_MSG('thread list'))
self.assertTrue(output.find('state is Stopped') > 0 and
output.find('main.c:20') > 0 and
output.find('where = a.out`f1') > 0 and
output.find('stop reason = breakpoint') > 0,
STOPPED_DUE_TO_BREAKPOINT)
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['state is Stopped',
'main.c:20',
'where = a.out`f1',
'stop reason = breakpoint'])
# The breakpoint should have a hit count of 1.
self.ci.HandleCommand("breakpoint list 1", 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 1", BREAKPOINT_HIT_ONCE,
substrs = [' resolved, hit count = 1'])
self.ci.HandleCommand("continue", res)
self.assertTrue(res.Succeeded(), CMD_MSG('continue'))
self.runCmd("continue")
# The stop reason of the thread should be breakpoint (breakpoint #3).
self.ci.HandleCommand("thread list", res)
output = res.GetOutput()
self.assertTrue(res.Succeeded(), CMD_MSG('thread list'))
self.assertTrue(output.find('state is Stopped') > 0 and
output.find('main.c:40') > 0 and
output.find('where = a.out`f3') > 0 and
output.find('stop reason = breakpoint') > 0,
STOPPED_DUE_TO_BREAKPOINT)
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['state is Stopped',
'main.c:40',
'where = a.out`f3',
'stop reason = breakpoint'])
# The breakpoint should have a hit count of 1.
self.ci.HandleCommand("breakpoint list 3", 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 3", BREAKPOINT_HIT_ONCE,
substrs = [' resolved, hit count = 1'])
if __name__ == '__main__':

View File

@ -126,6 +126,8 @@ class TestBase(unittest2.TestCase):
if cmd.startswith("run"):
self.runStarted = True
if check:
if (not self.res.Succeeded()):
print self.res.GetError()
self.assertTrue(self.res.Succeeded(),
msg if msg else CMD_MSG(cmd))