TestWatchpointSetErrorCases.py [plain text]
"""
Test error cases for the 'watchpoint set' command to make sure it errors out when necessary.
"""
import os, time
import unittest2
import lldb
from lldbtest import *
class WatchpointSetErrorTestCase(TestBase):
mydir = os.path.join("functionalities", "watchpoint", "watchpoint_set_command")
def test_error_cases_with_watchpoint_set(self):
"""Test error cases with the 'watchpoint set' command."""
self.buildDwarf(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
self.error_cases_with_watchpoint_set()
def setUp(self):
TestBase.setUp(self)
self.source = 'main.cpp'
self.line = line_number(self.source, '// Set break point at this line.')
self.exe_name = self.testMethodName
self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
def error_cases_with_watchpoint_set(self):
"""Test error cases with the 'watchpoint set' command."""
exe = os.path.join(os.getcwd(), self.exe_name)
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
self.expect("breakpoint set -l %d" % self.line, BREAKPOINT_CREATED,
startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" %
(self.source, self.line))
self.runCmd("run", RUN_SUCCEEDED)
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['stopped',
'stop reason = breakpoint'])
self.expect("watchpoint set",
substrs = ['The following subcommands are supported:',
'expression',
'variable'])
self.runCmd("watchpoint set variable -w read_write", check=False)
self.expect("watchpoint set expression -w write --", error=True,
startstr = 'error: required argument missing; specify an expression to evaulate into the addres to watch for')
self.expect("watchpoint set expression MyAggregateDataType", error=True,
startstr = 'error: expression did not evaluate to an address')
self.expect("watchpoint set expression -w write -x 1 g_char_ptr", error=True,
startstr = 'error: did you forget to enter the option terminator string "--"?')
self.expect("watchpoint set variable -x -128", error=True,
substrs = ['invalid enumeration value'])
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()