Skip to content

Commit b1cf073

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 b1cf073

File tree

4 files changed

+128
-137
lines changed

4 files changed

+128
-137
lines changed

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

Lines changed: 25 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,43 @@ fi
3030
. "$TOOLS/functestlib.sh"
3131

3232
TESTNAME="adsp_remoteproc"
33+
res_file="./$TESTNAME.res"
3334
test_path=$(find_test_case_by_name "$TESTNAME")
3435
cd "$test_path" || exit 1
35-
# shellcheck disable=SC2034
36-
res_file="./$TESTNAME.res"
3736

3837
log_info "-----------------------------------------------------------------------------------------"
3938
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
4039
log_info "=== Test Initialization ==="
40+
log_info "Get the firmware output and find the position of adsp"
4141

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"
42+
rproc_path=$(get_remoteproc_path_by_firmware "adsp") || {
43+
log_fail "$TESTNAME" "adsp remoteproc path not found"
44+
echo "$TESTNAME FAIL" > "$res_file"
5945
exit 1
60-
fi
46+
}
47+
log_info "Found adsp remoteproc: $rproc_path"
6148

62-
# Execute command 2 (no output expected)
63-
log_info "Stopping remoteproc"
64-
echo stop > ${remoteproc_path}/state
49+
state=$(get_remoteproc_state "$rproc_path")
50+
[ "$state" = "running" ] || {
51+
log_fail "$TESTNAME" "adsp remoteproc not running"
52+
echo "$TESTNAME FAIL" > "$res_file"
53+
exit 1
54+
}
6555

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"
56+
stop_remoteproc "$rproc_path" || {
57+
log_fail "$TESTNAME" "adsp remoteproc stop failed"
58+
echo "$TESTNAME FAIL" > "$res_file"
7159
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
60+
}
61+
log_pass "adsp stop successful"
7862

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"
63+
log_info "Restarting remoteproc"
64+
start_remoteproc "$rproc_path" || {
65+
log_fail "$TESTNAME" "adsp remoteproc start failed"
66+
echo "$TESTNAME FAIL" > "$res_file"
8467
exit 1
85-
fi
68+
}
8669

87-
# If all checks pass, print "PASS"
8870
echo "adsp PASS"
8971
log_pass "adsp PASS"
9072
echo "$TESTNAME PASS" > "$res_file"

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

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

3232
TESTNAME="cdsp_remoteproc"
33+
res_file="./$TESTNAME.res"
3334
test_path=$(find_test_case_by_name "$TESTNAME")
3435
cd "$test_path" || exit 1
35-
# shellcheck disable=SC2034
36-
res_file="./$TESTNAME.res"
3736

3837
log_info "-----------------------------------------------------------------------------------------"
3938
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
4039
log_info "=== Test Initialization ==="
41-
42-
# Get the firmware output and find the position of cdsp
4340
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))
4941

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
42+
rproc_path=$(get_remoteproc_path_by_firmware "cdsp") || {
43+
log_fail "$TESTNAME" "cdsp remoteproc path not found"
44+
echo "$TESTNAME FAIL" > "$res_file"
5845
exit 1
59-
fi
46+
}
47+
log_info "Found cdsp remoteproc: $rproc_path"
6048

61-
# Execute command 2 (no output expected)
62-
echo stop > ${remoteproc_path}/state
49+
state=$(get_remoteproc_state "$rproc_path")
50+
[ "$state" = "running" ] || {
51+
log_fail "$TESTNAME" "cdsp remoteproc not running"
52+
echo "$TESTNAME FAIL" > "$res_file"
53+
exit 1
54+
}
6355

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
56+
stop_remoteproc "$rproc_path" || {
57+
log_fail "$TESTNAME" "cdsp remoteproc stop failed"
58+
echo "$TESTNAME FAIL" > "$res_file"
6959
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
60+
}
61+
log_pass "cdsp stop successful"
7662

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"
63+
log_info "Restarting remoteproc"
64+
start_remoteproc "$rproc_path" || {
65+
log_fail "$TESTNAME" "cdsp remoteproc start failed"
8166
echo "$TESTNAME FAIL" > "$res_file"
8267
exit 1
83-
fi
68+
}
8469

