Skip to content

[lldb] Fix the test TestGdbRemotePlatformFile when run with a remote target #91918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# lldb test suite imports
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import TestBase
from lldbsuite.test import lldbutil

# gdb-remote-specific imports
import lldbgdbserverutils
Expand Down Expand Up @@ -117,6 +118,7 @@ def test_platform_file_wronly_creat_excl_fail(self):
temp_file = self.getBuildArtifact("test")
with open(temp_file, "wb"):
pass
temp_file = lldbutil.install_to_target(self, temp_file)

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

self.do_handshake()
self.test_sequence.add_log_lines(
Expand Down Expand Up @@ -167,7 +170,11 @@ def test_platform_file_mode(self):
test_mode = 0o751

with open(temp_path, "wb") as temp_file:
os.chmod(temp_file.fileno(), test_mode)
if lldbplatformutil.getHostPlatform() == "windows":
test_mode = 0o700
else:
os.chmod(temp_file.fileno(), test_mode)
temp_path = lldbutil.install_to_target(self, temp_path)

self.do_handshake()
self.test_sequence.add_log_lines(
Expand Down Expand Up @@ -213,6 +220,7 @@ def test_platform_file_exists(self):
temp_path = self.getBuildArtifact("test")
with open(temp_path, "wb"):
pass
temp_path = lldbutil.install_to_target(self, temp_path)

self.do_handshake()
self.test_sequence.add_log_lines(
Expand Down Expand Up @@ -244,6 +252,10 @@ def test_platform_file_exists_not(self):
self.expect_gdbremote_sequence()

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

self.do_handshake()
self.test_sequence.add_log_lines(
[
"read packet: $vFile:open:%s,0,0#00"
% (binascii.b2a_hex(temp_file.name.encode()).decode(),),
% (binascii.b2a_hex(temp_path.encode()).decode(),),
{
"direction": "send",
"regex": r"^\$F([0-9a-fA-F]+)#[0-9a-fA-F]{2}$",
Expand Down Expand Up @@ -359,9 +372,12 @@ def vFile_test(

if creat:
self.assertFalse(os.path.exists(temp_path))
if lldb.remote_platform:
temp_path = lldbutil.append_to_process_working_directory(self, "test")
else:
with open(temp_path, "wb") as temp_file:
temp_file.write(test_data.encode())
temp_path = lldbutil.install_to_target(self, temp_path)

# open the file for reading
self.do_handshake()
Expand Down Expand Up @@ -448,8 +464,19 @@ def vFile_test(

if write:
# check if the data was actually written
if lldb.remote_platform:
local_path = self.getBuildArtifact("file_from_target")
error = lldb.remote_platform.Get(
lldb.SBFileSpec(temp_path, False), lldb.SBFileSpec(local_path, True)
)
self.assertTrue(
error.Success(),
"Reading file {0} failed: {1}".format(temp_path, error),
)
temp_path = local_path

with open(temp_path, "rb") as temp_file:
if creat:
if creat and lldbplatformutil.getHostPlatform() != "windows":
self.assertEqual(
os.fstat(temp_file.fileno()).st_mode & 0o7777, 0o640
)
Expand Down
Loading