22
33# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
44# SPDX-License-Identifier: BSD-3-Clause-Clear
5+
56# Robustly find and source init_env
67SCRIPT_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
78INIT_ENV=" "
2930. " $TOOLS /functestlib.sh"
3031
3132TESTNAME=" cdsp_remoteproc"
32- firmware_name=" cdsp"
33- res_file=" ./$TESTNAME .res"
34- LOG_FILE=" ./$TESTNAME .log"
33+ RES_FILE=" ./$TESTNAME .res"
34+ FW=" cdsp"
3535
3636test_path=$( find_test_case_by_name " $TESTNAME " )
3737cd " $test_path " || exit 1
3838
3939log_info " -----------------------------------------------------------------------------------------"
4040log_info " ------------------- Starting $TESTNAME Testcase ----------------------------"
4141log_info " === Test Initialization ==="
42-
43- if ! validate_remoteproc_running " $firmware_name " " $LOG_FILE " 15 2; then
44- log_fail " $firmware_name remoteproc is not in running state after bootup"
45- echo " $TESTNAME FAIL" > " $res_file "
46- exit 1
42+
43+ # Timeouts (can be overridden via env)
44+ STOP_TO=" ${STOP_TO:- 10} "
45+ START_TO=" ${START_TO:- 10} "
46+ POLL_I=" ${POLL_I:- 1} "
47+
48+ log_info " DEBUG: STOP_TO=$STOP_TO START_TO=$START_TO POLL_I=$POLL_I "
49+
50+ # --- Device Tree gate ----------------------------------------------------
51+ if dt_has_remoteproc_fw " $FW " ; then
52+ log_info " DT indicates $FW is present"
53+ else
54+ log_skip " $TESTNAME SKIP – $FW not described in DT"
55+ echo " ${TESTNAME} SKIP" > " $RES_FILE "
56+ exit 0
4757fi
48-
49- log_pass " $firmware_name remoteproc validated as running"
50-
51- rproc_path=$( get_remoteproc_path_by_firmware " $firmware_name " )
52-
53- stop_remoteproc " $rproc_path " || {
54- log_fail " $TESTNAME stop failed"
55- echo " $TESTNAME FAIL" > " $res_file "
56- exit 1
57- }
58- log_pass " $firmware_name stop successful"
59-
60- log_info " Restarting $firmware_name "
61- start_remoteproc " $rproc_path " || {
62- log_fail " $TESTNAME start failed"
63- echo " $TESTNAME FAIL" > " $res_file "
58+
59+ # ---------- Discover all matching remoteproc entries ----------
60+ # get_remoteproc_by_firmware prints: "path|state|firmware|name"
61+ entries=" $( get_remoteproc_by_firmware " $FW " " " all) " || entries=" "
62+ if [ -z " $entries " ]; then
63+ fail_and_exit " $FW present in DT but no /sys/class/remoteproc entry found"
64+ fi
65+
66+ count_instances=$( printf ' %s\n' " $entries " | wc -l)
67+ log_info " Found $count_instances $FW instance(s)"
68+
69+ inst_fail=0
70+ RESULT_LINES=" "
71+
72+ # Avoid subshell var-scope issues: feed loop from a temp file
73+ tmp_list=" $( mktemp) "
74+ printf ' %s\n' " $entries " > " $tmp_list "
75+
76+ while IFS=' |' read -r rpath rstate rfirm rname; do
77+ [ -n " $rpath " ] || continue # safety
78+
79+ inst_id=" $( basename " $rpath " ) "
80+ log_info " ---- $inst_id : path=$rpath state=$rstate firmware=$rfirm name=$rname ----"
81+
82+ boot_res=" PASS"
83+ stop_res=" NA"
84+ start_res=" NA"
85+ ping_res=" SKIPPED"
86+
87+ # Boot check
88+ if [ " $rstate " = " running" ]; then
89+ log_pass " $inst_id : boot check PASS"
90+ else
91+ log_fail " $inst_id : boot check FAIL (state=$rstate )"
92+ boot_res=" FAIL"
93+ inst_fail=$(( inst_fail + 1 ))
94+ RESULT_LINES=" $RESULT_LINES
95+ $inst_id : boot=$boot_res , stop=$stop_res , start=$start_res , ping=$ping_res "
96+ continue
97+ fi
98+
99+ # Stop
100+ dump_rproc_logs " $rpath " before-stop
101+ t0=$( date +%s)
102+ log_info " $inst_id : stopping"
103+ if stop_remoteproc " $rpath " && wait_remoteproc_state " $rpath " offline " $STOP_TO " " $POLL_I " ; then
104+ t1=$( date +%s)
105+ log_pass " $inst_id : stop PASS ($(( t1 - t0 )) s)"
106+ stop_res=" PASS"
107+ else
108+ dump_rproc_logs " $rpath " after-stop-fail
109+ log_fail " $inst_id : stop FAIL"
110+ stop_res=" FAIL"
111+ inst_fail=$(( inst_fail + 1 ))
112+ RESULT_LINES=" $RESULT_LINES
113+ $inst_id : boot=$boot_res , stop=$stop_res , start=$start_res , ping=$ping_res "
114+ continue
115+ fi
116+ dump_rproc_logs " $rpath " after-stop
117+
118+ # Start
119+ dump_rproc_logs " $rpath " before-start
120+ t2=$( date +%s)
121+ log_info " $inst_id : starting"
122+ if start_remoteproc " $rpath " && wait_remoteproc_state " $rpath " running " $START_TO " " $POLL_I " ; then
123+ t3=$( date +%s)
124+ log_pass " $inst_id : start PASS ($(( t3 - t2 )) s)"
125+ start_res=" PASS"
126+ else
127+ dump_rproc_logs " $rpath " after-start-fail
128+ log_fail " $inst_id : start FAIL"
129+ start_res=" FAIL"
130+ inst_fail=$(( inst_fail + 1 ))
131+ RESULT_LINES=" $RESULT_LINES
132+ $inst_id : boot=$boot_res , stop=$stop_res , start=$start_res , ping=$ping_res "
133+ continue
134+ fi
135+ dump_rproc_logs " $rpath " after-start
136+
137+ # Optional RPMsg ping
138+ if CTRL_DEV=$( find_rpmsg_ctrl_for " $FW " ) ; then
139+ log_info " $inst_id : RPMsg ctrl dev: $CTRL_DEV "
140+ if rpmsg_ping_generic " $CTRL_DEV " ; then
141+ log_pass " $inst_id : rpmsg ping PASS"
142+ ping_res=" PASS"
143+ else
144+ log_warn " $inst_id : rpmsg ping FAIL"
145+ ping_res=" FAIL"
146+ inst_fail=$(( inst_fail + 1 ))
147+ fi
148+ else
149+ log_info " $inst_id : no RPMsg channel, skipping ping"
150+ fi
151+
152+ RESULT_LINES=" $RESULT_LINES
153+ $inst_id : boot=$boot_res , stop=$stop_res , start=$start_res , ping=$ping_res "
154+
155+ done < " $tmp_list "
156+ rm -f " $tmp_list "
157+
158+ # ---------- Summary ----------
159+ log_info " Instance results:$RESULT_LINES "
160+
161+ if [ " $inst_fail " -gt 0 ]; then
162+ log_fail " One or more $FW instance(s) failed ($inst_fail /$count_instances )"
163+ echo " $TESTNAME FAIL" > " $RES_FILE "
64164 exit 1
65- }
66-
67- log_pass " $firmware_name PASS"
68- echo " $TESTNAME PASS" > " $res_file "
69-
70- log_info " ------------------- Completed $TESTNAME Testcase ----------------------------"
165+ fi
166+
167+ log_pass " All $count_instances $FW instance(s) passed"
168+ echo " $TESTNAME PASS" > " $RES_FILE "
71169exit 0
72-
0 commit comments