[Lldb-commits] [lldb] [lldb] Fix the test TestGdbRemotePlatformFile (PR #91918)

2024-05-14 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett approved this pull request.


https://github.com/llvm/llvm-project/pull/91918
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Fix the test TestGdbRemotePlatformFile (PR #91918)

2024-05-14 Thread Dmitry Vasilyev via lldb-commits


@@ -108,6 +109,20 @@ def test_platform_file_wronly_fail(self):
 )
 self.expect_gdbremote_sequence()
 
+def remote_install(self, path, filename="test"):
+if lldb.remote_platform:
+remote_path = lldbutil.append_to_process_working_directory(self, 
filename)
+err = lldb.remote_platform.Install(
+lldb.SBFileSpec(path, True), lldb.SBFileSpec(remote_path, 
False)
+)
+if err.Fail():
+raise Exception(
+"remote_platform.Install('%s', '%s') failed: %s"
+% (path, remote_path, err)
+)
+path = remote_path
+return path

slydiman wrote:

I have updated this patch using lldbutil.install_to_target().

https://github.com/llvm/llvm-project/pull/91918
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Fix the test TestGdbRemotePlatformFile (PR #91918)

2024-05-14 Thread Dmitry Vasilyev via lldb-commits

https://github.com/slydiman updated 
https://github.com/llvm/llvm-project/pull/91918

>From 4eee83a3a6b923075a9e6db217349726780c31f4 Mon Sep 17 00:00:00 2001
From: Dmitry Vasilyev 
Date: Mon, 13 May 2024 10:34:04 +0400
Subject: [PATCH] [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.
---
 .../lldb-server/TestGdbRemotePlatformFile.py  | 33 +--
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py 
b/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py
index 4c8ce01e8ba31..2e1c72ee56d7a 100644
--- a/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py
+++ b/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py
@@ -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
@@ -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()
@@ -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(
@@ -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(
@@ -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(
@@ -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()
@@ -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}$",
@@ -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()
@@ -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 

[Lldb-commits] [lldb] [lldb] Fix the test TestGdbRemotePlatformFile (PR #91918)

2024-05-13 Thread Dmitry Vasilyev via lldb-commits


@@ -108,6 +109,20 @@ def test_platform_file_wronly_fail(self):
 )
 self.expect_gdbremote_sequence()
 
+def remote_install(self, path, filename="test"):
+if lldb.remote_platform:
+remote_path = lldbutil.append_to_process_working_directory(self, 
filename)
+err = lldb.remote_platform.Install(
+lldb.SBFileSpec(path, True), lldb.SBFileSpec(remote_path, 
False)
+)
+if err.Fail():
+raise Exception(
+"remote_platform.Install('%s', '%s') failed: %s"
+% (path, remote_path, err)
+)
+path = remote_path
+return path

slydiman wrote:

Sure. Please look at #91944.

https://github.com/llvm/llvm-project/pull/91918
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Fix the test TestGdbRemotePlatformFile (PR #91918)

2024-05-13 Thread David Spickett via lldb-commits


@@ -108,6 +109,20 @@ def test_platform_file_wronly_fail(self):
 )
 self.expect_gdbremote_sequence()
 
+def remote_install(self, path, filename="test"):
+if lldb.remote_platform:
+remote_path = lldbutil.append_to_process_working_directory(self, 
filename)
+err = lldb.remote_platform.Install(
+lldb.SBFileSpec(path, True), lldb.SBFileSpec(remote_path, 
False)
+)
+if err.Fail():
+raise Exception(
+"remote_platform.Install('%s', '%s') failed: %s"
+% (path, remote_path, err)
+)
+path = remote_path
+return path

DavidSpickett wrote:

This looks almost the same as the code in 
https://github.com/llvm/llvm-project/pull/91931, can this be de-duplicated?

https://github.com/llvm/llvm-project/pull/91918
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Fix the test TestGdbRemotePlatformFile (PR #91918)

2024-05-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Dmitry Vasilyev (slydiman)


Changes

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 the 
Windows host.

---
Full diff: https://github.com/llvm/llvm-project/pull/91918.diff


1 Files Affected:

- (modified) lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py 
(+44-3) 


``diff
diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py 
b/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py
index 4c8ce01e8ba31..13274696a9a5c 100644
--- a/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py
+++ b/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py
@@ -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
@@ -108,6 +109,20 @@ def test_platform_file_wronly_fail(self):
 )
 self.expect_gdbremote_sequence()
 
+def remote_install(self, path, filename="test"):
+if lldb.remote_platform:
+remote_path = lldbutil.append_to_process_working_directory(self, 
filename)
+err = lldb.remote_platform.Install(
+lldb.SBFileSpec(path, True), lldb.SBFileSpec(remote_path, 
False)
+)
+if err.Fail():
+raise Exception(
+"remote_platform.Install('%s', '%s') failed: %s"
+% (path, remote_path, err)
+)
+path = remote_path
+return path
+
 @skipIfWindows
 @add_test_categories(["llgs"])
 def test_platform_file_wronly_creat_excl_fail(self):
@@ -117,6 +132,7 @@ def test_platform_file_wronly_creat_excl_fail(self):
 temp_file = self.getBuildArtifact("test")
 with open(temp_file, "wb"):
 pass
+temp_file = self.remote_install(temp_file)
 
 # attempt to open the file with O_CREAT|O_EXCL
 self.do_handshake()
@@ -140,6 +156,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 = self.remote_install(temp_path)
 
 self.do_handshake()
 self.test_sequence.add_log_lines(
@@ -167,7 +184,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 = self.remote_install(temp_path)
 
 self.do_handshake()
 self.test_sequence.add_log_lines(
@@ -213,6 +234,7 @@ def test_platform_file_exists(self):
 temp_path = self.getBuildArtifact("test")
 with open(temp_path, "wb"):
 pass
+temp_path = self.remote_install(temp_path)
 
 self.do_handshake()
 self.test_sequence.add_log_lines(
@@ -244,6 +266,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()
@@ -252,12 +278,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 = self.remote_install(temp_file.name, "temp")
 
 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}$",
@@ -359,9 +386,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 = self.remote_install(temp_path)
 
 # open the file for reading
 self.do_handshake()
@@ -448,8 +478,19 @@ def vFile_test(
 
 if 

[Lldb-commits] [lldb] [lldb] Fix the test TestGdbRemotePlatformFile (PR #91918)

2024-05-13 Thread Dmitry Vasilyev via lldb-commits

https://github.com/slydiman created 
https://github.com/llvm/llvm-project/pull/91918

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 the 
Windows host.

>From 24d0eb93672570aec4e53dfcf10b53eac8c6acb9 Mon Sep 17 00:00:00 2001
From: Dmitry Vasilyev 
Date: Mon, 13 May 2024 10:34:04 +0400
Subject: [PATCH] [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.
---
 .../lldb-server/TestGdbRemotePlatformFile.py  | 47 +--
 1 file changed, 44 insertions(+), 3 deletions(-)

diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py 
b/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py
index 4c8ce01e8ba31..13274696a9a5c 100644
--- a/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py
+++ b/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py
@@ -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
@@ -108,6 +109,20 @@ def test_platform_file_wronly_fail(self):
 )
 self.expect_gdbremote_sequence()
 
+def remote_install(self, path, filename="test"):
+if lldb.remote_platform:
+remote_path = lldbutil.append_to_process_working_directory(self, 
filename)
+err = lldb.remote_platform.Install(
+lldb.SBFileSpec(path, True), lldb.SBFileSpec(remote_path, 
False)
+)
+if err.Fail():
+raise Exception(
+"remote_platform.Install('%s', '%s') failed: %s"
+% (path, remote_path, err)
+)
+path = remote_path
+return path
+
 @skipIfWindows
 @add_test_categories(["llgs"])
 def test_platform_file_wronly_creat_excl_fail(self):
@@ -117,6 +132,7 @@ def test_platform_file_wronly_creat_excl_fail(self):
 temp_file = self.getBuildArtifact("test")
 with open(temp_file, "wb"):
 pass
+temp_file = self.remote_install(temp_file)
 
 # attempt to open the file with O_CREAT|O_EXCL
 self.do_handshake()
@@ -140,6 +156,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 = self.remote_install(temp_path)
 
 self.do_handshake()
 self.test_sequence.add_log_lines(
@@ -167,7 +184,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 = self.remote_install(temp_path)
 
 self.do_handshake()
 self.test_sequence.add_log_lines(
@@ -213,6 +234,7 @@ def test_platform_file_exists(self):
 temp_path = self.getBuildArtifact("test")
 with open(temp_path, "wb"):
 pass
+temp_path = self.remote_install(temp_path)
 
 self.do_handshake()
 self.test_sequence.add_log_lines(
@@ -244,6 +266,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()
@@ -252,12 +278,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 = self.remote_install(temp_file.name, "temp")
 
 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}$",
@@ -359,9 +386,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")