summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/packages/Python/lldbsuite')
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py22
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/process_group/TestChangeProcessGroup.py24
-rw-r--r--lldb/packages/Python/lldbsuite/test/lldbtest.py6
-rw-r--r--lldb/packages/Python/lldbsuite/test/lldbutil.py17
-rw-r--r--lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py29
-rw-r--r--lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py7
6 files changed, 34 insertions, 71 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py b/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py
index d1420394332..3d1d7fdc790 100644
--- a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py
@@ -19,12 +19,6 @@ class AttachDeniedTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
- def run_platform_command(self, cmd):
- platform = self.dbg.GetSelectedPlatform()
- shell_command = lldb.SBPlatformShellCommand(cmd)
- err = platform.Run(shell_command)
- return (err, shell_command.GetStatus(), shell_command.GetOutput())
-
@skipIfWindows
@skipIfiOSSimulator
def test_attach_to_process_by_id_denied(self):
@@ -41,21 +35,7 @@ class AttachDeniedTestCase(TestBase):
popen = self.spawnSubprocess(exe, [pid_file_path])
self.addTearDownHook(self.cleanupSubprocesses)
- max_attempts = 5
- for i in range(max_attempts):
- err, retcode, msg = self.run_platform_command("ls %s" % pid_file_path)
- if err.Success() and retcode == 0:
- break
- else:
- print(msg)
- if i < max_attempts:
- # Exponential backoff!
- time.sleep(pow(2, i) * 0.25)
- else:
- self.fail("Child PID file %s not found even after %d attempts." % (pid_file_path, max_attempts))
- err, retcode, pid = self.run_platform_command("cat %s" % (pid_file_path))
- self.assertTrue(err.Success() and retcode == 0,
- "Failed to read file %s: %s, retcode: %d" % (pid_file_path, err.GetCString(), retcode))
+ pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
self.expect('process attach -p ' + pid,
startstr = 'error: attach failed:',
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/process_group/TestChangeProcessGroup.py b/lldb/packages/Python/lldbsuite/test/functionalities/process_group/TestChangeProcessGroup.py
index 5aa6e795491..c20d66aa3ab 100644
--- a/lldb/packages/Python/lldbsuite/test/functionalities/process_group/TestChangeProcessGroup.py
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/process_group/TestChangeProcessGroup.py
@@ -36,23 +36,7 @@ class ChangeProcessGroupTestCase(TestBase):
popen = self.spawnSubprocess(exe, [pid_file_path])
self.addTearDownHook(self.cleanupSubprocesses)
- max_attempts = 5
- for i in range(max_attempts):
- err, retcode, msg = self.run_platform_command("ls %s" % pid_file_path)
- if err.Success() and retcode == 0:
- break
- else:
- print(msg)
- if i < max_attempts:
- # Exponential backoff!
- time.sleep(pow(2, i) * 0.30)
- else:
- self.fail("Child PID file %s not found even after %d attempts." % (pid_file_path, max_attempts))
-
- err, retcode, pid = self.run_platform_command("cat %s" % (pid_file_path))
-
- self.assertTrue(err.Success() and retcode == 0,
- "Failed to read file %s: %s, retcode: %d" % (pid_file_path, err.GetCString(), retcode))
+ pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
# make sure we cleanup the forked child also
def cleanupChild():
@@ -100,9 +84,3 @@ class ChangeProcessGroupTestCase(TestBase):
# run to completion
process.Continue()
self.assertEqual(process.GetState(), lldb.eStateExited)
-
- def run_platform_command(self, cmd):
- platform = self.dbg.GetSelectedPlatform()
- shell_command = lldb.SBPlatformShellCommand(cmd)
- err = platform.Run(shell_command)
- return (err, shell_command.GetStatus(), shell_command.GetOutput())
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index ee84a7f2796..f7d018b91c3 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1946,6 +1946,12 @@ class TestBase(Base):
else:
self.fail("Can't build for debug info: %s" % self.debug_info)
+ def run_platform_command(self, cmd):
+ platform = self.dbg.GetSelectedPlatform()
+ shell_command = lldb.SBPlatformShellCommand(cmd)
+ err = platform.Run(shell_command)
+ return (err, shell_command.GetStatus(), shell_command.GetOutput())
+
# =================================================
# Misc. helper methods for debugging test execution
# =================================================
diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index ea34ed6271e..00f0da94d55 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1029,3 +1029,20 @@ def skip_if_library_missing(test, target, library):
def find_library_callable(test):
return find_library(target, library)
return skip_if_callable(test, find_library_callable, "could not find library matching '%s' in target %s" % (library, target))
+
+def wait_for_file_on_target(testcase, file_path, max_attempts = 6):
+ for i in range(max_attempts):
+ err, retcode, msg = testcase.run_platform_command("ls %s" % file_path)
+ if err.Success() and retcode == 0:
+ break
+ if i < max_attempts:
+ # Exponential backoff!
+ time.sleep(pow(2, i) * 0.25)
+ else:
+ testcase.fail("File %s not found even after %d attempts." % (file_path, max_attempts))
+
+ err, retcode, data = testcase.run_platform_command("cat %s" % (file_path))
+
+ testcase.assertTrue(err.Success() and retcode == 0,
+ "Failed to read file %s: %s, retcode: %d" % (file_path, err.GetCString(), retcode))
+ return data
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
index 61327e6f461..1bf7fff9c3b 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
@@ -214,30 +214,21 @@ class GdbRemoteTestCaseBase(TestBase):
return stub_port
- def run_shell_cmd(self, cmd):
- platform = self.dbg.GetSelectedPlatform()
- shell_cmd = lldb.SBPlatformShellCommand(cmd)
- err = platform.Run(shell_cmd)
- if err.Fail() or shell_cmd.GetStatus():
- m = "remote_platform.RunShellCommand('%s') failed:\n" % cmd
- m += ">>> return code: %d\n" % shell_cmd.GetStatus()
- if err.Fail():
- m += ">>> %s\n" % str(err).strip()
- m += ">>> %s\n" % (shell_cmd.GetOutput() or
- "Command generated no output.")
- raise Exception(m)
- return shell_cmd.GetOutput().strip()
-
def init_llgs_test(self, use_named_pipe=True):
if lldb.remote_platform:
# Remote platforms don't support named pipe based port negotiation
use_named_pipe = False
# Grab the ppid from /proc/[shell pid]/stat
- shell_stat = self.run_shell_cmd("cat /proc/$$/stat")
+ err, retcode, shell_stat = self.run_platform_command("cat /proc/$$/stat")
+ self.assertTrue(err.Success() and retcode == 0,
+ "Failed to read file /proc/$$/stat: %s, retcode: %d" % (err.GetCString(), retcode))
+
# [pid] ([executable]) [state] [*ppid*]
pid = re.match(r"^\d+ \(.+\) . (\d+)", shell_stat).group(1)
- ls_output = self.run_shell_cmd("ls -l /proc/%s/exe" % pid)
+ err, retcode, ls_output = self.run_platform_command("ls -l /proc/%s/exe" % pid)
+ self.assertTrue(err.Success() and retcode == 0,
+ "Failed to read file /proc/%s/exe: %s, retcode: %d" % (pid, err.GetCString(), retcode))
exe = ls_output.split()[-1]
# If the binary has been deleted, the link name has " (deleted)" appended.
@@ -346,12 +337,6 @@ class GdbRemoteTestCaseBase(TestBase):
commandline_args += ["--named-pipe", self.named_pipe_path]
return commandline_args
- def run_platform_command(self, cmd):
- platform = self.dbg.GetSelectedPlatform()
- shell_command = lldb.SBPlatformShellCommand(cmd)
- err = platform.Run(shell_command)
- return (err, shell_command.GetOutput())
-
def launch_debug_monitor(self, attach_pid=None, logfile=None):
# Create the command line.
commandline_args = self.get_debug_monitor_command_line_args(attach_pid=attach_pid)
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py
index 015483519c8..5c28d288db5 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py
@@ -38,11 +38,8 @@ class TestPlatformProcessConnect(gdbremote_testcase.GdbRemoteTestCaseBase):
commandline_args = ["platform", "--listen", listen_url, "--socket-file", port_file, "--", "%s/a.out" % working_dir, "foo"]
self.spawnSubprocess(self.debug_monitor_exe, commandline_args, install_remote=False)
self.addTearDownHook(self.cleanupSubprocesses)
-
- # Wait until the port_file have been created. Doing it with 1 shell command will fail because
- # of a bug in LLDB shell escaping code
- _, _ = self.run_platform_command("while [ ! -f %s ]; do sleep 0.25; done" % port_file)
- _, socket_id = self.run_platform_command("cat %s" % port_file)
+
+ socket_id = lldbutil.wait_for_file_on_target(self, port_file)
new_debugger = lldb.SBDebugger.Create()
new_debugger.SetAsync(False)
OpenPOWER on IntegriCloud