Commit | Line | Data |
---|---|---|
c87b9c60 PM |
1 | #!/bin/bash |
2 | # | |
3 | # Run a series of 14 tests under KVM. These are not particularly | |
4 | # well-selected or well-tuned, but are the current set. Run from the | |
5 | # top level of the source tree. | |
6 | # | |
7 | # Edit the definitions below to set the locations of the various directories, | |
8 | # as well as the test duration. | |
9 | # | |
3327d924 | 10 | # Usage: kvm.sh [ options ] |
c87b9c60 PM |
11 | # |
12 | # This program is free software; you can redistribute it and/or modify | |
13 | # it under the terms of the GNU General Public License as published by | |
14 | # the Free Software Foundation; either version 2 of the License, or | |
15 | # (at your option) any later version. | |
16 | # | |
17 | # This program is distributed in the hope that it will be useful, | |
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | # GNU General Public License for more details. | |
21 | # | |
22 | # You should have received a copy of the GNU General Public License | |
0e342a87 PM |
23 | # along with this program; if not, you can access it online at |
24 | # http://www.gnu.org/licenses/gpl-2.0.html. | |
c87b9c60 PM |
25 | # |
26 | # Copyright (C) IBM Corporation, 2011 | |
27 | # | |
28 | # Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com> | |
29 | ||
30 | scriptname=$0 | |
330a76f1 | 31 | args="$*" |
c87b9c60 | 32 | |
43e38ab3 PM |
33 | T=/tmp/kvm.sh.$$ |
34 | trap 'rm -rf $T' 0 | |
35 | mkdir $T | |
36 | ||
c87b9c60 | 37 | dur=30 |
a7582815 | 38 | dryrun="" |
73931b5e | 39 | KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM |
32caccb8 | 40 | PATH=${KVM}/bin:$PATH; export PATH |
8c55f227 | 41 | TORTURE_DEFCONFIG=defconfig |
f189cc8c | 42 | TORTURE_BOOT_IMAGE="" |
2f66dbc1 | 43 | TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD |
58d280bd | 44 | TORTURE_KMAKE_ARG="" |
61010e74 | 45 | TORTURE_SUITE=rcu |
c87b9c60 | 46 | resdir="" |
4275be83 | 47 | configs="" |
43e38ab3 | 48 | cpus=0 |
847bfd25 | 49 | ds=`date +%Y.%m.%d-%H:%M:%S` |
c87b9c60 | 50 | |
32caccb8 PM |
51 | . functions.sh |
52 | ||
c87b9c60 PM |
53 | usage () { |
54 | echo "Usage: $scriptname optional arguments:" | |
7dca9273 | 55 | echo " --bootargs kernel-boot-arguments" |
f189cc8c | 56 | echo " --bootimage relative-path-to-kernel-boot-image" |
11274813 | 57 | echo " --buildonly" |
c87b9c60 | 58 | echo " --configs \"config-file list\"" |
43e38ab3 | 59 | echo " --cpus N" |
847bfd25 | 60 | echo " --datestamp string" |
8c55f227 | 61 | echo " --defconfig string" |
a7582815 | 62 | echo " --dryrun sched|script" |
c87b9c60 | 63 | echo " --duration minutes" |
315c540d | 64 | echo " --interactive" |
74878fb6 | 65 | echo " --kmake-arg kernel-make-arguments" |
315c540d | 66 | echo " --mac nn:nn:nn:nn:nn:nn" |
73931b5e | 67 | echo " --no-initrd" |
e9ce6400 | 68 | echo " --qemu-args qemu-system-..." |
4f8a0312 | 69 | echo " --qemu-cmd qemu-system-..." |
61010e74 PM |
70 | echo " --results absolute-pathname" |
71 | echo " --torture rcu" | |
c87b9c60 PM |
72 | exit 1 |
73 | } | |
74 | ||
c87b9c60 PM |
75 | while test $# -gt 0 |
76 | do | |
c87b9c60 | 77 | case "$1" in |
7dca9273 PM |
78 | --bootargs) |
79 | checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--' | |
98bc8cc8 | 80 | TORTURE_BOOTARGS="$2" |
7dca9273 PM |
81 | shift |
82 | ;; | |
f189cc8c PM |
83 | --bootimage) |
84 | checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--' | |
85 | TORTURE_BOOT_IMAGE="$2" | |
86 | shift | |
87 | ;; | |
11274813 | 88 | --buildonly) |
805ffee2 | 89 | TORTURE_BUILDONLY=1 |
11274813 | 90 | ;; |
c87b9c60 PM |
91 | --configs) |
92 | checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--' | |
93 | configs="$2" | |
94 | shift | |
95 | ;; | |
43e38ab3 PM |
96 | --cpus) |
97 | checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--' | |
98 | cpus=$2 | |
99 | shift | |
100 | ;; | |
847bfd25 PM |
101 | --datestamp) |
102 | checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--' | |
103 | ds=$2 | |
104 | shift | |
105 | ;; | |
8c55f227 PM |
106 | --defconfig) |
107 | checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--' | |
108 | TORTURE_DEFCONFIG=$2 | |
109 | shift | |
110 | ;; | |
a7582815 PM |
111 | --dryrun) |
112 | checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--' | |
113 | dryrun=$2 | |
114 | shift | |
115 | ;; | |
c87b9c60 | 116 | --duration) |
e9ce6400 | 117 | checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error' |
c87b9c60 PM |
118 | dur=$2 |
119 | shift | |
120 | ;; | |
315c540d | 121 | --interactive) |
a0edd47c | 122 | TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE |
315c540d | 123 | ;; |
74878fb6 PM |
124 | --kmake-arg) |
125 | checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$' | |
58d280bd | 126 | TORTURE_KMAKE_ARG="$2" |
74878fb6 PM |
127 | shift |
128 | ;; | |
315c540d PM |
129 | --mac) |
130 | checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error | |
58f724f7 | 131 | TORTURE_QEMU_MAC=$2 |
315c540d PM |
132 | shift |
133 | ;; | |
73931b5e | 134 | --no-initrd) |
2f66dbc1 | 135 | TORTURE_INITRD=""; export TORTURE_INITRD |
73931b5e | 136 | ;; |
e9ce6400 PM |
137 | --qemu-args) |
138 | checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error' | |
d1b1e517 | 139 | TORTURE_QEMU_ARG="$2" |
e9ce6400 PM |
140 | shift |
141 | ;; | |
4f8a0312 PM |
142 | --qemu-cmd) |
143 | checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--' | |
250da31e | 144 | TORTURE_QEMU_CMD="$2" |
4f8a0312 PM |
145 | shift |
146 | ;; | |
c87b9c60 | 147 | --results) |
e9ce6400 | 148 | checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error' |
c87b9c60 PM |
149 | resdir=$2 |
150 | shift | |
151 | ;; | |
61010e74 | 152 | --torture) |
9dfa5b35 | 153 | checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\)$' '^--' |
61010e74 PM |
154 | TORTURE_SUITE=$2 |
155 | shift | |
156 | ;; | |
c87b9c60 | 157 | *) |
2bcdf4e3 | 158 | echo Unknown argument $1 |
c87b9c60 PM |
159 | usage |
160 | ;; | |
161 | esac | |
162 | shift | |
163 | done | |
164 | ||
61010e74 | 165 | CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG |
4275be83 PM |
166 | |
167 | if test -z "$configs" | |
168 | then | |
edae018d | 169 | configs="`cat $CONFIGFRAG/CFLIST`" |
4275be83 | 170 | fi |
c87b9c60 PM |
171 | |
172 | if test -z "$resdir" | |
173 | then | |
174 | resdir=$KVM/res | |
daeda23d PM |
175 | fi |
176 | ||
78ad0693 | 177 | # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus. |
43e38ab3 | 178 | touch $T/cfgcpu |
c87b9c60 PM |
179 | for CF in $configs |
180 | do | |
edae018d | 181 | if test -f "$CONFIGFRAG/$CF" |
f43f8f73 | 182 | then |
edae018d PK |
183 | cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF` |
184 | cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF" "$cpu_count"` | |
ae867ff0 | 185 | echo $CF $cpu_count >> $T/cfgcpu |
43e38ab3 PM |
186 | else |
187 | echo "The --configs file $CF does not exist, terminating." | |
188 | exit 1 | |
f43f8f73 | 189 | fi |
c87b9c60 | 190 | done |
43e38ab3 PM |
191 | sort -k2nr $T/cfgcpu > $T/cfgcpu.sort |
192 | ||
78ad0693 | 193 | # Use a greedy bin-packing algorithm, sorting the list accordingly. |
53954671 PM |
194 | awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus ' |
195 | BEGIN { | |
196 | njobs = 0; | |
197 | } | |
198 | ||
199 | { | |
78ad0693 | 200 | # Read file of tests and corresponding required numbers of CPUs. |
53954671 PM |
201 | cf[njobs] = $1; |
202 | cpus[njobs] = $2; | |
203 | njobs++; | |
204 | } | |
205 | ||
206 | END { | |
207 | alldone = 0; | |
208 | batch = 0; | |
209 | nc = -1; | |
78ad0693 PM |
210 | |
211 | # Each pass through the following loop creates on test batch | |
212 | # that can be executed concurrently given ncpus. Note that a | |
213 | # given test that requires more than the available CPUs will run in | |
214 | # their own batch. Such tests just have to make do with what | |
215 | # is available. | |
53954671 PM |
216 | while (nc != ncpus) { |
217 | batch++; | |
218 | nc = ncpus; | |
78ad0693 PM |
219 | |
220 | # Each pass through the following loop considers one | |
221 | # test for inclusion in the current batch. | |
53954671 PM |
222 | for (i = 0; i < njobs; i++) { |
223 | if (done[i]) | |
78ad0693 | 224 | continue; # Already part of a batch. |
53954671 | 225 | if (nc >= cpus[i] || nc == ncpus) { |
78ad0693 PM |
226 | |
227 | # This test fits into the current batch. | |
53954671 PM |
228 | done[i] = batch; |
229 | nc -= cpus[i]; | |
230 | if (nc <= 0) | |
78ad0693 | 231 | break; # Too-big test in its own batch. |
53954671 PM |
232 | } |
233 | } | |
234 | } | |
78ad0693 PM |
235 | |
236 | # Dump out the tests in batch order. | |
53954671 PM |
237 | for (b = 1; b <= batch; b++) |
238 | for (i = 0; i < njobs; i++) | |
239 | if (done[i] == b) | |
240 | print cf[i], cpus[i]; | |
241 | }' | |
242 | ||
78ad0693 | 243 | # Generate a script to execute the tests in appropriate batches. |
61010e74 | 244 | cat << ___EOF___ > $T/script |
14d9d84c PM |
245 | CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG |
246 | KVM="$KVM"; export KVM | |
14d9d84c | 247 | PATH="$PATH"; export PATH |
f189cc8c | 248 | TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE |
14d9d84c | 249 | TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY |
8c55f227 | 250 | TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG |
14d9d84c PM |
251 | TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD |
252 | TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG | |
253 | TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD | |
254 | TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE | |
255 | TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC | |
256 | TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE | |
1f5d0920 PM |
257 | if ! test -e $resdir |
258 | then | |
259 | mkdir -p "$resdir" || : | |
260 | fi | |
261 | mkdir $resdir/$ds | |
262 | echo Results directory: $resdir/$ds | |
263 | echo $scriptname $args | |
264 | touch $resdir/$ds/log | |
265 | echo $scriptname $args >> $resdir/$ds/log | |
266 | echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE | |
267 | pwd > $resdir/$ds/testid.txt | |
268 | if test -d .git | |
269 | then | |
270 | git status >> $resdir/$ds/testid.txt | |
271 | git rev-parse HEAD >> $resdir/$ds/testid.txt | |
8be7f505 PM |
272 | if ! git diff HEAD > $T/git-diff 2>&1 |
273 | then | |
274 | cp $T/git-diff $resdir/$ds | |
275 | fi | |
1f5d0920 | 276 | fi |
61010e74 | 277 | ___EOF___ |
53954671 | 278 | awk < $T/cfgcpu.pack \ |
edae018d | 279 | -v CONFIGDIR="$CONFIGFRAG/" \ |
43e38ab3 PM |
280 | -v KVM="$KVM" \ |
281 | -v ncpus=$cpus \ | |
282 | -v rd=$resdir/$ds/ \ | |
283 | -v dur=$dur \ | |
06188731 PM |
284 | -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \ |
285 | -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \ | |
43e38ab3 PM |
286 | 'BEGIN { |
287 | i = 0; | |
288 | } | |
289 | ||
290 | { | |
291 | cf[i] = $1; | |
292 | cpus[i] = $2; | |
293 | i++; | |
294 | } | |
295 | ||
78ad0693 | 296 | # Dump out the scripting required to run one test batch. |
43e38ab3 PM |
297 | function dump(first, pastlast) |
298 | { | |
73fa867e PM |
299 | print "echo ----Start batch: `date`"; |
300 | print "echo ----Start batch: `date` >> " rd "/log"; | |
43e38ab3 PM |
301 | jn=1 |
302 | for (j = first; j < pastlast; j++) { | |
303 | builddir=KVM "/b" jn | |
0ae3f73a | 304 | cpusr[jn] = cpus[j]; |
43e38ab3 | 305 | if (cfrep[cf[j]] == "") { |
0ae3f73a | 306 | cfr[jn] = cf[j]; |
43e38ab3 PM |
307 | cfrep[cf[j]] = 1; |
308 | } else { | |
309 | cfrep[cf[j]]++; | |
0ae3f73a | 310 | cfr[jn] = cf[j] "." cfrep[cf[j]]; |
43e38ab3 | 311 | } |
df1cc81b | 312 | if (cpusr[jn] > ncpus && ncpus != 0) |
91afa21d | 313 | ovf = "-ovf"; |
df1cc81b PM |
314 | else |
315 | ovf = ""; | |
3c626237 | 316 | print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`"; |
73fa867e | 317 | print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log"; |
0ae3f73a PM |
318 | print "rm -f " builddir ".*"; |
319 | print "touch " builddir ".wait"; | |
320 | print "mkdir " builddir " > /dev/null 2>&1 || :"; | |
321 | print "mkdir " rd cfr[jn] " || :"; | |
d1b1e517 | 322 | print "kvm-test-1-run.sh " CONFIGDIR cf[j], builddir, rd cfr[jn], dur " \"" TORTURE_QEMU_ARG "\" \"" TORTURE_BOOTARGS "\" > " rd cfr[jn] "/kvm-test-1-run.sh.out 2>&1 &" |
73fa867e PM |
323 | print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`"; |
324 | print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log"; | |
43e38ab3 PM |
325 | print "while test -f " builddir ".wait" |
326 | print "do" | |
327 | print "\tsleep 1" | |
328 | print "done" | |
73fa867e PM |
329 | print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`"; |
330 | print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log"; | |
43e38ab3 PM |
331 | jn++; |
332 | } | |
43e38ab3 PM |
333 | for (j = 1; j < jn; j++) { |
334 | builddir=KVM "/b" j | |
335 | print "rm -f " builddir ".ready" | |
9bee2c6f PM |
336 | print "if test -z \"$TORTURE_BUILDONLY\"" |
337 | print "then" | |
338 | print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`"; | |
339 | print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log"; | |
340 | print "fi" | |
43e38ab3 PM |
341 | } |
342 | print "wait" | |
9bee2c6f PM |
343 | print "if test -z \"$TORTURE_BUILDONLY\"" |
344 | print "then" | |
345 | print "\techo ---- All kernel runs complete. `date`"; | |
346 | print "\techo ---- All kernel runs complete. `date` >> " rd "/log"; | |
347 | print "fi" | |
43e38ab3 PM |
348 | for (j = 1; j < jn; j++) { |
349 | builddir=KVM "/b" j | |
73fa867e PM |
350 | print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:"; |
351 | print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log"; | |
352 | print "cat " rd cfr[j] "/kvm-test-1-run.sh.out"; | |
353 | print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log"; | |
43e38ab3 PM |
354 | } |
355 | } | |
356 | ||
357 | END { | |
358 | njobs = i; | |
359 | nc = ncpus; | |
360 | first = 0; | |
78ad0693 PM |
361 | |
362 | # Each pass through the following loop considers one test. | |
43e38ab3 PM |
363 | for (i = 0; i < njobs; i++) { |
364 | if (ncpus == 0) { | |
78ad0693 | 365 | # Sequential test specified, each test its own batch. |
43e38ab3 PM |
366 | dump(i, i + 1); |
367 | first = i; | |
368 | } else if (nc < cpus[i] && i != 0) { | |
78ad0693 | 369 | # Out of CPUs, dump out a batch. |
43e38ab3 PM |
370 | dump(first, i); |
371 | first = i; | |
372 | nc = ncpus; | |
373 | } | |
78ad0693 | 374 | # Account for the CPUs needed by the current test. |
43e38ab3 PM |
375 | nc -= cpus[i]; |
376 | } | |
78ad0693 | 377 | # Dump the last batch. |
43e38ab3 PM |
378 | if (ncpus != 0) |
379 | dump(first, i); | |
61010e74 | 380 | }' >> $T/script |
43e38ab3 | 381 | |
1f5d0920 PM |
382 | cat << ___EOF___ >> $T/script |
383 | echo | |
384 | echo | |
385 | echo " --- `date` Test summary:" | |
386 | echo Results directory: $resdir/$ds | |
9bee2c6f | 387 | kvm-recheck.sh $resdir/$ds |
1f5d0920 PM |
388 | ___EOF___ |
389 | ||
a7582815 PM |
390 | if test "$dryrun" = script |
391 | then | |
a7582815 PM |
392 | cat $T/script |
393 | exit 0 | |
394 | elif test "$dryrun" = sched | |
395 | then | |
78ad0693 | 396 | # Extract the test run schedule from the script. |
9352ad13 PM |
397 | egrep 'Start batch|Starting build\.' $T/script | |
398 | grep -v ">>" | | |
a7582815 PM |
399 | sed -e 's/:.*$//' -e 's/^echo //' |
400 | exit 0 | |
401 | else | |
9bee2c6f | 402 | # Not a dryrun, so run the script. |
a7582815 PM |
403 | sh $T/script |
404 | fi | |
43e38ab3 | 405 | |
782ab4cd | 406 | # Tracing: trace_event=rcu:rcu_grace_period,rcu:rcu_future_grace_period,rcu:rcu_grace_period_init,rcu:rcu_nocb_wake,rcu:rcu_preempt_task,rcu:rcu_unlock_preempted_task,rcu:rcu_quiescent_state_report,rcu:rcu_fqs,rcu:rcu_callback,rcu:rcu_kfree_callback,rcu:rcu_batch_start,rcu:rcu_invoke_callback,rcu:rcu_invoke_kfree_callback,rcu:rcu_batch_end,rcu:rcu_torture_read,rcu:rcu_barrier |