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
49 ds=`date +%Y.%m.%d-%H:%M:%S`
54 echo "Usage: $scriptname optional arguments:"
55 echo " --bootargs kernel-boot-arguments"
56 echo " --bootimage relative-path-to-kernel-boot-image"
58 echo " --configs \"config-file list\""
60 echo " --datestamp string"
61 echo " --defconfig string"
62 echo " --dryrun sched|script"
63 echo " --duration minutes"
65 echo " --kmake-arg kernel-make-arguments"
66 echo " --mac nn:nn:nn:nn:nn:nn"
68 echo " --qemu-args qemu-system-..."
69 echo " --qemu-cmd qemu-system-..."
70 echo " --results absolute-pathname"
79 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
84 checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
85 TORTURE_BOOT_IMAGE="$2"
92 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
97 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
102 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
107 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
112 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
117 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
122 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
125 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
126 TORTURE_KMAKE_ARG="$2"
130 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
135 TORTURE_INITRD=""; export TORTURE_INITRD
138 checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
139 TORTURE_QEMU_ARG="$2"
143 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
144 TORTURE_QEMU_CMD="$2"
148 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
153 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\)$' '^--'
158 echo Unknown argument $1
165 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
167 if test -z "$configs"
169 configs="`cat $CONFIGFRAG/CFLIST`"
177 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
181 if test -f "$CONFIGFRAG/$CF"
183 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF`
184 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF" "$cpu_count"`
185 echo $CF $cpu_count >> $T/cfgcpu
187 echo "The --configs file $CF does not exist, terminating."
191 sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
193 # Use a greedy bin-packing algorithm, sorting the list accordingly.
194 awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
200 # Read file of tests and corresponding required numbers of CPUs.
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
216 while (nc != ncpus) {
220 # Each pass through the following loop considers one
221 # test for inclusion in the current batch.
222 for (i = 0; i < njobs; i++) {
224 continue; # Already part of a batch.
225 if (nc >= cpus[i] || nc == ncpus) {
227 # This test fits into the current batch.
231 break; # Too-big test in its own batch.
236 # Dump out the tests in batch order.
237 for (b = 1; b <= batch; b++)
238 for (i = 0; i < njobs; i++)
240 print cf[i], cpus[i];
243 # Generate a script to execute the tests in appropriate batches.
244 cat << ___EOF___ > $T/script
245 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
246 KVM="$KVM"; export KVM
247 PATH="$PATH"; export PATH
248 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
249 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
250 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
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
259 mkdir -p "$resdir" || :
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
270 git status >> $resdir/$ds/testid.txt
271 git rev-parse HEAD >> $resdir/$ds/testid.txt
272 if ! git diff HEAD > $T/git-diff 2>&1
274 cp $T/git-diff $resdir/$ds
278 awk < $T/cfgcpu.pack \
279 -v CONFIGDIR="$CONFIGFRAG/" \
284 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
285 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
296 # Dump out the scripting required to run one test batch.
297 function dump(first, pastlast)
299 print "echo ----Start batch: `date`";
300 print "echo ----Start batch: `date` >> " rd "/log";
302 for (j = first; j < pastlast; j++) {
305 if (cfrep[cf[j]] == "") {
310 cfr[jn] = cf[j] "." cfrep[cf[j]];
312 if (cpusr[jn] > ncpus && ncpus != 0)
316 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
317 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
318 print "rm -f " builddir ".*";
319 print "touch " builddir ".wait";
320 print "mkdir " builddir " > /dev/null 2>&1 || :";
321 print "mkdir " rd cfr[jn] " || :";
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 &"
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";
325 print "while test -f " builddir ".wait"
329 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
330 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
333 for (j = 1; j < jn; j++) {
335 print "rm -f " builddir ".ready"
336 print "if test -z \"$TORTURE_BUILDONLY\""
338 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`";
339 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log";
343 print "if test -z \"$TORTURE_BUILDONLY\""
345 print "\techo ---- All kernel runs complete. `date`";
346 print "\techo ---- All kernel runs complete. `date` >> " rd "/log";
348 for (j = 1; j < jn; j++) {
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";
362 # Each pass through the following loop considers one test.
363 for (i = 0; i < njobs; i++) {
365 # Sequential test specified, each test its own batch.
368 } else if (nc < cpus[i] && i != 0) {
369 # Out of CPUs, dump out a batch.
374 # Account for the CPUs needed by the current test.
377 # Dump the last batch.
382 cat << ___EOF___ >> $T/script
385 echo " --- `date` Test summary:"
386 echo Results directory: $resdir/$ds
387 kvm-recheck.sh $resdir/$ds
390 if test "$dryrun" = script
394 elif test "$dryrun" = sched
396 # Extract the test run schedule from the script.
397 egrep 'Start batch|Starting build\.' $T/script |
399 sed -e 's/:.*$//' -e 's/^echo //'
402 # Not a dryrun, so run the script.
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