xref: /OK3568_Linux_fs/external/rockchip-test/suspend_resume/suspend_resume.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/bash
2
3RESULT_DIR=/userdata/rockchip-test/
4RESULT_LOG=${RESULT_DIR}/suspend_resume.txt
5SUSPEND_MAX=60
6SUSPEND_MIN=30
7SUSPEND_INTERVAL=$(($SUSPEND_MAX - $SUSPEND_MIN + 1 ))
8WAKE_MAX=60
9WAKE_MIN=30
10WKAE_INTERVAL=$(($WAKE_MAX - $WAKE_MIN + 1 ))
11MAX_CYCLES=10000
12
13if [ ! -e "/sys/class/rtc/rtc0/wakealarm" ];then
14    echo "non-existent rtc, please check if rtc enabled"
15    exit
16fi
17
18mkdir -p ${RESULT_DIR}
19
20random() {
21  hexdump -n 2 -e '/2 "%u"' /dev/urandom
22}
23
24auto_suspend_resume_rtc()
25{
26    cnt=0
27
28    # set sys time same with rtc
29    hwclock --systohc
30    hwclock -w
31    echo "$(date): auto_suspend_resume_rtc start" > ${RESULT_LOG}
32
33    while true; do
34        echo "have done $cnt suspend/resume"
35        if [ $cnt -ge $MAX_CYCLES ]
36        then
37            echo "run $MAX_CYCLES cycles, finish test"
38            exit 0
39        fi
40        sus_time=$(( ( $(random) % $SUSPEND_INTERVAL ) + $SUSPEND_MIN ))
41        echo "sleep for $sus_time second"
42        echo 0 > /sys/class/rtc/rtc0/wakealarm
43        echo "+${sus_time}" > /sys/class/rtc/rtc0/wakealarm
44        pm-suspend
45        wake_time=$(( ( $(random) % $WKAE_INTERVAL ) + $WAKE_MIN ))
46        echo "wake for $wake_time second"
47        sleep $wake_time
48        echo "$(date): Count: $cnt - sleep: $sus_time wake: $wake_time " >> ${RESULT_LOG}
49        let "cnt=$cnt+1"
50    done
51}
52auto_suspend_resume_rtc
53
54