drm/bridge: adv7511: Switch to atomic operations
[drm/drm-misc.git] / tools / testing / selftests / net / gre_gso.sh
blob5100d90f92d2143baef13e41b643687ccdda89e9
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # This test is for checking GRE GSO.
5 source lib.sh
6 ret=0
8 # all tests in this script. Can be overridden with -t option
9 TESTS="gre_gso"
11 VERBOSE=0
12 PAUSE_ON_FAIL=no
13 PAUSE=no
14 TMPFILE=`mktemp`
15 PID=
17 log_test()
19 local rc=$1
20 local expected=$2
21 local msg="$3"
23 if [ ${rc} -eq ${expected} ]; then
24 printf " TEST: %-60s [ OK ]\n" "${msg}"
25 nsuccess=$((nsuccess+1))
26 else
27 ret=1
28 nfail=$((nfail+1))
29 printf " TEST: %-60s [FAIL]\n" "${msg}"
30 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
31 echo
32 echo "hit enter to continue, 'q' to quit"
33 read a
34 [ "$a" = "q" ] && exit 1
38 if [ "${PAUSE}" = "yes" ]; then
39 echo
40 echo "hit enter to continue, 'q' to quit"
41 read a
42 [ "$a" = "q" ] && exit 1
46 setup()
48 set -e
49 setup_ns ns1
50 IP="ip -netns $ns1"
51 NS_EXEC="ip netns exec $ns1"
53 ip link add veth0 type veth peer name veth1
54 ip link set veth0 up
55 ip link set veth1 netns $ns1
56 $IP link set veth1 name veth0
57 $IP link set veth0 up
59 dd if=/dev/urandom of=$TMPFILE bs=1024 count=2048 &>/dev/null
60 set +e
63 cleanup()
65 rm -rf $TMPFILE
66 [ -n "$PID" ] && kill $PID
67 ip link del dev gre1 &> /dev/null
68 ip link del dev veth0 &> /dev/null
69 cleanup_ns $ns1
72 get_linklocal()
74 local dev=$1
75 local ns=$2
76 local addr
78 [ -n "$ns" ] && ns="-netns $ns"
80 addr=$(ip -6 -br $ns addr show dev ${dev} | \
81 awk '{
82 for (i = 3; i <= NF; ++i) {
83 if ($i ~ /^fe80/)
84 print $i
88 addr=${addr/\/*}
90 [ -z "$addr" ] && return 1
92 echo $addr
94 return 0
97 gre_create_tun()
99 local a1=$1
100 local a2=$2
101 local mode
103 [[ $a1 =~ ^[0-9.]*$ ]] && mode=gre || mode=ip6gre
105 ip tunnel add gre1 mode $mode local $a1 remote $a2 dev veth0
106 ip link set gre1 up
107 $IP tunnel add gre1 mode $mode local $a2 remote $a1 dev veth0
108 $IP link set gre1 up
111 gre_gst_test_checks()
113 local name=$1
114 local addr=$2
115 local proto=$3
117 [ "$proto" == 6 ] && addr="[$addr]"
119 $NS_EXEC socat - tcp${proto}-listen:$port,reuseaddr,fork >/dev/null &
120 PID=$!
121 while ! $NS_EXEC ss -ltn | grep -q $port; do ((i++)); sleep 0.01; done
123 cat $TMPFILE | timeout 1 socat -u STDIN TCP:$addr:$port
124 log_test $? 0 "$name - copy file w/ TSO"
126 ethtool -K veth0 tso off
128 cat $TMPFILE | timeout 1 socat -u STDIN TCP:$addr:$port
129 log_test $? 0 "$name - copy file w/ GSO"
131 ethtool -K veth0 tso on
133 kill $PID
134 PID=
137 gre6_gso_test()
139 local port=7777
141 setup
143 a1=$(get_linklocal veth0)
144 a2=$(get_linklocal veth0 $ns1)
146 gre_create_tun $a1 $a2
148 ip addr add 172.16.2.1/24 dev gre1
149 $IP addr add 172.16.2.2/24 dev gre1
151 ip -6 addr add 2001:db8:1::1/64 dev gre1 nodad
152 $IP -6 addr add 2001:db8:1::2/64 dev gre1 nodad
154 sleep 2
156 gre_gst_test_checks GREv6/v4 172.16.2.2 4
157 gre_gst_test_checks GREv6/v6 2001:db8:1::2 6
159 cleanup
162 gre_gso_test()
164 gre6_gso_test
167 ################################################################################
168 # usage
170 usage()
172 cat <<EOF
173 usage: ${0##*/} OPTS
175 -t <test> Test(s) to run (default: all)
176 (options: $TESTS)
177 -p Pause on fail
178 -P Pause after each test before cleanup
179 -v verbose mode (show commands and output)
183 ################################################################################
184 # main
186 while getopts :t:pPhv o
188 case $o in
189 t) TESTS=$OPTARG;;
190 p) PAUSE_ON_FAIL=yes;;
191 P) PAUSE=yes;;
192 v) VERBOSE=$(($VERBOSE + 1));;
193 h) usage; exit 0;;
194 *) usage; exit 1;;
195 esac
196 done
198 PEER_CMD="ip netns exec ${PEER_NS}"
200 # make sure we don't pause twice
201 [ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
203 if [ "$(id -u)" -ne 0 ];then
204 echo "SKIP: Need root privileges"
205 exit $ksft_skip;
208 if [ ! -x "$(command -v ip)" ]; then
209 echo "SKIP: Could not run test without ip tool"
210 exit $ksft_skip
213 if [ ! -x "$(command -v socat)" ]; then
214 echo "SKIP: Could not run test without socat tool"
215 exit $ksft_skip
218 # start clean
219 cleanup &> /dev/null
221 for t in $TESTS
223 case $t in
224 gre_gso) gre_gso_test;;
226 help) echo "Test names: $TESTS"; exit 0;;
227 esac
228 done
230 if [ "$TESTS" != "none" ]; then
231 printf "\nTests passed: %3d\n" ${nsuccess}
232 printf "Tests failed: %3d\n" ${nfail}
235 exit $ret