Skip to contentSkip to conversation

Fix cxl-translate.sh test failures

PATCH In review Li Ming 2 participants 7 messages Nov 20 – Nov 23

lore
Share & tools
lore

Li Ming

author
#0 lore raw

cover Fix cxl-translate.sh test failures

When running cxl-translate.sh repeatedly in my test environment, I can occasionally reproduce test failures. The failure point varies from run to run, but the root cause is the same: the test is unable to find the expected kernel log messages.

Investigation shows that the expected messages are actually present in dmesg. However, immediately after "modprobe cxl_translate" completes, "journalctl --reverse --dmesg" may not yet have received all kernel messages emitted during cxl_translate_init(). This timing gap causes the test script to miss expected log entries and report false failures.

This patchset addresses the issue in two steps:
Patch 1 adds a helper that retries fetching the expected kernel log message for up to 5 seconds. This mitigates failures caused by temporary delays in log visibility through journalctl.

Patch 2 updates the result checking logic for test cases that use a specific translation table. Instead of treating the appearance of a "CXL Translate Test.*PASS|FAIL" message as an indication that the test has finished, it waits for the "CXL translate test completed" message. During test execution, multiple "CXL Translate Test.*PASS|FAIL" messages may be emitted as individual checks complete, so the presence of such messages does not necessarily mean that the entire test has finished. The completion message provides a reliable indication that all test cases have completed and all results are available for verification.

Li Ming (2):
test/cxl-translate.sh: Wait expected log before checking result test/cxl-translate.sh: Wait for test completion before checking result

 test/cxl-translate.sh | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/2 test/cxl-translate.sh: Wait expected log before checking result

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.

Fixes f643715 ("test/cxl-translate.sh: add new cxl-translate.sh unit test")
---
 test/cxl-translate.sh | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
test/cxl-translate.sh +21 -2
index b839179..2fbc310 100755
@@ -41,12 +41,31 @@ 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
+
+	while [ $timeout -gt 0 ]; do
+		local log=$(journalctl --reverse --dmesg --since "$log_start_time")
+
+		if echo "$log" | grep -Eq "$pattern";then
+			echo "$log"
+			return
+		fi
+
+		sleep 1
+		timeout=$((timeout - 1))
+	done
+
+	err $LINENO
+}
+
 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.*(PASS|FAIL)")
 
 	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
