From f5a574a9a992db3e74748de8e8a513a4efc92d0a Mon Sep 17 00:00:00 2001 From: Mats Erik Andersson Date: Sun, 31 Oct 2010 03:51:47 +0100 Subject: [PATCH 1/2] Improve the present test script. --- ChangeLog | 8 +++++++ tests/ping-localhost.sh | 24 +++++++++++++++++++- tests/tftp.sh | 47 ++++++++++++++++++++++++++++++++++------- tests/traceroute-localhost.sh | 19 ++++++++++++++- 4 files changed, 86 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 11e79f0..ed8141a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-10-31 Mats Erik Andersson + + Improve the three test scripts. + + * tests/tftp.sh: Make it robust and portable to GNU/Linux and BSD. + * tests/ping-localhost.sh: Test `ping' and `ping6'. Configurable targets. + * tests/traceroute-localhost.sh: Test UDP and ICMP. Configurable target. + 2010-10-30 Mats Erik Andersson * src/traceroute.c (trace_init): Change type of TTLP to `int'. diff --git a/tests/ping-localhost.sh b/tests/ping-localhost.sh index 35bf87c..94c7e5c 100755 --- a/tests/ping-localhost.sh +++ b/tests/ping-localhost.sh @@ -19,6 +19,12 @@ PING=${PING:-../ping/ping$EXEEXT} +TARGET=${TARGET:-127.0.0.1} + +PING6=${PING6:-../ping/ping6$EXEEXT} + +TARGET6=${TARGET6:-::1} + if [ $VERBOSE ]; then set -x $PING --version @@ -29,6 +35,20 @@ if [ `id -u` != 0 ]; then exit 77 fi -$PING -c 1 127.0.0.1; errno=$? +errno=0 + +$PING -c 1 $TARGET || errno=$? + +test $errno -eq 0 || echo "Failed at pinging $TARGET." >&2 + +errno2=0 + +# Host might not have been building with `IPV6=1'. +test -x $PING6 && $PING6 -c 1 $TARGET6 || errno2=$? + +test $errno2 -eq 0 || echo "Failed at pinging $TARGET6." >&2 + + +test $errno -eq 0 || exit $errno -exit $errno +exit $errno2 diff --git a/tests/tftp.sh b/tests/tftp.sh index 6b2dc80..f14f758 100755 --- a/tests/tftp.sh +++ b/tests/tftp.sh @@ -22,13 +22,15 @@ TFTP="${TFTP:-../src/tftp$EXEEXT}" TFTPD="${TFTPD:-$PWD/../src/tftpd$EXEEXT}" INETD="${INETD:-../src/inetd$EXEEXT}" -IFCONFIG="${IFCONFIG:-../ifconfig/ifconfig$EXEEXT}" +IFCONFIG="${IFCONFIG:-../ifconfig/ifconfig$EXEEXT --format=unix}" -PORT=7777 +AF=${AF:-inet} +PROTO=${PROTO:-udp} +PORT=${PORT:-7777} INETD_CONF="$PWD/inetd.conf.tmp" -ADDRESSES="`$IFCONFIG | grep 'inet addr:' | \ - sed -e's/inet addr:\([^ ]\+\)[[:blank:]].*$/\1/g'`" +ADDRESSES="`$IFCONFIG | sed -e "/$AF /!d" \ + -e "s/^.*$AF[[:blank:]]\([:.0-9]\{1,\}\)[[:blank:]].*$/\1/g"`" if [ "$VERBOSE" ]; then set -x @@ -37,17 +39,38 @@ if [ "$VERBOSE" ]; then "$INETD" --version fi +# Check that the port is still available +netstat -na | grep -q "^$PROTO .*$PORT " +if test $? -eq 0; then + echo "Desired port $PORT/$PROTO is already in use." + exit 1 +fi + # Create `inetd.conf'. Note: We want $TFTPD to be an absolute file # name because `inetd' chdirs to `/' in daemon mode; ditto for # $INETD_CONF. cat > "$INETD_CONF" <&2 + +# Wait somewhat for the service to settle +sleep 1 + +# Did `inetd' really succeed in establishing a listener? +netstat -na | grep "^$PROTO .*$PORT " +if test $? -ne 0; then + # No it did not + ps "$inetd_pid" >/dev/null 2>&1 && kill "$inetd_pid" + echo "Failed in starting correct Inetd instance." >&2 + exit 1 +fi + if [ -f /dev/urandom ]; then input="/dev/urandom" else @@ -56,7 +79,9 @@ fi rm -fr tftp-test tftp-test-file mkdir tftp-test && \ - dd if="$input" of="tftp-test/tftp-test-file" bs=1024 count=170 + dd if="$input" of="tftp-test/tftp-test-file" bs=1024 count=170 2>/dev/null + +echo "Looks into $ADDRESSES." for addr in $ADDRESSES; do echo "trying with address \`$addr'..." >&2 @@ -69,12 +94,18 @@ for addr in $ADDRESSES; do if [ "$result" -ne 0 ]; then # Failure. + test -z "$VERBOSE" || echo "Failed comparison for $addr." >&2 break + else + test -z "$VERBOSE" || echo "Successful comparison for $addr." >&2 fi done -kill "$inetd_pid" +ps "$inetd_pid" >/dev/null 2>&1 && kill "$inetd_pid" rm -rf tftp-test tftp-test-file "$INETD_CONF" +# Minimal clean up +echo + exit $result diff --git a/tests/traceroute-localhost.sh b/tests/traceroute-localhost.sh index 97d13dc..4a34158 100755 --- a/tests/traceroute-localhost.sh +++ b/tests/traceroute-localhost.sh @@ -19,6 +19,8 @@ TRACEROUTE=${TRACEROUTE:-../src/traceroute$EXEEXT} +TARGET=${TARGET:-127.0.0.1} + if [ $VERBOSE ]; then set -x $TRACEROUTE --version @@ -29,6 +31,19 @@ if [ `id -u` != 0 ]; then exit 77 fi -$TRACEROUTE 127.0.0.1; errno=$? +errno=0 + +$TRACEROUTE --type=udp $TARGET || errno=$? + +test $errno -eq 0 || echo "Failed at UDP tracing." >&2 + +errno2=0 + +$TRACEROUTE --type=icmp $TARGET || errno2=$? + +test $errno2 -eq 0 || echo "Failed at ICMP tracing." >&2 + + +test $errno -eq 0 || exit $errno -exit $errno +exit $errno2 -- 1.7.1