Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/net Use nc instead of ftp/httpd



details:   https://anonhg.NetBSD.org/src/rev/2d5d04134142
branches:  trunk
changeset: 351494:2d5d04134142
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Feb 16 08:12:47 2017 +0000

description:
Use nc instead of ftp/httpd

ftp with rumphijack is unstable probably because ftp uses siglongjmp from
a signal hander. So stop using ftp and use nc instead. This fixes test
failures of t_mtudisc on some environments such as my development machine
(amd64) and anita on sparc64.

diffstat:

 tests/net/net/t_mtudisc.sh |  86 +++++++++++++++++++++------------------------
 tests/net/net_common.sh    |  38 +++++++++++++++++++-
 2 files changed, 76 insertions(+), 48 deletions(-)

diffs (242 lines):

diff -r cc9c1734bdd0 -r 2d5d04134142 tests/net/net/t_mtudisc.sh
--- a/tests/net/net/t_mtudisc.sh        Thu Feb 16 08:12:43 2017 +0000
+++ b/tests/net/net/t_mtudisc.sh        Thu Feb 16 08:12:47 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_mtudisc.sh,v 1.8 2016/12/21 01:16:18 ozaki-r Exp $
+#      $NetBSD: t_mtudisc.sh,v 1.9 2017/02/16 08:12:47 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -28,7 +28,6 @@
 SOCKLOCAL=unix://commsock1
 SOCKGATEWAY=unix://commsock2
 SOCKREMOTE=unix://commsock3
-HTML_FILE=index.html
 
 DEBUG=${DEBUG:-false}
 
@@ -37,7 +36,7 @@
 mtudisc_basic_head()
 {
        atf_set "descr" "Tests for IPv4 Path MTU Dicorvery basic behavior"
-       atf_set "require.progs" "rump_server"
+       atf_set "require.progs" "rump_server nc"
 }
 
 setup_server()
@@ -57,7 +56,7 @@
        $DEBUG && rump.ifconfig $if
 }
 
-prepare_download_file()
+prepare_file()
 {
        local file=$1
        local data="0123456789"
@@ -69,17 +68,6 @@
        done
 }
 
