aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
authorPetr Machata <petrm@mellanox.com>2020-01-24 15:23:16 +0200
committerDavid S. Miller <davem@davemloft.net>2020-01-25 10:56:31 +0100
commit4121d9479b24c20ff7d3e7b62a7cf330fae7b2af (patch)
tree14f81a442d81c22b2239cab4a8b9f2e4456f6cf8 /tools/testing
parentselftests: Move two functions from mlxsw's qos_lib to lib (diff)
downloadlinux-dev-4121d9479b24c20ff7d3e7b62a7cf330fae7b2af.tar.xz
linux-dev-4121d9479b24c20ff7d3e7b62a7cf330fae7b2af.zip
selftests: forwarding: lib: Add helpers for busywaiting
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> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/net/forwarding/lib.sh18
1 files changed, 18 insertions, 0 deletions
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()
done
}
+until_counter_is()
+{
+ local value=$1; shift
+ local current=$("$@")
+
+ echo $((current))
+ ((current >= value))
+}
+
+busywait_for_counter()
+{
+ local timeout=$1; shift
+ local delta=$1; shift
+
+ local base=$("$@")
+ busywait "$timeout" until_counter_is $((base + delta)) "$@"
+}
+
setup_wait_dev()
{
local dev=$1; shift