2 # SPDX-License-Identifier: GPL-2.0
8 source special-tests.sh
10 DIR
="$(dirname $(readlink -f "$0"))"
11 source "${DIR}"/..
/kselftest
/ktap_helpers.sh
13 FUNC
=basic
# do basic tests by default
14 OUTFILE
=cpufreq_selftest
21 printf "Usage: $0 [-h] [-todg args]
23 [-o <output-file-for-dump>]
24 [-t <basic: Basic cpufreq testing
25 suspend: suspend/resume,
26 hibernate: hibernate/resume,
27 suspend_rtc: suspend/resume back using the RTC wakeup alarm,
28 hibernate_rtc: hibernate/resume back using the RTC wakeup alarm,
29 modtest: test driver or governor modules. Only to be used with -d or -g options,
30 sptest1: Simple governor switch to produce lockdep.
31 sptest2: Concurrent governor switch to produce lockdep.
32 sptest3: Governor races, shuffle between governors quickly.
33 sptest4: CPU hotplugs with updates to cpufreq files.>]
34 [-d <driver's module name: only with \"-t modtest>\"]
35 [-g <governor's module name: only with \"-t modtest>\"]
44 if [ $UID != 0 ]; then
45 ktap_skip_all
"$msg must be run as root"
51 SYSFS
=`mount -t sysfs | head -1 | awk '{ print $3 }'`
53 if [ ! -d "$SYSFS" ]; then
54 ktap_skip_all
"$msg sysfs is not mounted"
58 CPUROOT
=$SYSFS/devices
/system
/cpu
59 CPUFREQROOT
="$CPUROOT/cpufreq"
61 if ! ls $CPUROOT/cpu
* > /dev
/null
2>&1; then
62 ktap_skip_all
"$msg cpus not available in sysfs"
66 if ! ls $CPUROOT/cpufreq
> /dev
/null
2>&1; then
67 ktap_skip_all
"$msg cpufreq directory not available in sysfs"
74 while getopts ht
:o
:d
:g
: arg
81 t
) # --func_type (Function to perform: basic, suspend, hibernate,
82 # suspend_rtc, hibernate_rtc, modtest, sptest1/2/3/4 (default: basic))
86 o
) # --output-file (Output file to store dumps)
90 d
) # --driver-mod-name (Name of the driver module)
94 g
) # --governor-mod-name (Name of the governor module)
107 # Check if CPUs are managed by cpufreq or not
108 count
=$
(count_cpufreq_managed_cpus
)
110 if [ $count = 0 -a $FUNC != "modtest" ]; then
111 ktap_exit_fail_msg
"No cpu is managed by cpufreq core, exiting"
120 do_suspend
"suspend" 1
124 do_suspend
"hibernate" 1
128 do_suspend
"suspend" 1 rtc
132 do_suspend
"hibernate" 1 rtc
136 # Do we have modules in place?
137 if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
138 ktap_exit_fail_msg
"No driver or governor module passed with -d or -g"
141 if [ $DRIVER_MOD ]; then
142 if [ $GOVERNOR_MOD ]; then
143 module_test
$DRIVER_MOD $GOVERNOR_MOD
145 module_driver_test
$DRIVER_MOD
148 if [ $count = 0 ]; then
149 ktap_exit_fail_msg
"No cpu is managed by cpufreq core, exiting"
152 module_governor_test
$GOVERNOR_MOD
173 ktap_print_msg
"Invalid [-f] function type"
184 echo "" > $1.dmesg_cpufreq.txt
185 echo "" > $1.dmesg_full.txt
188 # $1: output file name
191 dmesg |
grep cpufreq
>> $1.dmesg_cpufreq.txt
193 # We may need the full logs as well
194 dmesg
>> $1.dmesg_full.txt
204 # Make sure all requirements are met
207 # Run requested functions
209 do_test |
tee -a $OUTFILE.txt
210 if [ "${PIPESTATUS[0]}" -ne 0 ]; then
211 exit ${PIPESTATUS[0]};
215 ktap_test_pass
"Completed successfully"