summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2023-04-25 17:14:40 -0700
committerZorro Lang <zlang@kernel.org>2023-05-01 00:05:02 +0800
commit2e361b3da66d3537ec9b78d1b7bd12654a3a1ef8 (patch)
tree76be56a1eb565dc6361b778012d521aa97158dfd /common
parent3e85dd4fe4236d8ef8dc9f9b542a56dd00d16a17 (diff)
misc: add duration for recovery loop testsv2023.05.01
Make it so that we can run recovery loop tests for an exact number of seconds. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Andrey Albershteyn <aalbersh@redhat.com> Signed-off-by: Zorro Lang <zlang@kernel.org>
Diffstat (limited to 'common')
-rw-r--r--common/rc34
1 files changed, 34 insertions, 0 deletions
diff --git a/common/rc b/common/rc
index ad9179e2..37074371 100644
--- a/common/rc
+++ b/common/rc
@@ -5183,6 +5183,40 @@ _require_unix_perm_checking()
esac
}
+# Decide if a soak test should continue looping. The sole parameter is the
+# number of soak loops that the test wants to run by default. The actual
+# loop iteration number is stored in SOAK_LOOPIDX until the loop completes.
+#
+# If the test runner set a SOAK_DURATION value, this predicate will keep
+# looping until it has run for at least that long.
+_soak_loop_running() {
+ local max_soak_loops="$1"
+
+ test -z "$SOAK_LOOPIDX" && SOAK_LOOPIDX=1
+
+ if [ -n "$SOAK_DURATION" ]; then
+ if [ -z "$SOAK_DEADLINE" ]; then
+ SOAK_DEADLINE="$(( $(date +%s) + SOAK_DURATION))"
+ fi
+
+ local now="$(date +%s)"
+ if [ "$now" -gt "$SOAK_DEADLINE" ]; then
+ unset SOAK_DEADLINE
+ unset SOAK_LOOPIDX
+ return 1
+ fi
+ SOAK_LOOPIDX=$((SOAK_LOOPIDX + 1))
+ return 0
+ fi
+
+ if [ "$SOAK_LOOPIDX" -gt "$max_soak_loops" ]; then
+ unset SOAK_LOOPIDX
+ return 1
+ fi
+ SOAK_LOOPIDX=$((SOAK_LOOPIDX + 1))
+ return 0
+}
+
init_rc
################################################################################