Skip to content

Commit 24d0eb9

Browse files
committed
[lldb] Fix the test TestGdbRemotePlatformFile
It is necessary to transfer the test file to/from the really remote target (for example Windows host and Linux target). Also ignore chmod check in case of Windows host.
1 parent 1d6bf0c commit 24d0eb9

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# lldb test suite imports
22
from lldbsuite.test.decorators import *
33
from lldbsuite.test.lldbtest import TestBase
4+
from lldbsuite.test import lldbutil
45

56
# gdb-remote-specific imports
67
import lldbgdbserverutils
@@ -108,6 +109,20 @@ def test_platform_file_wronly_fail(self):
108109
)
109110
self.expect_gdbremote_sequence()
110111

112+
def remote_install(self, path, filename="test"):
113+
if lldb.remote_platform:
114+
remote_path = lldbutil.append_to_process_working_directory(self, filename)
115+
err = lldb.remote_platform.Install(
116+
lldb.SBFileSpec(path, True), lldb.SBFileSpec(remote_path, False)
117+
)
118+
if err.Fail():
119+
raise Exception(
120+
"remote_platform.Install('%s', '%s') failed: %s"
121+
% (path, remote_path, err)
122+
)
123+
path = remote_path
124+
return path
125+
111126
@skipIfWindows
112127
@add_test_categories(["llgs"])
113128
def test_platform_file_wronly_creat_excl_fail(self):
@@ -117,6 +132,7 @@ def test_platform_file_wronly_creat_excl_fail(self):
117132
temp_file = self.getBuildArtifact("test")
118133
with open(temp_file, "wb"):
119134
pass
135+
temp_file = self.remote_install(temp_file)
120136

121137
# attempt to open the file with O_CREAT|O_EXCL
122138
self.do_handshake()
@@ -140,6 +156,7 @@ def test_platform_file_size(self):
140156
test_data = b"test data of some length"
141157
with open(temp_path, "wb") as temp_file:
142158
temp_file.write(test_data)
159+
temp_path = self.remote_install(temp_path)
143160

144161
self.do_handshake()
145162
self.test_sequence.add_log_lines(
@@ -167,7 +184,11 @@ def test_platform_file_mode(self):
167184
test_mode = 0o751
168185

169186
with open(temp_path, "wb") as temp_file:
170-
os.chmod(temp_file.fileno(), test_mode)
187+
if lldbplatformutil.getHostPlatform() == "windows":
188+
test_mode = 0o700
189+
else:
190+
os.chmod(temp_file.fileno(), test_mode)
191+
temp_path = self.remote_install(temp_path)
171192

172193
self.do_handshake()
173194
self.test_sequence.add_log_lines(
@@ -213,6 +234,7 @@ def test_platform_file_exists(self):
213234
temp_path = self.getBuildArtifact("test")
214235
with open(temp_path, "wb"):
215236
pass
237+
temp_path = self.remote_install(temp_path)
216238

217239
self.do_handshake()
218240
self.test_sequence.add_log_lines(
@@ -244,6 +266,10 @@ def test_platform_file_exists_not(self):
244266
self.expect_gdbremote_sequence()
245267

246268
@skipIfWindows
269+
# FIXME: lldb.remote_platform.Install() cannot copy opened temp file on Windows.
270+
# It is possible to use tempfile.NamedTemporaryFile(..., delete=False) and
271+
# delete the temp file manually at the end.
272+
@skipIf(hostoslist=["windows"])
247273
@add_test_categories(["llgs"])
248274
def test_platform_file_fstat(self):
249275
server = self.connect_to_debug_monitor()
@@ -252,12 +278,13 @@ def test_platform_file_fstat(self):
252278
with tempfile.NamedTemporaryFile() as temp_file:
253279
temp_file.write(b"some test data for stat")
254280
temp_file.flush()
281+
temp_path = self.remote_install(temp_file.name, "temp")
255282

256283
self.do_handshake()
257284
self.test_sequence.add_log_lines(
258285
[
259286
"read packet: $vFile:open:%s,0,0#00"
260-
% (binascii.b2a_hex(temp_file.name.encode()).decode(),),
287+
% (binascii.b2a_hex(temp_path.encode()).decode(),),
261288
{
262289
"direction": "send",
263290
"regex": r"^\$F([0-9a-fA-F]+)#[0-9a-fA-F]{2}$",
@@ -359,9 +386,12 @@ def vFile_test(
359386

360387
if creat:
361388
self.assertFalse(os.path.exists(temp_path))
389+
if lldb.remote_platform:
390+
temp_path = lldbutil.append_to_process_working_directory(self, "test")
362391
else:
363392
with open(temp_path, "wb") as temp_file:
364393
temp_file.write(test_data.encode())
394+
temp_path = self.remote_install(temp_path)
365395

366396
# open the file for reading
367397
self.do_handshake()
@@ -448,8 +478,19 @@ def vFile_test(
448478

449479
if write:
450480
# check if the data was actually written
481+
if lldb.remote_platform:
482+
local_path = self.getBuildArtifact("file_from_target")
483+
error = lldb.remote_platform.Get(
484+
lldb.SBFileSpec(temp_path, False), lldb.SBFileSpec(local_path, True)
485+
)
486+
self.assertTrue(
487+
error.Success(),
488+
"Reading file {0} failed: {1}".format(temp_path, error),
489+
)
490+
temp_path = local_path
491+
451492
with open(temp_path, "rb") as temp_file:
452-
if creat:
493+
if creat and lldbplatformutil.getHostPlatform() != "windows":
453494
self.assertEqual(
454495
os.fstat(temp_file.fileno()).st_mode & 0o7777, 0o640
455496
)

0 commit comments

Comments
 (0)