Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: forwarding: fix race between packet receive and tc check

It is possible that tc stats get checked before the packet we check for
actually arrived into the interface and accounted for.
Fix it by checking for the expected result in a loop until
timeout is reached (by default 1 second).

Fixes: 07e5c75184a1 ("selftests: forwarding: Introduce tc flower matching tests")
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jiri Pirko and committed by
David S. Miller
408469d3 14e54ab9

+31 -8
+31 -8
tools/testing/selftests/net/forwarding/tc_common.sh
··· 3 3 4 4 CHECK_TC="yes" 5 5 6 + # Can be overridden by the configuration file. See lib.sh 7 + TC_HIT_TIMEOUT=${TC_HIT_TIMEOUT:=1000} # ms 8 + 9 + __tc_check_packets() 10 + { 11 + local id=$1 12 + local handle=$2 13 + local count=$3 14 + local operator=$4 15 + 16 + start_time="$(date -u +%s%3N)" 17 + while true 18 + do 19 + cmd_jq "tc -j -s filter show $id" \ 20 + ".[] | select(.options.handle == $handle) | \ 21 + select(.options.actions[0].stats.packets $operator $count)" \ 22 + &> /dev/null 23 + ret=$? 24 + if [[ $ret -eq 0 ]]; then 25 + return $ret 26 + fi 27 + current_time="$(date -u +%s%3N)" 28 + diff=$(expr $current_time - $start_time) 29 + if [ "$diff" -gt "$TC_HIT_TIMEOUT" ]; then 30 + return 1 31 + fi 32 + done 33 + } 34 + 6 35 tc_check_packets() 7 36 { 8 37 local id=$1 9 38 local handle=$2 10 39 local count=$3 11 40 12 - cmd_jq "tc -j -s filter show $id" \ 13 - ".[] | select(.options.handle == $handle) | \ 14 - select(.options.actions[0].stats.packets == $count)" \ 15 - &> /dev/null 41 + __tc_check_packets "$id" "$handle" "$count" "==" 16 42 } 17 43 18 44 tc_check_packets_hitting() ··· 46 20 local id=$1 47 21 local handle=$2 48 22 49 - cmd_jq "tc -j -s filter show $id" \ 50 - ".[] | select(.options.handle == $handle) | \ 51 - select(.options.actions[0].stats.packets > 0)" \ 52 - &> /dev/null 23 + __tc_check_packets "$id" "$handle" 0 ">" 53 24 }