Skip to content

Commit

Permalink
Refactor GdbRemote test cases to support remote platforms
Browse files Browse the repository at this point in the history
Previously these test cases execute lldb-server on the host and run the
tests against it even if a remote platform was specified. With this CL
these tests always test the communication with an lldb-server instance
running on the target.

Differential revision: http://reviews.llvm.org/D8202

llvm-svn: 231922
  • Loading branch information
Tamas Berghammer committed Mar 11, 2015
1 parent 868b074 commit 04f51d1
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 118 deletions.
32 changes: 19 additions & 13 deletions lldb/test/lldbtest.py
Expand Up @@ -269,25 +269,33 @@ def terminate(self):
if self._proc.poll() == None:
self._proc.terminate()

def poll(self):
return self._proc.poll()

class _RemoteProcess(_BaseProcess):

def __init__(self):
def __init__(self, install_remote):
self._pid = None
self._install_remote = install_remote

@property
def pid(self):
return self._pid

def launch(self, executable, args):
remote_work_dir = lldb.remote_platform.GetWorkingDirectory()
src_path = executable
dst_path = os.path.join(remote_work_dir, os.path.basename(executable))

dst_file_spec = lldb.SBFileSpec(dst_path, False)
err = lldb.remote_platform.Install(lldb.SBFileSpec(src_path, True),
dst_file_spec)
if err.Fail():
raise Exception("remote_platform.Install('%s', '%s') failed: %s" % (src_path, dst_path, err))
if self._install_remote:
src_path = executable
dst_path = os.path.join(remote_work_dir, os.path.basename(executable))

dst_file_spec = lldb.SBFileSpec(dst_path, False)
err = lldb.remote_platform.Install(lldb.SBFileSpec(src_path, True), dst_file_spec)
if err.Fail():
raise Exception("remote_platform.Install('%s', '%s') failed: %s" % (src_path, dst_path, err))
else:
dst_path = executable
dst_file_spec = lldb.SBFileSpec(executable, False)

launch_info = lldb.SBLaunchInfo(args)
launch_info.SetExecutableFile(dst_file_spec, True)
Expand All @@ -303,9 +311,7 @@ def launch(self, executable, args):
self._pid = launch_info.GetProcessID()

def terminate(self):
err = lldb.remote_platform.Kill(self._pid)
if err.Fail():
raise Exception("remote_platform.Kill(%d) failed: %s" % (self._pid, err))
lldb.remote_platform.Kill(self._pid)

# From 2.7's subprocess.check_output() convenience function.
# Return a tuple (stdoutdata, stderrdata).
Expand Down Expand Up @@ -1047,7 +1053,7 @@ def cleanupSubprocesses(self):
if os.path.exists("/proc/" + str(pid)):
os.kill(pid, signal.SIGTERM)

def spawnSubprocess(self, executable, args=[]):
def spawnSubprocess(self, executable, args=[], install_remote=True):
""" Creates a subprocess.Popen object with the specified executable and arguments,
saves it in self.subprocesses, and returns the object.
NOTE: if using this function, ensure you also call:
Expand All @@ -1056,7 +1062,7 @@ def spawnSubprocess(self, executable, args=[]):
otherwise the test suite will leak processes.
"""
proc = _RemoteProcess() if lldb.remote_platform else _LocalProcess(self.TraceOn())
proc = _RemoteProcess(install_remote) if lldb.remote_platform else _LocalProcess(self.TraceOn())
proc.launch(executable, args)
self.subprocesses.append(proc)
return proc
Expand Down
7 changes: 4 additions & 3 deletions lldb/test/tools/lldb-server/TestGdbRemoteKill.py
Expand Up @@ -24,9 +24,10 @@ def attach_commandline_kill_after_initial_stop(self):
# Wait a moment for completed and now-detached inferior process to clear.
time.sleep(1)

# Process should be dead now. Reap results.
poll_result = procs["inferior"].poll()
self.assertIsNotNone(poll_result)
if not lldb.remote_platform:
# Process should be dead now. Reap results.
poll_result = procs["inferior"].poll()
self.assertIsNotNone(poll_result)

# Where possible, verify at the system level that the process is not running.
self.assertFalse(lldbgdbserverutils.process_is_running(procs["inferior"].pid, False))
Expand Down
70 changes: 41 additions & 29 deletions lldb/test/tools/lldb-server/TestLldbGdbServer.py
Expand Up @@ -89,12 +89,24 @@ def test_list_threads_in_stop_reply_supported_llgs(self):
self.init_llgs_test()
self.list_threads_in_stop_reply_supported()

