Source-Changes-HG archive

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

[src/trunk]: src/tests/net Reduce duplicate codes



details:   https://anonhg.NetBSD.org/src/rev/f5c4f3e847a1
branches:  trunk
changeset: 349108:f5c4f3e847a1
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Nov 24 08:52:19 2016 +0000

description:
Reduce duplicate codes

Introduce net_common.sh that is to share common functions used in tests
for networking. This commit commonizes extract_new_packets. Other duplicate
codes will be moved to the file in further commits.

diffstat:

 tests/net/arp/Makefile        |   8 ++++--
 tests/net/arp/t_arp.sh        |  29 ++++++--------------------
 tests/net/arp/t_dad.sh        |  17 +--------------
 tests/net/ndp/Makefile        |   9 ++++---
 tests/net/ndp/t_dad.sh        |  27 +++++-------------------
 tests/net/ndp/t_ndp.sh        |  23 +++-----------------
 tests/net/net/Makefile        |  15 ++++++-------
 tests/net/net/t_mtudisc.sh    |  18 +---------------
 tests/net/net/t_mtudisc6.sh   |  18 +---------------
 tests/net/net/t_ping6_opts.sh |  18 +---------------
 tests/net/net_common.sh       |  47 +++++++++++++++++++++++++++++++++++++++++++
 11 files changed, 85 insertions(+), 144 deletions(-)

diffs (truncated from 466 to 300 lines):

diff -r cdadde3752d2 -r f5c4f3e847a1 tests/net/arp/Makefile
--- a/tests/net/arp/Makefile    Thu Nov 24 08:41:20 2016 +0000
+++ b/tests/net/arp/Makefile    Thu Nov 24 08:52:19 2016 +0000
@@ -1,11 +1,13 @@
-# $NetBSD: Makefile,v 1.3 2015/07/30 05:43:42 ozaki-r Exp $
+# $NetBSD: Makefile,v 1.4 2016/11/24 08:52:19 ozaki-r Exp $
 #
 
 .include <bsd.own.mk>
 
 TESTSDIR=      ${TESTSBASE}/net/arp
 
-TESTS_SH=      t_arp
-TESTS_SH+=     t_dad
+.for name in arp dad
+TESTS_SH+=             t_${name}
+TESTS_SH_SRC_t_${name}=        ../net_common.sh t_${name}.sh
+.endfor
 
 .include <bsd.test.mk>
diff -r cdadde3752d2 -r f5c4f3e847a1 tests/net/arp/t_arp.sh
--- a/tests/net/arp/t_arp.sh    Thu Nov 24 08:41:20 2016 +0000
+++ b/tests/net/arp/t_arp.sh    Thu Nov 24 08:52:19 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_arp.sh,v 1.18 2016/11/07 05:25:36 ozaki-r Exp $
+#      $NetBSD: t_arp.sh,v 1.19 2016/11/24 08:52:19 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -363,21 +363,6 @@
        echo $pkt
 }
 
-extract_new_packets()
-{
-       local old=./old
-
-       if [ ! -f $old ]; then
-               old=/dev/null
-       fi
-
-       shmif_dumpbus -p - bus1 2>/dev/null| \
-           tcpdump -n -e -r - 2>/dev/null > ./new
-       diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
-       mv -f ./new ./old
-       cat ./diff
-}
-
 test_proxy_arp()
 {
        local arp_keep=5
@@ -416,7 +401,7 @@
            rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
 
        # Flushing
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
 
        # Set up proxy ARP entry
        export RUMP_SERVER=$SOCKDST
@@ -435,7 +420,7 @@
                    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
        fi
 
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
        $DEBUG && cat ./out
 
        pkt1=$(make_pkt_str_arprep $IP4DST_PROXYARP1 $macaddr_dst)
@@ -461,7 +446,7 @@
        atf_check -s not-exit:0 -o ignore -e ignore \
            rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
 
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
        $DEBUG && cat ./out
 
        # ARP reply should be sent
@@ -502,7 +487,7 @@
        setup_src_server $arp_keep
 
        # flush old packets
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
 
        export RUMP_SERVER=$SOCKSRC
 
@@ -510,7 +495,7 @@
            b2:a1:00:00:00:01
 
        atf_check -s exit:0 sleep 1
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
        $DEBUG && cat ./out
 
        pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
@@ -520,7 +505,7 @@
            b2:a1:00:00:00:02 active
 
        atf_check -s exit:0 sleep 1
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
        $DEBUG && cat ./out
 
        pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
diff -r cdadde3752d2 -r f5c4f3e847a1 tests/net/arp/t_dad.sh
--- a/tests/net/arp/t_dad.sh    Thu Nov 24 08:41:20 2016 +0000
+++ b/tests/net/arp/t_dad.sh    Thu Nov 24 08:52:19 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_dad.sh,v 1.9 2016/11/07 05:25:36 ozaki-r Exp $
+#      $NetBSD: t_dad.sh,v 1.10 2016/11/24 08:52:19 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -74,21 +74,6 @@
        echo $pkt
 }
 
