Module Name:    src
Committed By:   ozaki-r
Date:           Mon Sep  2 05:16:37 UTC 2024

Modified Files:
        src/tests/usr.bin: Makefile
Added Files:
        src/tests/usr.bin/shmif_pcapin: Makefile d_pcap.in.bz2.uue
            d_pcap.out.bz2.uue t_basic.sh

Log Message:
tests: add a basic test for shmif_pcapin

The original author of the test is k-goda@IIJ.  ozaki-r tweaked
the test to improve stability and added comments.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/tests/usr.bin/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/shmif_pcapin/Makefile \
    src/tests/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue \
    src/tests/usr.bin/shmif_pcapin/d_pcap.out.bz2.uue \
    src/tests/usr.bin/shmif_pcapin/t_basic.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/Makefile
diff -u src/tests/usr.bin/Makefile:1.40 src/tests/usr.bin/Makefile:1.41
--- src/tests/usr.bin/Makefile:1.40	Thu Mar 14 21:00:33 2024
+++ src/tests/usr.bin/Makefile	Mon Sep  2 05:16:37 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.40 2024/03/14 21:00:33 rillig Exp $
+#	$NetBSD: Makefile,v 1.41 2024/09/02 05:16:37 ozaki-r Exp $
 #
 
 .include <bsd.own.mk>
@@ -9,8 +9,8 @@ TESTS_SUBDIRS=	awk basename bzip2 cc cmp
 		diff dirname error find fstat gdb grep gzip id indent \
 		infocmp jot ld locale m4 make mixerctl mkdep mtree nbperf \
 		netpgpverify patch pkill pr printf pwhash realpath rump_server \
-		shmif_dumpbus sdiff sed sort stat tar tmux tr unifdef uniq \
-		vmstat xlint ztest
+		shmif_dumpbus shmif_pcapin sdiff sed sort stat tar tmux tr \
+		unifdef uniq vmstat xlint ztest
 
 .if ${MKCXX} != "no"
 TESTS_SUBDIRS+=	c++

Added files:

