t_basic.sh revision 1.1 1 # $NetBSD: t_basic.sh,v 1.1 2024/09/02 05:16:37 ozaki-r Exp $
2 #
3 # Copyright (c) 2017-2018 Internet Initiative Japan Inc.
4 # Copyright (c) 2011 The NetBSD Foundation, Inc.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 # POSSIBILITY OF SUCH DAMAGE.
27 #
28
29 SOCK=unix://commsock
30 BUS=bus0
31
32 unpack_file()
33 {
34
35 atf_check -s exit:0 uudecode $(atf_get_srcdir)/${1}.bz2.uue
36 atf_check -s exit:0 bunzip2 -f ${1}.bz2
37 }
38
39 atf_test_case pcap cleanup
40
41 pcap_head()
42 {
43
44 atf_set "descr" "Write frames from pcap(3) file to shmif(4) interface"
45 }
46
47 pcap_body()
48 {
49 unpack_file d_pcap.in
50 unpack_file d_pcap.out
51
52 rump_server_npf_start ${SOCK} # need librumpdev_bpf
53 rump_server_add_iface ${SOCK} shmif0 ${BUS}
54
55 export RUMP_SERVER=${SOCK}
56 export LD_PRELOAD=/usr/lib/librumphijack.so
57 export RUMPHIJACK=path=/rump,socket=all:nolocal,sysctl=yes,,blanket=/dev/bpf
58
59 atf_check -s exit:0 rump.ifconfig shmif0 up
60
61 # Capture frames on shmif0 to examine later.
62 tcpdump -c 58 -eni shmif0 -w shmif0.in.pcap &
63 sleep 1 # give shmif0 a change to turn into promiscuous mode
64 # Write frames to the bus.
65 atf_check -s exit:0 -o ignore shmif_pcapin d_pcap.in ${BUS}
66 wait # for tcpdump to exit
67
68 # Check if written frames surely arrives at shmif0.
69 atf_check -s exit:0 -o match:"input: 58 packets, 5684 bytes" rump.ifconfig -v shmif0
70 # Check if frames captured on shmif0 are expected ones.
71 atf_check -s exit:0 -o file:d_pcap.out -e ignore tcpdump -entr shmif0.in.pcap
72
73 unset LD_PRELOAD
74 unset RUMP_SERVER
75 }
76
77 pcap_cleanup()
78 {
79
80 $DEBUG && dump
81 cleanup
82 }
83
84
85 atf_init_test_cases()
86 {
87
88 atf_add_test_case pcap
89 }
90