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 10readonly TESTPORT=8000 11 12readonly KSFT_PASS=0 13readonly KSFT_FAIL=1 14readonly KSFT_SKIP=4 15 16num_pass=0 17num_err=0 18num_skip=0 19 20kselftest_test_exitcode() { 21 local -r exitcode=$1 22 23 if [[ ${exitcode} -eq ${KSFT_PASS} ]]; then 24 num_pass=$(( $num_pass + 1 )) 25 elif [[ ${exitcode} -eq ${KSFT_SKIP} ]]; then 26 num_skip=$(( $num_skip + 1 )) 27 else 28 num_err=$(( $num_err + 1 )) 29 fi 30} 31 32kselftest_exit() { 33 echo -e "$(basename $0): PASS=${num_pass} SKIP=${num_skip} FAIL=${num_err}" 34 35 if [[ $num_err -ne 0 ]]; then 36 echo -e "$(basename $0): ${RED}FAIL${NC}" 37 exit ${KSFT_FAIL} 38 fi 39 40 if [[ $num_skip -ne 0 ]]; then 41 echo -e "$(basename $0): ${YELLOW}SKIP${NC}" 42 exit ${KSFT_SKIP} 43 fi 44 45 echo -e "$(basename $0): ${GREEN}PASS${NC}" 46 exit ${KSFT_PASS} 47} 48 49wake_children() { 50 local -r jobs="$(jobs -p)" 51 52 if [[ "${jobs}" != "" ]]; then 53 kill -1 ${jobs} 2>/dev/null 54 fi 55} 56trap wake_children EXIT 57 58run_one() { 59 local -r args=$@ 60 local nr_socks=0 61 local i=0 62 local -r timeout=10 63 64 ./udpgso_bench_rx -p "$TESTPORT" & 65 ./udpgso_bench_rx -p "$TESTPORT" -t & 66 67 # Wait for the above test program to get ready to receive connections. 68 while [ "$i" -lt "$timeout" ]; do 69 nr_socks="$(ss -lnHi | grep -c "\*:${TESTPORT}")" 70 [ "$nr_socks" -eq 2 ] && break 71 i=$((i + 1)) 72 sleep 1 73 done 74 if [ "$nr_socks" -ne 2 ]; then 75 echo "timed out while waiting for udpgso_bench_rx" 76 exit 1 77 fi 78 79 ./udpgso_bench_tx -p "$TESTPORT" ${args} 80} 81 82run_in_netns() { 83 local -r args=$@ 84 85 ./in_netns.sh $0 __subprocess ${args} 86 kselftest_test_exitcode $? 87} 88 89run_udp() { 90 local -r args=$@ 91 92 echo "udp" 93 run_in_netns ${args} 94 95 echo "udp gso" 96 run_in_netns ${args} -S 0 97 98 echo "udp gso zerocopy" 99 run_in_netns ${args} -S 0 -z 100 101 echo "udp gso timestamp" 102 run_in_netns ${args} -S 0 -T 103 104 echo "udp gso zerocopy audit" 105 run_in_netns ${args} -S 0 -z -a 106 107 echo "udp gso timestamp audit" 108 run_in_netns ${args} -S 0 -T -a 109 110 echo "udp gso zerocopy timestamp audit" 111 run_in_netns ${args} -S 0 -T -z -a 112} 113 114run_tcp() { 115 local -r args=$@ 116 117 echo "tcp" 118 run_in_netns ${args} -t 119 120 echo "tcp zerocopy" 121 run_in_netns ${args} -t -z 122 123 # excluding for now because test fails intermittently 124 # add -P option to include poll() to reduce possibility of lost messages 125 #echo "tcp zerocopy audit" 126 #run_in_netns ${args} -t -z -P -a 127} 128 129run_all() { 130 local -r core_args="-l 3" 131 local -r ipv4_args="${core_args} -4 -D 127.0.0.1" 132 local -r ipv6_args="${core_args} -6 -D ::1" 133 134 echo "ipv4" 135 run_tcp "${ipv4_args}" 136 run_udp "${ipv4_args}" 137 138 echo "ipv6" 139 run_tcp "${ipv6_args}" 140 run_udp "${ipv6_args}" 141} 142 143if [[ $# -eq 0 ]]; then 144 run_all 145 kselftest_exit 146elif [[ $1 == "__subprocess" ]]; then 147 shift 148 run_one $@ 149else 150 run_in_netns $@ 151fi 152