Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/bash
2#
3# Modules specific tests cases
4
5# protect against multiple inclusion
6if [ $FILE_MODULE ]; then
7 return 0
8else
9 FILE_MODULE=DONE
10fi
11
12source cpu.sh
13source cpufreq.sh
14source governor.sh
15
16# Check basic insmod/rmmod
17# $1: module
18test_basic_insmod_rmmod()
19{
20 printf "** Test: Running ${FUNCNAME[0]} **\n\n"
21
22 printf "Inserting $1 module\n"
23 # insert module
24 insmod $1
25 if [ $? != 0 ]; then
26 printf "Insmod $1 failed\n"
27 exit;
28 fi
29
30 printf "Removing $1 module\n"
31 # remove module
32 rmmod $1
33 if [ $? != 0 ]; then
34 printf "rmmod $1 failed\n"
35 exit;
36 fi
37
38 printf "\n"
39}
40
41# Insert cpufreq driver module and perform basic tests
42# $1: cpufreq-driver module to insert
43# $2: If we want to play with CPUs (1) or not (0)
44module_driver_test_single()
45{
46 printf "** Test: Running ${FUNCNAME[0]} for driver $1 and cpus_hotplug=$2 **\n\n"
47
48 if [ $2 -eq 1 ]; then
49 # offline all non-boot CPUs
50 for_each_non_boot_cpu offline_cpu
51 printf "\n"
52 fi
53
54 # insert module
55 printf "Inserting $1 module\n\n"
56 insmod $1
57 if [ $? != 0 ]; then
58 printf "Insmod $1 failed\n"
59 return;
60 fi
61
62 if [ $2 -eq 1 ]; then
63 # online all non-boot CPUs
64 for_each_non_boot_cpu online_cpu
65 printf "\n"
66 fi
67
68 # run basic tests
69 cpufreq_basic_tests
70
71 # remove module
72 printf "Removing $1 module\n\n"
73 rmmod $1
74 if [ $? != 0 ]; then
75 printf "rmmod $1 failed\n"
76 return;
77 fi
78
79 # There shouldn't be any cpufreq directories now.
80 for_each_cpu cpu_should_not_have_cpufreq_directory
81 printf "\n"
82}
83
84# $1: cpufreq-driver module to insert
85module_driver_test()
86{
87 printf "** Test: Running ${FUNCNAME[0]} **\n\n"
88
89 # check if module is present or not
90 ls $1 > /dev/null
91 if [ $? != 0 ]; then
92 printf "$1: not present in `pwd` folder\n"
93 return;
94 fi
95
96 # test basic module tests
97 test_basic_insmod_rmmod $1
98
99 # Do simple module test
100 module_driver_test_single $1 0
101
102 # Remove CPUs before inserting module and then bring them back
103 module_driver_test_single $1 1
104 printf "\n"
105}
106
107# find governor name based on governor module name
108# $1: governor module name
109find_gov_name()
110{
111 if [ $1 = "cpufreq_ondemand.ko" ]; then
112 printf "ondemand"
113 elif [ $1 = "cpufreq_conservative.ko" ]; then
114 printf "conservative"
115 elif [ $1 = "cpufreq_userspace.ko" ]; then
116 printf "userspace"
117 elif [ $1 = "cpufreq_performance.ko" ]; then
118 printf "performance"
119 elif [ $1 = "cpufreq_powersave.ko" ]; then
120 printf "powersave"
121 elif [ $1 = "cpufreq_schedutil.ko" ]; then
122 printf "schedutil"
123 fi
124}
125
126# $1: governor string, $2: governor module, $3: policy
127# example: module_governor_test_single "ondemand" "cpufreq_ondemand.ko" 2
128module_governor_test_single()
129{
130 printf "** Test: Running ${FUNCNAME[0]} for $3 **\n\n"
131
132 backup_governor $3
133
134 # switch to new governor
135 printf "Switch from $CUR_GOV to $1\n"
136 switch_show_governor $3 $1
137
138 # try removing module, it should fail as governor is used
139 printf "Removing $2 module\n\n"
140 rmmod $2
141 if [ $? = 0 ]; then
142 printf "WARN: rmmod $2 succeeded even if governor is used\n"
143 insmod $2
144 else
145 printf "Pass: unable to remove $2 while it is being used\n\n"
146 fi
147
148 # switch back to old governor
149 printf "Switchback to $CUR_GOV from $1\n"
150 restore_governor $3
151 printf "\n"
152}
153
154# Insert cpufreq governor module and perform basic tests
155# $1: cpufreq-governor module to insert
156module_governor_test()
157{
158 printf "** Test: Running ${FUNCNAME[0]} **\n\n"
159
160 # check if module is present or not
161 ls $1 > /dev/null
162 if [ $? != 0 ]; then
163 printf "$1: not present in `pwd` folder\n"
164 return;
165 fi
166
167 # test basic module tests
168 test_basic_insmod_rmmod $1
169
170 # insert module
171 printf "Inserting $1 module\n\n"
172 insmod $1
173 if [ $? != 0 ]; then
174 printf "Insmod $1 failed\n"
175 return;
176 fi
177
178 # switch to new governor for each cpu
179 for_each_policy module_governor_test_single $(find_gov_name $1) $1
180
181 # remove module
182 printf "Removing $1 module\n\n"
183 rmmod $1
184 if [ $? != 0 ]; then
185 printf "rmmod $1 failed\n"
186 return;
187 fi
188 printf "\n"
189}
190
191# test modules: driver and governor
192# $1: driver module, $2: governor module
193module_test()
194{
195 printf "** Test: Running ${FUNCNAME[0]} **\n\n"
196
197 # check if modules are present or not
198 ls $1 $2 > /dev/null
199 if [ $? != 0 ]; then
200 printf "$1 or $2: is not present in `pwd` folder\n"
201 return;
202 fi
203
204 # TEST1: Insert gov after driver
205 # insert driver module
206 printf "Inserting $1 module\n\n"
207 insmod $1
208 if [ $? != 0 ]; then
209 printf "Insmod $1 failed\n"
210 return;
211 fi
212
213 # run governor tests
214 module_governor_test $2
215
216 # remove driver module
217 printf "Removing $1 module\n\n"
218 rmmod $1
219 if [ $? != 0 ]; then
220 printf "rmmod $1 failed\n"
221 return;
222 fi
223
224 # TEST2: Insert driver after governor
225 # insert governor module
226 printf "Inserting $2 module\n\n"
227 insmod $2
228 if [ $? != 0 ]; then
229 printf "Insmod $2 failed\n"
230 return;
231 fi
232
233 # run governor tests
234 module_driver_test $1
235
236 # remove driver module
237 printf "Removing $2 module\n\n"
238 rmmod $2
239 if [ $? != 0 ]; then
240 printf "rmmod $2 failed\n"
241 return;
242 fi
243}