I wanted to change this test so it tries connections on both IPv4 &
IPv6. Having it connect on both is the easy bit. Harder was making
it not fail on machines that don't have IPv6 stack (or IPv4 in some
rare cases). TBH I wasn't able to test this, but it seems like this
should work.
In the end we want to modify nbdkit so it can listen on only certain
interfaces, but that's a bit more complicated.
Rich.
Show replies by date
---
tests/Makefile.am | 4 ++--
tests/{test-ipv4.sh => test-ip.sh} | 34 ++++++++++++++++++++++------------
tests/test-socket-activation.c | 2 +-
3 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1e32cb6..ec33109 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -50,7 +50,7 @@ EXTRA_DIST = \
test-foreground.sh \
test-help.sh \
test-help-plugin.sh \
- test-ipv4.sh \
+ test-ip.sh \
test_ocaml_plugin.ml \
test-ocaml.c \
test-parallel-file.sh \
@@ -104,7 +104,7 @@ TESTS += \
test-captive.sh \
test-random-sock.sh \
test-tls.sh \
- test-ipv4.sh \
+ test-ip.sh \
test-socket-activation \
test-foreground.sh
diff --git a/tests/test-ipv4.sh b/tests/test-ip.sh
similarity index 76%
rename from tests/test-ipv4.sh
rename to tests/test-ip.sh
index 67a5281..756921c 100755
--- a/tests/test-ipv4.sh
+++ b/tests/test-ip.sh
@@ -1,6 +1,6 @@
#!/bin/bash -
# nbdkit
-# Copyright (C) 2016 Red Hat Inc.
+# Copyright (C) 2016-2018 Red Hat Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,10 +32,7 @@
# SUCH DAMAGE.
# Every other test uses a Unix domain socket. This tests nbdkit over
-# IPv4 localhost connections.
-#
-# XXX We should be able to test "just IPv6". However there is
-# currently no option to listen only on particular interfaces.
+# IPv4 and IPv6 localhost connections.
set -e
source ./functions.sh
@@ -49,6 +46,10 @@ if ! socat -h; then
echo "$0: 'socat' command not available"
exit 77
fi
+if ! ip -V; then
+ echo "$0: 'ip' command not available"
+ exit 77
+fi
# Find an unused port to listen on.
for port in `seq 49152 65535`; do
@@ -56,28 +57,37 @@ for port in `seq 49152 65535`; do
done
echo picked unused port $port
-nbdkit -P ipv4.pid -p $port example1
+# By default nbdkit will listen on all available interfaces, ie.
+# IPv4 and IPv6.
+nbdkit -P ip.pid -p $port example1
# We may have to wait a short time for the pid file to appear.
for i in `seq 1 10`; do
- if test -f ipv4.pid; then
+ if test -f ip.pid; then
break
fi
sleep 1
done
-if ! test -f ipv4.pid; then
+if ! test -f ip.pid; then
echo "$0: PID file was not created"
exit 1
fi
-pid="$(cat ipv4.pid)"
+pid="$(cat ip.pid)"
# Check the process exists.
kill -s 0 $pid
-# Check we can connect to the socket.
-socat TCP:localhost:$port STDIO </dev/null
+# Check we can connect to the socket over all loopback interfaces.
+ipv4_lo="$(ip -o -4 addr show scope host)"
+if test -n "$ipv4_lo"; then
+ socat TCP:localhost:$port STDIO </dev/null
+fi
+ipv6_lo="$(ip -o -6 addr show scope host)"
+if test -n "$ipv6_lo"; then
+ socat TCP6:localhost:$port STDIO </dev/null
+fi
# Kill the process.
kill $pid
-rm ipv4.pid
+rm ip.pid
diff --git a/tests/test-socket-activation.c b/tests/test-socket-activation.c
index 81bd79e..8b1a1f0 100644
--- a/tests/test-socket-activation.c
+++ b/tests/test-socket-activation.c
@@ -39,7 +39,7 @@
* from the test framework.
*
* It's *almost* possible to test this from a shell script
- * (cf. test-ipv4.sh) but as far as I can tell setting LISTEN_PID
+ * (cf. test-ip.sh) but as far as I can tell setting LISTEN_PID
* correctly is impossible from shell.
*/
--
2.13.2