Skip to content

Commit 39b46f1

Browse files
Sai-teja573Kotha Sai Teja
authored andcommitted
Modularized adsp, cdsp, and wpss remoteproc tests using common helper functions.
Refactored adsp, cdsp, and wpss remoteproc tests. Introduced modular helper usage and standardized logging. Signed-off-by: Sai-teja573 <[email protected]>
1 parent 8e078f4 commit 39b46f1

File tree

4 files changed

+163
-138
lines changed

4 files changed

+163
-138
lines changed

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

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ while [ "$SEARCH" != "/" ]; do
1414
fi
1515
SEARCH=$(dirname "$SEARCH")
1616
done
17-
17+
1818
if [ -z "$INIT_ENV" ]; then
1919
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
2020
exit 1
2121
fi
22-
22+
2323
# Only source if not already loaded (idempotent)
2424
if [ -z "$__INIT_ENV_LOADED" ]; then
2525
# shellcheck disable=SC1090
@@ -30,61 +30,45 @@ fi
3030
. "$TOOLS/functestlib.sh"
3131

3232
TESTNAME="adsp_remoteproc"
33+
firmware_name="adsp"
34+
res_file="./$TESTNAME.res"
35+
LOG_FILE="./$TESTNAME.log"
36+
37+
exec > >(tee -a "$LOG_FILE") 2>&1
38+
3339
test_path=$(find_test_case_by_name "$TESTNAME")
3440
cd "$test_path" || exit 1
35-
# shellcheck disable=SC2034
36-
res_file="./$TESTNAME.res"
3741

3842
log_info "-----------------------------------------------------------------------------------------"
3943
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
4044
log_info "=== Test Initialization ==="
45+
log_info "Get the firmware output and find the position of adsp"
4146

42-
# Get the firmware output and find the position of adsp
43-
log_info "Checking for firmware"
44-
firmware_output=$(cat /sys/class/remoteproc/remoteproc*/firmware)
45-
adsp_position=$(echo "$firmware_output" | grep -n "adsp" | cut -d: -f1)
46-
47-
# Adjust the position to match the remoteproc numbering (starting from 0)
48-
remoteproc_number=$((adsp_position - 1))
49-
50-
# Construct the remoteproc path based on the adsp position
51-
remoteproc_path="/sys/class/remoteproc/remoteproc${remoteproc_number}"
52-
log_info "Remoteproc node is $remoteproc_path"
53-
# Execute command 1 and check if the output is "running"
54-
state1=$(cat ${remoteproc_path}/state)
55-
56-
if [ "$state1" != "running" ]; then
57-
log_fail "$TESTNAME : Test Failed"
58-
echo "$TESTNAME FAIL" > "$test_path/$TESTNAME.res"
59-
exit 1
47+
if validate_remoteproc_running "$firmware_name" "$LOG_FILE"; then
48+
log_pass "$firmware_name remoteproc validated as running"
49+
echo "$TESTNAME PASS" > "$RES_FILE"
50+
else
51+
log_fail "$firmware_name remoteproc failed validation"
52+
echo "$TESTNAME FAIL" > "$RES_FILE"
6053
fi
54+
# At this point we are sure: path exists and is in running state
55+
rproc_path=$(get_remoteproc_path_by_firmware "$firmware_name")
6156

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

66-
# Execute command 3 and check if the output is "offline"
67-
state3=$(cat ${remoteproc_path}/state)
68-
if [ "$state3" != "offline" ]; then
69-
log_fail "adsp stop failed"
70-
echo "$TESTNAME FAIL" > "$test_path/$TESTNAME.res"
58+
stop_remoteproc "$rproc_path" || {
59+
log_fail "$TESTNAME" "stop failed"
60+
echo "$TESTNAME FAIL" > "$res_file"
7161
exit 1
72-
else
73-
log_pass "adsp stop successful"
74-
fi
75-
log_info "Restarting remoteproc"
76-
# Execute command 4 (no output expected)
77-
echo start > ${remoteproc_path}/state
62+
}
63+
log_pass "adsp stop successful"
7864

79-
# Execute command 5 and check if the output is "running"
80-
state5=$(cat ${remoteproc_path}/state)
81-
if [ "$state5" != "running" ]; then
82-
log_fail "adsp start failed"
83-
echo "$TESTNAME FAIL" > "$res_file"
65+
log_info "Restarting remoteproc"
66+
start_remoteproc "$rproc_path" || {
67+
log_fail "$TESTNAME" "start failed"
68+
echo "$TESTNAME FAIL" > "$res_file"
8469
exit 1
85-
fi
70+
}
8671

87-
# If all checks pass, print "PASS"
8872
echo "adsp PASS"
8973
log_pass "adsp PASS"
9074
echo "$TESTNAME PASS" > "$res_file"

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

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,61 +30,46 @@ fi
3030
. "$TOOLS/functestlib.sh"
3131

3232
TESTNAME="cdsp_remoteproc"
33+
firmware_name="cdsp"
34+
res_file="./$TESTNAME.res"
35+
LOG_FILE="./$TESTNAME.log"
36+
37+
exec > >(tee -a "$LOG_FILE") 2>&1
38+
3339
test_path=$(find_test_case_by_name "$TESTNAME")
3440
cd "$test_path" || exit 1
35-
# shellcheck disable=SC2034
36-
res_file="./$TESTNAME.res"
3741

3842
log_info "-----------------------------------------------------------------------------------------"
3943
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
4044
log_info "=== Test Initialization ==="
41-
42-
# Get the firmware output and find the position of cdsp
4345
log_info "Get the firmware output and find the position of cdsp"
44-
firmware_output=$(cat /sys/class/remoteproc/remoteproc*/firmware)
45-
cdsp_position=$(echo "$firmware_output" | grep -n "cdsp" | cut -d: -f1)
46-
47-
# Adjust the position to match the remoteproc numbering (starting from 0)
48-
remoteproc_number=$((cdsp_position - 1))
4946

50-
# Construct the remoteproc path based on the cdsp position
51-
remoteproc_path="/sys/class/remoteproc/remoteproc${remoteproc_number}"
52-
53-
# Execute command 1 and check if the output is "running"
54-
state1=$(cat ${remoteproc_path}/state)
55-
if [ "$state1" != "running" ]; then
56-
log_fail "$TESTNAME : Test Failed"
57-
echo "$TESTNAME FAIL" > $test_path/$TESTNAME.res
58-
exit 1
47+
if validate_remoteproc_running "$firmware_name" "$LOG_FILE"; then
48+
log_pass "$firmware_name remoteproc validated as running"
49+
echo "$TESTNAME PASS" > "$RES_FILE"
50+
else
51+
log_fail "$firmware_name remoteproc failed validation"
52+
echo "$TESTNAME FAIL" > "$RES_FILE"
5953
fi
54+
# At this point we are sure: path exists and is in running state
55+
rproc_path=$(get_remoteproc_path_by_firmware "$firmware_name")
6056

61-
# Execute command 2 (no output expected)
62-
echo stop > ${remoteproc_path}/state
63-
64-
# Execute command 3 and check if the output is "offline"
65-
state3=$(cat ${remoteproc_path}/state)
66-
if [ "$state3" != "offline" ]; then
67-
log_fail "cdsp stop failed"
68-
echo "$TESTNAME FAIL" > $test_path/$TESTNAME.res
57+
stop_remoteproc "$rproc_path" || {
58+
log_fail "$TESTNAME" "stop failed"
59+
echo "$TESTNAME FAIL" > "$res_file"
6960
exit 1
70-
else
71-
log_pass "cdsp stop successful"
72-
fi
73-
log_info "Restarting remoteproc"
74-
# Execute command 4 (no output expected)
75-
echo start > ${remoteproc_path}/state
61+
}
62+
log_pass "cdsp stop successful"
7663

77-
# Execute command 5 and check if the output is "running"
78-
state5=$(cat ${remoteproc_path}/state)
79-
if [ "$state5" != "running" ]; then
80-
log_fail "cdsp start failed"
64+
log_info "Restarting remoteproc"
65+
start_remoteproc "$rproc_path" || {
66+
log_fail "$TESTNAME" "start failed"
8167
echo "$TESTNAME FAIL" > "$res_file"
8268
exit 1
83-
fi
69+
}
8470

85-
# If all checks pass, print "PASS"
8671
echo "cdsp PASS"
8772
log_pass "cdsp PASS"
88-
echo "$TESTNAME PASS" > "$res_file"
73+
echo "$TESTNAME PASS" > "$res_file"
8974
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
9075
exit 0

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

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ while [ "$SEARCH" != "/" ]; do
1414
fi
1515
SEARCH=$(dirname "$SEARCH")
1616
done
17-
17+
1818
if [ -z "$INIT_ENV" ]; then
1919
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
2020
exit 1
2121
fi
22-
22+
2323
# Only source if not already loaded (idempotent)
2424
if [ -z "$__INIT_ENV_LOADED" ]; then
2525
# shellcheck disable=SC1090
@@ -29,70 +29,48 @@ fi
2929
# shellcheck disable=SC1090,SC1091
3030
. "$TOOLS/functestlib.sh"
3131

32+
3233
TESTNAME="wpss_remoteproc"
34+
firmware_name=wpss
35+
res_file="./$TESTNAME.res"
36+
LOG_FILE="./$TESTNAME.log"
37+
38+
exec > >(tee -a "$LOG_FILE") 2>&1
39+
3340
test_path=$(find_test_case_by_name "$TESTNAME")
3441
cd "$test_path" || exit 1
35-
# shellcheck disable=SC2034
36-
res_file="./$TESTNAME.res"
3742

3843
log_info "-----------------------------------------------------------------------------------------"
3944
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
4045
log_info "=== Test Initialization ==="
46+
log_info "Get the firmware output and find the position of wpss"
4147

42-
log_info "=== Detecting and validating WPSS remoteproc instance ==="
43-
44-
log_info "Looking for remoteproc device exposing WPSS..."
45-
wpss_path=""
46-
for node in /sys/class/remoteproc/remoteproc*; do
47-
[ -f "$node/name" ] || continue
48-
name=$(cat "$node/name" 2>/dev/null | tr '[:upper:]' '[:lower:]')
49-
if echo "$name" | grep -qi "wpss"; then
50-
wpss_path="$node"
51-
break
52-
fi
53-
done
54-
55-
if [ -z "$wpss_path" ]; then
56-
log_skip "WPSS remoteproc node not found"
57-
echo "$TESTNAME SKIP" > "$res_file"
58-
exit 0
59-
fi
60-
61-
log_info "Found WPSS remoteproc node at: $wpss_path"
62-
firmware=$(cat "$wpss_path/firmware" 2>/dev/null)
63-
log_info "WPSS firmware: $firmware"
64-
65-
# Capture state before any change
66-
orig_state=$(cat "$wpss_path/state" 2>/dev/null)
67-
log_info "Original state: $orig_state"
68-
69-
log_info "Attempting to stop WPSS..."
70-
if echo stop > "$wpss_path/state" 2>/dev/null; then
71-
sleep 1
72-
new_state=$(cat "$wpss_path/state" 2>/dev/null)
73-
if [ "$new_state" != "offline" ]; then
74-
log_warn "Expected offline state after stop, got: $new_state"
75-
fi
48+
if validate_remoteproc_running "$firmware_name" "$LOG_FILE"; then
49+
log_pass "$firmware_name remoteproc validated as running"
50+
echo "$TESTNAME PASS" > "$RES_FILE"
7651
else
77-
log_warn "Could not stop WPSS; may already be offline"
52+
log_fail "$firmware_name remoteproc failed validation"
53+
echo "$TESTNAME FAIL" > "$RES_FILE"
7854
fi
79-
80-
log_info "Attempting to start WPSS..."
81-
if echo start > "$wpss_path/state" 2>/dev/null; then
82-
sleep 1
83-
final_state=$(cat "$wpss_path/state" 2>/dev/null)
84-
if [ "$final_state" = "running" ]; then
85-
log_pass "WPSS remoteproc started successfully"
86-
echo "$TESTNAME PASS" > "$res_file"
87-
exit 0
88-
else
89-
log_fail "WPSS remoteproc failed to start, state: $final_state"
90-
echo "$TESTNAME FAIL" > "$res_file"
91-
exit 1
92-
fi
93-
else
94-
log_fail "Failed to write 'start' to $wpss_path/state"
55+
# At this point we are sure: path exists and is in running state
56+
rproc_path=$(get_remoteproc_path_by_firmware "$firmware_name")
57+
58+
stop_remoteproc "$rproc_path" || {
59+
log_fail "$TESTNAME" "stop failed"
9560
echo "$TESTNAME FAIL" > "$res_file"
9661
exit 1
97-
fi
62+
}
63+
log_pass "wpss stop successful"
64+
65+
log_info "Restarting remoteproc"
66+
start_remoteproc "$rproc_path" || {
67+
log_fail "$TESTNAME" " start failed"
68+
echo "$TESTNAME FAIL" > "$res_file"
69+
exit 1
70+
}
71+
72+
echo "wpss PASS"
73+
log_pass "wpss PASS"
74+
echo "$TESTNAME PASS" > "$res_file"
9875
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
76+
exit 0

