All of lore.kernel.org
 help / color / mirror / Atom feed
* [ndctl PATCH v3] test/monitor.sh: replace sleep with event driven wait
@ 2025-05-19 19:28 alison.schofield
  2025-05-19 22:42 ` Marc Herbert
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: alison.schofield @ 2025-05-19 19:28 UTC (permalink / raw)
  To: nvdimm, Marc Herbert, Li Zhijian; +Cc: Alison Schofield

From: Alison Schofield <alison.schofield@intel.com>

monitor.sh runs for 50 seconds and spends 48 of those seconds sleeping
after sync. It sleeps for 3 seconds each time it restarts the monitor,
and 3 seconds before checking for expected log entries.

Add a wait_for_logfile_update() helper that waits a max of 3 seconds
for an expected string to appear N times in the logfile using tail -F.

Add a "monitor ready" log message to the monitor executable and wait
for that message once after monitor start. Note that if no DIMM has an
event flag set, there will be no log entry at startup. Always look for
the "monitor ready" message.

Expand the check_result() function to handle both the sync and wait
that were previously duplicated in inject_smart() and call_notify().
It now waits for the expected N of new log entries.

Again, looking for Tested-by Tags. Thanks!

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---

Changes in v3:
- Add and use a helper that uses tail -F
- Add ready message to monitor.c
- Update commit msg and log
Link to v2: https://lore.kernel.org/nvdimm/20250516044628.1532939-1-alison.schofield@intel.com/

Changes in v2:
- Poll for 3 seconds instead of removing sleep entirely (MarcH)
- Update commit msg & log
Link to v1: https://lore.kernel.org/nvdimm/20250514014133.1431846-1-alison.schofield@intel.com/


 ndctl/monitor.c |  2 +-
 test/monitor.sh | 24 +++++++++++++++++++++---
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/ndctl/monitor.c b/ndctl/monitor.c
index bd8a74863476..925b37f4184b 100644
--- a/ndctl/monitor.c
+++ b/ndctl/monitor.c
@@ -658,7 +658,7 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx)
 			rc = -ENXIO;
 		goto out;
 	}
-
+	info(&monitor, "monitor ready\n");
 	rc = monitor_event(ctx, &mfa);
 out:
 	if (monitor.ctx.log_file)
diff --git a/test/monitor.sh b/test/monitor.sh
index be8e24d6f3aa..d0666392ab5b 100755
--- a/test/monitor.sh
+++ b/test/monitor.sh
@@ -21,12 +21,28 @@ trap 'err $LINENO' ERR
 
 check_min_kver "4.15" || do_skip "kernel $KVER may not support monitor service"
 
+wait_for_logfile_update()
+{
+	local expect_string="$1"
+	local expect_count="$2"
+
+	# Wait up to 3s for $expect_count occurrences of $expect_string
+	# tail -n +1 -F: starts watching the logfile from the first line
+
+	if ! timeout 3s tail -n +1 -F "$logfile" | grep -m "$expect_count" -q "$expect_string"; then
+		echo "logfile not updated in 3 secs"
+		err "$LINENO"
+	fi
+}
+
 start_monitor()
 {
 	logfile=$(mktemp)
 	$NDCTL monitor -c "$monitor_conf" -l "$logfile" $1 &
 	monitor_pid=$!
-	sync; sleep 3
+
+	sync
+	wait_for_logfile_update "monitor ready" 1
 	truncate --size 0 "$logfile" #remove startup log
 }
 
@@ -49,17 +65,19 @@ get_monitor_dimm()
 call_notify()
 {
 	"$TEST_PATH"/smart-notify "$smart_supported_bus"
-	sync; sleep 3
 }
 
 inject_smart()
 {
 	$NDCTL inject-smart "$monitor_dimms" $1
-	sync; sleep 3
 }
 
 check_result()
 {
+	sync
+	expect_count=$(wc -w <<< "$1")
+	wait_for_logfile_update "timestamp" "$expect_count"
+
 	jlog=$(cat "$logfile")
 	notify_dimms=$(jq ."dimm"."dev" <<<"$jlog" | sort | uniq | xargs)
 	[[ "$1" == "$notify_dimms" ]]
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-05-22 22:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-19 19:28 [ndctl PATCH v3] test/monitor.sh: replace sleep with event driven wait alison.schofield
2025-05-19 22:42 ` Marc Herbert
2025-05-22  4:20   ` Alison Schofield
2025-05-20 20:47 ` Verma, Vishal L
2025-05-22  4:22   ` Alison Schofield
2025-05-21  9:00 ` Zhijian Li (Fujitsu)
2025-05-22  4:35   ` Alison Schofield
2025-05-22 18:38     ` Dan Williams
2025-05-22 22:05       ` Alison Schofield

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.