blob: 01bac76ac0ec71e8c9aa1371e45ee3736ecc1d24 [file] [log] [blame]
Viresh Kumare66d5b62017-01-13 12:06:45 +05301#!/bin/bash
2
3source cpu.sh
4source cpufreq.sh
5source governor.sh
Viresh Kumar6751faf2017-01-13 12:06:47 +05306source module.sh
Viresh Kumar1e4c2832017-01-13 12:06:48 +05307source special-tests.sh
Viresh Kumare66d5b62017-01-13 12:06:45 +05308
9FUNC=basic # do basic tests by default
10OUTFILE=cpufreq_selftest
11SYSFS=
12CPUROOT=
13CPUFREQROOT=
14
15helpme()
16{
Viresh Kumar6751faf2017-01-13 12:06:47 +053017 printf "Usage: $0 [-h] [-todg args]
Viresh Kumare66d5b62017-01-13 12:06:45 +053018 [-h <help>]
19 [-o <output-file-for-dump>]
Viresh Kumarb03eaf82017-01-13 12:06:46 +053020 [-t <basic: Basic cpufreq testing
21 suspend: suspend/resume,
Viresh Kumar6751faf2017-01-13 12:06:47 +053022 hibernate: hibernate/resume,
Viresh Kumar1e4c2832017-01-13 12:06:48 +053023 modtest: test driver or governor modules. Only to be used with -d or -g options,
24 sptest1: Simple governor switch to produce lockdep.
25 sptest2: Concurrent governor switch to produce lockdep.
26 sptest3: Governor races, shuffle between governors quickly.
27 sptest4: CPU hotplugs with updates to cpufreq files.>]
Viresh Kumar6751faf2017-01-13 12:06:47 +053028 [-d <driver's module name: only with \"-t modtest>\"]
29 [-g <governor's module name: only with \"-t modtest>\"]
Viresh Kumare66d5b62017-01-13 12:06:45 +053030 \n"
31 exit 2
32}
33
34prerequisite()
35{
36 msg="skip all tests:"
37
38 if [ $UID != 0 ]; then
39 echo $msg must be run as root >&2
40 exit 2
41 fi
42
43 taskset -p 01 $$
44
45 SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
46
47 if [ ! -d "$SYSFS" ]; then
48 echo $msg sysfs is not mounted >&2
49 exit 2
50 fi
51
52 CPUROOT=$SYSFS/devices/system/cpu
53 CPUFREQROOT="$CPUROOT/cpufreq"
54
55 if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
56 echo $msg cpus not available in sysfs >&2
57 exit 2
58 fi
59
60 if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
61 echo $msg cpufreq directory not available in sysfs >&2
62 exit 2
63 fi
64}
65
66parse_arguments()
67{
Viresh Kumar6751faf2017-01-13 12:06:47 +053068 while getopts ht:o:d:g: arg
Viresh Kumare66d5b62017-01-13 12:06:45 +053069 do
70 case $arg in
71 h) # --help
72 helpme
73 ;;
74
Viresh Kumar1e4c2832017-01-13 12:06:48 +053075 t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
Viresh Kumare66d5b62017-01-13 12:06:45 +053076 FUNC=$OPTARG
77 ;;
78
79 o) # --output-file (Output file to store dumps)
80 OUTFILE=$OPTARG
81 ;;
82
Viresh Kumar6751faf2017-01-13 12:06:47 +053083 d) # --driver-mod-name (Name of the driver module)
84 DRIVER_MOD=$OPTARG
85 ;;
86
87 g) # --governor-mod-name (Name of the governor module)
88 GOVERNOR_MOD=$OPTARG
89 ;;
90
Viresh Kumare66d5b62017-01-13 12:06:45 +053091 \?)
92 helpme
93 ;;
94 esac
95 done
96}
97
98do_test()
99{
100 # Check if CPUs are managed by cpufreq or not
101 count=$(count_cpufreq_managed_cpus)
102
Viresh Kumar6751faf2017-01-13 12:06:47 +0530103 if [ $count = 0 -a $FUNC != "modtest" ]; then
Viresh Kumare66d5b62017-01-13 12:06:45 +0530104 echo "No cpu is managed by cpufreq core, exiting"
105 exit 2;
106 fi
107
108 case "$FUNC" in
109 "basic")
110 cpufreq_basic_tests
111 ;;
112
Viresh Kumarb03eaf82017-01-13 12:06:46 +0530113 "suspend")
114 do_suspend "suspend" 1
115 ;;
116
117 "hibernate")
118 do_suspend "hibernate" 1
119 ;;
120
Viresh Kumar6751faf2017-01-13 12:06:47 +0530121 "modtest")
122 # Do we have modules in place?
123 if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
124 echo "No driver or governor module passed with -d or -g"
125 exit 2;
126 fi
127
128 if [ $DRIVER_MOD ]; then
129 if [ $GOVERNOR_MOD ]; then
130 module_test $DRIVER_MOD $GOVERNOR_MOD
131 else
132 module_driver_test $DRIVER_MOD
133 fi
134 else
135 if [ $count = 0 ]; then
136 echo "No cpu is managed by cpufreq core, exiting"
137 exit 2;
138 fi
139
140 module_governor_test $GOVERNOR_MOD
141 fi
142 ;;
143
Viresh Kumar1e4c2832017-01-13 12:06:48 +0530144 "sptest1")
145 simple_lockdep
146 ;;
147
148 "sptest2")
149 concurrent_lockdep
150 ;;
151
152 "sptest3")
153 governor_race
154 ;;
155
156 "sptest4")
157 hotplug_with_updates
158 ;;
159
Viresh Kumare66d5b62017-01-13 12:06:45 +0530160 *)
161 echo "Invalid [-f] function type"
162 helpme
163 ;;
164 esac
165}
166
167# clear dumps
168# $1: file name
169clear_dumps()
170{
171 echo "" > $1.txt
172 echo "" > $1.dmesg_cpufreq.txt
173 echo "" > $1.dmesg_full.txt
174}
175
176# $1: output file name
177dmesg_dumps()
178{
179 dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt
180
181 # We may need the full logs as well
182 dmesg >> $1.dmesg_full.txt
183}
184
185# Parse arguments
186parse_arguments $@
187
188# Make sure all requirements are met
189prerequisite
190
191# Run requested functions
192clear_dumps $OUTFILE
193do_test >> $OUTFILE.txt
194dmesg_dumps $OUTFILE