TestMyFirstWatchpoint.py [plain text]
"""
Test my first lldb watchpoint.
"""
import os, time
import unittest2
import lldb
from lldbtest import *
class HelloWatchpointTestCase(TestBase):
mydir = os.path.join("functionalities", "watchpoint", "hello_watchpoint")
@dsym_test
def test_hello_watchpoint_with_dsym_using_watchpoint_set(self):
"""Test a simple sequence of watchpoint creation and watchpoint hit."""
self.buildDsym(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
self.hello_watchpoint()
@dwarf_test
def test_hello_watchpoint_with_dwarf_using_watchpoint_set(self):
"""Test a simple sequence of watchpoint creation and watchpoint hit."""
self.buildDwarf(dictionary=self.d)
self.setTearDownCleanup(dictionary=self.d)
self.hello_watchpoint()
def setUp(self):
TestBase.setUp(self)
self.source = 'main.c'
self.line = line_number(self.source, '// Set break point at this line.')
self.decl = line_number(self.source, '// Watchpoint variable declaration.')
self.exe_name = self.testMethodName
self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
def hello_watchpoint(self):
"""Test a simple sequence of watchpoint creation and watchpoint hit."""
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 variable -w write global", WATCHPOINT_CREATED,
substrs = ['Watchpoint created', 'size = 4', 'type = w',
'%s:%d' % (self.source, self.decl)])
self.expect("watchpoint list -v",
substrs = ['hit_count = 0'])
self.runCmd("process continue")
self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
substrs = ['stopped',
'stop reason = watchpoint'])
self.runCmd("process continue")
self.expect("process status",
substrs = ['exited'])
self.expect("watchpoint list -v",
substrs = ['hit_count = 1'])
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()