Index: lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py =================================================================== --- lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py +++ lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py @@ -100,6 +100,80 @@ True) self.expect_gdbremote_sequence() + @skipIfWindows + @add_test_categories(["llgs"]) + def test_platform_file_size(self): + server = self.connect_to_debug_monitor() + self.assertIsNotNone(server) + + with tempfile.NamedTemporaryFile() as temp_file: + test_data = b"test data of some length" + temp_file.write(test_data) + temp_file.flush() + + self.do_handshake() + self.test_sequence.add_log_lines( + ["read packet: $vFile:size:%s#00" % ( + binascii.b2a_hex(temp_file.name.encode()).decode(),), + {"direction": "send", + "regex": r"^\$F([0-9a-fA-F]+)+#[0-9a-fA-F]{2}$", + "capture": {1: "size"}}], + True) + context = self.expect_gdbremote_sequence() + self.assertEqual(int(context["size"], 16), len(test_data)) + + @skipIfWindows + @add_test_categories(["llgs"]) + def test_platform_file_mode(self): + server = self.connect_to_debug_monitor() + self.assertIsNotNone(server) + + with tempfile.NamedTemporaryFile() as temp_file: + test_mode = 0o751 + os.chmod(temp_file.fileno(), test_mode) + + self.do_handshake() + self.test_sequence.add_log_lines( + ["read packet: $vFile:mode:%s#00" % ( + binascii.b2a_hex(temp_file.name.encode()).decode(),), + {"direction": "send", + "regex": r"^\$F([0-9a-fA-F]+)+#[0-9a-fA-F]{2}$", + "capture": {1: "mode"}}], + True) + context = self.expect_gdbremote_sequence() + self.assertEqual(int(context["mode"], 16), test_mode) + + @skipIfWindows + @add_test_categories(["llgs"]) + def test_platform_file_exists(self): + server = self.connect_to_debug_monitor() + self.assertIsNotNone(server) + + with tempfile.NamedTemporaryFile() as temp_file: + self.do_handshake() + self.test_sequence.add_log_lines( + ["read packet: $vFile:exists:%s#00" % ( + binascii.b2a_hex(temp_file.name.encode()).decode(),), + "send packet: $F,1#00"], + True) + self.expect_gdbremote_sequence() + + @skipIfWindows + @add_test_categories(["llgs"]) + def test_platform_file_exists_not(self): + server = self.connect_to_debug_monitor() + self.assertIsNotNone(server) + + with tempfile.TemporaryDirectory() as temp_dir: + test_path = os.path.join(temp_dir, "nonexist") + self.do_handshake() + self.test_sequence.add_log_lines( + ["read packet: $vFile:exists:%s#00" % ( + binascii.b2a_hex(test_path.encode()).decode(),), + "send packet: $F,0#00"], + True) + self.expect_gdbremote_sequence() + def expect_error(self): self.test_sequence.add_log_lines( [{"direction": "send",