@@ -26,27 +26,33 @@ 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' ]=' run-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' ]=' times-thresholds' OPT_DESC[' t' ]=' sleepgraph thresholds'
55+ OPT_HAS_ARG[' t' ]=1 OPT_VAL[' t' ]=' '
5056
5157func_opt_parse_option " $@ "
5258func_lib_check_sudo
@@ -69,21 +75,29 @@ dlogi "Current suspend/resume type mode: $(cat /sys/power/mem_sleep)"
6975loop_count=${OPT_VAL['l']}
7076declare -a sleep_lst wait_lst
7177
72- if [ ${OPT_VAL['r']} -eq 1 ]; then
78+ if [ " ${OPT_VAL['r']} " -eq 1 ]; then
7379 # create random number list
74- for i in $( seq 1 $loop_count )
80+ for i in $( seq 1 " $loop_count " )
7581 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 )
82+ sleep_lst[i]=$( func_lib_get_random $random_max $random_min )
83+ wait_lst[i]=$( func_lib_get_random $random_max $random_min )
7884 done
7985else
80- for i in $( seq 1 $loop_count )
86+ for i in $( seq 1 " $loop_count " )
8187 do
82- sleep_lst[$ i ]=${OPT_VAL['S']}
83- wait_lst[$ i ]=${OPT_VAL['w']}
88+ sleep_lst[i]=${OPT_VAL['S']}
89+ wait_lst[i]=${OPT_VAL['w']}
8490 done
8591fi
8692
93+ if [ " ${OPT_VAL['s']} " -eq 1 ]; then
94+ SLEEPGRAPH_PATH=" $HOME /pm-graph/sleepgraph.py"
95+ if [ ! -f " $SLEEPGRAPH_PATH " ]; then
96+ echo " Sleepgraph is not installed! Exiting..."
97+ exit 1
98+ fi
99+ fi
100+
87101save_initial_stats ()
88102{
89103 printf ' \n\n'
@@ -143,7 +157,7 @@ main()
143157
144158 local keep_modules=true already_unloaded=false
145159
146- if [ ${OPT_VAL['u']} = 1 ]; then
160+ if [ " ${OPT_VAL['u']} " = 1 ]; then
147161 keep_modules=false
148162 fi
149163
@@ -159,7 +173,7 @@ main()
159173 expected_wakeup_count=$( cat /sys/power/wakeup_count)
160174 expected_stats_success=$( cat /sys/power/suspend_stats/success)
161175 save_initial_stats
162- for i in $( seq 1 $loop_count )
176+ for i in $( seq 1 " $loop_count " )
163177 do
164178 sleep_once " $i "
165179 done
@@ -170,6 +184,40 @@ main()
170184 die " Found kernel error after reloading audio drivers"
171185}
172186
187+ analyze_sleepgraph_results ()
188+ {
189+ dlogi " Analyzing sleepgraph results"
190+ results_file=$( find suspend-* /* .html)
191+ cp " $results_file " " $LOG_ROOT /"
192+ thresholds=" ${OPT_VAL['t']} "
193+
194+ dlogi " Analyzing $results_file file..."
195+ if python3 " $SCRIPT_HOME " /tools/analyze-sleepgraph-results.py " $results_file " " $thresholds " ; then
196+ dlogi " All times measurements within the thresholds"
197+ return 0
198+ else
199+ dlogw " Time measurements not within the thresholds!"
200+ return 1
201+ fi
202+ }
203+
204+ run_rtcwake ()
205+ {
206+ if [ " ${OPT_VAL['s']} " -eq 1 ]; then
207+ # remove any files from previous sleepgraph runs
208+ rm -rf suspend-*
209+
210+ dlogc " Run the command: $SLEEPGRAPH_PATH -rtcwake ${sleep_lst[$i]} -m freeze"
211+ sudo " $SLEEPGRAPH_PATH " -rtcwake " ${sleep_lst[$i]} " -m freeze ||
212+ dump_and_die " rtcwake returned $? "
213+ analyze_sleepgraph_results
214+ else
215+ dlogc " Run the command: rtcwake -m mem -s ${sleep_lst[$i]} "
216+ sudo rtcwake -m mem -s " ${sleep_lst[$i]} " ||
217+ dump_and_die " rtcwake returned $? "
218+ fi
219+ }
220+
173221sleep_once ()
174222{
175223 local i=" $1 "
@@ -179,11 +227,9 @@ sleep_once()
179227 setup_kernel_check_point
180228 expected_wakeup_count=$(( expected_wakeup_count+ 1 ))
181229 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 $? "
230+ run_rtcwake
185231 dlogc " sleep for ${wait_lst[$i]} "
186- sleep ${wait_lst[$i]}
232+ sleep " ${wait_lst[$i]} "
187233 dlogi " Check for the kernel log status"
188234 # check kernel log for each iteration to catch issues
189235 sof-kernel-log-check.sh " $KERNEL_CHECKPOINT " || dump_and_die " Caught error in kernel log"
0 commit comments