def install_and_create_launch_args(self):
exe_path = os.path.abspath('a.out')
if not lldb.remote_platform:
return [exe_path]
remote_work_dir = lldb.remote_platform.GetWorkingDirectory()
remote_path = os.path.join(remote_work_dir, os.path.basename(exe_path))
remote_file_spec = lldb.SBFileSpec(remote_path, False)
err = lldb.remote_platform.Install(lldb.SBFileSpec(exe_path, True), remote_file_spec)
if err.Fail():
raise Exception("remote_platform.Install('%s', '%s') failed: %s" % (exe_path, remote_path, err))
return [remote_path]

def start_inferior(self):
launch_args = self.install_and_create_launch_args()

server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)

# build launch args
launch_args = [os.path.abspath('a.out')]
self.add_no_ack_remote_stream()
self.test_sequence.add_log_lines(
["read packet: %s" % lldbgdbserverutils.build_gdbremote_A_packet(launch_args),
Expand All @@ -117,12 +129,11 @@ def test_start_inferior_llgs_dwarf(self):
self.start_inferior()

def inferior_exit_0(self):
launch_args = self.install_and_create_launch_args()

server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)

# build launch args
launch_args = [os.path.abspath('a.out')]

self.add_no_ack_remote_stream()
self.add_verified_launch_packets(launch_args)
self.test_sequence.add_log_lines(
Expand All @@ -147,13 +158,15 @@ def test_inferior_exit_0_llgs_dwarf(self):
self.inferior_exit_0()

def inferior_exit_42(self):
launch_args = self.install_and_create_launch_args()

server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)

RETVAL = 42

# build launch args
launch_args = [os.path.abspath('a.out'), "retval:%d" % RETVAL]
launch_args += ["retval:%d" % RETVAL]

self.add_no_ack_remote_stream()
self.add_verified_launch_packets(launch_args)
Expand All @@ -179,12 +192,11 @@ def test_inferior_exit_42_llgs_dwarf(self):
self.inferior_exit_42()

def c_packet_works(self):
launch_args = self.install_and_create_launch_args()

server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)

# build launch args
launch_args = [os.path.abspath('a.out')]

self.add_no_ack_remote_stream()
self.add_verified_launch_packets(launch_args)
self.test_sequence.add_log_lines(
Expand All @@ -209,11 +221,13 @@ def test_c_packet_works_llgs_dwarf(self):
self.c_packet_works()

def inferior_print_exit(self):
launch_args = self.install_and_create_launch_args()

server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)

# build launch args
launch_args = [os.path.abspath('a.out'), "hello, world"]
launch_args += ["hello, world"]

self.add_no_ack_remote_stream()
self.add_verified_launch_packets(launch_args)
Expand Down Expand Up @@ -241,11 +255,13 @@ def test_inferior_print_exit_llgs_dwarf(self):
self.inferior_print_exit()

def first_launch_stop_reply_thread_matches_first_qC(self):
launch_args = self.install_and_create_launch_args()

server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)

# build launch args
launch_args = [os.path.abspath('a.out'), "hello, world"]
launch_args += ["hello, world"]

self.add_no_ack_remote_stream()
self.add_verified_launch_packets(launch_args)
Expand Down Expand Up @@ -282,9 +298,10 @@ def attach_commandline_continue_app_exits(self):
# Wait a moment for completed and now-detached inferior process to clear.
time.sleep(1)

# Process should be dead now. Reap results.
poll_result = procs["inferior"].poll()
self.assertIsNotNone(poll_result)
if not lldb.remote_platform:
# Process should be dead now. Reap results.
poll_result = procs["inferior"].poll()
self.assertIsNotNone(poll_result)

# Where possible, verify at the system level that the process is not running.
self.assertFalse(lldbgdbserverutils.process_is_running(procs["inferior"].pid, False))
Expand All @@ -306,12 +323,11 @@ def test_attach_commandline_continue_app_exits_llgs_dwarf(self):
self.attach_commandline_continue_app_exits()

def qRegisterInfo_returns_one_valid_result(self):
launch_args = self.install_and_create_launch_args()

server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)

# Build launch args
launch_args = [os.path.abspath('a.out')]

# Build the expected protocol stream
self.add_no_ack_remote_stream()
self.add_verified_launch_packets(launch_args)
Expand Down Expand Up @@ -343,12 +359,11 @@ def test_qRegisterInfo_returns_one_valid_result_llgs_dwarf(self):
self.qRegisterInfo_returns_one_valid_result()

def qRegisterInfo_returns_all_valid_results(self):
launch_args = self.install_and_create_launch_args()

