[PATCH v4 08/11] gdb, testsuite: handle async close in monitor-exit-quit.exp

Mohamed Bouhaouel <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
From: "Bouhaouel, Mohamed" <[email protected]>

With non-stop remote targets, the "Remote connection closed"
notification arrives asynchronously after "monitor exit" and may appear
while processing the quit command, causing test failures.

Fix by handling the async notification in both the monitor exit command
(for early delivery) and the quit sequence (for late delivery).

Reproducible when running gdb.server/monitor-exit-quit.exp, on
native-gdbserver or native-extended-gdbserver with target-non-stop
enabled.

export GDBFLAGS="-iex \"maint set target-non-stop on\""
make check TESTS="gdb.server/monitor-exit-quit.exp" \
    RUNTESTFLAGS="--target_board=native-gdbserver GDBFLAGS='$GDBFLAGS'"
---
 .../gdb.server/monitor-exit-quit.exp          | 21 ++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.server/monitor-exit-quit.exp b/gdb/testsuite/gdb.server/monitor-exit-quit.exp
index cb90169ef0c..46c11fe9462 100644
--- a/gdb/testsuite/gdb.server/monitor-exit-quit.exp
+++ b/gdb/testsuite/gdb.server/monitor-exit-quit.exp
@@ -49,12 +49,27 @@ set gdbserver_protocol [lindex $res 0]
 set gdbserver_gdbport [lindex $res 1]
 gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
 
-gdb_test_no_output "monitor exit"
-gdb_test_no_output "set confirm off"
+# With non-stop remote targets, the "Remote connection closed" notification is
+# delivered asynchronously and may appear while processing the monitor exit
+# command or shortly after (captured in the quit command later).  Handle the
+# early case here.
+set r_conn_closed "Remote connection closed"
+gdb_test_multiple "monitor exit" "monitor exit" {
+  -re -wrap "$r_conn_closed" {
+    pass "$gdb_test_name"
+  }
+  -re -wrap "" {
+    pass "$gdb_test_name"
+  }
+}
 
 set do_cleanup 1
 
-gdb_test_multiple "quit" "" {
+gdb_test_multiple "with confirm off -- quit" "" {
+    -re -wrap "$r_conn_closed" {
+	# Async "Remote connection closed" from monitor exit, delivered late.
+	exp_continue
+    }
     -re -wrap "" {
 	fail "$gdb_test_name (prompt)"
 	# Let default_gdb_exit do the cleanup.
-- 
2.43.0

Intel Deutschland GmbH

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 89 991 430, www.intel.de
Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell
Chairperson of the Supervisory Board: Nicole Lau
Registered Seat: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.