Index: src/tests/usr.bin/shmif_pcapin/Makefile
diff -u /dev/null src/tests/usr.bin/shmif_pcapin/Makefile:1.1
--- /dev/null	Mon Sep  2 05:16:37 2024
+++ src/tests/usr.bin/shmif_pcapin/Makefile	Mon Sep  2 05:16:37 2024
@@ -0,0 +1,11 @@
+.include <bsd.own.mk>
+
+TESTSDIR=	${TESTSBASE}/usr.bin/shmif_pcapin
+FILESDIR=	${TESTSDIR}
+
+TESTS_SH+=		t_basic
+TESTS_SH_SRC_t_basic=	../../net/net_common.sh t_basic.sh
+
+FILES+=		d_pcap.in.bz2.uue d_pcap.out.bz2.uue
+
+.include <bsd.test.mk>
Index: src/tests/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue
diff -u /dev/null src/tests/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue:1.1
--- /dev/null	Mon Sep  2 05:16:37 2024
+++ src/tests/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue	Mon Sep  2 05:16:37 2024
@@ -0,0 +1,27 @@
+begin 644 d_pcap.in.bz2
+M0EIH.3%!6293671X8T@`",M_______TOA>KK]E_____W_____^\C:_:XZKOZ
+M]#3:(5__T`/^`.@`&YM"%4,@-`!DQJ````T9&@``````T-!DT`&@````````
+M`:`/*%*@]1^GJHT`!ZAM(```#0T```:`!H:``&@````````````#1"?_ZJJ8
+MF`F```````!,``````````$R8````````$PFF(`T#30:#$R`&AD&C`(`#31D
+M!A`9,@R:9-#$9,@-``:,@8F3(```#0`"HI(HU-I)Z0]0]1Z@`&F@:``-H@TR
+M#:0\I_ZJ@]1I@@/4:,1ZAM33:FAIM3)ZCU-&F)^IFE/4\D:-E!Z@T:-J;-SK
+MR`JJ%4J5)T*)-32B3R*)+)(CJ$2:E1)B(DZE826U/9(DPB3#@JQ9*B2PSSSS
+M9LVP9M5FS9LV;-FS9LV;-FS9LV;-FS9YY^B\\0\^J17N5=!4RI/5U,(DK%&*
+M+4Q6)$F+99227:0M%1)4F*+2]"26DF2),B\_$F%B2IHRPQ<&+5MEM7SBR),+
+M5NA$EP56V8PDD<U$E)I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ests/usr.bin/shmif_pcapin/d_pcap.out.bz2.uue	Mon Sep  2 05:16:37 2024
@@ -0,0 +1,13 @@
+begin 644 d_pcap.out.bz2
+M0EIH.3%!62936>CJBS$`#$]?@``00&5_\0@B0``_Y?]@0`*8VP``<_2/4T_U
+M4!,``0P1AS_]50(9#31D9&1H9,@)JDDTF*>13U/4&0>IFB:;:H8`9--!D,$-
+M,1HQTI'UI>:/S1B,1J3^)&3UD9,D=9'Y(_1'A(_J1RD?*1Y5(]I&2/&1SD<D
+M<T??OF9F````````".THE5<[;+;H6@P`!555408@``-!@!SY[[[[[[\_C(\)
+M'"D<Y&J1D)=NFVM:^5(Q&D>$C$:1WD<9'K2/YD<N/'-:RY2,KQD95JD9(=9&
+M^M]9K4C:D:N$C*OWD962,K_*1OQVUK761DC>1VD=Y''COK6MY'G(VD<,X:UK
+MVD;R.'#AK6M4C)&I&LUK6MI&U(R1FVV:UY2.TCTD>,C4C?>S)'61QD;2,D=)
+M'I(X2/A(X2.E([2.5(^<C*1\Y'TD;2/*D?1&Z,1B/61]I'_2-I'WI'X1[R,1
+M]I'=&\CI(])'>D>T)>\C>$O@CM2.<CZR-4CA(R1DC$=4=Z1J1VD>Z/Q(^,CS
+.1VD?^+N2*<*$AT=468@C
+`
+end
Index: src/tests/usr.bin/shmif_pcapin/t_basic.sh
diff -u /dev/null src/tests/usr.bin/shmif_pcapin/t_basic.sh:1.1
--- /dev/null	Mon Sep  2 05:16:37 2024
+++ src/tests/usr.bin/shmif_pcapin/t_basic.sh	Mon Sep  2 05:16:37 2024
@@ -0,0 +1,89 @@
+#	$NetBSD: t_basic.sh,v 1.1 2024/09/02 05:16:37 ozaki-r Exp $
+#
+# Copyright (c) 2017-2018 Internet Initiative Japan Inc.
+# Copyright (c) 2011 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+SOCK=unix://commsock
+BUS=bus0
+
+unpack_file()
+{
+
+	atf_check -s exit:0 uudecode $(atf_get_srcdir)/${1}.bz2.uue
+	atf_check -s exit:0 bunzip2 -f ${1}.bz2
+}
+
+atf_test_case pcap cleanup
+
+pcap_head()
+{
+
+	atf_set "descr" "Write frames from pcap(3) file to shmif(4) interface"
+}
+
+pcap_body()
+{
+	unpack_file d_pcap.in
+	unpack_file d_pcap.out
+
+	rump_server_npf_start ${SOCK} # need librumpdev_bpf
+	rump_server_add_iface ${SOCK} shmif0 ${BUS}
+
+	export RUMP_SERVER=${SOCK}
+	export LD_PRELOAD=/usr/lib/librumphijack.so
+	export RUMPHIJACK=path=/rump,socket=all:nolocal,sysctl=yes,,blanket=/dev/bpf
+
+	atf_check -s exit:0 rump.ifconfig shmif0 up
+
+	# Capture frames on shmif0 to examine later.
+	tcpdump -c 58 -eni shmif0 -w shmif0.in.pcap &
+	sleep 1 # give shmif0 a change to turn into promiscuous mode
+	# Write frames to the bus.
+	atf_check -s exit:0 -o ignore shmif_pcapin d_pcap.in ${BUS}
+	wait # for tcpdump to exit
+
+	# Check if written frames surely arrives at shmif0.
+	atf_check -s exit:0 -o match:"input: 58 packets, 5684 bytes" rump.ifconfig -v shmif0
+	# Check if frames captured on shmif0 are expected ones.
+	atf_check -s exit:0 -o file:d_pcap.out -e ignore tcpdump -entr shmif0.in.pcap
+
+	unset LD_PRELOAD
+	unset RUMP_SERVER
+}
+
+pcap_cleanup()
+{
+
+	$DEBUG && dump
+	cleanup
+}
+
+
+atf_init_test_cases()
+{
+
+	atf_add_test_case pcap
+}

Reply via email to