122 lines
4.6 KiB
Python
Raw Normal View History

"""Test that lldb command 'process signal SIGUSR1' to send a signal to the inferior works."""
import os, time, signal
import unittest2
import lldb
from lldbtest import *
import lldbutil
class SendSignalTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@skipUnlessDarwin
Add a new option to the test driver, -N dsym or -N dwarf, in order to exclude tests decorated with either @dsym_test or @dwarf_test to be executed during the testsuite run. There are still lots of Test*.py files which have not been decorated with the new decorator. An example: # From TestMyFirstWatchpoint.py -> 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() # Invocation -> [17:50:14] johnny:/Volumes/data/lldb/svn/ToT/test $ ./dotest.py -N dsym -v -p TestMyFirstWatchpoint.py LLDB build dir: /Volumes/data/lldb/svn/ToT/build/Debug LLDB-137 Path: /Volumes/data/lldb/svn/ToT URL: https://johnny@llvm.org/svn/llvm-project/lldb/trunk Repository Root: https://johnny@llvm.org/svn/llvm-project Repository UUID: 91177308-0d34-0410-b5e6-96231b3b80d8 Revision: 154133 Node Kind: directory Schedule: normal Last Changed Author: gclayton Last Changed Rev: 154109 Last Changed Date: 2012-04-05 10:43:02 -0700 (Thu, 05 Apr 2012) Session logs for test failures/errors/unexpected successes will go into directory '2012-04-05-17_50_49' Command invoked: python ./dotest.py -N dsym -v -p TestMyFirstWatchpoint.py compilers=['clang'] Configuration: arch=x86_64 compiler=clang ---------------------------------------------------------------------- Collected 2 tests 1: test_hello_watchpoint_with_dsym_using_watchpoint_set (TestMyFirstWatchpoint.HelloWatchpointTestCase) Test a simple sequence of watchpoint creation and watchpoint hit. ... skipped 'dsym tests' 2: test_hello_watchpoint_with_dwarf_using_watchpoint_set (TestMyFirstWatchpoint.HelloWatchpointTestCase) Test a simple sequence of watchpoint creation and watchpoint hit. ... ok ---------------------------------------------------------------------- Ran 2 tests in 1.138s OK (skipped=1) Session logs for test failures/errors/unexpected successes can be found in directory '2012-04-05-17_50_49' [17:50:50] johnny:/Volumes/data/lldb/svn/ToT/test $ llvm-svn: 154154
2012-04-06 00:56:05 +00:00
@dsym_test
def test_with_dsym_and_run_command(self):
"""Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process."""
self.buildDsym()
self.send_signal()
@expectedFailureFreeBSD("llvm.org/pr23318: does not report running state")
@skipIfWindows # Windows does not support signals
Add a new option to the test driver, -N dsym or -N dwarf, in order to exclude tests decorated with either @dsym_test or @dwarf_test to be executed during the testsuite run. There are still lots of Test*.py files which have not been decorated with the new decorator. An example: # From TestMyFirstWatchpoint.py -> 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() # Invocation -> [17:50:14] johnny:/Volumes/data/lldb/svn/ToT/test $ ./dotest.py -N dsym -v -p TestMyFirstWatchpoint.py LLDB build dir: /Volumes/data/lldb/svn/ToT/build/Debug LLDB-137 Path: /Volumes/data/lldb/svn/ToT URL: https://johnny@llvm.org/svn/llvm-project/lldb/trunk Repository Root: https://johnny@llvm.org/svn/llvm-project Repository UUID: 91177308-0d34-0410-b5e6-96231b3b80d8 Revision: 154133 Node Kind: directory Schedule: normal Last Changed Author: gclayton Last Changed Rev: 154109 Last Changed Date: 2012-04-05 10:43:02 -0700 (Thu, 05 Apr 2012) Session logs for test failures/errors/unexpected successes will go into directory '2012-04-05-17_50_49' Command invoked: python ./dotest.py -N dsym -v -p TestMyFirstWatchpoint.py compilers=['clang'] Configuration: arch=x86_64 compiler=clang ---------------------------------------------------------------------- Collected 2 tests 1: test_hello_watchpoint_with_dsym_using_watchpoint_set (TestMyFirstWatchpoint.HelloWatchpointTestCase) Test a simple sequence of watchpoint creation and watchpoint hit. ... skipped 'dsym tests' 2: test_hello_watchpoint_with_dwarf_using_watchpoint_set (TestMyFirstWatchpoint.HelloWatchpointTestCase) Test a simple sequence of watchpoint creation and watchpoint hit. ... ok ---------------------------------------------------------------------- Ran 2 tests in 1.138s OK (skipped=1) Session logs for test failures/errors/unexpected successes can be found in directory '2012-04-05-17_50_49' [17:50:50] johnny:/Volumes/data/lldb/svn/ToT/test $ llvm-svn: 154154
2012-04-06 00:56:05 +00:00
@dwarf_test
def test_with_dwarf_and_run_command(self):
"""Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process."""
self.buildDwarf()
self.send_signal()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break inside main().
self.line = line_number('main.c', 'Put breakpoint here')
def match_state(self, process_listener, expected_state):
num_seconds = 5
broadcaster = self.process().GetBroadcaster()
event_type_mask = lldb.SBProcess.eBroadcastBitStateChanged
event = lldb.SBEvent()
got_event = process_listener.WaitForEventForBroadcasterWithType(
num_seconds, broadcaster, event_type_mask, event)
self.assertTrue(got_event, "Got an event")
state = lldb.SBProcess.GetStateFromEvent(event)
self.assertTrue(state == expected_state,
"It was the %s state." %
lldb.SBDebugger_StateAsCString(expected_state))
def send_signal(self):
"""Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process."""
exe = os.path.join(os.getcwd(), "a.out")
# Create a target by the debugger.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
# Now create a breakpoint on main.c by name 'c'.
breakpoint = target.BreakpointCreateByLocation('main.c', self.line)
self.assertTrue(breakpoint and
breakpoint.GetNumLocations() == 1,
VALID_BREAKPOINT)
# Get the breakpoint location from breakpoint after we verified that,
# indeed, it has one location.
location = breakpoint.GetLocationAtIndex(0)
self.assertTrue(location and
location.IsEnabled(),
VALID_BREAKPOINT_LOCATION)
# Now launch the process, no arguments & do not stop at entry point.
launch_info = lldb.SBLaunchInfo([exe])
launch_info.SetWorkingDirectory(self.get_process_working_directory())
process_listener = lldb.SBListener("signal_test_listener")
launch_info.SetListener(process_listener)
error = lldb.SBError()
process = target.Launch(launch_info, error)
self.assertTrue(process, PROCESS_IS_VALID)
self.runCmd("process handle -n False -p True -s True SIGUSR1")
thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
self.assertTrue(thread.IsValid(), "We hit the first breakpoint.")
# After resuming the process, send it a SIGUSR1 signal.
self.setAsync(True)
self.assertTrue(process_listener.IsValid(), "Got a good process listener")
# Disable our breakpoint, we don't want to hit it anymore...
breakpoint.SetEnabled(False)
# Now continue:
process.Continue()
# If running remote test, there should be a connected event
if lldb.remote_platform:
self.match_state(process_listener, lldb.eStateConnected)
self.match_state(process_listener, lldb.eStateRunning)
# Now signal the process, and make sure it stops:
process.Signal(lldbutil.get_signal_number('SIGUSR1'))
self.match_state(process_listener, lldb.eStateStopped)
# Now make sure the thread was stopped with a SIGUSR1:
threads = lldbutil.get_stopped_threads(process, lldb.eStopReasonSignal)
self.assertTrue(len(threads) == 1, "One thread stopped for a signal.")
thread = threads[0]
self.assertTrue(thread.GetStopReasonDataCount() >= 1, "There was data in the event.")
self.assertTrue(thread.GetStopReasonDataAtIndex(0) == lldbutil.get_signal_number('SIGUSR1'),
"The stop signal was SIGUSR1")
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()