server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)

# Build launch args.
launch_args = [os.path.abspath('a.out')]

# Build the expected protocol stream.
self.add_no_ack_remote_stream()
self.add_verified_launch_packets(launch_args)
Expand Down Expand Up @@ -377,12 +392,11 @@ def test_qRegisterInfo_returns_all_valid_results_llgs_dwarf(self):
self.qRegisterInfo_returns_all_valid_results()

def qRegisterInfo_contains_required_generics(self):
launch_args = self.install_and_create_launch_args()

server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)

# Build launch args
launch_args = [os.path.abspath('a.out')]

# Build the expected protocol stream
self.add_no_ack_remote_stream()
self.add_verified_launch_packets(launch_args)
Expand Down Expand Up @@ -425,12 +439,11 @@ def test_qRegisterInfo_contains_required_generics_llgs_dwarf(self):
self.qRegisterInfo_contains_required_generics()

def qRegisterInfo_contains_at_least_one_register_set(self):
launch_args = self.install_and_create_launch_args()

server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)

# Build launch args
launch_args = [os.path.abspath('a.out')]

# Build the expected protocol stream
self.add_no_ack_remote_stream()
self.add_verified_launch_packets(launch_args)
Expand Down Expand Up @@ -462,12 +475,11 @@ def test_qRegisterInfo_contains_at_least_one_register_set_llgs_dwarf(self):
self.qRegisterInfo_contains_at_least_one_register_set()

def qRegisterInfo_contains_avx_registers_on_linux_x86_64(self):
launch_args = self.install_and_create_launch_args()

server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)

# Build launch args
launch_args = [os.path.abspath('a.out')]

# Build the expected protocol stream
self.add_no_ack_remote_stream()
self.add_verified_launch_packets(launch_args)
Expand Down
Expand Up @@ -5,6 +5,7 @@
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))

import gdbremote_testcase
import lldbgdbserverutils
import re
import select
import socket
Expand Down Expand Up @@ -43,7 +44,7 @@ def tear_down_listener():

def reverse_connect_works(self):
# Indicate stub startup should do a reverse connect.
appended_stub_args = " --reverse-connect"
appended_stub_args = ["--reverse-connect"]
if self.debug_monitor_extra_args:
self.debug_monitor_extra_args += appended_stub_args
else:
Expand All @@ -55,7 +56,7 @@ def reverse_connect_works(self):
# Start the stub.
server = self.launch_debug_monitor(logfile=sys.stdout)
self.assertIsNotNone(server)
self.assertTrue(server.isalive())
self.assertTrue(lldbgdbserverutils.process_is_running(server.pid, True))

# Listen for the stub's connection to us.
(stub_socket, address) = self.listener_socket.accept()
Expand Down
17 changes: 5 additions & 12 deletions lldb/test/tools/lldb-server/commandline/TestStubSetSID.py
Expand Up @@ -7,29 +7,22 @@
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))

import gdbremote_testcase
import lldbgdbserverutils
import os
import select
import tempfile
import time
from lldbtest import *


def get_common_stub_args():
return [] if 'darwin' in sys.platform else ['g']


class TestStubSetSIDTestCase(gdbremote_testcase.GdbRemoteTestCaseBase):
def get_stub_sid(self, extra_stub_args=None):
# Launch debugserver
if extra_stub_args:
self.debug_monitor_extra_args = extra_stub_args
else:
self.debug_monitor_extra_args = ""
self.debug_monitor_extra_args += extra_stub_args

server = self.launch_debug_monitor()
self.assertIsNotNone(server)
self.assertTrue(server.isalive())
server.expect("(debugserver|lldb-server)", timeout=10)
self.assertTrue(lldbgdbserverutils.process_is_running(server.pid, True))

# Get the process id for the stub.
return os.getsid(server.pid)
Expand All @@ -39,11 +32,11 @@ def sid_is_same_without_setsid(self):
self.assertEquals(stub_sid, os.getsid(0))

def sid_is_different_with_setsid(self):
stub_sid = self.get_stub_sid(" %s --setsid" % ' '.join(get_common_stub_args()))
stub_sid = self.get_stub_sid(["--setsid"])
self.assertNotEquals(stub_sid, os.getsid(0))

def sid_is_different_with_S(self):
stub_sid = self.get_stub_sid(" %s -S" % ' '.join(get_common_stub_args()))
stub_sid = self.get_stub_sid(["-S"])
self.assertNotEquals(stub_sid, os.getsid(0))

@debugserver_test
Expand Down

0 comments on commit 04f51d1

Please sign in to comment.