diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py index 0b81912e3d3f..d702d8ee6820 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py @@ -31,10 +31,10 @@ class GdbRemoteTestCaseBase(TestBase): NO_DEBUG_INFO_TESTCASE = True - _TIMEOUT_SECONDS = 120 * (10 if ('ASAN_OPTIONS' in os.environ) else 1) - _DEFAULT_TIMEOUT = 10 * (10 if ('ASAN_OPTIONS' in os.environ) else 1) - _READ_TIMEOUT = 5 * (10 if ('ASAN_OPTIONS' in os.environ) else 1) - _WAIT_TIMEOUT = 5 * (10 if ('ASAN_OPTIONS' in os.environ) else 1) + # Default time out in seconds. The timeout is increased tenfold under Asan. + DEFAULT_TIMEOUT = 10 * (10 if ('ASAN_OPTIONS' in os.environ) else 1) + # Default sleep time in seconds. The sleep time is doubled under Asan. + DEFAULT_SLEEP = 5 * (2 if ('ASAN_OPTIONS' in os.environ) else 1) _GDBREMOTE_KILL_PACKET = "$k#6b" @@ -204,10 +204,10 @@ class GdbRemoteTestCaseBase(TestBase): return (named_pipe_path, named_pipe, named_pipe_fd) - def get_stub_port_from_named_socket(self, read_timeout_seconds): + def get_stub_port_from_named_socket(self): # Wait for something to read with a max timeout. (ready_readers, _, _) = select.select( - [self.named_pipe_fd], [], [], read_timeout_seconds) + [self.named_pipe_fd], [], [], self.DEFAULT_TIMEOUT) self.assertIsNotNone( ready_readers, "write side of pipe has not written anything - stub isn't writing to pipe.") @@ -407,7 +407,7 @@ class GdbRemoteTestCaseBase(TestBase): # If we're receiving the stub's listening port from the named pipe, do # that here. if self.named_pipe: - self.port = self.get_stub_port_from_named_socket(self._READ_TIMEOUT) + self.port = self.get_stub_port_from_named_socket() return server @@ -568,14 +568,14 @@ class GdbRemoteTestCaseBase(TestBase): def expect_socket_recv( self, sock, - expected_content_regex, - timeout_seconds): + expected_content_regex + ): response = "" - timeout_time = time.time() + timeout_seconds + timeout_time = time.time() + self.DEFAULT_TIMEOUT while not expected_content_regex.match( response) and time.time() < timeout_time: - can_read, _, _ = select.select([sock], [], [], timeout_seconds) + can_read, _, _ = select.select([sock], [], [], self.DEFAULT_TIMEOUT) if can_read and sock in can_read: recv_bytes = sock.recv(4096) if recv_bytes: @@ -583,24 +583,21 @@ class GdbRemoteTestCaseBase(TestBase): self.assertTrue(expected_content_regex.match(response)) - def expect_socket_send(self, sock, content, timeout_seconds): + def expect_socket_send(self, sock, content): request_bytes_remaining = content - timeout_time = time.time() + timeout_seconds + timeout_time = time.time() + self.DEFAULT_TIMEOUT while len(request_bytes_remaining) > 0 and time.time() < timeout_time: - _, can_write, _ = select.select([], [sock], [], timeout_seconds) + _, can_write, _ = select.select([], [sock], [], self.DEFAULT_TIMEOUT) if can_write and sock in can_write: written_byte_count = sock.send(request_bytes_remaining.encode()) request_bytes_remaining = request_bytes_remaining[ written_byte_count:] self.assertEqual(len(request_bytes_remaining), 0) - def do_handshake(self, stub_socket, timeout_seconds=None): - if not timeout_seconds: - timeout_seconds = self._WAIT_TIMEOUT - + def do_handshake(self, stub_socket): # Write the ack. - self.expect_socket_send(stub_socket, "+", timeout_seconds) + self.expect_socket_send(stub_socket, "+") # Send the start no ack mode packet. NO_ACK_MODE_REQUEST = "$QStartNoAckMode#b0" @@ -609,10 +606,10 @@ class GdbRemoteTestCaseBase(TestBase): # Receive the ack and "OK" self.expect_socket_recv(stub_socket, re.compile( - r"^\+\$OK#[0-9a-fA-F]{2}$"), timeout_seconds) + r"^\+\$OK#[0-9a-fA-F]{2}$")) # Send the final ack. - self.expect_socket_send(stub_socket, "+", timeout_seconds) + self.expect_socket_send(stub_socket, "+") def add_no_ack_remote_stream(self): self.test_sequence.add_log_lines( @@ -700,15 +697,13 @@ class GdbRemoteTestCaseBase(TestBase): return [parse_reg_info_response(reg_info_response) for reg_info_response in reg_info_responses] - def expect_gdbremote_sequence(self, timeout_seconds=None): - if not timeout_seconds: - timeout_seconds = self._TIMEOUT_SECONDS + def expect_gdbremote_sequence(self): return expect_lldb_gdbserver_replay( self, self.sock, self.test_sequence, self._pump_queues, - timeout_seconds, + self.DEFAULT_TIMEOUT, self.logger) _KNOWN_REGINFO_KEYS = [ @@ -856,11 +851,9 @@ class GdbRemoteTestCaseBase(TestBase): thread_ids.extend(new_thread_infos) return thread_ids - def wait_for_thread_count(self, thread_count, timeout_seconds=None): - if not timeout_seconds: - timeout_seconds = self._WAIT_TIMEOUT + def wait_for_thread_count(self, thread_count): start_time = time.time() - timeout_time = start_time + timeout_seconds + timeout_time = start_time + self.DEFAULT_TIMEOUT actual_thread_count = 0 while actual_thread_count < thread_count: @@ -878,7 +871,7 @@ class GdbRemoteTestCaseBase(TestBase): if time.time() > timeout_time: raise Exception( 'timed out after {} seconds while waiting for theads: waiting for at least {} threads, found {}'.format( - timeout_seconds, thread_count, actual_thread_count)) + self.DEFAULT_TIMEOUT, thread_count, actual_thread_count)) return threads diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteKill.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteKill.py index 48f919aa94b9..bab02e7cfc1d 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteKill.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteKill.py @@ -31,7 +31,7 @@ class TestGdbRemoteKill(gdbremote_testcase.GdbRemoteTestCaseBase): # Wait a moment for completed and now-detached inferior process to # clear. - time.sleep(self._WAIT_TIMEOUT) + time.sleep(self.DEFAULT_SLEEP) if not lldb.remote_platform: # Process should be dead now. Reap results. diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteProcessInfo.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteProcessInfo.py index bc793a36e998..5ee32a5d18cc 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteProcessInfo.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteProcessInfo.py @@ -52,7 +52,7 @@ class TestGdbRemoteProcessInfo(gdbremote_testcase.GdbRemoteTestCaseBase): self.add_process_info_collection_packets() # Run the stream - context = self.expect_gdbremote_sequence(timeout_seconds=self._DEFAULT_TIMEOUT) + context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) # Gather process info response diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py index 951932863409..891a0101614a 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py @@ -42,7 +42,7 @@ class TestGdbRemoteThreadsInStopReply( hw_info = self.parse_hw_info(context) # Give threads time to start up, then break. - time.sleep(self._WAIT_TIMEOUT) + time.sleep(self.DEFAULT_SLEEP) self.reset_test_sequence() self.test_sequence.add_log_lines( [ @@ -60,8 +60,7 @@ class TestGdbRemoteThreadsInStopReply( self.assertIsNotNone(context) # Wait until all threads have started. - threads = self.wait_for_thread_count(thread_count, - timeout_seconds=self._WAIT_TIMEOUT) + threads = self.wait_for_thread_count(thread_count) self.assertIsNotNone(threads) self.assertEqual(len(threads), thread_count) diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py b/lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py index 51dd0cb1a3bd..d7fd97e693c6 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py @@ -33,7 +33,7 @@ class TestGdbRemote_qThreadStopInfo(gdbremote_testcase.GdbRemoteTestCaseBase): self.assertIsNotNone(context) # Give threads time to start up, then break. - time.sleep(self._WAIT_TIMEOUT) + time.sleep(self.DEFAULT_SLEEP) self.reset_test_sequence() self.test_sequence.add_log_lines( [ @@ -51,8 +51,7 @@ class TestGdbRemote_qThreadStopInfo(gdbremote_testcase.GdbRemoteTestCaseBase): self.assertIsNotNone(context) # Wait until all threads have started. - threads = self.wait_for_thread_count(thread_count, - timeout_seconds=self._WAIT_TIMEOUT) + threads = self.wait_for_thread_count(thread_count) self.assertIsNotNone(threads) # On Windows, there could be more threads spawned. For example, DebugBreakProcess will diff --git a/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py b/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py index d46123e337c8..154f8b629dcc 100644 --- a/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py +++ b/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py @@ -642,7 +642,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod self.run_process_then_stop(run_seconds=1) # Wait at most x seconds for 3 threads to be present. - threads = self.wait_for_thread_count(3, timeout_seconds=self._WAIT_TIMEOUT) + threads = self.wait_for_thread_count(3) self.assertEqual(len(threads), 3) # verify we can $H to each thead, and $qC matches the thread we set. @@ -723,7 +723,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod # context = self.run_process_then_stop(run_seconds=1) # Wait at most x seconds for all threads to be present. - # threads = self.wait_for_thread_count(NUM_THREADS, timeout_seconds=5) + # threads = self.wait_for_thread_count(NUM_THREADS) # self.assertEquals(len(threads), NUM_THREADS) signaled_tids = {} @@ -739,7 +739,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod 2: "thread_id"}}], True) - context = self.expect_gdbremote_sequence(timeout_seconds=self._DEFAULT_TIMEOUT) + context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) signo = context.get("signo") self.assertEqual(int(signo, 16), segfault_signo) @@ -775,8 +775,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod True) # Run the sequence. - context = self.expect_gdbremote_sequence( - timeout_seconds=self._DEFAULT_TIMEOUT) + context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) # Ensure the stop signal is the signal we delivered. @@ -1491,7 +1490,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod self.assertIsNotNone(context) # Wait for 3 threads to be present. - threads = self.wait_for_thread_count(3, timeout_seconds=self._WAIT_TIMEOUT) + threads = self.wait_for_thread_count(3) self.assertEqual(len(threads), 3) expected_reg_values = [] diff --git a/lldb/test/API/tools/lldb-server/commandline/TestStubReverseConnect.py b/lldb/test/API/tools/lldb-server/commandline/TestStubReverseConnect.py index 664b6001d8da..a3250ab4f1bf 100644 --- a/lldb/test/API/tools/lldb-server/commandline/TestStubReverseConnect.py +++ b/lldb/test/API/tools/lldb-server/commandline/TestStubReverseConnect.py @@ -14,8 +14,6 @@ class TestStubReverseConnect(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) - _DEFAULT_TIMEOUT = 20 * (10 if ('ASAN_OPTIONS' in os.environ) else 1) - def setUp(self): # Set up the test. gdbremote_testcase.GdbRemoteTestCaseBase.setUp(self) @@ -25,11 +23,11 @@ class TestStubReverseConnect(gdbremote_testcase.GdbRemoteTestCaseBase): self.assertIsNotNone(self.listener_socket) self.listener_port = self.listener_socket.getsockname()[1] - def create_listener_socket(self, timeout_seconds=_DEFAULT_TIMEOUT): + def create_listener_socket(self): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.assertIsNotNone(sock) - sock.settimeout(timeout_seconds) + sock.settimeout(self.DEFAULT_TIMEOUT) sock.bind(("127.0.0.1", 0)) sock.listen(1) @@ -77,7 +75,7 @@ class TestStubReverseConnect(gdbremote_testcase.GdbRemoteTestCaseBase): address, stub_socket.getsockname())) # Verify we can do the handshake. If that works, we'll call it good. - self.do_handshake(stub_socket, timeout_seconds=self._DEFAULT_TIMEOUT) + self.do_handshake(stub_socket) # Clean up. stub_socket.shutdown(socket.SHUT_RDWR)