3
3
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4
4
# SPDX-License-Identifier: BSD-3-Clause-Clear
5
5
6
+ # Robustly find and source init_env
7
+ SCRIPT_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
8
+ INIT_ENV=" "
9
+ SEARCH=" $SCRIPT_DIR "
10
+ while [ " $SEARCH " != " /" ]; do
11
+ if [ -f " $SEARCH /init_env" ]; then
12
+ INIT_ENV=" $SEARCH /init_env"
13
+ break
14
+ fi
15
+ SEARCH=$( dirname " $SEARCH " )
16
+ done
17
+
18
+ if [ -z " $INIT_ENV " ]; then
19
+ echo " [ERROR] Could not find init_env (starting at $SCRIPT_DIR )" >&2
20
+ exit 1
21
+ fi
22
+
23
+ # Only source if not already loaded (idempotent)
24
+ if [ -z " $__INIT_ENV_LOADED " ]; then
25
+ # shellcheck disable=SC1090
26
+ . " $INIT_ENV "
27
+ fi
28
+ # Always source functestlib.sh, using $TOOLS exported by init_env
29
+ # shellcheck disable=SC1090,SC1091
30
+ . " $TOOLS /functestlib.sh"
31
+
6
32
TESTNAME=" wpss_remoteproc"
7
33
test_path=$( find_test_case_by_name " $TESTNAME " )
8
34
cd " $test_path " || exit 1
@@ -13,50 +39,59 @@ log_info "----------------------------------------------------------------------
13
39
log_info " -------------------Starting $TESTNAME Testcase----------------------------"
14
40
log_info " === Test Initialization ==="
15
41
16
- # Get the firmware output and find the position of wpss
17
- firmware_output=$( cat /sys/class/remoteproc/remoteproc* /firmware)
18
- wpss_position=$( echo " $firmware_output " | grep -n " wpss" | cut -d: -f1)
19
-
20
- # Adjust the position to match the remoteproc numbering (starting from 0)
21
- remoteproc_number=$(( wpss_position - 1 ))
22
-
23
- # Construct the remoteproc path based on the wpss position
24
- remoteproc_path=" /sys/class/remoteproc/remoteproc${remoteproc_number} "
25
-
26
- # Execute command 1 and check if the output is "running"
27
- state1=$( cat ${remoteproc_path} /state)
28
- if [ " $state1 " != " running" ]; then
29
- log_fail " $TESTNAME : Test Failed"
30
- echo " $TESTNAME FAIL" > $test_path /$TESTNAME .res
31
- exit 1
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
32
59
fi
33
-
34
- # Execute command 2 (no output expected)
35
- echo stop > ${remoteproc_path} /state
36
-
37
- # Execute command 3 and check if the output is "offline"
38
- state3=$( cat ${remoteproc_path} /state)
39
- if [ " $state3 " != " offline" ]; then
40
- log_fail " wpss stop failed"
41
- echo " $TESTNAME FAIL" > $test_path /$TESTNAME .res
42
- exit 1
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
43
76
else
44
- log_pass " wpss stop successful "
77
+ log_warn " Could not stop WPSS; may already be offline "
45
78
fi
46
-
47
- # Execute command 4 (no output expected)
48
- echo start > ${remoteproc_path} /state
49
-
50
- # Execute command 5 and check if the output is "running"
51
- state5=$( cat ${remoteproc_path} /state)
52
- if [ " $state5 " != " running" ]; then
53
- log_fail " wpss start failed"
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
+ else
88
+ log_fail " WPSS remoteproc failed to start, state: $final_state "
89
+ echo " $TESTNAME FAIL" > " $res_file "
90
+ exit 1
91
+ fi
92
+ else
93
+ log_fail " Failed to write 'start' to $wpss_path /state"
54
94
echo " $TESTNAME FAIL" > " $res_file "
55
95
exit 1
56
96
fi
57
-
58
- # If all checks pass, print "PASS"
59
- echo " wpss PASS"
60
- log_pass " wpss PASS"
61
- echo " $TESTNAME PASS" > " $res_file "
62
97
log_info " -------------------Completed $TESTNAME Testcase----------------------------"
0 commit comments