Files
binutils-gdb/gdb/testsuite/gdb.server/server-connect.exp
Tom de Vries 886d73049c [gdb/testsuite] Fix gdb.server/server-connect.exp for missing ipv6
On a system without ipv6 support enabled, when running test-case
gdb.server/server-connect.exp, it takes about 4 minutes, and I get:
...
builtin_spawn gdbserver --once ::1:2347 server-connect^M
Can't open socket: Address family not supported by protocol.^M
Exiting^M
PASS: gdb.server/server-connect.exp: tcp6: start gdbserver
target remote tcp6:::1:2347^M
A program is being debugged already.  Kill it? (y or n) y^M
could not connect: Address family not supported by protocol.^M
(gdb) FAIL: gdb.server/server-connect.exp: tcp6: connect to gdbserver using tcp6:::1
...

Fix this by:
- recognizing the error message in gdbserver_start, and returning an empty list
  to signal unsupported, and
- handling the unsupported response in the test-case.

This brings testing time down to 2 seconds, and gets me:
...
UNSUPPORTED: gdb.server/server-connect.exp: tcp6: start gdbserver
UNSUPPORTED: gdb.server/server-connect.exp: tcp6-with-brackets: start gdbserver
UNSUPPORTED: gdb.server/server-connect.exp: udp6: start gdbserver
UNSUPPORTED: gdb.server/server-connect.exp: udp6-with-brackets: start gdbserver
...

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>

PR testsuite/31502
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31502
2024-03-20 19:31:24 +01:00

114 lines
3.4 KiB
Plaintext

# This testcase is part of GDB, the GNU debugger.
#
# Copyright 2018-2024 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Test multiple types of connection (IPv4, IPv6, TCP, UDP) and make
# sure both gdbserver and GDB work.
load_lib gdbserver-support.exp
standard_testfile normal.c
require allow_gdbserver_tests
# We want to have control over where we start gdbserver.
require {!is_remote target}
if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } {
return -1
}
# Make sure we're disconnected, in case we're testing with an
# extended-remote board, therefore already connected.
gdb_test "disconnect" ".*"
set target_exec [gdbserver_download_current_prog]
# An array containing the test instructions for each scenario. The
# description of each field is as follows:
#
# - The connection specification to be used when starting
# gdbserver/GDB. This string will be used to set the
# GDB_TEST_SOCKETHOST when calling gdbserver_start.
#
# - A flag indicating whether gdbserver should fail when we attempt to
# start it. Useful when testing erroneous connection specs such as
# "tcp8:".
#
# - The prefix that should be prepended to the test messages.
set test_params \
{ \
{ "tcp4:127.0.0.1" 0 "tcp4" } \
{ "tcp6:::1" 0 "tcp6" } \
{ "tcp6:[::1]" 0 "tcp6-with-brackets" } \
{ "tcp:localhost" 0 "tcp" } \
{ "udp4:127.0.0.1" 0 "udp4" } \
{ "udp6:::1" 0 "udp6" } \
{ "udp6:[::1]" 0 "udp6-with-brackets" } \
{ "tcp8:123" 1 "tcp8" } \
{ "udp123:::" 1 "udp123" } \
{ "garbage:1234" 1 "garbage:1234" } \
}
# The best way to test different types of connections is to set the
# GDB_TEST_SOCKETHOST variable accordingly.
save_vars { GDB_TEST_SOCKETHOST } {
foreach line $test_params {
set sockhost [lindex $line 0]
set gdbserver_should_fail [lindex $line 1]
set prefix [lindex $line 2]
with_test_prefix $prefix {
set GDB_TEST_SOCKETHOST $sockhost
set test "start gdbserver"
# Try to start gdbserver.
set catchres [catch {set res [gdbserver_start "" $target_exec]} errmsg]
if { $catchres != 0 } {
if { $gdbserver_should_fail } {
pass "$test: gdbserver failed as expected"
} else {
fail "$test: $errmsg"
}
continue
} else {
if { $gdbserver_should_fail } {
fail "$test: gdbserver should fail but did not"
} elseif { [llength $res] == 0 } {
unsupported $test
continue
} else {
pass "$test"
}
}
set gdbserver_protocol [lindex $res 0]
set gdbserver_gdbport [lindex $res 1]
set test "connect to gdbserver using $sockhost"
set res [gdb_target_cmd_ext $gdbserver_protocol $gdbserver_gdbport]
if { $res == 0 } {
pass $test
} elseif { $res == 1 } {
fail $test
} else {
unsupported $test
}
}
}
}