Skip to content

Commit 983751d

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 983751d

File tree

2 files changed

+65
-26
lines changed

2 files changed

+65
-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: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,49 @@ 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+
# shellcheck disable=SC2009
22+
ps -o comm= -p "$PPID" | grep -q "run-test.sh"
23+
}
24+
25+
emit_result_and_signal() (
26+
TESTCASE="$1"
27+
RESULT="$2"
28+
29+
res_file="./${TESTCASE}.res"
30+
31+
# Overwrite only if running standalone and file doesn't exist
32+
if ! is_suite_run && [ ! -f "$res_file" ]; then
33+
: > "$res_file"
34+
fi
35+
36+
echo "$TESTCASE $RESULT" >> "$res_file"
37+
38+
echo "" >&2
39+
echo "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=${TESTCASE} RESULT=${RESULT}>" >&2
40+
echo "" >&2
41+
sleep 0.1
42+
)
43+
44+
log_pass_and_emit() {
45+
TESTCASE="$1"
46+
log_pass "$TESTCASE PASS"
47+
emit_result_and_signal "$TESTCASE" "PASS"
48+
}
49+
50+
log_fail_and_emit() {
51+
TESTCASE="$1"
52+
log_fail "$TESTCASE FAIL"
53+
emit_result_and_signal "$TESTCASE" "FAIL"
54+
}
55+
56+
log_skip_and_emit() {
57+
TESTCASE="$1"
58+
log_skip "$TESTCASE SKIP"
59+
emit_result_and_signal "$TESTCASE" "SKIP"
60+
}
61+
1962
# --- Kernel Log Collection ---
2063
get_kernel_log() {
2164
if command -v journalctl >/dev/null 2>&1; then
@@ -133,19 +176,19 @@ unload_kernel_module() {
133176
check_dependencies() {
134177
missing=0
135178
missing_cmds=""
179+
testname="${TESTNAME:-UnknownTest}"
180+
136181
for cmd in "$@"; do
137182
if ! command -v "$cmd" >/dev/null 2>&1; then
138183
log_warn "Required command '$cmd' not found in PATH."
139184
missing=1
140185
missing_cmds="$missing_cmds $cmd"
141186
fi
142187
done
188+
143189
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
190+
log_skip "${testname} SKIP: missing dependencies:$missing_cmds"
191+
log_skip_and_emit "$testname"
149192
exit 0
150193
fi
151194
}

0 commit comments

Comments
 (0)