diff options
author | 2024-04-12 19:03:04 +0200 | |
---|---|---|
committer | 2024-04-16 12:14:41 +0200 | |
commit | a4022a332f437ae5b10921d66058ce98a2db2c20 (patch) | |
tree | 46aefecf4b056fb06d87edb0479d11e92f9fe8c6 /tools/testing/selftests/net/lib.sh | |
parent | net: dsa: mt7530: provide own phylink MAC operations (diff) | |
download | linux-a4022a332f437ae5b10921d66058ce98a2db2c20.tar.gz linux-a4022a332f437ae5b10921d66058ce98a2db2c20.tar.bz2 linux-a4022a332f437ae5b10921d66058ce98a2db2c20.zip |
selftests: net: Unify code of busywait() and slowwait()
Bodies of busywait() and slowwait() functions are almost identical. Extract
the common code into a helper, loopy_wait, and convert busywait() and
slowwait() into trivial wrappers.
Moreover, the fact that slowwait() uses seconds for units is really not
intuitive, and the comment does not help much. Instead make the unit part
of the name of the argument to further clarify what units are expected.
Cc: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Benjamin Poirier <bpoirier@nvidia.com>
Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Diffstat (limited to 'tools/testing/selftests/net/lib.sh')
-rw-r--r-- | tools/testing/selftests/net/lib.sh | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/tools/testing/selftests/net/lib.sh b/tools/testing/selftests/net/lib.sh index b7f7b8695165..c868c0aec121 100644 --- a/tools/testing/selftests/net/lib.sh +++ b/tools/testing/selftests/net/lib.sh @@ -58,9 +58,10 @@ ksft_exit_status_merge() $ksft_xfail $ksft_pass $ksft_skip $ksft_fail } -busywait() +loopy_wait() { - local timeout=$1; shift + local sleep_cmd=$1; shift + local timeout_ms=$1; shift local start_time="$(date -u +%s%3N)" while true @@ -74,13 +75,22 @@ busywait() fi local current_time="$(date -u +%s%3N)" - if ((current_time - start_time > timeout)); then + if ((current_time - start_time > timeout_ms)); then echo -n "$out" return 1 fi + + $sleep_cmd done } +busywait() +{ + local timeout_ms=$1; shift + + loopy_wait : "$timeout_ms" "$@" +} + cleanup_ns() { local ns="" |