[Lldb-commits] [lldb] r208804 - Added gdbremote tests to verify kill and continue after attach.
Todd Fiala
todd.fiala at gmail.com
Wed May 14 12:34:07 PDT 2014
Author: tfiala
Date: Wed May 14 14:34:06 2014
New Revision: 208804
URL: http://llvm.org/viewvc/llvm-project?rev=208804&view=rev
Log:
Added gdbremote tests to verify kill and continue after attach.
Modified:
lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py
lldb/trunk/test/tools/lldb-gdbserver/main.cpp
Modified: lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py?rev=208804&r1=208803&r2=208804&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py (original)
+++ lldb/trunk/test/tools/lldb-gdbserver/TestLldbGdbServer.py Wed May 14 14:34:06 2014
@@ -7,6 +7,7 @@ import pexpect
import socket
import subprocess
import sys
+import time
from lldbtest import *
from lldbgdbserverutils import *
import logging
@@ -96,15 +97,15 @@ class LldbGdbServerTestCase(TestBase):
return server
- def launch_process_for_attach(self):
+ def launch_process_for_attach(self,sleep_seconds=3):
# We're going to start a child process that the debug monitor stub can later attach to.
# This process needs to be started so that it just hangs around for a while. We'll
# have it sleep.
exe_path = os.path.abspath("a.out")
- print("using exe for attach: %s" % exe_path)
- print("exists? {}".format(os.path.exists(exe_path)))
-
- args = [exe_path, "sleep:5"]
+ args = [exe_path]
+ if sleep_seconds:
+ args.append("sleep:%d" % sleep_seconds)
+
return subprocess.Popen(args)
def add_no_ack_remote_stream(self):
@@ -124,6 +125,12 @@ class LldbGdbServerTestCase(TestBase):
"send packet: $OK#00"],
True)
+ def add_get_pid(self):
+ self.test_sequence.add_log_lines(
+ ["read packet: $qProcessInfo#00",
+ { "direction":"send", "regex":r"^\$pid:([0-9a-fA-F]+);", "capture":{1:"pid"} }],
+ True)
+
def expect_gdbremote_sequence(self):
return expect_lldb_gdbserver_replay(self, self.sock, self.test_sequence, self._TIMEOUT_SECONDS, self.logger)
@@ -409,10 +416,7 @@ class LldbGdbServerTestCase(TestBase):
# Check that the stub reports attachment to the inferior.
self.add_no_ack_remote_stream()
- self.test_sequence.add_log_lines(
- ["read packet: $qProcessInfo#00",
- { "direction":"send", "regex":r"^\$pid:([0-9a-fA-F]+);", "capture":{1:"pid"} }],
- True)
+ self.add_get_pid()
context = self.expect_gdbremote_sequence()
# Ensure the process id matches what we expected.
@@ -436,5 +440,87 @@ class LldbGdbServerTestCase(TestBase):
self.buildDwarf()
self.attach_commandline_qProcessInfo_reports_pid()
+ def attach_commandline_continue_app_exits(self):
+ # Launch the process that we'll use as the inferior.
+ inferior = self.launch_process_for_attach(sleep_seconds=1)
+ self.assertIsNotNone(inferior)
+ self.assertTrue(inferior.pid > 0)
+
+ # Launch the debug monitor stub, attaching to the inferior.
+ server = self.start_server(attach_pid=inferior.pid)
+ self.assertIsNotNone(server)
+
+ # Check that the stub reports attachment to the inferior.
+ self.add_no_ack_remote_stream()
+ self.add_get_pid()
+ self.test_sequence.add_log_lines(
+ ["read packet: $vCont;c#00",
+ "send packet: $W00#00"],
+ True)
+ self.expect_gdbremote_sequence()
+
+ # Process should be dead now. Reap results.
+ poll_result = inferior.poll()
+ self.assertIsNotNone(poll_result)
+
+ # Where possible, verify at the system level that the process is not running.
+ self.assertFalse(process_is_running(inferior.pid, False))
+
+ @debugserver_test
+ @dsym_test
+ def test_attach_commandline_continue_app_exits_debugserver_dsym(self):
+ self.init_debugserver_test()
+ self.buildDsym()
+ self.attach_commandline_continue_app_exits()
+
+ @llgs_test
+ @dwarf_test
+ @unittest2.expectedFailure()
+ def test_attach_commandline_continue_app_exits_llgs_dwarf(self):
+ self.init_llgs_test()
+ self.buildDwarf()
+ self.attach_commandline_continue_app_exits()
+
+ def attach_commandline_kill_after_initial_stop(self):
+ # Launch the process that we'll use as the inferior.
+ inferior = self.launch_process_for_attach(sleep_seconds=10)
+ self.assertIsNotNone(inferior)
+ self.assertTrue(inferior.pid > 0)
+
+ # Launch the debug monitor stub, attaching to the inferior.
+ server = self.start_server(attach_pid=inferior.pid)
+ self.assertIsNotNone(server)
+
+ # Check that the stub reports attachment to the inferior.
+ self.add_no_ack_remote_stream()
+ self.add_get_pid()
+ self.test_sequence.add_log_lines(
+ ["read packet: $k#6b",
+ "send packet: $W09#00"],
+ True)
+ self.expect_gdbremote_sequence()
+
+ # Process should be dead now. Reap results.
+ poll_result = inferior.poll()
+ self.assertIsNotNone(poll_result)
+
+ # Where possible, verify at the system level that the process is not running.
+ self.assertFalse(process_is_running(inferior.pid, False))
+
+ @debugserver_test
+ @dsym_test
+ def test_attach_commandline_kill_after_initial_stop_debugserver_dsym(self):
+ self.init_debugserver_test()
+ self.buildDsym()
+ self.attach_commandline_kill_after_initial_stop()
+
+ @llgs_test
+ @dwarf_test
+ @unittest2.expectedFailure()
+ def test_attach_commandline_kill_after_initial_stop_llgs_dwarf(self):
+ self.init_llgs_test()
+ self.buildDwarf()
+ self.attach_commandline_kill_after_initial_stop()
+
if __name__ == '__main__':
unittest2.main()
Modified: lldb/trunk/test/tools/lldb-gdbserver/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-gdbserver/main.cpp?rev=208804&r1=208803&r2=208804&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-gdbserver/main.cpp (original)
+++ lldb/trunk/test/tools/lldb-gdbserver/main.cpp Wed May 14 14:34:06 2014
@@ -26,9 +26,15 @@ int main (int argc, char **argv)
else if (std::strstr (argv[i], SLEEP_PREFIX))
{
// Treat as the amount of time to have this process sleep (in seconds).
- const int sleep_seconds = std::atoi (argv[i] + strlen (SLEEP_PREFIX));
- const int sleep_result = sleep(sleep_seconds);
- std::cout << "sleep result: " << sleep_result << std::endl;
+ int sleep_seconds_remaining = std::atoi (argv[i] + strlen (SLEEP_PREFIX));
+
+ // Loop around, sleeping until all sleep time is used up. Note that
+ // signals will cause sleep to end early with the number of seconds remaining.
+ for (int i = 0; sleep_seconds_remaining > 0; ++i)
+ {
+ sleep_seconds_remaining = sleep (sleep_seconds_remaining);
+ std::cout << "sleep result (call " << i << "): " << sleep_seconds_remaining << std::endl;
+ }
}
else
{
More information about the lldb-commits
mailing list