Skip to content

Commit 4eee83a

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 c441aa5 commit 4eee83a

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

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

Lines changed: 30 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
@@ -117,6 +118,7 @@ def test_platform_file_wronly_creat_excl_fail(self):
117118
temp_file = self.getBuildArtifact("test")
118119
with open(temp_file, "wb"):
119120
pass
121+
temp_file = lldbutil.install_to_target(self, temp_file)
120122

121123
# attempt to open the file with O_CREAT|O_EXCL
122124
self.do_handshake()
@@ -140,6 +142,7 @@ def test_platform_file_size(self):
140142
test_data = b"test data of some length"
141143
with open(temp_path, "wb") as temp_file:
142144
temp_file.write(test_data)
145+
temp_path = lldbutil.install_to_target(self, temp_path)
143146

144147
self.do_handshake()
145148
self.test_sequence.add_log_lines(
@@ -167,7 +170,11 @@ def test_platform_file_mode(self):
167170
test_mode = 0o751
168171

169172
with open(temp_path, "wb") as temp_file:
170-
os.chmod(temp_file.fileno(), test_mode)
173+
if lldbplatformutil.getHostPlatform() == "windows":
174+
test_mode = 0o700
175+
else:
176+
os.chmod(temp_file.fileno(), test_mode)
177+
temp_path = lldbutil.install_to_target(self, temp_path)
171178

172179
self.do_handshake()
173180
self.test_sequence.add_log_lines(
@@ -213,6 +220,7 @@ def test_platform_file_exists(self):
213220
temp_path = self.getBuildArtifact("test")
214221
with open(temp_path, "wb"):
215222
pass
223+
temp_path = lldbutil.install_to_target(self, temp_path)
216224

217225
self.do_handshake()
218226
self.test_sequence.add_log_lines(
@@ -244,6 +252,10 @@ def test_platform_file_exists_not(self):
244252
self.expect_gdbremote_sequence()
245253

246254
@skipIfWindows
255+
# FIXME: lldb.remote_platform.Install() cannot copy opened temp file on Windows.
256+
# It is possible to use tempfile.NamedTemporaryFile(..., delete=False) and
257+
# delete the temp file manually at the end.
258+
@skipIf(hostoslist=["windows"])
247259
@add_test_categories(["llgs"])
248260
def test_platform_file_fstat(self):
249261
server = self.connect_to_debug_monitor()
@@ -252,12 +264,13 @@ def test_platform_file_fstat(self):
252264
with tempfile.NamedTemporaryFile() as temp_file:
253265
temp_file.write(b"some test data for stat")
254266
temp_file.flush()
267+
temp_path = lldbutil.install_to_target(self, temp_file.name)
255268

256269
self.do_handshake()
257270
self.test_sequence.add_log_lines(
258271
[
259272
"read packet: $vFile:open:%s,0,0#00"
260-
% (binascii.b2a_hex(temp_file.name.encode()).decode(),),
273+
% (binascii.b2a_hex(temp_path.encode()).decode(),),
261274
{
262275
"direction": "send",
263276
"regex": r"^\$F([0-9a-fA-F]+)#[0-9a-fA-F]{2}$",
@@ -359,9 +372,12 @@ def vFile_test(
359372

360373
if creat:
361374
self.assertFalse(os.path.exists(temp_path))
375+
if lldb.remote_platform:
376+
temp_path = lldbutil.append_to_process_working_directory(self, "test")
362377
else:
363378
with open(temp_path, "wb") as temp_file:
364379
temp_file.write(test_data.encode())
380+
temp_path = lldbutil.install_to_target(self, temp_path)
365381

366382
# open the file for reading
367383
self.do_handshake()
@@ -448,8 +464,19 @@ def vFile_test(
448464

449465
if write:
450466
# check if the data was actually written
467+
if lldb.remote_platform:
468+
local_path = self.getBuildArtifact("file_from_target")
469+
error = lldb.remote_platform.Get(
470+
lldb.SBFileSpec(temp_path, False), lldb.SBFileSpec(local_path, True)
471+
)
472+
self.assertTrue(
473+
error.Success(),
474+
"Reading file {0} failed: {1}".format(temp_path, error),
475+
)
476+
temp_path = local_path
477+
451478
with open(temp_path, "rb") as temp_file:
452-
if creat:
479+
if creat and lldbplatformutil.getHostPlatform() != "windows":
453480
self.assertEqual(
454481
os.fstat(temp_file.fileno()).st_mode & 0o7777, 0o640
455482
)

0 commit comments

Comments
 (0)