Author: Pavel Labath Date: 2022-07-07T17:35:15+02:00 New Revision: d955185b9413c4bbe90d4b1f91790ddcc78baf99
URL: https://github.com/llvm/llvm-project/commit/d955185b9413c4bbe90d4b1f91790ddcc78baf99 DIFF: https://github.com/llvm/llvm-project/commit/d955185b9413c4bbe90d4b1f91790ddcc78baf99.diff LOG: [lldb/test] Use the shim executable for TestGdbRemoteAttach*Or*Wait as well Without it, the test may nondeterminstically fail due to YAMA restrictions. Also, merge the two tests into one to reduce duplication. Added: Modified: lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py Removed: lldb/test/API/tools/lldb-server/TestGdbRemoteAttachOrWait.py ################################################################################ diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteAttachOrWait.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteAttachOrWait.py deleted file mode 100644 index 90a7eee7536f..000000000000 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteAttachOrWait.py +++ /dev/null @@ -1,111 +0,0 @@ - -import os -from time import sleep - -import gdbremote_testcase -import lldbgdbserverutils -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestGdbRemoteAttachOrWait(gdbremote_testcase.GdbRemoteTestCaseBase): - - @skipIfWindows # This test is flaky on Windows - def test_launch_before_attach_with_vAttachOrWait(self): - exe = '%s_%d' % (self.testMethodName, os.getpid()) - self.build(dictionary={'EXE': exe}) - self.set_inferior_startup_attach_manually() - - # Start the inferior, start the debug monitor, nothing is attached yet. - procs = self.prep_debug_monitor_and_inferior( - inferior_args=["sleep:60"], - inferior_exe_path=self.getBuildArtifact(exe)) - self.assertIsNotNone(procs) - - # Make sure the target process has been launched. - inferior = procs.get("inferior") - self.assertIsNotNone(inferior) - self.assertTrue(inferior.pid > 0) - self.assertTrue( - lldbgdbserverutils.process_is_running( - inferior.pid, True)) - - # Add attach packets. - self.test_sequence.add_log_lines([ - # Do the attach. - "read packet: $vAttachOrWait;{}#00".format(lldbgdbserverutils.gdbremote_hex_encode_string(exe)), - # Expect a stop notification from the attach. - {"direction": "send", - "regex": r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$", - "capture": {1: "stop_signal_hex"}}, - ], True) - self.add_process_info_collection_packets() - - # Run the stream - context = self.expect_gdbremote_sequence() - self.assertIsNotNone(context) - - # Gather process info response - process_info = self.parse_process_info_response(context) - self.assertIsNotNone(process_info) - - # Ensure the process id matches what we expected. - pid_text = process_info.get('pid', None) - self.assertIsNotNone(pid_text) - reported_pid = int(pid_text, base=16) - self.assertEqual(reported_pid, inferior.pid) - - @skipIfWindows # This test is flaky on Windows - def test_launch_after_attach_with_vAttachOrWait(self): - exe = '%s_%d' % (self.testMethodName, os.getpid()) - self.build(dictionary={'EXE': exe}) - self.set_inferior_startup_attach_manually() - - server = self.connect_to_debug_monitor() - self.assertIsNotNone(server) - - self.do_handshake() - self.test_sequence.add_log_lines([ - # Do the attach. - "read packet: $vAttachOrWait;{}#00".format(lldbgdbserverutils.gdbremote_hex_encode_string(exe)), - ], True) - # Run the stream until attachWait. - context = self.expect_gdbremote_sequence() - self.assertIsNotNone(context) - - # Sleep so we're sure that the inferior is launched after we ask for the attach. - sleep(1) - - # Launch the inferior. - inferior = self.launch_process_for_attach( - inferior_args=["sleep:60"], - exe_path=self.getBuildArtifact(exe)) - self.assertIsNotNone(inferior) - self.assertTrue(inferior.pid > 0) - self.assertTrue( - lldbgdbserverutils.process_is_running( - inferior.pid, True)) - - # Make sure the attach succeeded. - self.test_sequence.add_log_lines([ - {"direction": "send", - "regex": r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$", - "capture": {1: "stop_signal_hex"}}, - ], True) - self.add_process_info_collection_packets() - - - # Run the stream sending the response.. - context = self.expect_gdbremote_sequence() - self.assertIsNotNone(context) - - # Gather process info response. - process_info = self.parse_process_info_response(context) - self.assertIsNotNone(process_info) - - # Ensure the process id matches what we expected. - pid_text = process_info.get('pid', None) - self.assertIsNotNone(pid_text) - reported_pid = int(pid_text, base=16) - self.assertEqual(reported_pid, inferior.pid) diff --git a/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py b/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py index b1ec443788bf..bf2b60abcc9b 100644 --- a/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py +++ b/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py @@ -11,48 +11,134 @@ class TestGdbRemoteAttachWait(gdbremote_testcase.GdbRemoteTestCaseBase): - @skipIfWindows # This test is flaky on Windows - def test_attach_with_vAttachWait(self): - exe = '%s_%d' % (self.testMethodName, os.getpid()) - exe_to_attach = exe - sync_file_path = lldbutil.append_to_process_working_directory(self, "process_ready") - args = [sync_file_path] - - def launch_inferior(): - inferior = self.launch_process_for_attach( - inferior_args=args, - exe_path=self.getBuildArtifact(exe)) - self.assertIsNotNone(inferior) - self.assertTrue(inferior.pid > 0) - self.assertTrue( - lldbgdbserverutils.process_is_running( - inferior.pid, True)) - return inferior - - self.build(dictionary={'EXE': exe, 'CXX_SOURCES': 'main.cpp'}) + def _set_up_inferior(self): + self._exe_to_attach = '%s_%d' % (self.testMethodName, os.getpid()) + self.build(dictionary={'EXE': self._exe_to_attach, 'CXX_SOURCES': 'main.cpp'}) + if self.getPlatform() != "windows": # Use a shim to ensure that the process is ready to be attached from # the get-go. - args = [self.getBuildArtifact(exe)] + args - exe = "shim" - self.build(dictionary={'EXE': exe, 'CXX_SOURCES': 'shim.cpp'}) + self._exe_to_run = "shim" + self._run_args = [self.getBuildArtifact(self._exe_to_attach)] + self.build(dictionary={'EXE': self._exe_to_run, 'CXX_SOURCES': + 'shim.cpp'}) + else: + self._exe_to_run = self._exe_to_attach + self._run_args = [] + + def _launch_inferior(self, args): + inferior = self.spawnSubprocess(self.getBuildArtifact(self._exe_to_run), + args) + self.assertIsNotNone(inferior) + self.assertTrue(inferior.pid > 0) + self.assertTrue( + lldbgdbserverutils.process_is_running( + inferior.pid, True)) + return inferior + + def _launch_and_wait_for_init(self): + sync_file_path = lldbutil.append_to_process_working_directory(self, + "process_ready") + inferior = self._launch_inferior(self._run_args + [sync_file_path]) + lldbutil.wait_for_file_on_target(self, sync_file_path) + return inferior - self.set_inferior_startup_attach_manually() + def _attach_packet(self, packet_type): + return "read packet: ${};{}#00".format(packet_type, + lldbgdbserverutils.gdbremote_hex_encode_string(self._exe_to_attach)) + + @skipIfWindows # This test is flaky on Windows + def test_attach_with_vAttachWait(self): + self._set_up_inferior() + + self.set_inferior_startup_attach_manually() server = self.connect_to_debug_monitor() - self.assertIsNotNone(server) + self.do_handshake() # Launch the first inferior (we shouldn't attach to this one). - launch_inferior() + self._launch_and_wait_for_init() - lldbutil.wait_for_file_on_target(self, sync_file_path) + self.test_sequence.add_log_lines([self._attach_packet("vAttachWait")], + True) + # Run the stream until attachWait. + context = self.expect_gdbremote_sequence() + self.assertIsNotNone(context) + + # Sleep so we're sure that the inferior is launched after we ask for the attach. + sleep(1) + + # Launch the second inferior (we SHOULD attach to this one). + inferior_to_attach = self._launch_inferior(self._run_args) + + # Make sure the attach succeeded. + self.test_sequence.add_log_lines([ + {"direction": "send", + "regex": r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$", + "capture": {1: "stop_signal_hex"}}, + ], True) + self.add_process_info_collection_packets() + + + # Run the stream sending the response.. + context = self.expect_gdbremote_sequence() + self.assertIsNotNone(context) + + # Gather process info response. + process_info = self.parse_process_info_response(context) + self.assertIsNotNone(process_info) + # Ensure the process id matches what we expected. + pid_text = process_info.get('pid', None) + self.assertIsNotNone(pid_text) + reported_pid = int(pid_text, base=16) + self.assertEqual(reported_pid, inferior_to_attach.pid) + + @skipIfWindows # This test is flaky on Windows + def test_launch_before_attach_with_vAttachOrWait(self): + self._set_up_inferior() + + self.set_inferior_startup_attach_manually() + server = self.connect_to_debug_monitor() self.do_handshake() + + inferior = self._launch_and_wait_for_init() + + # Add attach packets. self.test_sequence.add_log_lines([ # Do the attach. - "read packet: $vAttachWait;{}#00".format( - lldbgdbserverutils.gdbremote_hex_encode_string(exe_to_attach)), + self._attach_packet("vAttachOrWait"), + # Expect a stop notification from the attach. + {"direction": "send", + "regex": r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$", + "capture": {1: "stop_signal_hex"}}, ], True) + self.add_process_info_collection_packets() + + # Run the stream + context = self.expect_gdbremote_sequence() + self.assertIsNotNone(context) + + # Gather process info response + process_info = self.parse_process_info_response(context) + self.assertIsNotNone(process_info) + + # Ensure the process id matches what we expected. + pid_text = process_info.get('pid', None) + self.assertIsNotNone(pid_text) + reported_pid = int(pid_text, base=16) + self.assertEqual(reported_pid, inferior.pid) + + @skipIfWindows # This test is flaky on Windows + def test_launch_after_attach_with_vAttachOrWait(self): + self._set_up_inferior() + + self.set_inferior_startup_attach_manually() + server = self.connect_to_debug_monitor() + self.do_handshake() + + self.test_sequence.add_log_lines([self._attach_packet("vAttachOrWait")], + True) # Run the stream until attachWait. context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -60,8 +146,8 @@ def launch_inferior(): # Sleep so we're sure that the inferior is launched after we ask for the attach. sleep(1) - # Launch the second inferior (we SHOULD attach to this one). - inferior_to_attach = launch_inferior() + # Launch the inferior. + inferior = self._launch_inferior(self._run_args) # Make sure the attach succeeded. self.test_sequence.add_log_lines([ @@ -84,4 +170,4 @@ def launch_inferior(): pid_text = process_info.get('pid', None) self.assertIsNotNone(pid_text) reported_pid = int(pid_text, base=16) - self.assertEqual(reported_pid, inferior_to_attach.pid) + self.assertEqual(reported_pid, inferior.pid) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits