[gdb/testsuite] Use unique portnum in parallel testing
commite82dca2a57b05a95d45be74cb59046c79c9ed7d3
authorTom de Vries <tdevries@suse.de>
Sat, 4 May 2024 08:41:09 +0000 (4 10:41 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 4 May 2024 08:41:09 +0000 (4 10:41 +0200)
tree5e56a35e197c7174e5609ed2a06a27c82e5c30b7
parenta0a6e110198c4f7fb4b5baa1f8d158ebf225f7e2
[gdb/testsuite] Use unique portnum in parallel testing

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.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/testsuite/lib/gdbserver-support.exp