-extract_new_packets()
-{
-       local old=./old
-
-       if [ ! -f $old ]; then
-               old=/dev/null
-       fi
-
-       shmif_dumpbus -p - bus1 2>/dev/null| \
-           tcpdump -n -e -r - 2>/dev/null > ./new
-       diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
-       mv -f ./new ./old
-       cat ./diff
-}
-
 dad_basic_body()
 {
        local pkt=
diff -r cdadde3752d2 -r f5c4f3e847a1 tests/net/ndp/Makefile
--- a/tests/net/ndp/Makefile    Thu Nov 24 08:41:20 2016 +0000
+++ b/tests/net/ndp/Makefile    Thu Nov 24 08:52:19 2016 +0000
@@ -1,12 +1,13 @@
-# $NetBSD: Makefile,v 1.2 2015/11/11 07:52:57 ozaki-r Exp $
+# $NetBSD: Makefile,v 1.3 2016/11/24 08:52:20 ozaki-r Exp $
 #
 
 .include <bsd.own.mk>
 
 TESTSDIR=      ${TESTSBASE}/net/ndp
 
-TESTS_SH=      t_dad
-TESTS_SH+=     t_ndp
-TESTS_SH+=     t_ra
+.for name in dad ndp ra
+TESTS_SH+=             t_${name}
+TESTS_SH_SRC_t_${name}=        ../net_common.sh t_${name}.sh
+.endfor
 
 .include <bsd.test.mk>
diff -r cdadde3752d2 -r f5c4f3e847a1 tests/net/ndp/t_dad.sh
--- a/tests/net/ndp/t_dad.sh    Thu Nov 24 08:41:20 2016 +0000
+++ b/tests/net/ndp/t_dad.sh    Thu Nov 24 08:52:19 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_dad.sh,v 1.9 2016/11/07 05:25:37 ozaki-r Exp $
+#      $NetBSD: t_dad.sh,v 1.10 2016/11/24 08:52:20 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -85,21 +85,6 @@
        echo $pkt
 }
 
-extract_new_packets()
-{
-       local old=./old
-
-       if [ ! -f $old ]; then
-               old=/dev/null
-       fi
-
-       shmif_dumpbus -p - bus1 2>/dev/null| \
-           tcpdump -n -e -r - 2>/dev/null > ./new
-       diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
-       mv -f ./new ./old
-       cat ./diff
-}
-
 dad_basic_body()
 {
        local pkt=
@@ -127,7 +112,7 @@
        #atf_check -s exit:0 -x "cat ./out |grep $localip2 |grep -q tentative"
 
        atf_check -s exit:0 sleep 2
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
        $DEBUG && cat ./out
 
        # Check DAD probe packets (Neighbor Solicitation Message)
@@ -139,7 +124,7 @@
 
        # Waiting for DAD complete
        atf_check -s exit:0 rump.ifconfig -w 10
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
        $DEBUG && cat ./out
 
        # IPv6 DAD doesn't announce (Neighbor Advertisement Message)
@@ -158,14 +143,14 @@
 
        # Check DAD probe packets (Neighbor Solicitation Message)
        atf_check -s exit:0 sleep 2
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
        $DEBUG && cat ./out
        pkt=$(make_ns_pkt_str 3 $localip3)
        atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
 
        # Waiting for DAD complete
        atf_check -s exit:0 rump.ifconfig -w 10
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
        $DEBUG && cat ./out
 
        # IPv6 DAD doesn't announce (Neighbor Advertisement Message)
@@ -229,7 +214,7 @@
 
        # Check the number of DAD probe packets (Neighbor Solicitation Message)
        atf_check -s exit:0 sleep 2
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
        $DEBUG && cat ./out
        pkt=$(make_ns_pkt_str $id $target)
        atf_check -s exit:0 -o match:"$count" \
diff -r cdadde3752d2 -r f5c4f3e847a1 tests/net/ndp/t_ndp.sh
--- a/tests/net/ndp/t_ndp.sh    Thu Nov 24 08:41:20 2016 +0000
+++ b/tests/net/ndp/t_ndp.sh    Thu Nov 24 08:52:19 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_ndp.sh,v 1.14 2016/11/07 05:25:37 ozaki-r Exp $
+#      $NetBSD: t_ndp.sh,v 1.15 2016/11/24 08:52:20 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -324,21 +324,6 @@
        echo $pkt
 }
 
-extract_new_packets()
-{
-       local old=./old
-
-       if [ ! -f $old ]; then
-               old=/dev/null
-       fi
-
-       shmif_dumpbus -p - bus1 2>/dev/null| \
-           tcpdump -n -e -r - 2>/dev/null > ./new
-       diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
-       mv -f ./new ./old
-       cat ./diff
-}
-
 ndp_link_activation_body()
 {
        local linklocal=
@@ -350,7 +335,7 @@
        setup_src_server
 
        # flush old packets
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
 
        export RUMP_SERVER=$SOCKSRC
 
@@ -358,7 +343,7 @@
            b2:a1:00:00:00:01
 
        atf_check -s exit:0 sleep 1
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
        $DEBUG && cat ./out
 
        linklocal=$(rump.ifconfig shmif0 |awk '/fe80/ {print $2;}' |awk -F % '{print $1;}')
@@ -371,7 +356,7 @@
            b2:a1:00:00:00:02 active
 
        atf_check -s exit:0 sleep 1
-       extract_new_packets > ./out
+       extract_new_packets bus1 > ./out
        $DEBUG && cat ./out
 
        linklocal=$(rump.ifconfig shmif0 |awk '/fe80/ {print $2;}' |awk -F % '{print $1;}')
diff -r cdadde3752d2 -r f5c4f3e847a1 tests/net/net/Makefile
--- a/tests/net/net/Makefile    Thu Nov 24 08:41:20 2016 +0000
+++ b/tests/net/net/Makefile    Thu Nov 24 08:52:19 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.18 2016/11/07 00:54:48 ozaki-r Exp $
+# $NetBSD: Makefile,v 1.19 2016/11/24 08:52:20 ozaki-r Exp $
 #
 
 .include <bsd.own.mk>
@@ -11,13 +11,12 @@



Home | Main Index | Thread Index | Old Index