]>
Commit | Line | Data |
---|---|---|
e66d5b67 | 1 | #!/bin/bash |
b2441318 | 2 | # SPDX-License-Identifier: GPL-2.0 |
e66d5b67 VK |
3 | |
4 | source cpu.sh | |
5 | source cpufreq.sh | |
6 | source governor.sh | |
6751faf3 | 7 | source module.sh |
1e4c2830 | 8 | source special-tests.sh |
e66d5b67 VK |
9 | |
10 | FUNC=basic # do basic tests by default | |
11 | OUTFILE=cpufreq_selftest | |
12 | SYSFS= | |
13 | CPUROOT= | |
14 | CPUFREQROOT= | |
15 | ||
16 | helpme() | |
17 | { | |
6751faf3 | 18 | printf "Usage: $0 [-h] [-todg args] |
e66d5b67 VK |
19 | [-h <help>] |
20 | [-o <output-file-for-dump>] | |
b03eaf8d VK |
21 | [-t <basic: Basic cpufreq testing |
22 | suspend: suspend/resume, | |
6751faf3 | 23 | hibernate: hibernate/resume, |
1e4c2830 VK |
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.>] | |
6751faf3 VK |
29 | [-d <driver's module name: only with \"-t modtest>\"] |
30 | [-g <governor's module name: only with \"-t modtest>\"] | |
e66d5b67 VK |
31 | \n" |
32 | exit 2 | |
33 | } | |
34 | ||
35 | prerequisite() | |
36 | { | |
37 | msg="skip all tests:" | |
38 | ||
39 | if [ $UID != 0 ]; then | |
40 | echo $msg must be run as root >&2 | |
41 | exit 2 | |
42 | fi | |
43 | ||
44 | taskset -p 01 $$ | |
45 | ||
46 | SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'` | |
47 | ||
48 | if [ ! -d "$SYSFS" ]; then | |
49 | echo $msg sysfs is not mounted >&2 | |
50 | exit 2 | |
51 | fi | |
52 | ||
53 | CPUROOT=$SYSFS/devices/system/cpu | |
54 | CPUFREQROOT="$CPUROOT/cpufreq" | |
55 | ||
56 | if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then | |
57 | echo $msg cpus not available in sysfs >&2 | |
58 | exit 2 | |
59 | fi | |
60 | ||
61 | if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then | |
62 | echo $msg cpufreq directory not available in sysfs >&2 | |
63 | exit 2 | |
64 | fi | |
65 | } | |
66 | ||
67 | parse_arguments() | |
68 | { | |
6751faf3 | 69 | while getopts ht:o:d:g: arg |
e66d5b67 VK |
70 | do |
71 | case $arg in | |
72 | h) # --help | |
73 | helpme | |
74 | ;; | |
75 | ||
1e4c2830 | 76 | t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic)) |
e66d5b67 VK |
77 | FUNC=$OPTARG |
78 | ;; | |
79 | ||
80 | o) # --output-file (Output file to store dumps) | |
81 | OUTFILE=$OPTARG | |
82 | ;; | |
83 | ||
6751faf3 VK |
84 | d) # --driver-mod-name (Name of the driver module) |
85 | DRIVER_MOD=$OPTARG | |
86 | ;; | |
87 | ||
88 | g) # --governor-mod-name (Name of the governor module) | |
89 | GOVERNOR_MOD=$OPTARG | |
90 | ;; | |
91 | ||
e66d5b67 VK |
92 | \?) |
93 | helpme | |
94 | ;; | |
95 | esac | |
96 | done | |
97 | } | |
98 | ||
99 | do_test() | |
100 | { | |
101 | # Check if CPUs are managed by cpufreq or not | |
102 | count=$(count_cpufreq_managed_cpus) | |
103 | ||
6751faf3 | 104 | if [ $count = 0 -a $FUNC != "modtest" ]; then |
e66d5b67 VK |
105 | echo "No cpu is managed by cpufreq core, exiting" |
106 | exit 2; | |
107 | fi | |
108 | ||
109 | case "$FUNC" in | |
110 | "basic") | |
111 | cpufreq_basic_tests | |
112 | ;; | |
113 | ||
b03eaf8d VK |
114 | "suspend") |
115 | do_suspend "suspend" 1 | |
116 | ;; | |
117 | ||
118 | "hibernate") | |
119 | do_suspend "hibernate" 1 | |
120 | ;; | |
121 | ||
6751faf3 VK |
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; | |
127 | fi | |
128 | ||
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 | |
134 | fi | |
135 | else | |
136 | if [ $count = 0 ]; then | |
137 | echo "No cpu is managed by cpufreq core, exiting" | |
138 | exit 2; | |
139 | fi | |
140 | ||
141 | module_governor_test $GOVERNOR_MOD | |
142 | fi | |
143 | ;; | |
144 | ||
1e4c2830 VK |
145 | "sptest1") |
146 | simple_lockdep | |
147 | ;; | |
148 | ||
149 | "sptest2") | |
150 | concurrent_lockdep | |
151 | ;; | |
152 | ||
153 | "sptest3") | |
154 | governor_race | |
155 | ;; | |
156 | ||
157 | "sptest4") | |
158 | hotplug_with_updates | |
159 | ;; | |
160 | ||
e66d5b67 VK |
161 | *) |
162 | echo "Invalid [-f] function type" | |
163 | helpme | |
164 | ;; | |
165 | esac | |
166 | } | |
167 | ||
168 | # clear dumps | |
169 | # $1: file name | |
170 | clear_dumps() | |
171 | { | |
172 | echo "" > $1.txt | |
173 | echo "" > $1.dmesg_cpufreq.txt | |
174 | echo "" > $1.dmesg_full.txt | |
175 | } | |
176 | ||
177 | # $1: output file name | |
178 | dmesg_dumps() | |
179 | { | |
180 | dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt | |
181 | ||
182 | # We may need the full logs as well | |
183 | dmesg >> $1.dmesg_full.txt | |
184 | } | |
185 | ||
186 | # Parse arguments | |
187 | parse_arguments $@ | |
188 | ||
189 | # Make sure all requirements are met | |
190 | prerequisite | |
191 | ||
192 | # Run requested functions | |
193 | clear_dumps $OUTFILE | |
194 | do_test >> $OUTFILE.txt | |
195 | dmesg_dumps $OUTFILE |