Skip to content

Commit

Permalink
selftests: forwarding: tc_common: Convert to use busywait
Browse files Browse the repository at this point in the history
A function busywait() was recently added based on the logic in
__tc_check_packets(). Convert the code in tc_common to use the new
function.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Reviewed-by: Amit Cohen <amitc@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Petr Machata authored and David S. Miller committed Mar 4, 2020
1 parent 844f055 commit 47b0e09
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions tools/testing/selftests/net/forwarding/tc_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,21 @@ 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()
{
local id=$1
local handle=$2
local count=$3

__tc_check_packets "$id" "$handle" "$count" "=="
busywait "$TC_HIT_TIMEOUT" until_counter_is "== $count" \
tc_rule_handle_stats_get "$id" "$handle" > /dev/null
}

tc_check_packets_hitting()
{
local id=$1
local handle=$2

__tc_check_packets "$id" "$handle" 0 ">"
busywait "$TC_HIT_TIMEOUT" until_counter_is "> 0" \
tc_rule_handle_stats_get "$id" "$handle" > /dev/null
}

0 comments on commit 47b0e09

Please sign in to comment.