1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 3 # 4 # Regression tests for the SO_TXTIME interface 5 6 set -e 7 8 readonly ksft_skip=4 9 readonly DEV="veth0" 10 readonly BIN="./so_txtime" 11 12 readonly RAND="$(mktemp -u XXXXXX)" 13 readonly NSPREFIX="ns-${RAND}" 14 readonly NS1="${NSPREFIX}1" 15 readonly NS2="${NSPREFIX}2" 16 17 readonly SADDR4='192.168.1.1' 18 readonly DADDR4='192.168.1.2' 19 readonly SADDR6='fd::1' 20 readonly DADDR6='fd::2' 21 22 cleanup() { 23 ip netns del "${NS2}" 24 ip netns del "${NS1}" 25 } 26 27 trap cleanup EXIT 28 29 # Create virtual ethernet pair between network namespaces 30 ip netns add "${NS1}" 31 ip netns add "${NS2}" 32 33 ip link add "${DEV}" netns "${NS1}" type veth \ 34 peer name "${DEV}" netns "${NS2}" 35 36 # Bring the devices up 37 ip -netns "${NS1}" link set "${DEV}" up 38 ip -netns "${NS2}" link set "${DEV}" up 39 40 # Set fixed MAC addresses on the devices 41 ip -netns "${NS1}" link set dev "${DEV}" address 02:02:02:02:02:02 42 ip -netns "${NS2}" link set dev "${DEV}" address 06:06:06:06:06:06 43 44 # Add fixed IP addresses to the devices 45 ip -netns "${NS1}" addr add 192.168.1.1/24 dev "${DEV}" 46 ip -netns "${NS2}" addr add 192.168.1.2/24 dev "${DEV}" 47 ip -netns "${NS1}" addr add fd::1/64 dev "${DEV}" nodad 48 ip -netns "${NS2}" addr add fd::2/64 dev "${DEV}" nodad 49 50 run_test() { 51 local readonly IP="$1" 52 local readonly CLOCK="$2" 53 local readonly TXARGS="$3" 54 local readonly RXARGS="$4" 55 56 if [[ "${IP}" == "4" ]]; then 57 local readonly SADDR="${SADDR4}" 58 local readonly DADDR="${DADDR4}" 59 elif [[ "${IP}" == "6" ]]; then 60 local readonly SADDR="${SADDR6}" 61 local readonly DADDR="${DADDR6}" 62 else 63 echo "Invalid IP version ${IP}" 64 exit 1 65 fi 66 67 local readonly START="$(date +%s%N --date="+ 0.1 seconds")" 68 69 ip netns exec "${NS2}" "${BIN}" -"${IP}" -c "${CLOCK}" -t "${START}" -S "${SADDR}" -D "${DADDR}" "${RXARGS}" -r & 70 ip netns exec "${NS1}" "${BIN}" -"${IP}" -c "${CLOCK}" -t "${START}" -S "${SADDR}" -D "${DADDR}" "${TXARGS}" 71 wait "$!" 72 } 73 74 do_test() { 75 run_test $@ 76 [ $? -ne 0 ] && ret=1 77 } 78 79 do_fail_test() { 80 run_test $@ 81 [ $? -eq 0 ] && ret=1 82 } 83 84 ip netns exec "${NS1}" tc qdisc add dev "${DEV}" root fq 85 set +e 86 ret=0 87 do_test 4 mono a,-1 a,-1 88 do_test 6 mono a,0 a,0 89 do_test 6 mono a,10 a,10 90 do_test 4 mono a,10,b,20 a,10,b,20 91 do_test 6 mono a,20,b,10 b,20,a,20 92 93 if ip netns exec "${NS1}" tc qdisc replace dev "${DEV}" root etf clockid CLOCK_TAI delta 400000; then 94 do_fail_test 4 tai a,-1 a,-1 95 do_fail_test 6 tai a,0 a,0 96 do_test 6 tai a,10 a,10 97 do_test 4 tai a,10,b,20 a,10,b,20 98 do_test 6 tai a,20,b,10 b,10,a,20 99 else 100 echo "tc ($(tc -V)) does not support qdisc etf. skipping" 101 [ $ret -eq 0 ] && ret=$ksft_skip 102 fi 103 104 if [ $ret -eq 0 ]; then 105 echo OK. All tests passed 106 elif [[ $ret -ne $ksft_skip && -n "$KSFT_MACHINE_SLOW" ]]; then 107 echo "Ignoring errors due to slow environment" 1>&2 108 ret=0 109 fi 110 exit $ret
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.