Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py @@ -19,12 +19,6 @@ 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 @@ 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:', Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_group/TestChangeProcessGroup.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_group/TestChangeProcessGroup.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_group/TestChangeProcessGroup.py @@ -36,23 +36,7 @@ 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 @@ # 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()) Index: lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py +++ lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py @@ -1946,6 +1946,12 @@ 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 # ================================================= Index: lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py +++ lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py @@ -1029,3 +1029,20 @@ 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 Index: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py +++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py @@ -214,30 +214,21 @@ 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 @@ 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) Index: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py +++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py @@ -38,11 +38,8 @@ 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)