xref: /linux/tools/testing/selftests/net/udpgso_bench.sh (revision a7f7f6248d9740d710fd6bd190293fe5e16410ac)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Run a series of udpgso benchmarks
5
6readonly GREEN='\033[0;92m'
7readonly YELLOW='\033[0;33m'
8readonly RED='\033[0;31m'
9readonly NC='\033[0m' # No Color
10
11readonly KSFT_PASS=0
12readonly KSFT_FAIL=1
13readonly KSFT_SKIP=4
14
15num_pass=0
16num_err=0
17num_skip=0
18
19kselftest_test_exitcode() {
20	local -r exitcode=$1
21
22	if [[ ${exitcode} -eq ${KSFT_PASS} ]]; then
23		num_pass=$(( $num_pass + 1 ))
24	elif [[ ${exitcode} -eq ${KSFT_SKIP} ]]; then
25		num_skip=$(( $num_skip + 1 ))
26	else
27		num_err=$(( $num_err + 1 ))
28	fi
29}
30
31kselftest_exit() {
32	echo -e "$(basename $0): PASS=${num_pass} SKIP=${num_skip} FAIL=${num_err}"
33
34	if [[ $num_err -ne 0 ]]; then
35		echo -e "$(basename $0): ${RED}FAIL${NC}"
36		exit ${KSFT_FAIL}
37	fi
38
39	if [[ $num_skip -ne 0 ]]; then
40		echo -e "$(basename $0): ${YELLOW}SKIP${NC}"
41		exit ${KSFT_SKIP}
42	fi
43
44	echo -e "$(basename $0): ${GREEN}PASS${NC}"
45	exit ${KSFT_PASS}
46}
47
48wake_children() {
49	local -r jobs="$(jobs -p)"
50
51	if [[ "${jobs}" != "" ]]; then
52		kill -1 ${jobs} 2>/dev/null
53	fi
54}
55trap wake_children EXIT
56
57run_one() {
58	local -r args=$@
59
60	./udpgso_bench_rx &
61	./udpgso_bench_rx -t &
62
63	./udpgso_bench_tx ${args}
64}
65
66run_in_netns() {
67	local -r args=$@
68
69	./in_netns.sh $0 __subprocess ${args}
70	kselftest_test_exitcode $?
71}
72
73run_udp() {
74	local -r args=$@
75
76	echo "udp"
77	run_in_netns ${args}
78
79	echo "udp gso"
80	run_in_netns ${args} -S 0
81
82	echo "udp gso zerocopy"
83	run_in_netns ${args} -S 0 -z
84
85	echo "udp gso timestamp"
86	run_in_netns ${args} -S 0 -T
87
88	echo "udp gso zerocopy audit"
89	run_in_netns ${args} -S 0 -z -a
90
91	echo "udp gso timestamp audit"
92	run_in_netns ${args} -S 0 -T -a
93
94	echo "udp gso zerocopy timestamp audit"
95	run_in_netns ${args} -S 0 -T -z -a
96}
97
98run_tcp() {
99	local -r args=$@
100
101	echo "tcp"
102	run_in_netns ${args} -t
103
104	echo "tcp zerocopy"
105	run_in_netns ${args} -t -z
106
107	# excluding for now because test fails intermittently
108	# add -P option to include poll() to reduce possibility of lost messages
109	#echo "tcp zerocopy audit"
110	#run_in_netns ${args} -t -z -P -a
111}
112
113run_all() {
114	local -r core_args="-l 3"
115	local -r ipv4_args="${core_args} -4 -D 127.0.0.1"
116	local -r ipv6_args="${core_args} -6 -D ::1"
117
118	echo "ipv4"
119	run_tcp "${ipv4_args}"
120	run_udp "${ipv4_args}"
121
122	echo "ipv6"
123	run_tcp "${ipv4_args}"
124	run_udp "${ipv6_args}"
125}
126
127if [[ $# -eq 0 ]]; then
128	run_all
129	kselftest_exit
130elif [[ $1 == "__subprocess" ]]; then
131	shift
132	run_one $@
133else
134	run_in_netns $@
135fi
136