Merge tag 'kvm-x86-misc-6.9' of https://github.com/kvm-x86/linux into HEAD
[linux-2.6-block.git] / tools / testing / selftests / net / so_txtime.sh
CommitLineData
af5136f9
WB
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Regression tests for the SO_TXTIME interface
5
04080634
CL
6set -e
7
a7ee79b9 8readonly ksft_skip=4
04080634
CL
9readonly DEV="veth0"
10readonly BIN="./so_txtime"
11
12readonly RAND="$(mktemp -u XXXXXX)"
13readonly NSPREFIX="ns-${RAND}"
14readonly NS1="${NSPREFIX}1"
15readonly NS2="${NSPREFIX}2"
16
17readonly SADDR4='192.168.1.1'
18readonly DADDR4='192.168.1.2'
19readonly SADDR6='fd::1'
20readonly DADDR6='fd::2'
21
22cleanup() {
23 ip netns del "${NS2}"
24 ip netns del "${NS1}"
25}
26
27trap cleanup EXIT
28
29# Create virtual ethernet pair between network namespaces
30ip netns add "${NS1}"
31ip netns add "${NS2}"
32
33ip link add "${DEV}" netns "${NS1}" type veth \
34 peer name "${DEV}" netns "${NS2}"
35
36# Bring the devices up
37ip -netns "${NS1}" link set "${DEV}" up
38ip -netns "${NS2}" link set "${DEV}" up
39
40# Set fixed MAC addresses on the devices
41ip -netns "${NS1}" link set dev "${DEV}" address 02:02:02:02:02:02
42ip -netns "${NS2}" link set dev "${DEV}" address 06:06:06:06:06:06
43
44# Add fixed IP addresses to the devices
45ip -netns "${NS1}" addr add 192.168.1.1/24 dev "${DEV}"
46ip -netns "${NS2}" addr add 192.168.1.2/24 dev "${DEV}"
47ip -netns "${NS1}" addr add fd::1/64 dev "${DEV}" nodad
48ip -netns "${NS2}" addr add fd::2/64 dev "${DEV}" nodad
49
a7ee79b9 50run_test() {
04080634
CL
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
ea6a5476
WB
65 fi
66
04080634 67 local readonly START="$(date +%s%N --date="+ 0.1 seconds")"
a7ee79b9 68
04080634
CL
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}
af5136f9 73
a7ee79b9
PA
74do_test() {
75 run_test $@
76 [ $? -ne 0 ] && ret=1
77}
78
79do_fail_test() {
80 run_test $@
81 [ $? -eq 0 ] && ret=1
82}
83
04080634 84ip netns exec "${NS1}" tc qdisc add dev "${DEV}" root fq
a7ee79b9
PA
85set +e
86ret=0
04080634
CL
87do_test 4 mono a,-1 a,-1
88do_test 6 mono a,0 a,0
89do_test 6 mono a,10 a,10
90do_test 4 mono a,10,b,20 a,10,b,20
91do_test 6 mono a,20,b,10 b,20,a,20
af5136f9 92
04080634 93if ip netns exec "${NS1}" tc qdisc replace dev "${DEV}" root etf clockid CLOCK_TAI delta 400000; then
a7ee79b9
PA
94 do_fail_test 4 tai a,-1 a,-1
95 do_fail_test 6 tai a,0 a,0
04080634
CL
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
af5136f9
WB
99else
100 echo "tc ($(tc -V)) does not support qdisc etf. skipping"
a7ee79b9 101 [ $ret -eq 0 ] && ret=$ksft_skip
af5136f9
WB
102fi
103
a7ee79b9
PA
104if [ $ret -eq 0 ]; then
105 echo OK. All tests passed
106elif [[ $ret -ne $ksft_skip && -n "$KSFT_MACHINE_SLOW" ]]; then
107 echo "Ignoring errors due to slow environment" 1>&2
108 ret=0
109fi
110exit $ret