drm/bridge: adv7511: Switch to atomic operations
[drm/drm-misc.git] / tools / testing / selftests / net / cmsg_time.sh
blob1d7e756644bc1ff15af7ad3c0fdd5bac13b00e97
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 source lib.sh
6 IP4=172.16.0.1/24
7 TGT4=172.16.0.2
8 IP6=2001:db8:1::1/64
9 TGT6=2001:db8:1::2
11 cleanup()
13 cleanup_ns $NS
16 trap cleanup EXIT
18 # Namespaces
19 setup_ns NS
21 ip netns exec $NS sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null
23 # Connectivity
24 ip -netns $NS link add type dummy
25 ip -netns $NS link set dev dummy0 up
26 ip -netns $NS addr add $IP4 dev dummy0
27 ip -netns $NS addr add $IP6 dev dummy0
29 # Need FQ for TXTIME
30 ip netns exec $NS tc qdisc replace dev dummy0 root fq
32 # Test
33 BAD=0
34 TOTAL=0
36 check_result() {
37 ((TOTAL++))
38 if [ $1 -ne 0 ]; then
39 echo " Case $4 returned $1, expected 0"
40 ((BAD++))
41 elif [ "$2" != "$3" ]; then
42 echo " Case $4 returned '$2', expected '$3'"
43 ((BAD++))
47 for i in "-4 $TGT4" "-6 $TGT6"; do
48 for p in u i r; do
49 [ $p == "u" ] && prot=UDPv${i:1:2}
50 [ $p == "i" ] && prot=ICMPv${i:1:2}
51 [ $p == "r" ] && prot=RAWv${i:1:2}
53 ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234)
54 check_result $? "$ts" "" "$prot - no options"
56 ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t | wc -l)
57 check_result $? "$ts" "2" "$prot - ts cnt"
58 ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t |
59 sed -n "s/.*SCHED ts0 [0-9].*/OK/p")
60 check_result $? "$ts" "OK" "$prot - ts0 SCHED"
61 ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t |
62 sed -n "s/.*SND ts0 [0-9].*/OK/p")
63 check_result $? "$ts" "OK" "$prot - ts0 SND"
65 ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t -d 1000 |
66 awk '/SND/ { if ($3 > 1000) print "OK"; }')
67 check_result $? "$ts" "OK" "$prot - TXTIME abs"
69 [ "$KSFT_MACHINE_SLOW" = yes ] && delay=8000 || delay=1000
71 ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t -d $delay |
72 awk '/SND/ {snd=$3}
73 /SCHED/ {sch=$3}
74 END { if (snd - sch > '$((delay/2))') print "OK";
75 else print snd, "-", sch, "<", '$((delay/2))'; }')
76 check_result $? "$ts" "OK" "$prot - TXTIME rel"
77 done
78 done
80 # Summary
81 if [ $BAD -ne 0 ]; then
82 echo "FAIL - $BAD/$TOTAL cases failed"
83 exit 1
84 else
85 echo "OK"
86 exit 0