2 # SPDX-License-Identifier: GPL-2.0+
4 # Run a series of tests under KVM. By default, this series is specified
5 # by the relevant CFLIST file, but can be overridden by the --configs
6 # command-line argument.
8 # Usage: kvm.sh [ options ]
10 # Copyright (C) IBM Corporation, 2011
12 # Authors: Paul E. McKenney <paulmck@linux.ibm.com>
17 T
=${TMPDIR-/tmp}/kvm.sh.$$
21 cd `dirname $scriptname`/..
/..
/..
/..
/..
/
25 KVM
="`pwd`/tools/testing/selftests/rcutorture"; export KVM
26 PATH
=${KVM}/bin
:$PATH; export PATH
27 TORTURE_ALLOTED_CPUS
=""
28 TORTURE_DEFCONFIG
=defconfig
30 TORTURE_INITRD
="$KVM/initrd"; export TORTURE_INITRD
31 TORTURE_KCONFIG_ARG
=""
34 TORTURE_SHUTDOWN_GRACE
=180
40 ds
=`date +%Y.%m.%d-%H:%M:%S`
46 echo "Usage: $scriptname optional arguments:"
47 echo " --bootargs kernel-boot-arguments"
48 echo " --bootimage relative-path-to-kernel-boot-image"
50 echo " --configs \"config-file list w/ repeat factor (3*TINY01)\""
52 echo " --datestamp string"
53 echo " --defconfig string"
54 echo " --dryrun sched|script"
55 echo " --duration minutes"
57 echo " --jitter N [ maxsleep (us) [ maxspin (us) ] ]"
58 echo " --kconfig Kconfig-options"
59 echo " --kmake-arg kernel-make-arguments"
60 echo " --mac nn:nn:nn:nn:nn:nn"
61 echo " --memory megabytes | nnnG"
63 echo " --qemu-args qemu-arguments"
64 echo " --qemu-cmd qemu-system-..."
65 echo " --results absolute-pathname"
75 checkarg
--bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
80 checkarg
--bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
81 TORTURE_BOOT_IMAGE
="$2"
88 checkarg
--configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
93 checkarg
--cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
95 TORTURE_ALLOTED_CPUS
="$2"
99 checkarg
--datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
104 checkarg
--defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
109 checkarg
--dryrun "sched|script" $# "$2" 'sched\|script' '^--'
114 checkarg
--duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
119 TORTURE_QEMU_INTERACTIVE
=1; export TORTURE_QEMU_INTERACTIVE
122 checkarg
--jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$'
127 checkarg
--kconfig "(Kconfig options)" $# "$2" '^CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\( CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\)*$' '^error$'
128 TORTURE_KCONFIG_ARG
="$2"
132 checkarg
--kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
133 TORTURE_KMAKE_ARG
="$2"
137 checkarg
--mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
142 checkarg
--memory "(memory size)" $# "$2" '^[0-9]\+[MG]\?$' error
147 TORTURE_INITRD
=""; export TORTURE_INITRD
149 --qemu-args|
--qemu-arg)
150 checkarg
--qemu-args "(qemu arguments)" $# "$2" '^-' '^error'
151 TORTURE_QEMU_ARG
="$2"
155 checkarg
--qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
156 TORTURE_QEMU_CMD
="$2"
160 checkarg
--results "(absolute pathname)" "$#" "$2" '^/' '^error'
165 checkarg
--shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
166 TORTURE_SHUTDOWN_GRACE
=$2
170 checkarg
--torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuperf\)$' '^--'
173 if test "$TORTURE_SUITE" = rcuperf
175 # If you really want jitter for rcuperf, specify
176 # it after specifying rcuperf. (But why?)
181 TORTURE_TRUST_MAKE
="y"
184 echo Unknown argument
$1
191 if test -z "$TORTURE_INITRD" || tools
/testing
/selftests
/rcutorture
/bin
/mkinitrd.sh
195 echo No initrd and unable to create one
, aborting
test >&2
199 CONFIGFRAG
=${KVM}/configs
/${TORTURE_SUITE}; export CONFIGFRAG
201 if test -z "$configs"
203 configs
="`cat $CONFIGFRAG/CFLIST`"
211 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
216 [0-9]\
**|
[0-9][0-9]\
**|
[0-9][0-9][0-9]\
**)
217 config_reps
=`echo $CF | sed -e 's/\*.*$//'`
218 CF1
=`echo $CF | sed -e 's/^[^*]*\*//'`
225 if test -f "$CONFIGFRAG/$CF1"
227 cpu_count
=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
228 cpu_count
=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
229 cpu_count
=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
230 for ((cur_rep
=0;cur_rep
<$config_reps;cur_rep
++))
232 echo $CF1 $cpu_count >> $T/cfgcpu
235 echo "The --configs file $CF1 does not exist, terminating."
239 sort -k2nr $T/cfgcpu
-T="$T" > $T/cfgcpu.
sort
241 # Use a greedy bin-packing algorithm, sorting the list accordingly.
242 awk < $T/cfgcpu.
sort > $T/cfgcpu.pack
-v ncpus
=$cpus '
248 # Read file of tests and corresponding required numbers of CPUs.
258 # Each pass through the following loop creates on test batch
259 # that can be executed concurrently given ncpus. Note that a
260 # given test that requires more than the available CPUs will run in
261 # their own batch. Such tests just have to make do with what
263 while (nc != ncpus) {
267 # Each pass through the following loop considers one
268 # test for inclusion in the current batch.
269 for (i = 0; i < njobs; i++) {
271 continue; # Already part of a batch.
272 if (nc >= cpus[i] || nc == ncpus) {
274 # This test fits into the current batch.
278 break; # Too-big test in its own batch.
283 # Dump out the tests in batch order.
284 for (b = 1; b <= batch; b++)
285 for (i = 0; i < njobs; i++)
287 print cf[i], cpus[i];
290 # Generate a script to execute the tests in appropriate batches.
291 cat << ___EOF___ > $T/script
292 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
293 KVM="$KVM"; export KVM
294 PATH="$PATH"; export PATH
295 TORTURE_ALLOTED_CPUS="$TORTURE_ALLOTED_CPUS"; export TORTURE_ALLOTED_CPUS
296 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
297 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
298 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
299 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
300 TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG
301 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
302 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
303 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
304 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
305 TORTURE_QEMU_MEM="$TORTURE_QEMU_MEM"; export TORTURE_QEMU_MEM
306 TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
307 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
308 TORTURE_TRUST_MAKE="$TORTURE_TRUST_MAKE"; export TORTURE_TRUST_MAKE
311 mkdir -p "$resdir" || :
314 echo Results directory: $resdir/$ds
315 echo $scriptname $args
316 touch $resdir/$ds/log
317 echo $scriptname $args >> $resdir/$ds/log
318 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
319 pwd > $resdir/$ds/testid.txt
322 git status >> $resdir/$ds/testid.txt
323 git rev-parse HEAD >> $resdir/$ds/testid.txt
324 git diff HEAD >> $resdir/$ds/testid.txt
327 awk < $T/cfgcpu.pack \
328 -v TORTURE_BUILDONLY
="$TORTURE_BUILDONLY" \
329 -v CONFIGDIR
="$CONFIGFRAG/" \
332 -v jitter
="$jitter" \
335 -v TORTURE_QEMU_ARG
="$TORTURE_QEMU_ARG" \
336 -v TORTURE_BOOTARGS
="$TORTURE_BOOTARGS" \
347 # Dump out the scripting required to run one test batch.
348 function dump(first, pastlast, batchnum)
350 print "echo ----Start batch " batchnum ": `date` | tee -a " rd "log";
353 for (j = first; j < pastlast; j++) {
354 builddir=KVM "/b" j - first + 1
356 if (cfrep[cf[j]] == "") {
361 cfr[jn] = cf[j] "." cfrep[cf[j]];
363 if (cpusr[jn] > ncpus && ncpus != 0)
367 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` | tee -a " rd "log";
368 print "rm -f " builddir ".*";
369 print "touch " builddir ".wait";
370 print "mkdir " rd cfr[jn] " || :";
371 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 &"
372 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` | tee -a " rd "log";
373 print "while test -f " builddir ".wait"
377 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` | tee -a " rd "log";
380 for (j = 1; j < jn; j++) {
382 print "rm -f " builddir ".ready"
383 print "if test -f \"" rd cfr[j] "/builtkernel\""
385 print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date` | tee -a " rd "log";
386 print "\tneedqemurun=1"
391 if (ja[1] == -1 && ncpus == 0)
393 else if (ja[1] == -1)
397 if (TORTURE_BUILDONLY && njitter != 0) {
399 print "echo Build-only run, so suppressing jitter | tee -a " rd "log"
401 if (TORTURE_BUILDONLY) {
404 print "if test -n \"$needqemurun\""
406 print "\techo ---- Starting kernels. `date` | tee -a " rd "log";
407 for (j = 0; j < njitter; j++)
408 print "\tjitter.sh " j " " dur " " ja[2] " " ja[3] "&"
410 print "\techo ---- All kernel runs complete. `date` | tee -a " rd "log";
413 print "\techo ---- No kernel runs. `date` | tee -a " rd "log";
415 for (j = 1; j < jn; j++) {
417 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: | tee -a " rd "log";
418 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out | tee -a " rd "log";
428 # Each pass through the following loop considers one test.
429 for (i = 0; i < njobs; i++) {
431 # Sequential test specified, each test its own batch.
432 dump(i, i + 1, batchnum);
435 } else if (nc < cpus[i] && i != 0) {
436 # Out of CPUs, dump out a batch.
437 dump(first, i, batchnum);
442 # Account for the CPUs needed by the current test.
445 # Dump the last batch.
447 dump(first, i, batchnum);
450 cat << ___EOF___ >> $T/script
453 echo " --- `date` Test summary:"
454 echo Results directory: $resdir/$ds
455 kvm-recheck.sh $resdir/$ds
458 if test "$dryrun" = script
462 elif test "$dryrun" = sched
464 # Extract the test run schedule from the script.
465 egrep 'Start batch|Starting build\.' $T/script |
467 sed -e 's/:.*$//' -e 's/^echo //'
470 # Not a dryrun, so run the script.
474 # 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
475 # Function-graph tracing: ftrace=function_graph ftrace_graph_filter=sched_setaffinity,migration_cpu_stop
476 # Also --kconfig "CONFIG_FUNCTION_TRACER=y CONFIG_FUNCTION_GRAPH_TRACER=y"