Source-Changes-HG archive

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

[src/trunk]: src/tests/net Share httpd start/stop code



details:   https://anonhg.NetBSD.org/src/rev/99524f5b134c
branches:  trunk
changeset: 819256:99524f5b134c
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Nov 24 11:54:57 2016 +0000

description:
Share httpd start/stop code

diffstat:

 tests/net/net/t_forwarding.sh |  48 ++++++++++++++----------------------------
 tests/net/net/t_mtudisc.sh    |  28 ++++++++-----------------
 tests/net/net/t_mtudisc6.sh   |  28 ++++++++-----------------
 tests/net/net_common.sh       |  30 +++++++++++++++++++++++++-
 4 files changed, 63 insertions(+), 71 deletions(-)

diffs (295 lines):

diff -r b686e93b734b -r 99524f5b134c tests/net/net/t_forwarding.sh
--- a/tests/net/net/t_forwarding.sh     Thu Nov 24 11:34:51 2016 +0000
+++ b/tests/net/net/t_forwarding.sh     Thu Nov 24 11:54:57 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_forwarding.sh,v 1.16 2016/11/07 05:25:37 ozaki-r Exp $
+#      $NetBSD: t_forwarding.sh,v 1.17 2016/11/24 11:54:57 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -40,7 +40,6 @@
 IP6SRCGW=fc00:0:0:1::1
 IP6DSTGW=fc00:0:0:2::1
 IP6DST=fc00:0:0:2::2
-HTTPD_PID=httpd.pid
 HTML_FILE=index.html
 
 DEBUG=${DEBUG:-false}
@@ -166,20 +165,6 @@
        setup_forwarder ipv6
 }
 
-setup_bozo()
-{
-       local ip=$1
-
-       export RUMP_SERVER=$SOCKDST
-
-       touch $HTML_FILE
-       # start bozo in daemon mode
-       atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
-           /usr/libexec/httpd -P $HTTPD_PID -i $ip -b -s $(pwd)
-
-       $DEBUG && rump.netstat -a
-}
-
 test_http_get()
 {
        local ip=$1
@@ -314,16 +299,6 @@
        env RUMP_SERVER=$SOCKDST rump.halt
 }
 
-cleanup_bozo()
-{
-
-       if [ -f $HTTPD_PID ]; then
-               kill -9 "$(cat $HTTPD_PID)"
-               rm -f $HTTPD_PID
-       fi
-       rm -f $HTML_FILE
-}
-
 dump()
 {
        env RUMP_SERVER=$SOCKSRC rump.netstat -nr
@@ -481,7 +456,10 @@
        setup_forwarding
        test_setup_forwarding
 
-       setup_bozo $IP4DST
+       touch $HTML_FILE
+       start_httpd $SOCKDST $IP4DST
+       $DEBUG && rump.netstat -a
+
        test_http_get $IP4DST
 
        teardown_interfaces
@@ -495,7 +473,10 @@
        setup_forwarding6
        test_setup_forwarding6
 
-       setup_bozo $IP6DST
+       touch $HTML_FILE
+       start_httpd $SOCKDST $IP6DST
+       $DEBUG && rump.netstat -a
+
        test_http_get "[$IP6DST]"
 
        teardown_interfaces
@@ -513,7 +494,10 @@
 
        test_directed_broadcast
 
-       setup_bozo $IP4DST
+       touch $HTML_FILE
+       start_httpd $SOCKDST $IP4DST
+       $DEBUG && rump.netstat -a
+
        test_sysctl_ttl $IP4DST
 
        teardown_interfaces
@@ -535,21 +519,21 @@
 ipforwarding_fastforward_v4_cleanup()
 {
        dump
-       cleanup_bozo
+       stop_httpd
        cleanup
 }
 
 ipforwarding_fastforward_v6_cleanup()
 {
        dump
-       cleanup_bozo
+       stop_httpd
        cleanup
 }
 
 ipforwarding_misc_cleanup()
 {
        dump
-       cleanup_bozo
+       stop_httpd
        cleanup
 }
 
diff -r b686e93b734b -r 99524f5b134c tests/net/net/t_mtudisc.sh
--- a/tests/net/net/t_mtudisc.sh        Thu Nov 24 11:34:51 2016 +0000
+++ b/tests/net/net/t_mtudisc.sh        Thu Nov 24 11:54:57 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_mtudisc.sh,v 1.5 2016/11/24 09:03:53 ozaki-r Exp $
+#      $NetBSD: t_mtudisc.sh,v 1.6 2016/11/24 11:54:57 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -32,7 +32,6 @@
 SOCKLOCAL=unix://commsock1
 SOCKGATEWAY=unix://commsock2
 SOCKREMOTE=unix://commsock3
-HTTPD_PID=httpd.pid
 HTML_FILE=index.html
 
 DEBUG=${DEBUG:-false}
@@ -63,27 +62,16 @@
        $DEBUG && rump.ifconfig $if
 }
 
