Skip to content

Commit

Permalink
selftests/net/forwarding: add slowwait functions
Browse files Browse the repository at this point in the history
Add slowwait functions to wait for some operations that may need a long time
to finish. The busywait executes the cmd too fast, which is kind of wasting
cpu in this scenario. At the same time, if shell debugging is enabled with
`set -x`. the busywait will output too much logs.

Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Link: https://lore.kernel.org/r/20240205130048.282087-2-liuhangbin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Hangbin Liu authored and Jakub Kicinski committed Feb 8, 2024
1 parent b27696c commit c8f4b19
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tools/testing/selftests/net/forwarding/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@ fi

source "$net_forwarding_dir/../lib.sh"

# timeout in seconds
slowwait()
{
local timeout=$1; shift

local start_time="$(date -u +%s)"
while true
do
local out
out=$("$@")
local ret=$?
if ((!ret)); then
echo -n "$out"
return 0
fi

local current_time="$(date -u +%s)"
if ((current_time - start_time > timeout)); then
echo -n "$out"
return 1
fi

sleep 0.1
done
}

##############################################################################
# Sanity checks

Expand Down Expand Up @@ -478,6 +504,15 @@ busywait_for_counter()
busywait "$timeout" until_counter_is ">= $((base + delta))" "$@"
}

slowwait_for_counter()
{
local timeout=$1; shift
local delta=$1; shift

local base=$("$@")
slowwait "$timeout" until_counter_is ">= $((base + delta))" "$@"
}

setup_wait_dev()
{
local dev=$1; shift
Expand Down

0 comments on commit c8f4b19

Please sign in to comment.