@@ -310,7 +329,7 @@ test_internal() {
 	modprobe cxl_translate
 
 	local log
-	log=$(journalctl --reverse --dmesg --since "$log_start_time")
+	log=$(wait_for_expected_log "Internal validation test completed successfully")
 
 	if echo "$log" | grep -q "Internal validation test completed successfully"; then
 		echo "Internal validation test: PASS"
Signature · 1 line
2.43.0
#2 lore raw

Re: [ndctl PATCH 1/2] test/cxl-translate.sh: Wait expected log before checking result

On Fri, Nov 20, 2026 at 03:14:14PM +0800, Li Ming wrote:

For the Subject, ndctl uses lowercase after the prefix. With patch 2 folded in, how about "test/cxl-translate.sh: wait for completion messages in the journal"?

Add [email protected] to recipients list.

Quoted 25 lines

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.

Fixes f643715 ("test/cxl-translate.sh: add new cxl-translate.sh unit test")
---
 test/cxl-translate.sh | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
test/cxl-translate.sh +0 -0
index b839179..2fbc310 100755
@@ -41,12 +41,31 @@ set_log_start_time() {
 	log_start_time=$(date '+%Y-%m-%d %H:%M:%S.%3N')

test/cxl-translate.sh set_log_start_time() { · line 51

Quoted 10 lines
test/cxl-translate.sh +8 -0
 }
 
+wait_for_expected_log() {
+	local pattern="$1"
+	local timeout=5
+
+	while [ $timeout -gt 0 ]; do
+		local log=$(journalctl --reverse --dmesg --since "$log_start_time")
+
+		if echo "$log" | grep -Eq "$pattern";then

Please declare log once above the loop and assign it separately to avoid SC2155. Check the journalctl status explicitly so a failed read is reported as such. Please also add the space before "then" to keep the script shfmt-clean.

shfmt -d test/cxl-translate.sh
That one was clean before these changes, so keep it clean ;)

shellcheck test/cxl-translate.sh
For shellcheck we are excusing SC1091 (sourcing common) and SC2034 (rc is used by err() in common. I've also disable sometimes for shellcheck complaints without nice fixups, like the namerefs.

I think for the one you have above, tidy'ing it up by declaring log once above the loop works well.

test/cxl-translate.sh set_log_start_time() { · line 58

Quoted 7 lines
test/cxl-translate.sh +7 -0
+			echo "$log"
+			return
+		fi
+
+		sleep 1
+		timeout=$((timeout - 1))
+	done

Since the first check is immediate, the last check happens about four seconds in. The loop then sleeps for another second and exits. Can we check once more after that last sleep to catch a marker that arrives during it?

test/cxl-translate.sh set_log_start_time() { · line 60

Quoted 2 lines
test/cxl-translate.sh +2 -0
+
+	err $LINENO

Could the helper return a failure status on timeout and let the callers call err "$LINENO" so we still get the usual failure output?

Quoted 13 lines
test/cxl-translate.sh +3 -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.*(PASS|FAIL)")
 
 	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

test/cxl-translate.sh test_internal() { · line 335

Quoted 8 lines
test/cxl-translate.sh +1 -1
@@ -310,7 +329,7 @@ test_internal() {
 	modprobe cxl_translate
 
 	local log
-	log=$(journalctl --reverse --dmesg --since "$log_start_time")
+	log=$(wait_for_expected_log "Internal validation test completed successfully")
 
 	if echo "$log" | grep -q "Internal validation test completed successfully"; then
 		echo "Internal validation test: PASS"

Now that wait_for_expected_log() checks for the success message, try letting test_internal() use the helper’s return status directly and drop the second grep and its else branch?

-- Alison

Quoted 3 lines
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH 2/2 test/cxl-translate.sh: Wait for test completion before checking result

In reply to Li Ming

The cxl-translate test emits multiple PASS/FAIL messages while the test is still running. Checking the results immediately after seeing a PASS/FAIL message may race with the remaining test execution and lead to incorrect result accounting.

Use the "CXL translate test completed" message as the completion marker before collecting PASS/FAIL statistics, since it is printed only after all test cases have finished.

---
 test/cxl-translate.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
test/cxl-translate.sh +1 -1
index 2fbc310..51d0676 100755
@@ -65,7 +65,7 @@ check_dmesg_results() {
 	local expect_failures=${2:-false} # Optional param, builtin true|false
 	local log nr_pass nr_fail
 
-	log=$(wait_for_expected_log "CXL Translate Test.*(PASS|FAIL)")
+	log=$(wait_for_expected_log "CXL translate test completed")
 
 	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
Signature · 1 line
2.43.0
#4 lore raw

Re: [ndctl PATCH 2/2] test/cxl-translate.sh: Wait for test completion before checking result

Quoted 4 lines · Li Ming

The cxl-translate test emits multiple PASS/FAIL messages while the test is still running. Checking the results immediately after seeing a PASS/FAIL message may race with the remaining test execution and lead to incorrect result accounting.

Clarify that the test has finished when modprobe returns, but journalctl can read the journal before journald has recorded all the results?

Quoted 15 lines

Use the "CXL translate test completed" message as the completion marker before collecting PASS/FAIL statistics, since it is printed only after all test cases have finished.

---
 test/cxl-translate.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
test/cxl-translate.sh +0 -0
index 2fbc310..51d0676 100755

test/cxl-translate.sh check_dmesg_results() { · line 68

Quoted 5 lines
test/cxl-translate.sh +1 -1
@@ -65,7 +65,7 @@ check_dmesg_results() {
 	local expect_failures=${2:-false} # Optional param, builtin true|false
 	local log nr_pass nr_fail
 
-	log=$(wait_for_expected_log "CXL Translate Test.*(PASS|FAIL)")
+	log=$(wait_for_expected_log "CXL translate test completed")

Please fold this into patch 1 so the table tests wait for the completion marker from the first commit that adds polling. Waiting for the first PASS/FAIL line still leaves the count check racy.

-- Alison

Quoted 6 lines
test/cxl-translate.sh +0 -0
 	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
Signature · 1 line
2.43.0
#5 lore raw
In reply to Li Ming
Quoted 10 lines · Li Ming

When running cxl-translate.sh repeatedly in my test environment, I can occasionally reproduce test failures. The failure point varies from run to run, but the root cause is the same: the test is unable to find the expected kernel log messages.

Investigation shows that the expected messages are actually present in dmesg. However, immediately after "modprobe cxl_translate" completes, "journalctl --reverse --dmesg" may not yet have received all kernel messages emitted during cxl_translate_init(). This timing gap causes the test script to miss expected log entries and report false failures.

Hi Ming,

Good catch! Can you fold patch 2 into patch 1. Both address the same delay between modprobe returning and the results becoming visible in the journal. Patch 1 can still fail if journald has recorded only the first PASS or FAIL line, and patch 2 supplies the completion marker that makes the polling work.

-- Alison

Quoted 27 lines

This patchset addresses the issue in two steps:
Patch 1 adds a helper that retries fetching the expected kernel log message for up to 5 seconds. This mitigates failures caused by temporary delays in log visibility through journalctl.

Patch 2 updates the result checking logic for test cases that use a specific translation table. Instead of treating the appearance of a "CXL Translate Test.*PASS|FAIL" message as an indication that the test has finished, it waits for the "CXL translate test completed" message. During test execution, multiple "CXL Translate Test.*PASS|FAIL" messages may be emitted as individual checks complete, so the presence of such messages does not necessarily mean that the entire test has finished. The completion message provides a reliable indication that all test cases have completed and all results are available for verification.

Li Ming (2):
test/cxl-translate.sh: Wait expected log before checking result test/cxl-translate.sh: Wait for test completion before checking result

 test/cxl-translate.sh | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
author
#6 lore raw
Quoted 11 lines · Alison Schofield
Quoted 10 lines · Li Ming

When running cxl-translate.sh repeatedly in my test environment, I can occasionally reproduce test failures. The failure point varies from run to run, but the root cause is the same: the test is unable to find the expected kernel log messages.

Investigation shows that the expected messages are actually present in dmesg. However, immediately after "modprobe cxl_translate" completes, "journalctl --reverse --dmesg" may not yet have received all kernel messages emitted during cxl_translate_init(). This timing gap causes the test script to miss expected log entries and report false failures.

Quoted 8 lines

Hi Ming,

Good catch! Can you fold patch 2 into patch 1. Both address the same delay between modprobe returning and the results becoming visible in the journal. Patch 1 can still fail if journald has recorded only the first PASS or FAIL line, and patch 2 supplies the completion marker that makes the polling work.

-- Alison

Hi Alison,

Thanks for your review.

I have read all your comments, will send out v2 based on your suggestions.

Ming

Quoted 27 lines
Quoted 27 lines

This patchset addresses the issue in two steps:
Patch 1 adds a helper that retries fetching the expected kernel log message for up to 5 seconds. This mitigates failures caused by temporary delays in log visibility through journalctl.

Patch 2 updates the result checking logic for test cases that use a specific translation table. Instead of treating the appearance of a "CXL Translate Test.*PASS|FAIL" message as an indication that the test has finished, it waits for the "CXL translate test completed" message. During test execution, multiple "CXL Translate Test.*PASS|FAIL" messages may be emitted as individual checks complete, so the presence of such messages does not necessarily mean that the entire test has finished. The completion message provides a reliable indication that all test cases have completed and all results are available for verification.

Li Ming (2):
test/cxl-translate.sh: Wait expected log before checking result test/cxl-translate.sh: Wait for test completion before checking result

  test/cxl-translate.sh | 23 +++++++++++++++++++++--
  1 file changed, 21 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0