Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / tools / testing / selftests / cpufreq / main.sh
blobd83922de9d8997addb8704a983e59c50a0c06c01
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 helpme()
18 printf "Usage: $0 [-h] [-todg args]
19 [-h <help>]
20 [-o <output-file-for-dump>]
21 [-t <basic: Basic cpufreq testing
22 suspend: suspend/resume,
23 hibernate: hibernate/resume,
24 modtest: test driver or governor modules. Only to be used with -d or -g options,
25 sptest1: Simple governor switch to produce lockdep.
26 sptest2: Concurrent governor switch to produce lockdep.
27 sptest3: Governor races, shuffle between governors quickly.
28 sptest4: CPU hotplugs with updates to cpufreq files.>]
29 [-d <driver's module name: only with \"-t modtest>\"]
30 [-g <governor's module name: only with \"-t modtest>\"]
31 \n"
32 exit 2
35 prerequisite()
37 msg="skip all tests:"
39 if [ $UID != 0 ]; then
40 echo $msg must be run as root >&2
41 exit 2
44 taskset -p 01 $$
46 SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
48 if [ ! -d "$SYSFS" ]; then
49 echo $msg sysfs is not mounted >&2
50 exit 2
53 CPUROOT=$SYSFS/devices/system/cpu
54 CPUFREQROOT="$CPUROOT/cpufreq"
56 if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
57 echo $msg cpus not available in sysfs >&2
58 exit 2
61 if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
62 echo $msg cpufreq directory not available in sysfs >&2
63 exit 2
67 parse_arguments()
69 while getopts ht:o:d:g: arg
71 case $arg in
72 h) # --help
73 helpme
76 t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
77 FUNC=$OPTARG
80 o) # --output-file (Output file to store dumps)
81 OUTFILE=$OPTARG
84 d) # --driver-mod-name (Name of the driver module)
85 DRIVER_MOD=$OPTARG
88 g) # --governor-mod-name (Name of the governor module)
89 GOVERNOR_MOD=$OPTARG
92 \?)
93 helpme
95 esac
96 done
99 do_test()
101 # Check if CPUs are managed by cpufreq or not
102 count=$(count_cpufreq_managed_cpus)
104 if [ $count = 0 -a $FUNC != "modtest" ]; then
105 echo "No cpu is managed by cpufreq core, exiting"
106 exit 2;
109 case "$FUNC" in
110 "basic")
111 cpufreq_basic_tests
114 "suspend")
115 do_suspend "suspend" 1
118 "hibernate")
119 do_suspend "hibernate" 1
122 "modtest")
123 # Do we have modules in place?
124 if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
125 echo "No driver or governor module passed with -d or -g"
126 exit 2;
129 if [ $DRIVER_MOD ]; then
130 if [ $GOVERNOR_MOD ]; then
131 module_test $DRIVER_MOD $GOVERNOR_MOD
132 else
133 module_driver_test $DRIVER_MOD
135 else
136 if [ $count = 0 ]; then
137 echo "No cpu is managed by cpufreq core, exiting"
138 exit 2;
141 module_governor_test $GOVERNOR_MOD
145 "sptest1")
146 simple_lockdep
149 "sptest2")
150 concurrent_lockdep
153 "sptest3")
154 governor_race
157 "sptest4")
158 hotplug_with_updates
162 echo "Invalid [-f] function type"
163 helpme
165 esac
168 # clear dumps
169 # $1: file name
170 clear_dumps()
172 echo "" > $1.txt
173 echo "" > $1.dmesg_cpufreq.txt
174 echo "" > $1.dmesg_full.txt
177 # $1: output file name
178 dmesg_dumps()
180 dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt
182 # We may need the full logs as well
183 dmesg >> $1.dmesg_full.txt
186 # Parse arguments
187 parse_arguments $@
189 # Make sure all requirements are met
190 prerequisite
192 # Run requested functions
193 clear_dumps $OUTFILE
194 do_test >> $OUTFILE.txt
195 dmesg_dumps $OUTFILE