Skip to contentSkip to conversation

test/cxl-translate.sh: wait for completion messages in the journal

PATCH New Li Ming 1 participant 1 message Nov 24 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Li Ming

author
#0 lore raw

PATCH v2 1/1 test/cxl-translate.sh: wait for completion messages in the journal

The cxl-translate test occasionally fails when verifying kernel log messages immediately after loading cxl_translate.

Although the expected messages have been emitted by the kernel, they may not yet be visible through "journalctl --reverse --dmesg" due to the delay between kernel log generation and journald processing. As a result, log verification can run before the required messages become available and report a false failure.

Add a helper to wait for the expected completion messages before checking test results. This avoids timing-related failures and makes the test more reliable.

Additionally, the table test emits multiple PASS/FAIL messages during testing. Although the test has completed when modprobe returns, journalctl may query the journal before journald has recorded all PASS/FAIL messages. The final message emitted by the table test is "CXL translate test completed". Use it as the completion marker for the wait helper so that all PASS/FAIL messages are visible in the journal before the results are checked.

Fixes f643715 ("test/cxl-translate.sh: add new cxl-translate.sh unit test")

---
v2:
* Combine patch 2 with patch 1.
* wait_for_expected_log() returns a status.
* Check log again once after the final sleep in wait_for_expected_log().
* Check the return status of journalctl.
* Adjust commit log.

---
 test/cxl-translate.sh | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)
test/cxl-translate.sh +33 -5
index b839179..a48c114 100755
@@ -41,12 +41,43 @@ set_log_start_time() {
 	log_start_time=$(date '+%Y-%m-%d %H:%M:%S.%3N')
 }
 
+wait_for_expected_log() {
+	local pattern="$1"
+	local timeout=5
+	local log
+
+	if ! log=$(journalctl --reverse --dmesg --since "$log_start_time"); then
+		return 1
+	fi
+
+	if echo "$log" | grep -Eq "$pattern"; then
+		echo "$log"
+		return 0
+	fi
+
+	while [ $timeout -gt 0 ]; do
+		sleep 1
+		timeout=$((timeout - 1))
+
+		if ! log=$(journalctl --reverse --dmesg --since "$log_start_time"); then
+			return 1
+		fi
+
+		if echo "$log" | grep -Eq "$pattern"; then
+			echo "$log"
+			return 0
+		fi
+	done
+
+	return 1
+}
+
 check_dmesg_results() {
 	local nr_entries=$1
 	local expect_failures=${2:-false} # Optional param, builtin true|false
 	local log nr_pass nr_fail
 
-	log=$(journalctl --reverse --dmesg --since "$log_start_time")
+	log=$(wait_for_expected_log "CXL translate test completed") || err "$LINENO"
 
 	nr_pass=$(echo "$log" | grep -c "CXL Translate Test.*PASS") || nr_pass=0
 	nr_fail=$(echo "$log" | grep -c "CXL Translate Test.*FAIL") || nr_fail=0
@@ -309,10 +340,7 @@ test_internal() {
 	rmmod cxl-translate 2>/dev/null || true
 	modprobe cxl_translate
 
-	local log
-	log=$(journalctl --reverse --dmesg --since "$log_start_time")
-
-	if echo "$log" | grep -q "Internal validation test completed successfully"; then
+	if wait_for_expected_log "Internal validation test completed successfully"; then
 		echo "Internal validation test: PASS"
 	else
 		echo "Internal validation test: FAIL"
Signature · 1 line
2.43.0