55# #
66# # Case Name: check suspend/resume status
77# # Preconditions:
8- # # N/A
8+ # # - (if ran with --sleepgraph) Sleepgraph installed on dut
99# # Description:
1010# # Run the suspend/resume command to check device status
1111# # Case step:
@@ -26,27 +26,36 @@ source "$TOPDIR"/case-lib/lib.sh
2626random_min=3 # wait time should >= 3 for other device wakeup from sleep
2727random_max=20
2828
29- OPT_NAME[' l' ]=' loop' OPT_DESC[' l' ]=' loop count'
30- OPT_HAS_ARG[' l' ]=1 OPT_VAL[' l' ]=5
29+ OPT_NAME[' l' ]=' loop' OPT_DESC[' l' ]=' loop count'
30+ OPT_HAS_ARG[' l' ]=1 OPT_VAL[' l' ]=5
3131
32- OPT_NAME[' T' ]=' type' OPT_DESC[' T' ]=" suspend/resume type from /sys/power/mem_sleep"
33- OPT_HAS_ARG[' T' ]=1 OPT_VAL[' T' ]=" "
32+ OPT_NAME[' T' ]=' type' OPT_DESC[' T' ]=" suspend/resume type from /sys/power/mem_sleep"
33+ OPT_HAS_ARG[' T' ]=1 OPT_VAL[' T' ]=" "
3434
35- OPT_NAME[' S' ]=' sleep' OPT_DESC[' S' ]=' suspend/resume command:rtcwake sleep duration'
36- OPT_HAS_ARG[' S' ]=1 OPT_VAL[' S' ]=5
35+ OPT_NAME[' S' ]=' sleep' OPT_DESC[' S' ]=' suspend/resume command:rtcwake sleep duration'
36+ OPT_HAS_ARG[' S' ]=1 OPT_VAL[' S' ]=5
3737
38- OPT_NAME[' u' ]=' unload-audio' OPT_DESC[' u' ]=' unload audio modules for the test'
39- OPT_HAS_ARG[' u' ]=0 OPT_VAL[' u' ]=0
38+ OPT_NAME[' u' ]=' unload-audio' OPT_DESC[' u' ]=' unload audio modules for the test'
39+ OPT_HAS_ARG[' u' ]=0 OPT_VAL[' u' ]=0
4040
41- OPT_NAME[' w' ]=' wait' OPT_DESC[' w' ]=' idle time after suspend/resume wakeup'
42- OPT_HAS_ARG[' w' ]=1 OPT_VAL[' w' ]=5
41+ OPT_NAME[' w' ]=' wait' OPT_DESC[' w' ]=' idle time after suspend/resume wakeup'
42+ OPT_HAS_ARG[' w' ]=1 OPT_VAL[' w' ]=5
4343
44- OPT_NAME[' r' ]=' random' OPT_DESC[' r' ]=" Randomly setup wait/sleep time, range is [$random_min -$random_max ], this option will overwrite s & w option"
45- OPT_HAS_ARG[' r' ]=0 OPT_VAL[' r' ]=0
44+ OPT_NAME[' r' ]=' random' OPT_DESC[' r' ]=" Randomly setup wait/sleep time, range is [$random_min -$random_max ], this option will overwrite s & w option"
45+ OPT_HAS_ARG[' r' ]=0 OPT_VAL[' r' ]=0
4646
4747# processid is set by check-suspend-resume-with-audio.sh for audio test case
48- OPT_NAME[' p' ]=' processid' OPT_DESC[' p' ]=' Fail immediately if this process dies'
49- OPT_HAS_ARG[' p' ]=1 OPT_VAL[' p' ]=' '
48+ OPT_NAME[' p' ]=' processid' OPT_DESC[' p' ]=' Fail immediately if this process dies'
49+ OPT_HAS_ARG[' p' ]=1 OPT_VAL[' p' ]=' '
50+
51+ OPT_NAME[' s' ]=' sleepgraph' OPT_DESC[' s' ]=' run with sleepgraph (http://github.com/intel/pm-graph.git)'
52+ OPT_HAS_ARG[' s' ]=0 OPT_VAL[' s' ]=0
53+
54+ OPT_NAME[' t' ]=' resume-time' OPT_DESC[' t' ]=' resume time threshold'
55+ OPT_HAS_ARG[' t' ]=1 OPT_VAL[' t' ]=' '
56+
57+ OPT_NAME[' a' ]=' acceptance-range' OPT_DESC[' a' ]=' acceptance range for thresholds'
58+ OPT_HAS_ARG[' a' ]=1 OPT_VAL[' a' ]=0.3
5059
5160func_opt_parse_option " $@ "
5261func_lib_check_sudo
@@ -69,21 +78,28 @@ dlogi "Current suspend/resume type mode: $(cat /sys/power/mem_sleep)"
6978loop_count=${OPT_VAL['l']}
7079declare -a sleep_lst wait_lst
7180
72- if [ ${OPT_VAL['r']} -eq 1 ]; then
81+ if [ " ${OPT_VAL['r']} " -eq 1 ]; then
7382 # create random number list
74- for i in $( seq 1 $loop_count )
83+ for i in $( seq 1 " $loop_count " )
7584 do
76- sleep_lst[$ i ]=$( func_lib_get_random $random_max $random_min )
77- wait_lst[$ i ]=$( func_lib_get_random $random_max $random_min )
85+ sleep_lst[i]=$( func_lib_get_random $random_max $random_min )
86+ wait_lst[i]=$( func_lib_get_random $random_max $random_min )
7887 done
7988else
80- for i in $( seq 1 $loop_count )
89+ for i in $( seq 1 " $loop_count " )
8190 do
82- sleep_lst[$ i ]=${OPT_VAL['S']}
83- wait_lst[$ i ]=${OPT_VAL['w']}
91+ sleep_lst[i]=${OPT_VAL['S']}
92+ wait_lst[i]=${OPT_VAL['w']}
8493 done
8594fi
8695
96+ if [ " ${OPT_VAL['s']} " -eq 1 ]; then
97+ if ! command -v sleepgraph > /dev/null 2>&1 ; then
98+ echo " Sleepgraph is not installed! Exiting..."
99+ exit 1
100+ fi
101+ fi
102+
87103save_initial_stats ()
88104{
89105 printf ' \n\n'
@@ -143,7 +159,7 @@ main()
143159
144160 local keep_modules=true already_unloaded=false
145161
146- if [ ${OPT_VAL['u']} = 1 ]; then
162+ if [ " ${OPT_VAL['u']} " = 1 ]; then
147163 keep_modules=false
148164 fi
149165
@@ -159,7 +175,7 @@ main()
159175 expected_wakeup_count=$( cat /sys/power/wakeup_count)
160176 expected_stats_success=$( cat /sys/power/suspend_stats/success)
161177 save_initial_stats
162- for i in $( seq 1 $loop_count )
178+ for i in $( seq 1 " $loop_count " )
163179 do
164180 sleep_once " $i "
165181 done
@@ -170,6 +186,45 @@ main()
170186 die " Found kernel error after reloading audio drivers"
171187}
172188
189+ analyze_sleepgraph_results ()
190+ {
191+ dlogi " Analyzing sleepgraph results"
192+ results_file=$( find suspend-* /* .html)
193+ cp " $results_file " " $LOG_ROOT /"
194+
195+ thresholds=$( jq -n \
196+ --arg resume_time " ${OPT_VAL['t']} " \
197+ ' {"sof-audio-pci-intel-ptl":{"resume":$resume_time}}' )
198+
199+ thresholds_acceptance_range=" ${OPT_VAL['a']} "
200+
201+ dlogi " Analyzing $results_file file..."
202+ if python3 " $SCRIPT_HOME " /tools/analyze-sleepgraph-results.py " $results_file " " $thresholds " " $thresholds_acceptance_range " ; then
203+ dlogi " All times measurements within the thresholds"
204+ return 0
205+ else
206+ dlogw " Time measurements not within the thresholds!"
207+ return 1
208+ fi
209+ }
210+
211+ run_rtcwake ()
212+ {
213+ if [ " ${OPT_VAL['s']} " -eq 1 ]; then
214+ # remove any files from previous sleepgraph runs
215+ rm -rf suspend-*
216+
217+ dlogc " Run the command: sleepgraph -rtcwake ${sleep_lst[$i]} -m freeze"
218+ sudo sleepgraph -rtcwake " ${sleep_lst[$i]} " -m freeze ||
219+ dump_and_die " rtcwake returned $? "
220+ analyze_sleepgraph_results
221+ else
222+ dlogc " Run the command: rtcwake -m mem -s ${sleep_lst[$i]} "
223+ sudo rtcwake -m mem -s " ${sleep_lst[$i]} " ||
224+ dump_and_die " rtcwake returned $? "
225+ fi
226+ }
227+
173228sleep_once ()
174229{
175230 local i=" $1 "
@@ -179,11 +234,9 @@ sleep_once()
179234 setup_kernel_check_point
180235 expected_wakeup_count=$(( expected_wakeup_count+ 1 ))
181236 expected_stats_success=$(( expected_stats_success+ 1 ))
182- dlogc " Run the command: rtcwake -m mem -s ${sleep_lst[$i]} "
183- sudo rtcwake -m mem -s " ${sleep_lst[$i]} " ||
184- dump_and_die " rtcwake returned $? "
237+ run_rtcwake
185238 dlogc " sleep for ${wait_lst[$i]} "
186- sleep ${wait_lst[$i]}
239+ sleep " ${wait_lst[$i]} "
187240 dlogi " Check for the kernel log status"
188241 # check kernel log for each iteration to catch issues
189242 sof-kernel-log-check.sh " $KERNEL_CHECKPOINT " || dump_and_die " Caught error in kernel log"
0 commit comments