summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/xsk_prereqs.sh
blob: 47c7b8064f38b02afeb1899a8866c5b8206e3ab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright(c) 2020 Intel Corporation.

ksft_pass=0
ksft_fail=1
ksft_xfail=2
ksft_xpass=3
ksft_skip=4

XSKOBJ=xskxceiver

validate_root_exec()
{
	msg="skip all tests:"
	if [ $UID != 0 ]; then
		echo $msg must be run as root >&2
		test_exit $ksft_fail
	else
		return $ksft_pass
	fi
}

validate_veth_support()
{
	msg="skip all tests:"
	if [ $(ip link add $1 type veth 2>/dev/null; echo $?;) != 0 ]; then
		echo $msg veth kernel support not available >&2
		test_exit $ksft_skip
	else
		ip link del $1
		return $ksft_pass
	fi
}

test_status()
{
	statusval=$1
	if [ $statusval -eq $ksft_fail ]; then
		echo "$2: [ FAIL ]"
	elif [ $statusval -eq $ksft_skip ]; then
		echo "$2: [ SKIPPED ]"
	elif [ $statusval -eq $ksft_pass ]; then
		echo "$2: [ PASS ]"
	fi
}

test_exit()
{
	if [ $1 -ne 0 ]; then
		test_status $1 $(basename $0)
	fi
	exit 1
}

cleanup_iface()
{
	ip link set $1 mtu $2
	ip link set $1 xdp off
	ip link set $1 xdpgeneric off
}

clear_configs()
{
	[ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] &&
		{ ip link del $1; }
}

cleanup_exit()
{
	clear_configs $1 $2
}

validate_ip_utility()
{
	[ ! $(type -P ip) ] && { echo "'ip' not found. Skipping tests."; test_exit $ksft_skip; }
}

exec_xskxceiver()
{
        if [[ $busy_poll -eq 1 ]]; then
	        ARGS+="-b "
	fi

	./${XSKOBJ} -i ${VETH0} -i ${VETH1} ${ARGS}
	retval=$?

	if [[ $list -ne 1 ]]; then
	    test_status $retval "${TEST_NAME}"
	    statusList+=($retval)
	    nameList+=(${TEST_NAME})
	fi
}