-setup_httpd()
+prepare_download_file()
 {
-       local sock=$1
-       local ip=$2
+       local file=$1
        local data="0123456789"
 
-       export RUMP_SERVER=$sock
-
-       touch $HTML_FILE
+       touch $file
        for i in `seq 1 512`
        do
-               echo $data >> $HTML_FILE
+               echo $data >> $file
        done
-
-       # start httpd in daemon mode
-       atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
-           /usr/libexec/httpd -P $HTTPD_PID -i $ip -b -s $(pwd)
-
-       $DEBUG && rump.netstat -a
-
-       sleep 5
 }
 
 do_http_get()
@@ -141,7 +129,9 @@
        atf_check -s exit:0 -o match:"1" rump.sysctl -n net.inet.ip.mtudisc
 
        # Start httpd daemon
-       setup_httpd $SOCKREMOTE $remote_ip
+       prepare_download_file $HTML_FILE
+       start_httpd $SOCKREMOTE $remote_ip
+       $DEBUG && rump.netstat -a
 
        # 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
@@ -224,7 +214,7 @@
 mtudisc_basic_cleanup()
 {
        $DEBUG && dump
-       kill "$(cat ${HTTPD_PID})"
+       stop_httpd
        env RUMP_SERVER=$SOCKLOCAL rump.halt
        env RUMP_SERVER=$SOCKGATEWAY rump.halt
        env RUMP_SERVER=$SOCKREMOTE rump.halt
diff -r b686e93b734b -r 99524f5b134c tests/net/net/t_mtudisc6.sh
--- a/tests/net/net/t_mtudisc6.sh       Thu Nov 24 11:34:51 2016 +0000
+++ b/tests/net/net/t_mtudisc6.sh       Thu Nov 24 11:54:57 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_mtudisc6.sh,v 1.3 2016/11/24 09:03:53 ozaki-r Exp $
+#      $NetBSD: t_mtudisc6.sh,v 1.4 2016/11/24 11:54:57 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -32,7 +32,6 @@
 SOCKLOCAL=unix://commsock1
 SOCKGATEWAY=unix://commsock2
 SOCKREMOTE=unix://commsock3
-HTTPD_PID=httpd.pid
 HTML_FILE=index.html
 
 DEBUG=${DEBUG:-false}
@@ -64,27 +63,16 @@
        $DEBUG && rump.ifconfig $if
 }
 
-setup_httpd()
+prepare_download_file()
 {
-       local sock=$1
-       local ip=$2
+       local file=$1
        local data="0123456789"
 
-       export RUMP_SERVER=$sock
-
-       touch $HTML_FILE
+       touch $file
        for i in `seq 1 512`
        do
-               echo $data >> $HTML_FILE
+               echo $data >> $file
        done
-
-       # start httpd in daemon mode
-       atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
-           /usr/libexec/httpd -P $HTTPD_PID -i $ip -b -s $(pwd)
-
-       $DEBUG && rump.netstat -a
-
-       sleep 5
 }
 
 do_http_get()
@@ -139,7 +127,9 @@
        export RUMP_SERVER=$SOCKREMOTE
 
        # Start httpd daemon
-       setup_httpd $SOCKREMOTE $remote_ip
+       prepare_download_file $HTML_FILE
+       start_httpd $SOCKREMOTE $remote_ip
+       $DEBUG && rump.netstat -a
 
        # Teach the peer that local serer is behind gateway server
        atf_check -s exit:0 -o ignore \
@@ -202,7 +192,7 @@
 {
 
        $DEBUG && dump
-       kill "$(cat ${HTTPD_PID})"
+       stop_httpd
        env RUMP_SERVER=$SOCKLOCAL rump.halt
        env RUMP_SERVER=$SOCKGATEWAY rump.halt
        env RUMP_SERVER=$SOCKREMOTE rump.halt
diff -r b686e93b734b -r 99524f5b134c tests/net/net_common.sh
--- a/tests/net/net_common.sh   Thu Nov 24 11:34:51 2016 +0000
+++ b/tests/net/net_common.sh   Thu Nov 24 11:54:57 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: net_common.sh,v 1.5 2016/11/24 09:07:09 ozaki-r Exp $
+#      $NetBSD: net_common.sh,v 1.6 2016/11/24 11:54:57 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -103,3 +103,31 @@
        env RUMP_SERVER=${1} \
            rump.ifconfig ${2} |awk '/address/ {print $2;}'
 }
+
+HTTPD_PID=./.__httpd.pid
+start_httpd()
+{
+       local sock=$1
+       local ip=$2
+       local backup=$RUMP_SERVER
+
+       export RUMP_SERVER=$sock
+
+       # start httpd in daemon mode
+       atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
+           /usr/libexec/httpd -P $HTTPD_PID -i $ip -b -s $(pwd)
+
+       export RUMP_SERVER=$backup
+
+       sleep 3
+}
+
+stop_httpd()
+{
+
+       if [ -f $HTTPD_PID ]; then
+               kill -9 $(cat $HTTPD_PID)
+               rm -f $HTTPD_PID
+               sleep 1
+       fi
+}



Home | Main Index | Thread Index | Old Index