Linux 4.19.133
[linux/fpc-iii.git] / tools / testing / selftests / cpufreq / main.sh
blob31f8c9a76c5ff9331c9eeb9f9c69ed4cb35f57b0
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 source cpu.sh
5 source cpufreq.sh
6 source governor.sh
7 source module.sh
8 source special-tests.sh
10 FUNC=basic # do basic tests by default
11 OUTFILE=cpufreq_selftest
12 SYSFS=
13 CPUROOT=
14 CPUFREQROOT=
16 # Kselftest framework requirement - SKIP code is 4.
17 ksft_skip=4
19 helpme()
21 printf "Usage: $0 [-h] [-todg args]
22 [-h <help>]
23 [-o <output-file-for-dump>]
24 [-t <basic: Basic cpufreq testing
25 suspend: suspend/resume,
26 hibernate: hibernate/resume,
27 modtest: test driver or governor modules. Only to be used with -d or -g options,
28 sptest1: Simple governor switch to produce lockdep.
29 sptest2: Concurrent governor switch to produce lockdep.
30 sptest3: Governor races, shuffle between governors quickly.
31 sptest4: CPU hotplugs with updates to cpufreq files.>]
32 [-d <driver's module name: only with \"-t modtest>\"]
33 [-g <governor's module name: only with \"-t modtest>\"]
34 \n"
35 exit 2
38 prerequisite()
40 msg="skip all tests:"
42 if [ $UID != 0 ]; then
43 echo $msg must be run as root >&2
44 exit $ksft_skip
47 taskset -p 01 $$
49 SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
51 if [ ! -d "$SYSFS" ]; then
52 echo $msg sysfs is not mounted >&2
53 exit 2
56 CPUROOT=$SYSFS/devices/system/cpu
57 CPUFREQROOT="$CPUROOT/cpufreq"
59 if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
60 echo $msg cpus not available in sysfs >&2
61 exit 2
64 if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
65 echo $msg cpufreq directory not available in sysfs >&2
66 exit 2
70 parse_arguments()
72 while getopts ht:o:d:g: arg
74 case $arg in
75 h) # --help
76 helpme
79 t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
80 FUNC=$OPTARG
83 o) # --output-file (Output file to store dumps)
84 OUTFILE=$OPTARG
87 d) # --driver-mod-name (Name of the driver module)
88 DRIVER_MOD=$OPTARG
91 g) # --governor-mod-name (Name of the governor module)
92 GOVERNOR_MOD=$OPTARG
95 \?)
96 helpme
98 esac
99 done
102 do_test()
104 # Check if CPUs are managed by cpufreq or not
105 count=$(count_cpufreq_managed_cpus)
107 if [ $count = 0 -a $FUNC != "modtest" ]; then
108 echo "No cpu is managed by cpufreq core, exiting"
109 exit 2;
112 case "$FUNC" in
113 "basic")
114 cpufreq_basic_tests
117 "suspend")
118 do_suspend "suspend" 1
121 "hibernate")
122 do_suspend "hibernate" 1
125 "modtest")
126 # Do we have modules in place?
127 if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
128 echo "No driver or governor module passed with -d or -g"
129 exit 2;
132 if [ $DRIVER_MOD ]; then
133 if [ $GOVERNOR_MOD ]; then
134 module_test $DRIVER_MOD $GOVERNOR_MOD
135 else
136 module_driver_test $DRIVER_MOD
138 else
139 if [ $count = 0 ]; then
140 echo "No cpu is managed by cpufreq core, exiting"
141 exit 2;
144 module_governor_test $GOVERNOR_MOD
148 "sptest1")
149 simple_lockdep
152 "sptest2")
153 concurrent_lockdep
156 "sptest3")
157 governor_race
160 "sptest4")
161 hotplug_with_updates
165 echo "Invalid [-f] function type"
166 helpme
168 esac
171 # clear dumps
172 # $1: file name
173 clear_dumps()
175 echo "" > $1.txt
176 echo "" > $1.dmesg_cpufreq.txt
177 echo "" > $1.dmesg_full.txt
180 # $1: output file name
181 dmesg_dumps()
183 dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt
185 # We may need the full logs as well
186 dmesg >> $1.dmesg_full.txt
189 # Parse arguments
190 parse_arguments $@
192 # Make sure all requirements are met
193 prerequisite
195 # Run requested functions
196 clear_dumps $OUTFILE
197 do_test >> $OUTFILE.txt
198 dmesg_dumps $OUTFILE