WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / xsk_prereqs.sh
blob9d54c4645127d56b3c1684a8e1b6a9b3241e0c32
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright(c) 2020 Intel Corporation.
5 ksft_pass=0
6 ksft_fail=1
7 ksft_xfail=2
8 ksft_xpass=3
9 ksft_skip=4
11 GREEN='\033[0;92m'
12 YELLOW='\033[0;93m'
13 RED='\033[0;31m'
14 NC='\033[0m'
15 STACK_LIM=131072
16 SPECFILE=veth.spec
17 XSKOBJ=xdpxceiver
18 NUMPKTS=10000
20 validate_root_exec()
22 msg="skip all tests:"
23 if [ $UID != 0 ]; then
24 echo $msg must be run as root >&2
25 test_exit $ksft_fail 2
26 else
27 return $ksft_pass
31 validate_veth_support()
33 msg="skip all tests:"
34 if [ $(ip link add $1 type veth 2>/dev/null; echo $?;) != 0 ]; then
35 echo $msg veth kernel support not available >&2
36 test_exit $ksft_skip 1
37 else
38 ip link del $1
39 return $ksft_pass
43 validate_veth_spec_file()
45 if [ ! -f ${SPECFILE} ]; then
46 test_exit $ksft_skip 1
50 test_status()
52 statusval=$1
53 if [ -n "${colorconsole+set}" ]; then
54 if [ $statusval -eq 2 ]; then
55 echo -e "${YELLOW}$2${NC}: [ ${RED}FAIL${NC} ]"
56 elif [ $statusval -eq 1 ]; then
57 echo -e "${YELLOW}$2${NC}: [ ${RED}SKIPPED${NC} ]"
58 elif [ $statusval -eq 0 ]; then
59 echo -e "${YELLOW}$2${NC}: [ ${GREEN}PASS${NC} ]"
61 else
62 if [ $statusval -eq 2 ]; then
63 echo -e "$2: [ FAIL ]"
64 elif [ $statusval -eq 1 ]; then
65 echo -e "$2: [ SKIPPED ]"
66 elif [ $statusval -eq 0 ]; then
67 echo -e "$2: [ PASS ]"
72 test_exit()
74 retval=$1
75 if [ $2 -ne 0 ]; then
76 test_status $2 $(basename $0)
78 exit $retval
81 clear_configs()
83 if [ $(ip netns show | grep $3 &>/dev/null; echo $?;) == 0 ]; then
84 [ $(ip netns exec $3 ip link show $2 &>/dev/null; echo $?;) == 0 ] &&
85 { echo "removing link $1:$2"; ip netns exec $3 ip link del $2; }
86 echo "removing ns $3"
87 ip netns del $3
89 #Once we delete a veth pair node, the entire veth pair is removed,
90 #this is just to be cautious just incase the NS does not exist then
91 #veth node inside NS won't get removed so we explicitly remove it
92 [ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] &&
93 { echo "removing link $1"; ip link del $1; }
94 if [ -f ${SPECFILE} ]; then
95 echo "removing spec file:" ${SPECFILE}
96 rm -f ${SPECFILE}
100 cleanup_exit()
102 echo "cleaning up..."
103 clear_configs $1 $2 $3
106 validate_ip_utility()
108 [ ! $(type -P ip) ] && { echo "'ip' not found. Skipping tests."; test_exit $ksft_skip 1; }
111 vethXDPgeneric()
113 ip link set dev $1 xdpdrv off
114 ip netns exec $3 ip link set dev $2 xdpdrv off
117 vethXDPnative()
119 ip link set dev $1 xdpgeneric off
120 ip netns exec $3 ip link set dev $2 xdpgeneric off
123 execxdpxceiver()
125 local -a 'paramkeys=("${!'"$1"'[@]}")' copy
126 paramkeysstr=${paramkeys[*]}
128 for index in $paramkeysstr;
130 current=$1"[$index]"
131 copy[$index]=${!current}
132 done
134 ./${XSKOBJ} -i ${VETH0} -i ${VETH1},${NS1} ${copy[*]} -C ${NUMPKTS}