Skip to content

Commit f7c36d2

Browse files
authored
[lldb] Fix API test for file redirection to existing files (llvm#114119)
API test failed for remote platform in [llvm#112657](llvm#112657) Previously when putting files onto remote platform, I used `platform file write -d <data>` which actually required a `platform file open <path>` first in order to obtain a file descriptor. eg. in file [TestGDBRemotePlatformFile.py](https://github.com/llvm/llvm-project/blob/94e7d9c0bfe517507ea08b00fb00c32fb2837a82/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py#L24-L32) To fix this, use the `platform put-file` method, which is used in the `redirect_stdin` from this test already.
1 parent bfe486f commit f7c36d2

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

lldb/test/API/python_api/process/io/TestProcessIO.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,31 +99,38 @@ def test_stdout_stderr_redirection(self):
9999
@expectedFlakeyLinux(bugnumber="llvm.org/pr26437")
100100
@skipIfDarwinEmbedded # debugserver can't create/write files on the device
101101
def test_stdout_stderr_redirection_to_existing_files(self):
102-
"""Exercise SBLaunchInfo::AddOpenFileAction() for STDOUT and STDERR without redirecting STDIN to output files already exist."""
102+
"""Exercise SBLaunchInfo::AddOpenFileAction() for STDOUT and STDERR redirect to output files already exist."""
103103
self.setup_test()
104104
self.build()
105105
self.create_target()
106-
self.write_file_with_placeholder(self.output_file)
107-
self.write_file_with_placeholder(self.error_file)
108-
self.redirect_stdout()
109-
self.redirect_stderr()
110-
self.run_process(True)
111-
output = self.read_output_file_and_delete()
112-
error = self.read_error_file_and_delete()
113-
self.check_process_output(output, error)
114106

115-
def write_file_with_placeholder(self, target_file):
107+
# Create the output and error files with placeholder
116108
placeholder = "This content should be overwritten."
109+
# Local file directory and working directory are the same for local debugging
110+
f = open(self.local_output_file, "w")
111+
f.write(placeholder)
112+
f.close()
113+
f = open(self.local_error_file, "w")
114+
f.write(placeholder)
115+
f.close()
117116
if lldb.remote_platform:
118117
self.runCmd(
119-
'platform file write "{target}" -d "{data}"'.format(
120-
target=target_file, data=placeholder
118+
'platform put-file "{local}" "{remote}"'.format(
119+
local=self.local_output_file, remote=self.output_file
120+
)
121+
)
122+
self.runCmd(
123+
'platform put-file "{local}" "{remote}"'.format(
124+
local=self.local_error_file, remote=self.error_file
121125
)
122126
)
123-
else:
124-
f = open(target_file, "w")
125-
f.write(placeholder)
126-
f.close()
127+
128+
self.redirect_stdout()
129+
self.redirect_stderr()
130+
self.run_process(True)
131+
output = self.read_output_file_and_delete()
132+
error = self.read_error_file_and_delete()
133+
self.check_process_output(output, error)
127134

128135
# target_file - path on local file system or remote file system if running remote
129136
# local_file - path on local system

0 commit comments

Comments
 (0)