[Lldb-commits] [lldb] 0fbbf3a - [lldb] Unify sleep and time outs in GDB remote testcases

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Jul 17 11:03:24 PDT 2020


Author: Jonas Devlieghere
Date: 2020-07-17T11:03:16-07:00
New Revision: 0fbbf3a98ca6fc75aafb6405943ee00e7c4d5594

URL: https://github.com/llvm/llvm-project/commit/0fbbf3a98ca6fc75aafb6405943ee00e7c4d5594
DIFF: https://github.com/llvm/llvm-project/commit/0fbbf3a98ca6fc75aafb6405943ee00e7c4d5594.diff

LOG: [lldb] Unify sleep and time outs in GDB remote testcases

Reduce sleep and time outs in GDB remote testcases to one default value
for each. Stop passing these values around and always use the default
instead.

Differential revision: https://reviews.llvm.org/D83904

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
    lldb/test/API/tools/lldb-server/TestGdbRemoteKill.py
    lldb/test/API/tools/lldb-server/TestGdbRemoteProcessInfo.py
    lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
    lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py
    lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
    lldb/test/API/tools/lldb-server/commandline/TestStubReverseConnect.py

Removed: 
    


################################################################################
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 @@ def shutdown_named_pipe():
 
         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 @@ def launch_debug_monitor(self, attach_pid=None, logfile=None):
         # 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 @@ def prep_debug_monitor_and_inferior(
     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 @@ def expect_socket_recv(
 
         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 @@ def do_handshake(self, stub_socket, timeout_seconds=None):
 
         # 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 @@ def parse_register_info_packets(self, context):
         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 @@ def parse_threadinfo_packets(self, context):
             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 @@ def wait_for_thread_count(self, thread_count, timeout_seconds=None):
             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 @@ def attach_commandline_kill_after_initial_stop(self):
 
         # 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 @@ def attach_commandline_qProcessInfo_reports_correct_pid(self):
         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 @@ def gather_stop_reply_fields(self, post_startup_log_lines, thread_count,
         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 @@ def gather_stop_reply_fields(self, post_startup_log_lines, thread_count,
         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 @@ def gather_stop_replies_via_qThreadStopInfo(self, thread_count):
         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 @@ def gather_stop_replies_via_qThreadStopInfo(self, thread_count):
         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 @@ def Hg_switches_to_3_threads(self):
         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 @@ def Hc_then_Csignal_signals_correct_thread(self, segfault_signo):
         # 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 @@ def Hc_then_Csignal_signals_correct_thread(self, segfault_signo):
                                                             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 @@ def Hc_then_Csignal_signals_correct_thread(self, segfault_signo):
                 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 @@ def P_and_p_thread_suffix_work(self):
         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 @@ def setUp(self):
         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 @@ def reverse_connect_works(self):
             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)


        


More information about the lldb-commits mailing list