[Lldb-commits] [lldb] [lldb] Fix API test for file redirection to existing files (PR #114119)

via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 29 12:54:41 PDT 2024


https://github.com/kusmour created https://github.com/llvm/llvm-project/pull/114119

API test failed for remote debugging in [#112657](https://github.com/llvm/llvm-project/pull/112657)

Fixing it properly

>From dfa32524d1e6cac75471975de1e2a28225efce83 Mon Sep 17 00:00:00 2001
From: Wanyi Ye <wanyi at meta.com>
Date: Tue, 29 Oct 2024 12:50:28 -0700
Subject: [PATCH] [lldb] Fix API test for file redirection to existing files

---
 .../python_api/process/io/TestProcessIO.py    | 40 +++++++++++++------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/lldb/test/API/python_api/process/io/TestProcessIO.py b/lldb/test/API/python_api/process/io/TestProcessIO.py
index 3b5c7c48c51f4d..24cd845904cc2c 100644
--- a/lldb/test/API/python_api/process/io/TestProcessIO.py
+++ b/lldb/test/API/python_api/process/io/TestProcessIO.py
@@ -99,31 +99,45 @@ def test_stdout_stderr_redirection(self):
     @expectedFlakeyLinux(bugnumber="llvm.org/pr26437")
     @skipIfDarwinEmbedded  # debugserver can't create/write files on the device
     def test_stdout_stderr_redirection_to_existing_files(self):
-        """Exercise SBLaunchInfo::AddOpenFileAction() for STDOUT and STDERR without redirecting STDIN to output files already exist."""
+        """Exercise SBLaunchInfo::AddOpenFileAction() for STDOUT and STDERR redirect to output files already exist."""
         self.setup_test()
         self.build()
         self.create_target()
-        self.write_file_with_placeholder(self.output_file)
-        self.write_file_with_placeholder(self.error_file)
-        self.redirect_stdout()
-        self.redirect_stderr()
-        self.run_process(True)
-        output = self.read_output_file_and_delete()
-        error = self.read_error_file_and_delete()
-        self.check_process_output(output, error)
 
-    def write_file_with_placeholder(self, target_file):
+        # Create the output and error files with placeholder
         placeholder = "This content should be overwritten."
         if lldb.remote_platform:
+            f = open(self.local_output_file, "w")
+            f.write(placeholder)
+            f.close()
+
+            f = open(self.local_error_file, "w")
+            f.write(placeholder)
+            f.close()
+            self.runCmd(
+                'platform put-file "{local}" "{remote}"'.format(
+                    local=self.local_output_file, remote=self.output_file
+                )
+            )
             self.runCmd(
-                'platform file write "{target}" -d "{data}"'.format(
-                    target=target_file, data=placeholder
+                'platform put-file "{local}" "{remote}"'.format(
+                    local=self.local_error_file, remote=self.error_file
                 )
             )
         else:
-            f = open(target_file, "w")
+            f = open(self.output_file, "w")
+            f.write(placeholder)
+            f.close()
+            f = open(self.error_file, "w")
             f.write(placeholder)
             f.close()
+            
+        self.redirect_stdout()
+        self.redirect_stderr()
+        self.run_process(True)
+        output = self.read_output_file_and_delete()
+        error = self.read_error_file_and_delete()
+        self.check_process_output(output, error)
 
     # target_file - path on local file system or remote file system if running remote
     # local_file - path on local system



More information about the lldb-commits mailing list