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