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: 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
45 TORTURE_SHUTDOWN_GRACE=180
50 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 w/ repeat factor (3*TINY01)\""
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 " --mac nn:nn:nn:nn:nn:nn"
69 echo " --qemu-args qemu-system-..."
70 echo " --qemu-cmd qemu-system-..."
71 echo " --results absolute-pathname"
80 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
85 checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
86 TORTURE_BOOT_IMAGE="$2"
93 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
98 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
103 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
108 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
113 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
118 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
123 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
126 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
127 TORTURE_KMAKE_ARG="$2"
131 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
136 TORTURE_INITRD=""; export TORTURE_INITRD
138 --qemu-args|--qemu-arg)
139 checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
140 TORTURE_QEMU_ARG="$2"
144 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
145 TORTURE_QEMU_CMD="$2"
149 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
154 checkarg --shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
155 TORTURE_SHUTDOWN_GRACE=$2
159 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuperf\)$' '^--'
164 echo Unknown argument $1
171 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
173 if test -z "$configs"
175 configs="`cat $CONFIGFRAG/CFLIST`"
183 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
188 [0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**)
189 config_reps=`echo $CF | sed -e 's/\*.*$//'`
190 CF1=`echo $CF | sed -e 's/^[^*]*\*//'`
197 if test -f "$CONFIGFRAG/$CF1"
199 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
200 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
201 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
203 echo $CF1 $cpu_count >> $T/cfgcpu
206 echo "The --configs file $CF1 does not exist, terminating."
210 sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
212 # Use a greedy bin-packing algorithm, sorting the list accordingly.
213 awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
219 # Read file of tests and corresponding required numbers of CPUs.
230 # Each pass through the following loop creates on test batch
231 # that can be executed concurrently given ncpus. Note that a
232 # given test that requires more than the available CPUs will run in
233 # their own batch. Such tests just have to make do with what
235 while (nc != ncpus) {
239 # Each pass through the following loop considers one
240 # test for inclusion in the current batch.
241 for (i = 0; i < njobs; i++) {
243 continue; # Already part of a batch.
244 if (nc >= cpus[i] || nc == ncpus) {
246 # This test fits into the current batch.
250 break; # Too-big test in its own batch.
255 # Dump out the tests in batch order.
256 for (b = 1; b <= batch; b++)
257 for (i = 0; i < njobs; i++)
259 print cf[i], cpus[i];
262 # Generate a script to execute the tests in appropriate batches.
263 cat << ___EOF___ > $T/script
264 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
265 KVM="$KVM"; export KVM
266 PATH="$PATH"; export PATH
267 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
268 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
269 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
270 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
271 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
272 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
273 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
274 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
275 TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
276 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
279 mkdir -p "$resdir" || :
282 echo Results directory: $resdir/$ds
283 echo $scriptname $args
284 touch $resdir/$ds/log
285 echo $scriptname $args >> $resdir/$ds/log
286 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
287 pwd > $resdir/$ds/testid.txt
290 git status >> $resdir/$ds/testid.txt
291 git rev-parse HEAD >> $resdir/$ds/testid.txt
292 if ! git diff HEAD > $T/git-diff 2>&1
294 cp $T/git-diff $resdir/$ds
298 awk < $T/cfgcpu.pack \
299 -v CONFIGDIR="$CONFIGFRAG/" \
304 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
305 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
316 # Dump out the scripting required to run one test batch.
317 function dump(first, pastlast, batchnum)
319 print "echo ----Start batch " batchnum ": `date`";
320 print "echo ----Start batch " batchnum ": `date` >> " rd "/log";
322 for (j = first; j < pastlast; j++) {
325 if (cfrep[cf[j]] == "") {
330 cfr[jn] = cf[j] "." cfrep[cf[j]];
332 if (cpusr[jn] > ncpus && ncpus != 0)
336 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
337 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
338 print "rm -f " builddir ".*";
339 print "touch " builddir ".wait";
340 print "mkdir " builddir " > /dev/null 2>&1 || :";
341 print "mkdir " rd cfr[jn] " || :";
342 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 &"
343 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
344 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
345 print "while test -f " builddir ".wait"
349 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
350 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
353 for (j = 1; j < jn; j++) {
355 print "rm -f " builddir ".ready"
356 print "if test -z \"$TORTURE_BUILDONLY\""
358 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`";
359 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log";
363 print "if test -z \"$TORTURE_BUILDONLY\""
365 print "\techo ---- All kernel runs complete. `date`";
366 print "\techo ---- All kernel runs complete. `date` >> " rd "/log";
368 for (j = 1; j < jn; j++) {
370 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
371 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
372 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
373 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
383 # Each pass through the following loop considers one test.
384 for (i = 0; i < njobs; i++) {
386 # Sequential test specified, each test its own batch.
387 dump(i, i + 1, batchnum);
390 } else if (nc < cpus[i] && i != 0) {
391 # Out of CPUs, dump out a batch.
392 dump(first, i, batchnum);
397 # Account for the CPUs needed by the current test.
400 # Dump the last batch.
402 dump(first, i, batchnum);
405 cat << ___EOF___ >> $T/script
408 echo " --- `date` Test summary:"
409 echo Results directory: $resdir/$ds
410 kvm-recheck.sh $resdir/$ds
413 if test "$dryrun" = script
417 elif test "$dryrun" = sched
419 # Extract the test run schedule from the script.
420 egrep 'Start batch|Starting build\.' $T/script |
422 sed -e 's/:.*$//' -e 's/^echo //'
425 # Not a dryrun, so run the script.
429 # 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