-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuspend.sh
executable file
·118 lines (100 loc) · 3.41 KB
/
suspend.sh
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
# Default values for command line options
min_delay=15
max_delay=30
resume_hook="./resume-hook.sh"
use_rtc=0
# Function to print usage information and exit
usage() {
echo "Usage: $0 [-m <min_delay>] [-M <max_delay>] [-r <resume_hook_path>] [-R] <n>"
echo " -m <min_delay> Minimum delay between suspend cycles (default: ${min_delay})"
echo " -M <max_delay> Maximum delay between suspend cycles (default: ${max_delay})"
echo " -r <resume_hook_path> Path to the resume hook script (default: ${resume_hook})"
echo " -R Use RTC method (bypassing rtcwake) for suspend test"
echo " <n> is the number of suspend cycles"
exit 1
}
# Parse command line options
while getopts ":m:M:r:R" opt; do
case $opt in
m)
min_delay="$OPTARG"
;;
M)
max_delay="$OPTARG"
;;
r)
resume_hook="$OPTARG"
;;
R)
use_rtc=1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
# Remove the parsed options from the positional parameters
shift $((OPTIND - 1))
# Ensure that at least one positional parameter (<n>) remains
if [ $# -lt 1 ]; then
usage
fi
suspend_count="$1"
# Cleanup previous files if they exist
[ -f ./count ] && rm -rvf ./count
[ -f results.log ] && sudo rm -rvf results.log
# List of packages to install
PKG_LIST=("fwts" "dbus-x11" "gnome-terminal")
./install.sh "${PKG_LIST[@]}"
# Adjust GNOME settings for the test
gsettings set org.gnome.desktop.session idle-delay 0
gsettings set org.gnome.settings-daemon.plugins.power idle-dim false
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type "nothing"
gsettings set org.gnome.desktop.screensaver lock-enabled false
gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend false
# Launch a terminal to monitor journal logs
sudo gnome-terminal -- bash -c 'journalctl -f | grep -i -e tpm -e suspend_test'
if [ "$use_rtc" -eq 1 ]; then
echo "Using RTC method for suspend test (bypassing rtcwake)..."
# Run the entire RTC loop in a single sudo shell so that the password isn't requested repeatedly.
sudo bash <<EOF
suspend_count=${suspend_count}
min_delay=${min_delay}
max_delay=${max_delay}
resume_hook='${resume_hook}'
for (( i=1; i<=suspend_count; i++ )); do
# Calculate a random delay between min_delay and max_delay (the wait time between cycles)
range=\$(( max_delay - min_delay + 1 ))
delay=\$(( RANDOM % range + min_delay ))
echo "Iteration \$i: Waiting \$delay seconds before suspending..."
sleep "\$delay"
echo "Clearing previous RTC wakealarm..."
echo 0 > /sys/class/rtc/rtc0/wakealarm
current_time=\$(date +%s)
wake_time=\$(( current_time + 35 ))
echo "Setting RTC wakealarm for \$(date -d @\$wake_time) (timestamp: \$wake_time)..."
echo \$wake_time > /sys/class/rtc/rtc0/wakealarm
echo "Iteration \$i: Suspending for 30 seconds..."
systemctl suspend
if [ -x "\$resume_hook" ]; then
echo "Executing resume hook: \$resume_hook"
sleep 10
"\$resume_hook"
fi
done
EOF
else
# Use fwts s3 suspend test with the specified parameters.
sudo fwts s3 --s3-multiple "$suspend_count" \
--s3-min-delay "$min_delay" \
--s3-max-delay "$max_delay" \
--s3-resume-hook "$resume_hook"
fi
# Display suspend statistics
sudo cat /sys/kernel/debug/suspend_stats