85-
# If all checks pass, print "PASS"
8670
echo "cdsp PASS"
8771
log_pass "cdsp PASS"
88-
echo "$TESTNAME PASS" > "$res_file"
72+
echo "$TESTNAME PASS" > "$res_file"
8973
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
9074
exit 0

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

Lines changed: 33 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,47 @@ fi
2929
# shellcheck disable=SC1090,SC1091
3030
. "$TOOLS/functestlib.sh"
3131

32+
3233
TESTNAME="wpss_remoteproc"
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 wpss"
4142

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"
43+
rproc_path=$(get_remoteproc_path_by_firmware "wpss") || {
44+
log_skip "wpss remoteproc path not found"
5745
echo "$TESTNAME SKIP" > "$res_file"
5846
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"
47+
}
48+
log_info "Found wpss remoteproc: $rproc_path"
49+
50+
state=$(get_remoteproc_state "$rproc_path")
51+
[ "$state" = "running" ] || {
52+
log_fail "$TESTNAME" "wpss remoteproc not running"
9553
echo "$TESTNAME FAIL" > "$res_file"
9654
exit 1
97-
fi
55+
}
56+
57+
stop_remoteproc "$rproc_path" || {
58+
log_fail "$TESTNAME" "wpss remoteproc stop failed"
59+
echo "$TESTNAME FAIL" > "$res_file"
60+
exit 1
61+
}
62+
log_pass "wpss stop successful"
63+
64+
log_info "Restarting remoteproc"
65+
start_remoteproc "$rproc_path" || {
66+
log_fail "$TESTNAME" "wpss remoteproc start failed"
67+
echo "$TESTNAME FAIL" > "$res_file"
68+
exit 1
69+
}
70+
71+
echo "wpss PASS"
72+
log_pass "wpss PASS"
73+
echo "$TESTNAME PASS" > "$res_file"
9874
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
75+
exit 0

Runner/utils/functestlib.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,51 @@ 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+
local idx path
398+
# List all remoteproc firmware nodes, match name, and return the remoteproc path
399+
idx=$(cat /sys/class/remoteproc/remoteproc*/firmware 2>/dev/null | grep -n "$name" | cut -d: -f1 | head -n1)
400+
[ -z "$idx" ] && return 1
401+
idx=$((idx - 1))
402+
path="/sys/class/remoteproc/remoteproc${idx}"
403+
[ -d "$path" ] && echo "$path" && return 0
404+
return 1
405+
}
406+
407+
# Get current remoteproc state
408+
get_remoteproc_state() {
409+
rproc_path="$1"
410+
[ -f "$rproc_path/state" ] && cat "$rproc_path/state"
411+
}
412+
413+
# Wait until remoteproc reaches a given state (with retries)
414+
wait_remoteproc_state() {
415+
rproc_path="$1"
416+
target="$2"
417+
retries="${3:-6}"
418+
i=0
419+
while [ $i -lt "$retries" ]; do
420+
state=$(get_remoteproc_state "$rproc_path")
421+
[ "$state" = "$target" ] && return 0
422+
sleep 1
423+
i=$((i+1))
424+
done
425+
return 1
426+
}
427+
428+
# Stop remoteproc (wait for "offline")
429+
stop_remoteproc() {
430+
rproc_path="$1"
431+
echo stop > "$rproc_path/state"
432+
wait_remoteproc_state "$rproc_path" "offline" 6
433+
}
434+
435+
# Start remoteproc (wait for "running")
436+
start_remoteproc() {
437+
rproc_path="$1"
438+
echo start > "$rproc_path/state"
439+
wait_remoteproc_state "$rproc_path" "running" 6
440+
}
441+

0 commit comments

Comments
 (0)