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