Skip to content

Commit f43a43f

Browse files
committed
send-to-lava.sh: rewrite for POSIX compliance and atomic signal emission
This patch rewrites send-to-lava.sh to: - Ensure POSIX-compliant syntax (avoiding bashisms and non-portable constructs) - Use a temporary buffer file to accumulate signals before emitting them atomically - Avoid dmesg interference by delaying output flush and eliminating inline prints - Clean up temporary signal file after emission This resolves earlier LAVA parsing issues caused by kernel messages being interleaved with partial LAVA signal lines. Signed-off-by: Srikanth Muppandam <[email protected]>
1 parent ee67fc5 commit f43a43f

File tree

1 file changed

+27
-43
lines changed

1 file changed

+27
-43
lines changed

Runner/utils/send-to-lava.sh

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,36 @@
11
#!/bin/sh
22

33
RESULT_FILE="$1"
4+
SIGNAL_FILE="/tmp/lava_signals_$$.log"
45

5-
command -v lava-test-case > /dev/null 2>&1
6-
lava_test_case="$?"
7-
command -v lava-test-set > /dev/null 2>&1
8-
lava_test_set="$?"
6+
valid_result() {
7+
case "$1" in
8+
PASS|FAIL|SKIP|UNKNOWN) return 0 ;;
9+
*) return 1 ;;
10+
esac
11+
}
912

10-
if [ -f "${RESULT_FILE}" ]; then
11-
while read -r line; do
12-
if echo "${line}" | grep -iq -E ".* +(pass|fail|skip|unknown)$"; then
13-
test="${line%% *}"
14-
result="${line##* }"
13+
# Collect signals in buffer
14+
if [ -f "$RESULT_FILE" ]; then
15+
while IFS= read -r line || [ -n "$line" ]; do
16+
testcase=$(echo "$line" | awk '{print $1}')
17+
result=$(echo "$line" | awk '{print $NF}' | tr '[:lower:]' '[:upper:]')
18+
testcase_clean=$(echo "$testcase" | tr -dc '[:alnum:]_-')
1519

16-
if [ "${lava_test_case}" -eq 0 ]; then
17-
lava-test-case "${test}" --result "${result}"
18-
else
19-
echo "<TEST_CASE_ID=${test} RESULT=${result}>"
20-
fi
21-
elif echo "${line}" | grep -iq -E ".*+ (pass|fail|skip|unknown)+ .*+"; then
22-
test="$(echo "${line}" | awk '{print $1}')"
23-
result="$(echo "${line}" | awk '{print $2}')"
24-
measurement="$(echo "${line}" | awk '{print $3}')"
25-
units="$(echo "${line}" | awk '{print $4}')"
26-
27-
if [ "${lava_test_case}" -eq 0 ]; then
28-
if [ -n "${units}" ]; then
29-
lava-test-case "${test}" --result "${result}" --measurement "${measurement}" --units "${units}"
30-
else
31-
lava-test-case "${test}" --result "${result}" --measurement "${measurement}"
32-
fi
33-
else
34-
echo "<TEST_CASE_ID=${test} RESULT=${result} MEASUREMENT=${measurement} UNITS=${units}>"
35-
fi
36-
elif echo "${line}" | grep -iq -E "^lava-test-set.*"; then
37-
test_set_status="$(echo "${line}" | awk '{print $2}')"
38-
test_set_name="$(echo "${line}" | awk '{print $3}')"
39-
if [ "${lava_test_set}" -eq 0 ]; then
40-
lava-test-set "${test_set_status}" "${test_set_name}"
41-
else
42-
if [ "${test_set_status}" = "start" ]; then
43-
echo "<LAVA_SIGNAL_TESTSET START ${test_set_name}>"
44-
else
45-
echo "<LAVA_SIGNAL_TESTSET STOP>"
46-
fi
47-
fi
20+
if valid_result "$result"; then
21+
printf '<<<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=%s>>>\n' \
22+
"$testcase_clean" "$result" >> "$SIGNAL_FILE"
4823
fi
49-
done < "${RESULT_FILE}"
24+
done < "$RESULT_FILE"
5025
else
51-
echo "WARNING: result file is missing!"
26+
echo "[WARNING] Result file missing: $RESULT_FILE" >&2
27+
fi
28+
29+
# Emit signals in one clean atomic flush
30+
if [ -s "$SIGNAL_FILE" ]; then
31+
sleep 1 # small delay to let dmesg calm
32+
cat "$SIGNAL_FILE"
5233
fi
34+
35+
# Cleanup
36+
rm -f "$SIGNAL_FILE"

0 commit comments

Comments
 (0)