Skip to content

Commit c8f4b19

Browse files
liuhangbinkuba-moo
authored andcommitted
selftests/net/forwarding: add slowwait functions
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 <[email protected]> Signed-off-by: Hangbin Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent b27696c commit c8f4b19

File tree

1 file changed

+35
-0
lines changed
  • tools/testing/selftests/net/forwarding

1 file changed

+35
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,32 @@ fi
3737

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

40+
# timeout in seconds
41+
slowwait()
42+
{
43+
local timeout=$1; shift
44+
45+
local start_time="$(date -u +%s)"
46+
while true
47+
do
48+
local out
49+
out=$("$@")
50+
local ret=$?
51+
if ((!ret)); then
52+
echo -n "$out"
53+
return 0
54+
fi
55+
56+
local current_time="$(date -u +%s)"
57+
if ((current_time - start_time > timeout)); then
58+
echo -n "$out"
59+
return 1
60+
fi
61+
62+
sleep 0.1
63+
done
64+
}
65+
4066
##############################################################################
4167
# Sanity checks
4268

@@ -478,6 +504,15 @@ busywait_for_counter()
478504
busywait "$timeout" until_counter_is ">= $((base + delta))" "$@"
479505
}
480506

507+
slowwait_for_counter()
508+
{
509+
local timeout=$1; shift
510+
local delta=$1; shift
511+
512+
local base=$("$@")
513+
slowwait "$timeout" until_counter_is ">= $((base + delta))" "$@"
514+
}
515+
481516
setup_wait_dev()
482517
{
483518
local dev=$1; shift

0 commit comments

Comments
 (0)