blob: 31f8c9a76c5ff9331c9eeb9f9c69ed4cb35f57b0 [file] [log] [blame]
Viresh Kumare66d5b62017-01-13 12:06:45 +05301#!/bin/bash
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01002# SPDX-License-Identifier: GPL-2.0
Viresh Kumare66d5b62017-01-13 12:06:45 +05303
4source cpu.sh
5source cpufreq.sh
6source governor.sh
Viresh Kumar6751faf2017-01-13 12:06:47 +05307source module.sh
Viresh Kumar1e4c2832017-01-13 12:06:48 +05308source special-tests.sh
Viresh Kumare66d5b62017-01-13 12:06:45 +05309
10FUNC=basic # do basic tests by default
11OUTFILE=cpufreq_selftest
12SYSFS=
13CPUROOT=
14CPUFREQROOT=
15
Shuah Khan (Samsung OSG)4c5b95c2018-05-02 18:08:12 -060016# Kselftest framework requirement - SKIP code is 4.
17ksft_skip=4
18
Viresh Kumare66d5b62017-01-13 12:06:45 +053019helpme()
20{
Viresh Kumar6751faf2017-01-13 12:06:47 +053021 printf "Usage: $0 [-h] [-todg args]
Viresh Kumare66d5b62017-01-13 12:06:45 +053022 [-h <help>]
23 [-o <output-file-for-dump>]
Viresh Kumarb03eaf82017-01-13 12:06:46 +053024 [-t <basic: Basic cpufreq testing
25 suspend: suspend/resume,
Viresh Kumar6751faf2017-01-13 12:06:47 +053026 hibernate: hibernate/resume,
Viresh Kumar1e4c2832017-01-13 12:06:48 +053027 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.>]
Viresh Kumar6751faf2017-01-13 12:06:47 +053032 [-d <driver's module name: only with \"-t modtest>\"]
33 [-g <governor's module name: only with \"-t modtest>\"]
Viresh Kumare66d5b62017-01-13 12:06:45 +053034 \n"
35 exit 2
36}
37
38prerequisite()
39{
40 msg="skip all tests:"
41
42 if [ $UID != 0 ]; then
43 echo $msg must be run as root >&2
Shuah Khan (Samsung OSG)4c5b95c2018-05-02 18:08:12 -060044 exit $ksft_skip
Viresh Kumare66d5b62017-01-13 12:06:45 +053045 fi
46
47 taskset -p 01 $$
48
49 SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
50
51 if [ ! -d "$SYSFS" ]; then
52 echo $msg sysfs is not mounted >&2
53 exit 2
54 fi
55
56 CPUROOT=$SYSFS/devices/system/cpu
57 CPUFREQROOT="$CPUROOT/cpufreq"
58
59 if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
60 echo $msg cpus not available in sysfs >&2
61 exit 2
62 fi
63
64 if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
65 echo $msg cpufreq directory not available in sysfs >&2
66 exit 2
67 fi
68}
69
70parse_arguments()
71{
Viresh Kumar6751faf2017-01-13 12:06:47 +053072 while getopts ht:o:d:g: arg
Viresh Kumare66d5b62017-01-13 12:06:45 +053073 do
74 case $arg in
75 h) # --help
76 helpme
77 ;;
78
Viresh Kumar1e4c2832017-01-13 12:06:48 +053079 t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
Viresh Kumare66d5b62017-01-13 12:06:45 +053080 FUNC=$OPTARG
81 ;;
82
83 o) # --output-file (Output file to store dumps)
84 OUTFILE=$OPTARG
85 ;;
86
Viresh Kumar6751faf2017-01-13 12:06:47 +053087 d) # --driver-mod-name (Name of the driver module)
88 DRIVER_MOD=$OPTARG
89 ;;
90
91 g) # --governor-mod-name (Name of the governor module)
92 GOVERNOR_MOD=$OPTARG
93 ;;
94
Viresh Kumare66d5b62017-01-13 12:06:45 +053095 \?)
96 helpme
97 ;;
98 esac
99 done
100}
101
102do_test()
103{
104 # Check if CPUs are managed by cpufreq or not
105 count=$(count_cpufreq_managed_cpus)
106
Viresh Kumar6751faf2017-01-13 12:06:47 +0530107 if [ $count = 0 -a $FUNC != "modtest" ]; then
Viresh Kumare66d5b62017-01-13 12:06:45 +0530108 echo "No cpu is managed by cpufreq core, exiting"
109 exit 2;
110 fi
111
112 case "$FUNC" in
113 "basic")
114 cpufreq_basic_tests
115 ;;
116
Viresh Kumarb03eaf82017-01-13 12:06:46 +0530117 "suspend")
118 do_suspend "suspend" 1
119 ;;
120
121 "hibernate")
122 do_suspend "hibernate" 1
123 ;;
124
Viresh Kumar6751faf2017-01-13 12:06:47 +0530125 "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;
130 fi
131
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
137 fi
138 else
139 if [ $count = 0 ]; then
140 echo "No cpu is managed by cpufreq core, exiting"
141 exit 2;
142 fi
143
144 module_governor_test $GOVERNOR_MOD
145 fi
146 ;;
147
Viresh Kumar1e4c2832017-01-13 12:06:48 +0530148 "sptest1")
149 simple_lockdep
150 ;;
151
152 "sptest2")
153 concurrent_lockdep
154 ;;
155
156 "sptest3")
157 governor_race
158 ;;
159
160 "sptest4")
161 hotplug_with_updates
162 ;;
163
Viresh Kumare66d5b62017-01-13 12:06:45 +0530164 *)
165 echo "Invalid [-f] function type"
166 helpme
167 ;;
168 esac
169}
170
171# clear dumps
172# $1: file name
173clear_dumps()
174{
175 echo "" > $1.txt
176 echo "" > $1.dmesg_cpufreq.txt
177 echo "" > $1.dmesg_full.txt
178}
179
180# $1: output file name
181dmesg_dumps()
182{
183 dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt
184
185 # We may need the full logs as well
186 dmesg >> $1.dmesg_full.txt
187}
188
189# Parse arguments
190parse_arguments $@
191
192# Make sure all requirements are met
193prerequisite
194
195# Run requested functions
196clear_dumps $OUTFILE
197do_test >> $OUTFILE.txt
198dmesg_dumps $OUTFILE