-do_http_get()
-{
-       local ip=$1
-       local ret=$2
-       local timeout=5
-
-       # get the webpage
-       atf_check -s exit:$ret env LD_PRELOAD=/usr/lib/librumphijack.so \
-           ftp -q $timeout -o ./out http://$ip/$HTML_FILE
-}
-
 mtudisc_basic_body()
 {
        local pkt=
@@ -88,6 +76,10 @@
        local gateway_remote_ip=10.0.1.1
        local remote_ip=10.0.1.2
        local prefixlen=24
+       local port=1234
+       local pid=
+       local file_send=./file.send
+       local file_recv=./file.recv
 
        rump_server_start $SOCKLOCAL
        rump_server_start $SOCKGATEWAY
@@ -96,9 +88,9 @@
        #
        # Setup servers
        #
-       # [local server]                 [gateway server]          [remote server with httpd]
+       # [local server]                 [gateway server]          [remote server]
        #       | 10.0.0.2        10.0.0.1 |          | 10.0.1.1       10.0.1.2 |
-       # shmif0(mtu=1500) ----- shmif1(mtu=1280)   shmif0(mtu=1500) ----- shmif0(mtu=1500)
+       # shmif0(mtu=1500) ----- shmif0(mtu=1500)   shmif1(mtu=1280) ----- shmif0(mtu=1500)
        #
 
        # Assign IP addresses
@@ -111,8 +103,7 @@
        export RUMP_SERVER=$SOCKGATEWAY
 
        # Set mtu of shmif0 to 1280
-       export RUMP_SERVER=$SOCKGATEWAY
-       atf_check -s exit:0 rump.ifconfig shmif0 mtu 1280
+       atf_check -s exit:0 rump.ifconfig shmif1 mtu 1280
 
        # Enable IPv4 forwarding
        atf_check -s exit:0 rump.sysctl -w -q net.inet.ip.forwarding=1
@@ -123,58 +114,61 @@
        # Check default value
        atf_check -s exit:0 -o match:"1" rump.sysctl -n net.inet.ip.mtudisc
 
-       # Start httpd daemon
-       prepare_download_file $HTML_FILE
-       start_httpd $SOCKREMOTE $remote_ip
-       $DEBUG && rump.netstat -a -f inet
+       # Teach the peer thar 10.0.0.2(local server) is behind 10.0.1.1(gateway server)
+       atf_check -s exit:0 -o ignore rump.route add $local_ip/32 $gateway_remote_ip
 
-       # Teach the peer thar 10.0.0.2(local serer) is behind 10.0.1.1(gateway server)
-       atf_check -s exit:0 -o ignore rump.route add $local_ip/32 $gateway_remote_ip
+       # Don't accept fragmented packets
+       atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet.ip.maxfragpackets=0
 
        ### Setup local server
        export RUMP_SERVER=$SOCKLOCAL
 
-       # Teach the peer thar 10.0.1.2(remote serer) is behind 10.0.0.1(gateway server)
+       # Teach the peer thar 10.0.1.2(remote server) is behind 10.0.0.1(gateway server)
        atf_check -s exit:0 -o ignore rump.route add $remote_ip/32 $gateway_local_ip
 
-       # Don't accept fragmented packets
-       atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet.ip.maxfragpackets=0
-
        #
        # Test disabled path mtu discorvery
        #
-       export RUMP_SERVER=$SOCKREMOTE
+       prepare_file $file_send
+
+       # Start nc server
+       start_nc_server $SOCKREMOTE $port $file_recv
+
+       export RUMP_SERVER=$SOCKLOCAL
        atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet.ip.mtudisc=0
 
-       # Get the webpage (expect: failed)
-       export RUMP_SERVER=$SOCKLOCAL
-       do_http_get $remote_ip 1
+       # Send a file to the server
+       atf_check -s exit:0 $HIJACKING nc -N -w 3 $remote_ip $port < $file_send
        $DEBUG && extract_new_packets bus2 > ./out
        $DEBUG && cat ./out
+       stop_nc_server
+       atf_check -s not-exit:0 -o match:"differ" diff -q $file_send $file_recv
 
-       # Check path mtu size on remote server
-       export RUMP_SERVER=$SOCKREMOTE
+       # Check path mtu size on the local server
        atf_check -s exit:0 \
-               -o match:"^10.0.0.2 +10.0.1.1 +UGHS +- +- +- +shmif0" \
-               rump.netstat -nr -f inet
+           -o match:"^10.0.1.2 +10.0.0.1 +UGHS +- +- +- +shmif0" \
+           rump.netstat -nr -f inet
 
        #
        # Test enabled path mtu discorvery
        #
-       export RUMP_SERVER=$SOCKREMOTE
+       # Start nc server
+       start_nc_server $SOCKREMOTE $port $file_recv
+
+       export RUMP_SERVER=$SOCKLOCAL
        atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet.ip.mtudisc=1
 
-       # Get the webpage (expect: success)
-       export RUMP_SERVER=$SOCKLOCAL
-       do_http_get $remote_ip 0
+       # Send a file to the server
+       atf_check -s exit:0 $HIJACKING nc -N -w 3 $remote_ip $port < $file_send
        $DEBUG && extract_new_packets bus2 > ./out
        $DEBUG && cat ./out
+       stop_nc_server
+       atf_check -s exit:0 diff -q $file_send $file_recv
 
-       # Check path mtu size on remote server
-       export RUMP_SERVER=$SOCKREMOTE
+       # Check path mtu size on the local server
        atf_check -s exit:0 \
-               -o match:"^10.0.0.2 +10.0.1.1 +UGHS +- +- +1280 +shmif0" \
-               rump.netstat -nr -f inet
+           -o match:"^10.0.1.2 +10.0.0.1 +UGHS +- +- +1280 +shmif0" \
+           rump.netstat -nr -f inet
 
        rump_server_destroy_ifaces
 }
@@ -182,7 +176,7 @@
 mtudisc_basic_cleanup()
 {
        $DEBUG && dump
-       stop_httpd
+       stop_nc_server
        cleanup
 }
 
diff -r cc9c1734bdd0 -r 2d5d04134142 tests/net/net_common.sh
--- a/tests/net/net_common.sh   Thu Feb 16 08:12:43 2017 +0000
+++ b/tests/net/net_common.sh   Thu Feb 16 08:12:47 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: net_common.sh,v 1.11 2017/01/10 05:55:34 ozaki-r Exp $
+#      $NetBSD: net_common.sh,v 1.12 2017/02/16 08:12:47 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -29,7 +29,8 @@
 # Common utility functions for tests/net
 #
 
-HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
+HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so \
+    RUMPHIJACK=path=/rump,socket=all:nolocal,sysctl=yes"
 
 extract_new_packets()
 {
@@ -132,6 +133,39 @@
        fi
 }
 
+NC_PID=./.__nc.pid
+start_nc_server()
+{
+       local sock=$1
+       local port=$2
+       local outfile=$3
+       local backup=$RUMP_SERVER
+       local pid=
+
+       export RUMP_SERVER=$sock
+
+       env LD_PRELOAD=/usr/lib/librumphijack.so \
+           nc -l $port > $outfile &
+       pid=$!
+       echo $pid > $NC_PID
+
+       $DEBUG && rump.netstat -a -f inet
+
+       export RUMP_SERVER=$backup
+
+       sleep 1
+}
+
+stop_nc_server()
+{
+
+       if [ -f $NC_PID ]; then
+               kill -9 $(cat $NC_PID)
+               rm -f $NC_PID
+               sleep 1
+       fi
+}
+
 BASIC_LIBS="-lrumpnet -lrumpnet_net -lrumpnet_netinet \
     -lrumpnet_shmif -lrumpdev"
 FS_LIBS="$BASIC_LIBS -lrumpvfs -lrumpfs_ffs"



Home | Main Index | Thread Index | Old Index