Commit 408469d3 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

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: 07e5c751 ("selftests: forwarding: Introduce tc flower matching tests")
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 14e54ab9
...@@ -3,16 +3,42 @@ ...@@ -3,16 +3,42 @@
CHECK_TC="yes" CHECK_TC="yes"
# Can be overridden by the configuration file. See lib.sh
TC_HIT_TIMEOUT=${TC_HIT_TIMEOUT:=1000} # ms
__tc_check_packets()
{
local id=$1
local handle=$2
local count=$3
local operator=$4
start_time="$(date -u +%s%3N)"
while true
do
cmd_jq "tc -j -s filter show $id" \
".[] | select(.options.handle == $handle) | \
select(.options.actions[0].stats.packets $operator $count)" \
&> /dev/null
ret=$?
if [[ $ret -eq 0 ]]; then
return $ret
fi
current_time="$(date -u +%s%3N)"
diff=$(expr $current_time - $start_time)
if [ "$diff" -gt "$TC_HIT_TIMEOUT" ]; then
return 1
fi
done
}
tc_check_packets() tc_check_packets()
{ {
local id=$1 local id=$1
local handle=$2 local handle=$2
local count=$3 local count=$3
cmd_jq "tc -j -s filter show $id" \ __tc_check_packets "$id" "$handle" "$count" "=="
".[] | select(.options.handle == $handle) | \
select(.options.actions[0].stats.packets == $count)" \
&> /dev/null
} }
tc_check_packets_hitting() tc_check_packets_hitting()
...@@ -20,8 +46,5 @@ tc_check_packets_hitting() ...@@ -20,8 +46,5 @@ tc_check_packets_hitting()
local id=$1 local id=$1
local handle=$2 local handle=$2
cmd_jq "tc -j -s filter show $id" \ __tc_check_packets "$id" "$handle" 0 ">"
".[] | select(.options.handle == $handle) | \
select(.options.actions[0].stats.packets > 0)" \
&> /dev/null
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment