Skip to content

Commit e41bcfb

Browse files
committed
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 e41bcfb

File tree

4 files changed

+152
-135
lines changed

4 files changed

+152
-135
lines changed

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

Lines changed: 28 additions & 42 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,47 @@ fi
3030
. "$TOOLS/functestlib.sh"
3131

3232
TESTNAME="adsp_remoteproc"
33+
firmware_name="adsp"
34+
res_file="./$TESTNAME.res"
3335
test_path=$(find_test_case_by_name "$TESTNAME")
3436
cd "$test_path" || exit 1
35-
# shellcheck disable=SC2034
36-
res_file="./$TESTNAME.res"
3737

3838
log_info "-----------------------------------------------------------------------------------------"
3939
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
4040
log_info "=== Test Initialization ==="
41+
log_info "Get the firmware output and find the position of adsp"
4142

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))
43+
rproc_path=$(get_remoteproc_path_by_firmware "$firmware_name") || {
44+
log_skip "adsp remoteproc path not found"
45+
echo "$TESTNAME SKIP" > "$res_file"
46+
exit 0
47+
}
48+
log_info "Found adsp remoteproc: $rproc_path"
4949

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)
50+
state=$(get_remoteproc_state "$rproc_path")
51+
log_info "Remoteproc state: $state"
5552

56-
if [ "$state1" != "running" ]; then
57-
log_fail "$TESTNAME : Test Failed"
58-
echo "$TESTNAME FAIL" > "$test_path/$TESTNAME.res"
53+
[ "$state" = "running" ] || {
54+
log_fail "$TESTNAME" "not running"
55+
check_firmware_loaded "$firmware_name"
56+
echo "$TESTNAME FAIL" > "$res_file"
5957
exit 1
60-
fi
58+
}
6159

62-
# Execute command 2 (no output expected)
63-
log_info "Stopping remoteproc"
64-
echo stop > ${remoteproc_path}/state
65-
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"
60+
stop_remoteproc "$rproc_path" || {
61+
log_fail "$TESTNAME" "stop failed"
62+
echo "$TESTNAME FAIL" > "$res_file"
7163
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
64+
}
65+
log_pass "adsp stop successful"
7866

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"
67+
log_info "Restarting remoteproc"
68+
start_remoteproc "$rproc_path" || {
69+
log_fail "$TESTNAME" "start failed"
70+
echo "$TESTNAME FAIL" > "$res_file"
8471
exit 1
85-
fi
72+
}
8673

87-
# If all checks pass, print "PASS"
8874
echo "adsp PASS"
8975
log_pass "adsp PASS"
9076
echo "$TESTNAME PASS" > "$res_file"

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

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

3232
TESTNAME="cdsp_remoteproc"
33+
firmware_name="cdsp"
34+
res_file="./$TESTNAME.res"
3335
test_path=$(find_test_case_by_name "$TESTNAME")
3436
cd "$test_path" || exit 1
35-
# shellcheck disable=SC2034
36-
res_file="./$TESTNAME.res"
3737

3838
log_info "-----------------------------------------------------------------------------------------"
3939
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
4040
log_info "=== Test Initialization ==="
41-
42-
# Get the firmware output and find the position of cdsp
4341
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)
4642

47-
# Adjust the position to match the remoteproc numbering (starting from 0)
48-
remoteproc_number=$((cdsp_position - 1))
43+
rproc_path=$(get_remoteproc_path_by_firmware "$firmware_name") || {
44+
log_skip "$TESTNAME" "path not found"
45+
echo "$TESTNAME SKIP" > "$res_file"
46+
exit 0
47+
}
48+
log_info "Found cdsp remoteproc: $rproc_path"
4949

50-
# Construct the remoteproc path based on the cdsp position
51-
remoteproc_path="/sys/class/remoteproc/remoteproc${remoteproc_number}"
50+
state=$(get_remoteproc_state "$rproc_path")
51+
log_info "Firmware state for $rproc_path : $state"
5252

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
53+
[ "$state" = "running" ] || {
54+
log_fail "$TESTNAME" " not running"
55+
check_firmware_loaded "$firmware_name"
56+
echo "$TESTNAME FAIL" > "$res_file"
5857
exit 1
59-
fi
60-
61-
# Execute command 2 (no output expected)
62-
echo stop > ${remoteproc_path}/state
58+
}
6359

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
60+
stop_remoteproc "$rproc_path" || {
61+
log_fail "$TESTNAME" "stop failed"
62+
echo "$TESTNAME FAIL" > "$res_file"
6963
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
64+
}
65+
log_pass "cdsp stop successful"
7666

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"
67+
log_info "Restarting remoteproc"
68+
start_remoteproc "$rproc_path" || {
69+
log_fail "$TESTNAME" "start failed"
8170
echo "$TESTNAME FAIL" > "$res_file"
8271
exit 1
83-
fi
72+
}
8473

85-
# If all checks pass, print "PASS"
8674
echo "cdsp PASS"
8775
log_pass "cdsp PASS"
88-
echo "$TESTNAME PASS" > "$res_file"
76+
echo "$TESTNAME PASS" > "$res_file"
8977
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
9078
exit 0

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

Lines changed: 37 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,51 @@ 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"
3336
test_path=$(find_test_case_by_name "$TESTNAME")
3437
cd "$test_path" || exit 1
35-
# shellcheck disable=SC2034
36-
res_file="./$TESTNAME.res"
3738

3839
log_info "-----------------------------------------------------------------------------------------"
3940
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
4041
log_info "=== Test Initialization ==="
42+
log_info "Get the firmware output and find the position of wpss"
4143

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"
44+
rproc_path=$(get_remoteproc_path_by_firmware "$firmware_name") || {
45+
log_skip "wpss remoteproc path not found"
5746
echo "$TESTNAME SKIP" > "$res_file"
5847
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
76-
else
77-
log_warn "Could not stop WPSS; may already be offline"
78-
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"
48+
}
49+
log_info "Found wpss remoteproc: $rproc_path"
50+
51+
state=$(get_remoteproc_state "$rproc_path")
52+
log_info "Firmware state for $rproc_path : $state"
53+
54+
[ "$state" = "running" ] || {
55+
log_fail "$TESTNAME" "not running"
56+
check_firmware_loaded "$firmware_name"
9557
echo "$TESTNAME FAIL" > "$res_file"
9658
exit 1
97-
fi
59+
}
60+
61+
stop_remoteproc "$rproc_path" || {
62+
log_fail "$TESTNAME" "stop failed"
63+
echo "$TESTNAME FAIL" > "$res_file"
64+
exit 1
65+
}
66+
log_pass "wpss stop successful"
67+
68+
log_info "Restarting remoteproc"
69+
start_remoteproc "$rproc_path" || {
70+
log_fail "$TESTNAME" " start failed"
71+
echo "$TESTNAME FAIL" > "$res_file"
72+
exit 1
73+
}
74+
75+
echo "wpss PASS"
76+
log_pass "wpss PASS"
77+
echo "$TESTNAME PASS" > "$res_file"
9878
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
79+
exit 0

Runner/utils/functestlib.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,65 @@ 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+
check_firmware_loaded() {
444+
name="$1"
445+
log_info "Checking if $name firmware is loaded via dmesg"
446+
447+
if dmesg | grep -i "Booting fw image" | grep -i "$name" >/dev/null; then
448+
log_info "Firmware for $name appears to be loaded (found in dmesg)"
449+
return 0
450+
else
451+
log_warn "Firmware for $name not found in dmesg logs"
452+
return 1
453+
fi
454+
}
455+

0 commit comments

Comments
 (0)