Skip to content

Commit cd8409b

Browse files
committed
Test Case: Add check suspend resume test
Add new Test Case for the suspend resume Signed-off-by: Wu, BinX <binx.wu@intel.com>
1 parent 1bdabcb commit cd8409b

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

case-lib/lib.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,20 @@ func_lib_restore_pulseaudio()
8585
unset PULSECMD_LST
8686
declare -ag PULSECMD_LST
8787
}
88+
89+
func_lib_get_random()
90+
{
91+
# RANDOM: Each time this parameter is referenced, a random integer between 0 and 32767 is generated
92+
local random_max random_min random_scope
93+
if [ $# -ge 2 ];then
94+
random_max=$2
95+
random_min=$1
96+
random_scope=$(expr $random_max - $random_min)
97+
expr $RANDOM % $random_scope + $random_min
98+
elif [ $# -eq 1 ];then
99+
random_max=$1
100+
expr $RANDOM % $random_max
101+
else
102+
echo $RANDOM
103+
fi
104+
}

test-case/check-suspend-resume.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
3+
##
4+
## Case Name: check suspend/resume status
5+
## Preconditions:
6+
## N/A
7+
## Description:
8+
## Run the suspend/resume command to check device status
9+
## Case step:
10+
## 1. switch suspend/resume operation
11+
## 2. use rtcwake -m mem command to do suspend/resume
12+
## 3. check command return value
13+
## 4. check dmesg errors
14+
## 5. check wakeup increase
15+
## Expect result:
16+
## suspend/resume recover
17+
## check kernel log and find no errors
18+
##
19+
20+
source $(dirname ${BASH_SOURCE[0]})/../case-lib/lib.sh
21+
22+
random_min=3 # wait time should >= 3 for other device wakeup from sleep
23+
random_max=20
24+
def_power=$(sed 's/ /\n/g' /sys/power/mem_sleep|grep '\['|sed 's/\[//g;s/\]//g')
25+
26+
OPT_OPT_lst['l']='loop' OPT_DESC_lst['l']='loop count'
27+
OPT_PARM_lst['l']=1 OPT_VALUE_lst['l']=5
28+
29+
OPT_OPT_lst['p']='power' OPT_DESC_lst['p']="suspend/resume type from /sys/power/mem_sleep"
30+
OPT_PARM_lst['p']=1 OPT_VALUE_lst['p']="$def_power"
31+
32+
OPT_OPT_lst['s']='sleep' OPT_DESC_lst['s']='suspend/resume command:rtcwake sleep option'
33+
OPT_PARM_lst['s']=1 OPT_VALUE_lst['s']=5
34+
35+
OPT_OPT_lst['w']='wait' OPT_DESC_lst['w']='wait time after suspend/resume wakeup'
36+
OPT_PARM_lst['w']=1 OPT_VALUE_lst['w']=5
37+
38+
OPT_OPT_lst['r']='random' OPT_DESC_lst['r']="Random setup wait/sleep time, time range is [$random_min-$random_max], this option will overwait s & w option"
39+
OPT_PARM_lst['r']=0 OPT_VALUE_lst['r']=0
40+
41+
func_opt_parse_option $*
42+
func_lib_check_sudo
43+
func_lib_setup_kernel_last_line
44+
45+
power=${OPT_VALUE_lst['p']}
46+
dlogi "Current suspend/resume type mode: $def_power"
47+
# switch type
48+
if [ "$power" != "$def_pwoer" ]; then
49+
# check for power value effect
50+
[[ ! "$(cat /sys/power/mem_sleep|grep $power)" ]] && dloge "useless power option" && exit 2
51+
dlogc "sudo bash -c 'echo $power > /sys/power/mem_sleep'"
52+
sudo bash -c "'echo $power > /sys/power/mem_sleep'"
53+
dlogi "Switch it to $(cat /sys/power/mem_sleep)"
54+
fi
55+
56+
loop_count=${OPT_VALUE_lst['l']}
57+
declare -a sleep_lst wait_lst
58+
59+
if [ ${OPT_VALUE_lst['r']} -eq 1 ]; then
60+
# create random number list
61+
for i in $(seq 1 $loop_count)
62+
do
63+
sleep_lst[$i]=$(func_lib_get_random $random_max $random_min)
64+
wait_lst[$i]=$(func_lib_get_random $random_max $random_min)
65+
done
66+
else
67+
for i in $(seq 1 $loop_count)
68+
do
69+
sleep_lst[$i]=${OPT_VALUE_lst['s']}
70+
wait_lst[$i]=${OPT_VALUE_lst['w']}
71+
done
72+
fi
73+
74+
for i in $(seq 1 $loop_count)
75+
do
76+
dlogi "Round($i/$loop_count)"
77+
# cleanup dmesg befor run case
78+
sudo dmesg --clear
79+
bcount=$(cat /sys/power/wakeup_count)
80+
dlogc "Run the command: rtcwake -m mem -s ${sleep_lst[$i]}"
81+
sudo rtcwake -m mem -s ${sleep_lst[$i]}
82+
[[ $? -ne 0 ]] && dloge "rtcwake return value error" && exit 1
83+
dlogc "sleep for ${wait_lst[$i]}"
84+
sleep ${wait_lst[$i]}
85+
dlogi "Check for the kernel log status"
86+
acount=$(cat /sys/power/wakeup_count)
87+
# sof-kernel-log-check script parameter number is 0/Non-Number will force check from dmesg
88+
sof-kernel-log-check.sh 0
89+
[[ $? -ne 0 ]] && dloge "Catch dmesg error" && exit 1
90+
# check wakeup count correct
91+
[[ $acount -le $bcount ]] && dloge "Fake suspend/resume, because /sys/power/wakeup_count is not increase" && exit 1
92+
done
93+
94+
# check full log
95+
sof-kernel-log-check.sh $KERNEL_LAST_LINE
96+
exit $?

0 commit comments

Comments
 (0)