Runner/utils/functestlib.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,81 @@ weston_start() {
391391
fi
392392
}
393393

394+
# Find the remoteproc path for a given firmware substring (e.g., "adsp", "cdsp", "gdsp").
395+
get_remoteproc_path_by_firmware() {
396+
name="$1"
397+
idx=""
398+
path=""
399+
# List all remoteproc firmware nodes, match name, and return the remoteproc path
400+
idx=$(cat /sys/class/remoteproc/remoteproc*/firmware 2>/dev/null | grep -n "$name" | cut -d: -f1 | head -n1)
401+
[ -z "$idx" ] && return 1
402+
idx=$((idx - 1))
403+
path="/sys/class/remoteproc/remoteproc${idx}"
404+
[ -d "$path" ] && echo "$path" && return 0
405+
return 1
406+
}
407+
408+
# Get current remoteproc state
409+
get_remoteproc_state() {
410+
rproc_path="$1"
411+
[ -f "$rproc_path/state" ] && cat "$rproc_path/state"
412+
}
413+
414+
# Wait until remoteproc reaches a given state (with retries)
415+
wait_remoteproc_state() {
416+
rproc_path="$1"
417+
target="$2"
418+
retries="${3:-6}"
419+
i=0
420+
while [ $i -lt "$retries" ]; do
421+
state=$(get_remoteproc_state "$rproc_path")
422+
[ "$state" = "$target" ] && return 0
423+
sleep 1
424+
i=$((i+1))
425+
done
426+
return 1
427+
}
428+
429+
# Stop remoteproc (wait for "offline")
430+
stop_remoteproc() {
431+
rproc_path="$1"
432+
echo stop > "$rproc_path/state"
433+
wait_remoteproc_state "$rproc_path" "offline" 6
434+
}
435+
436+
# Start remoteproc (wait for "running")
437+
start_remoteproc() {
438+
rproc_path="$1"
439+
echo start > "$rproc_path/state"
440+
wait_remoteproc_state "$rproc_path" "running" 6
441+
}
442+
443+
validate_remoteproc_running() {
444+
fw_name="$1"
445+
log_file="${2:-/dev/null}"
446+
447+
rproc_path=$(get_remoteproc_path_by_firmware "$fw_name")
448+
if [ -z "$rproc_path" ]; then
449+
{
450+
echo "[ERROR] Remoteproc for '$fw_name' not found"
451+
echo "---- Last 20 remoteproc dmesg logs ----"
452+
dmesg | grep -i "remoteproc" | tail -n 20
453+
echo "----------------------------------------"
454+
} >> "$log_file"
455+
return 1
456+
fi
457+
458+
state=$(get_remoteproc_state "$rproc_path")
459+
if [ "$state" = "running" ]; then
460+
return 0
461+
else
462+
{
463+
echo "[ERROR] $fw_name remoteproc is in state '$state' (expected: running)"
464+
echo "---- Last 20 remoteproc dmesg logs ----"
465+
dmesg | grep -i "remoteproc" | tail -n 20
466+
echo "----------------------------------------"
467+
} >> "$log_file"
468+
return 1
469+
fi
470+
}
471+

0 commit comments

Comments
 (0)