Debian Codegraph @

tools/testing/selftests/net/packetdrill/ksft_runner.sh

raw
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3
4 source "$(dirname $(realpath $0))/../../kselftest/ktap_helpers.sh"
5
6 declare -A ip_args=(
7 [ipv4]="--ip_version=ipv4
8 --local_ip=192.168.0.1
9 --gateway_ip=192.168.0.1
10 --netmask_ip=255.255.0.0
11 --remote_ip=192.0.2.1
12 -D TFO_COOKIE=3021b9d889017eeb
13 -D TFO_COOKIE_ZERO=b7c12350a90dc8f5
14 -D CMSG_LEVEL_IP=SOL_IP
15 -D CMSG_TYPE_RECVERR=IP_RECVERR"
16 [ipv4-mapped-ipv6]="--ip_version=ipv4-mapped-ipv6
17 --local_ip=192.168.0.1
18 --gateway_ip=192.168.0.1
19 --netmask_ip=255.255.0.0
20 --remote_ip=192.0.2.1
21 -D TFO_COOKIE=3021b9d889017eeb
22 -D TFO_COOKIE_ZERO=b7c12350a90dc8f5
23 -D CMSG_LEVEL_IP=SOL_IPV6
24 -D CMSG_TYPE_RECVERR=IPV6_RECVERR"
25 [ipv6]="--ip_version=ipv6
26 --mtu=1520
27 --local_ip=fd3d:0a0b:17d6::1
28 --gateway_ip=fd3d:0a0b:17d6:8888::1
29 --remote_ip=fd3d:fa7b:d17d::1
30 -D TFO_COOKIE=c1d1e9742a47a9bc
31 -D TFO_COOKIE_ZERO=82af1a8f9a205c34
32 -D CMSG_LEVEL_IP=SOL_IPV6
33 -D CMSG_TYPE_RECVERR=IPV6_RECVERR"
34 )
35
36 if [ $# -ne 1 ]; then
37 ktap_exit_fail_msg "usage: $0 <script>"
38 exit "$KSFT_FAIL"
39 fi
40 script="$(basename $1)"
41
42 if [ -z "$(which packetdrill)" ]; then
43 ktap_skip_all "packetdrill not found in PATH"
44 exit "$KSFT_SKIP"
45 fi
46
47 declare -a optargs
48 failfunc=ktap_test_fail
49
50 if [[ -n "${KSFT_MACHINE_SLOW}" ]]; then
51 optargs+=('--tolerance_usecs=14000')
52 failfunc=ktap_test_xfail
53 fi
54
55 ip_versions=$(grep -E '^--ip_version=' $script | cut -d '=' -f 2)
56 if [[ -z $ip_versions ]]; then
57 ip_versions="ipv4 ipv6 ipv4-mapped-ipv6"
58 elif [[ ! "$ip_versions" =~ ^ipv[46]$ ]]; then
59 ktap_exit_fail_msg "Too many or unsupported --ip_version: $ip_versions"
60 exit "$KSFT_FAIL"
61 fi
62
63 ktap_print_header
64 ktap_set_plan $(echo $ip_versions | wc -w)
65
66 for ip_version in $ip_versions; do
67 unshare -n packetdrill ${ip_args[$ip_version]} ${optargs[@]} $script > /dev/null \
68 && ktap_test_pass $ip_version || $failfunc $ip_version
69 done
70
71 ktap_finished