[net-next,12/14] selftests: forwarding: lib: Add helpers for busywaiting
diff mbox series

Message ID 20200124132318.712354-13-idosch@idosch.org
State Accepted
Delegated to: David Miller
Headers show
  • mlxsw: Offload TBF
Related show

Commit Message

Ido Schimmel Jan. 24, 2020, 1:23 p.m. UTC
From: Petr Machata <petrm@mellanox.com>

The function busywait() is handy as a safety-latched variant of a while
loop. Many selftests deal specifically with counter values, and busywaiting
on them is likely to be rather common (it is not quite common now, but
busywait() has not been around for very long). To facilitate expressing
simply what is tested, introduce two helpers:

- until_counter_is(), which can be used as a predicate passed to
  busywait(), which holds when expression, which is itself passed as an
  argument to until_counter_is(), reaches a desired value.

- busywait_for_counter(), which is useful for waiting until a given counter
  changes "by" (as opposed to "to") a certain amount.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
 tools/testing/selftests/net/forwarding/lib.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff mbox series

diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
index 10cdfc0adca8..096340f064db 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -248,6 +248,24 @@  busywait()
+	local value=$1; shift
+	local current=$("$@")
+	echo $((current))
+	((current >= value))
+	local timeout=$1; shift
+	local delta=$1; shift
+	local base=$("$@")
+	busywait "$timeout" until_counter_is $((base + delta)) "$@"
 	local dev=$1; shift