Skip to content

Commit d269ccb

Browse files
committed
utils: add emit_result_and_signal() with log_pass/fail/skip wrappers
Introduce emit_result_and_signal() to standardize writing test results to .res files and emitting LAVA-compatible result signals to stderr. This function ensures compatibility with both direct test execution and suite-based runs using run-test.sh. Adds: - emit_result_and_signal(TESTCASE, RESULT) - log_pass_and_emit() - log_fail_and_emit() - log_skip_and_emit() This avoids direct 'echo > .res' in run.sh, enables proper result accumulation, and ensures LAVA signals are robust even under dmesg log flooding. Signed-off-by: Srikanth Muppandam <[email protected]>
1 parent 7433bb9 commit d269ccb

File tree

2 files changed

+64
-26
lines changed

2 files changed

+64
-26
lines changed

Runner/suites/Kernel/FunctionalArea/baseport/adsp_remoteproc/run.sh

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,52 +41,48 @@ log_info "=== Test Initialization ==="
4141

4242
# Get the firmware output and find the position of adsp
4343
log_info "Checking for firmware"
44-
firmware_output=$(cat /sys/class/remoteproc/remoteproc*/firmware)
44+
firmware_output=$(cat /sys/class/remoteproc/remoteproc*/firmware 2>/dev/null)
4545
adsp_position=$(echo "$firmware_output" | grep -n "adsp" | cut -d: -f1)
4646

47-
# Adjust the position to match the remoteproc numbering (starting from 0)
48-
remoteproc_number=$((adsp_position - 1))
47+
if [ -z "$adsp_position" ]; then
48+
log_skip_and_emit "$TESTNAME"
49+
exit 0
50+
fi
4951

50-
# Construct the remoteproc path based on the adsp position
52+
remoteproc_number=$((adsp_position - 1))
5153
remoteproc_path="/sys/class/remoteproc/remoteproc${remoteproc_number}"
5254
log_info "Remoteproc node is $remoteproc_path"
53-
# Execute command 1 and check if the output is "running"
54-
state1=$(cat ${remoteproc_path}/state)
5555

56+
# Check if already running
57+
state1=$(cat "${remoteproc_path}/state" 2>/dev/null)
5658
if [ "$state1" != "running" ]; then
57-
log_fail "$TESTNAME : Test Failed"
58-
echo "$TESTNAME FAIL" > "$test_path/$TESTNAME.res"
59+
log_fail_and_emit "$TESTNAME"
5960
exit 1
6061
fi
6162

62-
# Execute command 2 (no output expected)
6363
log_info "Stopping remoteproc"
64-
echo stop > ${remoteproc_path}/state
64+
echo stop > "${remoteproc_path}/state"
6565

66-
# Execute command 3 and check if the output is "offline"
67-
state3=$(cat ${remoteproc_path}/state)
66+
state3=$(cat "${remoteproc_path}/state" 2>/dev/null)
6867
if [ "$state3" != "offline" ]; then
6968
log_fail "adsp stop failed"
70-
echo "$TESTNAME FAIL" > "$test_path/$TESTNAME.res"
69+
log_fail_and_emit "$TESTNAME"
7170
exit 1
7271
else
7372
log_pass "adsp stop successful"
7473
fi
74+
7575
log_info "Restarting remoteproc"
76-
# Execute command 4 (no output expected)
77-
echo start > ${remoteproc_path}/state
76+
echo start > "${remoteproc_path}/state"
7877

79-
# Execute command 5 and check if the output is "running"
80-
state5=$(cat ${remoteproc_path}/state)
78+
state5=$(cat "${remoteproc_path}/state" 2>/dev/null)
8179
if [ "$state5" != "running" ]; then
8280
log_fail "adsp start failed"
83-
echo "$TESTNAME FAIL" > "$res_file"
81+
log_fail_and_emit "$TESTNAME"
8482
exit 1
8583
fi
8684

87-
# If all checks pass, print "PASS"
88-
echo "adsp PASS"
8985
log_pass "adsp PASS"
90-
echo "$TESTNAME PASS" > "$res_file"
86+
log_pass_and_emit "$TESTNAME"
9187
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
9288
exit 0

Runner/utils/functestlib.sh

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,48 @@ log_error() { log "ERROR" "$@"; }
1616
log_skip() { log "SKIP" "$@"; }
1717
log_warn() { log "WARN" "$@"; }
1818

19+
# Detect whether test is run as part of suite (run-test.sh)
20+
is_suite_run() {
21+
grep -q "run-test.sh" "/proc/$PPID/cmdline" 2>/dev/null
22+
}
23+
24+
emit_result_and_signal() (
25+
TESTCASE="$1"
26+
RESULT="$2"
27+
28+
res_file="./${TESTCASE}.res"
29+
30+
# Overwrite only if running standalone and file doesn't exist
31+
if ! is_suite_run && [ ! -f "$res_file" ]; then
32+
: > "$res_file"
33+
fi
34+
35+
echo "$TESTCASE $RESULT" >> "$res_file"
36+
37+
echo "" >&2
38+
echo "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=${TESTCASE} RESULT=${RESULT}>" >&2
39+
echo "" >&2
40+
sleep 0.1
41+
)
42+
43+
log_pass_and_emit() {
44+
TESTCASE="$1"
45+
log_pass "$TESTCASE PASS"
46+
emit_result_and_signal "$TESTCASE" "PASS"
47+
}
48+
49+
log_fail_and_emit() {
50+
TESTCASE="$1"
51+
log_fail "$TESTCASE FAIL"
52+
emit_result_and_signal "$TESTCASE" "FAIL"
53+
}
54+
55+
log_skip_and_emit() {
56+
TESTCASE="$1"
57+
log_skip "$TESTCASE SKIP"
58+
emit_result_and_signal "$TESTCASE" "SKIP"
59+
}
60+
1961
# --- Kernel Log Collection ---
2062
get_kernel_log() {
2163
if command -v journalctl >/dev/null 2>&1; then
@@ -133,19 +175,19 @@ unload_kernel_module() {
133175
check_dependencies() {
134176
missing=0
135177
missing_cmds=""
178+
testname="${TESTNAME:-UnknownTest}"
179+
136180
for cmd in "$@"; do
137181
if ! command -v "$cmd" >/dev/null 2>&1; then
138182
log_warn "Required command '$cmd' not found in PATH."
139183
missing=1
140184
missing_cmds="$missing_cmds $cmd"
141185
fi
142186
done
187+
143188
if [ "$missing" -ne 0 ]; then
144-
testname="${TESTNAME:-}"
145-
log_skip "${testname:-UnknownTest} SKIP: missing dependencies:$missing_cmds"
146-
if [ -n "$testname" ]; then
147-
echo "$testname SKIP" > "./$testname.res"
148-
fi
189+
log_skip "${testname} SKIP: missing dependencies:$missing_cmds"
190+
log_skip_and_emit "$testname"
149191
exit 0
150192
fi
151193
}

0 commit comments

Comments
 (0)