Skip to content

Commit 408469d

Browse files
jpirkodavem330
authored andcommitted
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: 07e5c75 ("selftests: forwarding: Introduce tc flower matching tests") Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 14e54ab commit 408469d

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

tools/testing/selftests/net/forwarding/tc_common.sh

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,48 @@
33

44
CHECK_TC="yes"
55

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+
635
tc_check_packets()
736
{
837
local id=$1
938
local handle=$2
1039
local count=$3
1140

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" "=="
1642
}
1743

1844
tc_check_packets_hitting()
1945
{
2046
local id=$1
2147
local handle=$2
2248

23-
cmd_jq "tc -j -s filter show $id" \
24-
".[] | select(.options.handle == $handle) | \
25-
select(.options.actions[0].stats.packets > 0)" \
26-
&> /dev/null
49+
__tc_check_packets "$id" "$handle" 0 ">"
2750
}

0 commit comments

Comments
 (0)