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,39 @@ 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[' c' ]=' component-name' OPT_DESC[' c' ]=' component for which we check resume time'
55+ OPT_HAS_ARG[' c' ]=1 OPT_VAL[' c' ]=' '
56+
57+ OPT_NAME[' t' ]=' resume-time' OPT_DESC[' t' ]=' resume time threshold'
58+ OPT_HAS_ARG[' t' ]=1 OPT_VAL[' t' ]=' '
59+
60+ OPT_NAME[' a' ]=' acceptance-range' OPT_DESC[' a' ]=' acceptance range for thresholds'
61+ OPT_HAS_ARG[' a' ]=1 OPT_VAL[' a' ]=0.3
5062
5163func_opt_parse_option " $@ "
5264func_lib_check_sudo
@@ -69,21 +81,28 @@ dlogi "Current suspend/resume type mode: $(cat /sys/power/mem_sleep)"
6981loop_count=${OPT_VAL['l']}
7082declare -a sleep_lst wait_lst
7183
72- if [ ${OPT_VAL['r']} -eq 1 ]; then
84+ if [ " ${OPT_VAL['r']} " -eq 1 ]; then
7385 # create random number list
74- for i in $( seq 1 $loop_count )
86+ for i in $( seq 1 " $loop_count " )
7587 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 )
88+ sleep_lst[i]=$( func_lib_get_random $random_max $random_min )
89+ wait_lst[i]=$( func_lib_get_random $random_max $random_min )
7890 done
7991else
80- for i in $( seq 1 $loop_count )
92+ for i in $( seq 1 " $loop_count " )
8193 do
82- sleep_lst[$ i ]=${OPT_VAL['S']}
83- wait_lst[$ i ]=${OPT_VAL['w']}
94+ sleep_lst[i]=${OPT_VAL['S']}
95+ wait_lst[i]=${OPT_VAL['w']}
8496 done
8597fi
8698
99+ if [ " ${OPT_VAL['s']} " -eq 1 ]; then
100+ if ! command -v sleepgraph > /dev/null 2>&1 ; then
101+ echo " Sleepgraph is not installed! Exiting..."
102+ exit 1
103+ fi
104+ fi
105+
87106save_initial_stats ()
88107{
89108 printf ' \n\n'
@@ -143,7 +162,7 @@ main()
143162
144163 local keep_modules=true already_unloaded=false
145164
146- if [ ${OPT_VAL['u']} = 1 ]; then
165+ if [ " ${OPT_VAL['u']} " = 1 ]; then
147166 keep_modules=false
148167 fi
149168
@@ -159,7 +178,7 @@ main()
159178 expected_wakeup_count=$( cat /sys/power/wakeup_count)
160179 expected_stats_success=$( cat /sys/power/suspend_stats/success)
161180 save_initial_stats
162- for i in $( seq 1 $loop_count )
181+ for i in $( seq 1 " $loop_count " )
163182 do
164183 sleep_once " $i "
165184 done
@@ -170,6 +189,46 @@ main()
170189 die " Found kernel error after reloading audio drivers"
171190}
172191
192+ analyze_sleepgraph_results ()
193+ {
194+ dlogi " Analyzing sleepgraph results"
195+ results_file=$( find suspend-* /* .html)
196+ cp " $results_file " " $LOG_ROOT /"
197+
198+ thresholds=$( jq -n \
199+ --arg component_name " ${OPT_VAL['c']} " \
200+ --arg resume_time " ${OPT_VAL['t']} " \
201+ ' {$component_name:{"resume":$resume_time}}' )
202+
203+ thresholds_acceptance_range=" ${OPT_VAL['a']} "
204+
205+ dlogi " Analyzing $results_file file..."
206+ if python3 " $SCRIPT_HOME " /tools/analyze-sleepgraph-results.py " $results_file " " $thresholds " " $thresholds_acceptance_range " ; then
207+ dlogi " All times measurements within the thresholds"
208+ return 0
209+ else
210+ dlogw " Time measurements not within the thresholds!"
211+ return 1
212+ fi
213+ }
214+
215+ run_rtcwake ()
216+ {
217+ if [ " ${OPT_VAL['s']} " -eq 1 ]; then
218+ # remove any files from previous sleepgraph runs
219+ rm -rf suspend-*
220+
221+ dlogc " Run the command: sleepgraph -rtcwake ${sleep_lst[$i]} -m freeze"
222+ sudo sleepgraph -rtcwake " ${sleep_lst[$i]} " -m freeze ||
223+ dump_and_die " rtcwake returned $? "
224+ analyze_sleepgraph_results
225+ else
226+ dlogc " Run the command: rtcwake -m mem -s ${sleep_lst[$i]} "
227+ sudo rtcwake -m mem -s " ${sleep_lst[$i]} " ||
228+ dump_and_die " rtcwake returned $? "
229+ fi
230+ }
231+
173232sleep_once ()
174233{
175234 local i=" $1 "
@@ -179,11 +238,9 @@ sleep_once()
179238 setup_kernel_check_point
180239 expected_wakeup_count=$(( expected_wakeup_count+ 1 ))
181240 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 $? "
241+ run_rtcwake
185242 dlogc " sleep for ${wait_lst[$i]} "
186- sleep ${wait_lst[$i]}
243+ sleep " ${wait_lst[$i]} "
187244 dlogi " Check for the kernel log status"
188245 # check kernel log for each iteration to catch issues
189246 sof-kernel-log-check.sh " $KERNEL_CHECKPOINT " || dump_and_die " Caught error in kernel log"
0 commit comments