From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 6/7] [gdb/testsuite] Use unique portnum in parallel testing
Date: Mon, 15 Apr 2024 17:56:26 +0200 [thread overview]
Message-ID: <20240415155627.22108-6-tdevries@suse.de> (raw)
In-Reply-To: <20240415155627.22108-1-tdevries@suse.de>
When instrumenting get_portnum using:
...
puts "PORTNUM: $res"
...
and running:
...
$ cd build/gdb
$ make check-parallel -j2 TESTS=gdb.server/*.exp
...
we run into:
...
Running gdb.server/abspath.exp ...
PORTNUM: 2345
...
and:
...
Running gdb.server/bkpt-other-inferior.exp ...
PORTNUM: 2345
...
This is because the test-cases are run in independent runtest invocations.
Fix this by handling the parallel case in get_portnum using:
- a file $objdir/cache/portnum to keep the portnum variable, and
- a file $objdir/cache/portnum.lock to serialize access to it.
Tested on aarch64-linux.
---
gdb/testsuite/lib/gdbserver-support.exp | 47 ++++++++++++++++++++-----
1 file changed, 38 insertions(+), 9 deletions(-)
diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp
index 0f97ce9c0fd..41ad5e6cbfb 100644
--- a/gdb/testsuite/lib/gdbserver-support.exp
+++ b/gdb/testsuite/lib/gdbserver-support.exp
@@ -141,18 +141,47 @@ proc get_portnum {} {
# starting at $initial_portnum, to avoid conflicts with hung ports.
set initial_portnum 2345
- # Currently available port number.
- gdb_persistent_global portnum
+ if { ![info exists ::GDB_PARALLEL] } {
+ # Sequential case.
- # Initialize, if necessary.
- if { ![info exists portnum] } {
- set portnum $initial_portnum
+ # Currently available port number.
+ gdb_persistent_global portnum
+
+ # Initialize, if necessary.
+ if { ![info exists portnum] } {
+ set portnum $initial_portnum
+ }
+
+ # Return currently available port number, and update it.
+ set res $portnum
+ incr portnum
+ return $res
+ }
+
+ # Parallel case.
+ with_lock portnum.lock {
+ # Keep portnum file alongside the lock that guards it.
+ set portnum_file [lock_dir]/portnum
+
+ if { [file exists $portnum_file] } {
+ set fd [open $portnum_file r]
+ set portnum [read $fd]
+ close $fd
+
+ set portnum [string trim $portnum]
+ } else {
+ # Initialize.
+ set portnum $initial_portnum
+ }
+
+ set next_portnum [expr $portnum + 1]
+
+ set fd [open $portnum_file w]
+ puts $fd $next_portnum
+ close $fd
}
- # Return currently available port number, and update it.
- set res $portnum
- incr portnum
- return $res
+ return $portnum
}
# Locate the gdbserver binary. Returns "" if gdbserver could not be found.
--
2.35.3
next prev parent reply other threads:[~2024-04-15 15:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 15:56 [PATCH 1/7] [gdb/testsuite] Factor out proc get_portnum Tom de Vries
2024-04-15 15:56 ` [PATCH 2/7] [gdb/testsuite] Make portnum a persistent global Tom de Vries
2024-05-03 20:20 ` Tom Tromey
2024-04-15 15:56 ` [PATCH 3/7] [gdb/testsuite] Factor out proc with_lock Tom de Vries
2024-05-03 20:22 ` Tom Tromey
2024-04-15 15:56 ` [PATCH 4/7] [gdb/testsuite] Factor out proc lock_dir Tom de Vries
2024-05-03 20:23 ` Tom Tromey
2024-04-15 15:56 ` [PATCH 5/7] [gdb/testsuite] Move gpu-parallel.lock to cache dir Tom de Vries
2024-05-03 20:25 ` Tom Tromey
2024-04-15 15:56 ` Tom de Vries [this message]
2024-05-03 20:27 ` [PATCH 6/7] [gdb/testsuite] Use unique portnum in parallel testing Tom Tromey
2024-04-15 15:56 ` [PATCH 7/7] [gdb/testsuite] Use unique portnum in parallel testing (check//% case) Tom de Vries
2024-05-03 20:30 ` Tom Tromey
2024-05-04 7:48 ` Tom de Vries
2024-05-03 20:19 ` [PATCH 1/7] [gdb/testsuite] Factor out proc get_portnum Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240415155627.22108-6-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).