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.
7 # Edit the definitions below to set the locations of the various directories,
8 # as well as the test duration.
10 # Usage: sh kvm.sh [ options ]
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.
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.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, you can access it online at
24 # http://www.gnu.org/licenses/gpl-2.0.html.
26 # Copyright (C) IBM Corporation, 2011
28 # Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
39 KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
40 PATH=${KVM}/bin:$PATH; export PATH
41 TORTURE_DEFCONFIG=defconfig
43 TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD
49 ds=`date +%Y.%m.%d-%H:%M:%S`
55 echo "Usage: $scriptname optional arguments:"
56 echo " --bootargs kernel-boot-arguments"
57 echo " --bootimage relative-path-to-kernel-boot-image"
59 echo " --configs \"config-file list\""
61 echo " --datestamp string"
62 echo " --defconfig string"
63 echo " --dryrun sched|script"
64 echo " --duration minutes"
66 echo " --kmake-arg kernel-make-arguments"
67 echo " --kversion vN.NN"
68 echo " --mac nn:nn:nn:nn:nn:nn"
70 echo " --qemu-args qemu-system-..."
71 echo " --qemu-cmd qemu-system-..."
72 echo " --results absolute-pathname"
81 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
86 checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
87 TORTURE_BOOT_IMAGE="$2"
94 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
99 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
104 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
109 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
114 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
119 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
124 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
127 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
128 TORTURE_KMAKE_ARG="$2"
132 checkarg --kversion "(kernel version)" $# "$2" '^v[0-9.]*$' '^error'
137 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
142 TORTURE_INITRD=""; export TORTURE_INITRD
145 checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
146 TORTURE_QEMU_ARG="$2"
150 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
151 TORTURE_QEMU_CMD="$2"
155 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
160 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\)$' '^--'
165 echo Unknown argument $1
172 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
173 KVPATH=${CONFIGFRAG}/$kversion; export KVPATH
175 if test -z "$configs"
177 configs="`cat $CONFIGFRAG/$kversion/CFLIST`"
185 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
189 if test -f "$CONFIGFRAG/$kversion/$CF"
191 echo $CF `configNR_CPUS.sh $CONFIGFRAG/$kversion/$CF` >> $T/cfgcpu
193 echo "The --configs file $CF does not exist, terminating."
197 sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
199 # Use a greedy bin-packing algorithm, sorting the list accordingly.
200 awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
206 # Read file of tests and corresponding required numbers of CPUs.
217 # Each pass through the following loop creates on test batch
218 # that can be executed concurrently given ncpus. Note that a
219 # given test that requires more than the available CPUs will run in
220 # their own batch. Such tests just have to make do with what
222 while (nc != ncpus) {
226 # Each pass through the following loop considers one
227 # test for inclusion in the current batch.
228 for (i = 0; i < njobs; i++) {
230 continue; # Already part of a batch.
231 if (nc >= cpus[i] || nc == ncpus) {
233 # This test fits into the current batch.
237 break; # Too-big test in its own batch.
242 # Dump out the tests in batch order.
243 for (b = 1; b <= batch; b++)
244 for (i = 0; i < njobs; i++)
246 print cf[i], cpus[i];
249 # Generate a script to execute the tests in appropriate batches.
250 cat << ___EOF___ > $T/script
251 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
252 KVM="$KVM"; export KVM
253 KVPATH="$KVPATH"; export KVPATH
254 PATH="$PATH"; export PATH
255 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
256 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
257 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
258 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
259 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
260 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
261 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
262 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
263 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
266 mkdir -p "$resdir" || :
269 echo Results directory: $resdir/$ds
270 echo $scriptname $args
271 touch $resdir/$ds/log
272 echo $scriptname $args >> $resdir/$ds/log
273 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
274 pwd > $resdir/$ds/testid.txt
277 git status >> $resdir/$ds/testid.txt
278 git rev-parse HEAD >> $resdir/$ds/testid.txt
279 if ! git diff HEAD > $T/git-diff 2>&1
281 cp $T/git-diff $resdir/$ds
285 awk < $T/cfgcpu.pack \
286 -v CONFIGDIR="$CONFIGFRAG/$kversion/" \
291 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
292 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
303 # Dump out the scripting required to run one test batch.
304 function dump(first, pastlast)
306 print "echo ----Start batch: `date`";
307 print "echo ----Start batch: `date` >> " rd "/log";
309 for (j = first; j < pastlast; j++) {
312 if (cfrep[cf[j]] == "") {
317 cfr[jn] = cf[j] "." cfrep[cf[j]];
319 if (cpusr[jn] > ncpus && ncpus != 0)
323 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
324 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
325 print "rm -f " builddir ".*";
326 print "touch " builddir ".wait";
327 print "mkdir " builddir " > /dev/null 2>&1 || :";
328 print "mkdir " rd cfr[jn] " || :";
329 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 &"
330 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
331 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
332 print "while test -f " builddir ".wait"
336 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
337 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
340 for (j = 1; j < jn; j++) {
342 print "rm -f " builddir ".ready"
343 print "if test -z \"$TORTURE_BUILDONLY\""
345 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`";
346 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log";
350 print "if test -z \"$TORTURE_BUILDONLY\""
352 print "\techo ---- All kernel runs complete. `date`";
353 print "\techo ---- All kernel runs complete. `date` >> " rd "/log";
355 for (j = 1; j < jn; j++) {
357 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
358 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
359 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
360 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
369 # Each pass through the following loop considers one test.
370 for (i = 0; i < njobs; i++) {
372 # Sequential test specified, each test its own batch.
375 } else if (nc < cpus[i] && i != 0) {
376 # Out of CPUs, dump out a batch.
381 # Account for the CPUs needed by the current test.
384 # Dump the last batch.
389 cat << ___EOF___ >> $T/script
392 echo " --- `date` Test summary:"
393 echo Results directory: $resdir/$ds
394 kvm-recheck.sh $resdir/$ds
397 if test "$dryrun" = script
401 elif test "$dryrun" = sched
403 # Extract the test run schedule from the script.
404 egrep 'Start batch|Starting build\.' $T/script |
406 sed -e 's/:.*$//' -e 's/^echo //'
409 # Not a dryrun, so run the script.
413 # 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