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