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
29 TORTURE_ALLOTED_CPUS
="`identify_qemu_vcpus`"
30 TORTURE_DEFCONFIG
=defconfig
32 TORTURE_INITRD
="$KVM/initrd"; export TORTURE_INITRD
33 TORTURE_KCONFIG_ARG
=""
34 TORTURE_KCONFIG_GDB_ARG
=""
35 TORTURE_BOOT_GDB_ARG
=""
36 TORTURE_QEMU_GDB_ARG
=""
37 TORTURE_KCONFIG_KASAN_ARG
=""
38 TORTURE_KCONFIG_KCSAN_ARG
=""
41 TORTURE_SHUTDOWN_GRACE
=180
47 ds
=`date +%Y.%m.%d-%H.%M.%S`
51 echo "Usage: $scriptname optional arguments:"
53 echo " --bootargs kernel-boot-arguments"
54 echo " --bootimage relative-path-to-kernel-boot-image"
56 echo " --configs \"config-file list w/ repeat factor (3*TINY01)\""
58 echo " --datestamp string"
59 echo " --defconfig string"
60 echo " --dryrun sched|script"
61 echo " --duration minutes | <seconds>s | <hours>h | <days>d"
65 echo " --jitter N [ maxsleep (us) [ maxspin (us) ] ]"
66 echo " --kconfig Kconfig-options"
67 echo " --kmake-arg kernel-make-arguments"
68 echo " --mac nn:nn:nn:nn:nn:nn"
69 echo " --memory megabytes|nnnG"
71 echo " --qemu-args qemu-arguments"
72 echo " --qemu-cmd qemu-system-..."
73 echo " --results absolute-pathname"
74 echo " --torture lock|rcu|rcuscale|refscale|scf"
83 cpus
=$TORTURE_ALLOTED_CPUS
84 max_cpus
=$TORTURE_ALLOTED_CPUS
87 checkarg
--bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
92 checkarg
--bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
93 TORTURE_BOOT_IMAGE
="$2"
96 --buildonly|
--build-only)
100 checkarg
--configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
105 checkarg
--cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
107 TORTURE_ALLOTED_CPUS
="$2"
108 max_cpus
="`identify_qemu_vcpus`"
109 if test "$TORTURE_ALLOTED_CPUS" -gt "$max_cpus"
111 TORTURE_ALLOTED_CPUS
=$max_cpus
116 checkarg
--datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
121 checkarg
--defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
126 checkarg
--dryrun "sched|script" $# "$2" 'sched\|script' '^--'
131 checkarg
--duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'
133 if echo "$2" |
grep -q 's$'
136 elif echo "$2" |
grep -q 'h$'
139 elif echo "$2" |
grep -q 'd$'
143 ts
=`echo $2 | sed -e 's/[smhd]$//'`
148 TORTURE_KCONFIG_GDB_ARG
="CONFIG_DEBUG_INFO=y"; export TORTURE_KCONFIG_GDB_ARG
149 TORTURE_BOOT_GDB_ARG
="nokaslr"; export TORTURE_BOOT_GDB_ARG
150 TORTURE_QEMU_GDB_ARG
="-s -S"; export TORTURE_QEMU_GDB_ARG
156 TORTURE_QEMU_INTERACTIVE
=1; export TORTURE_QEMU_INTERACTIVE
159 checkarg
--jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$'
163 --kconfig|
--kconfigs)
164 checkarg
--kconfig "(Kconfig options)" $# "$2" '^CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\( CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\)*$' '^error$'
165 TORTURE_KCONFIG_ARG
="$2"
169 TORTURE_KCONFIG_KASAN_ARG
="CONFIG_DEBUG_INFO=y CONFIG_KASAN=y"; export TORTURE_KCONFIG_KASAN_ARG
172 TORTURE_KCONFIG_KCSAN_ARG
="CONFIG_DEBUG_INFO=y CONFIG_KCSAN=y CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=n CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY=n CONFIG_KCSAN_REPORT_ONCE_IN_MS=100000 CONFIG_KCSAN_VERBOSE=y CONFIG_KCSAN_INTERRUPT_WATCHER=y"; export TORTURE_KCONFIG_KCSAN_ARG
174 --kmake-arg|
--kmake-args)
175 checkarg
--kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
176 TORTURE_KMAKE_ARG
="$2"
180 checkarg
--mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
185 checkarg
--memory "(memory size)" $# "$2" '^[0-9]\+[MG]\?$' error
190 TORTURE_INITRD
=""; export TORTURE_INITRD
192 --qemu-args|
--qemu-arg)
193 checkarg
--qemu-args "(qemu arguments)" $# "$2" '^-' '^error'
194 TORTURE_QEMU_ARG
="$2"
198 checkarg
--qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
199 TORTURE_QEMU_CMD
="$2"
203 checkarg
--results "(absolute pathname)" "$#" "$2" '^/' '^error'
208 checkarg
--shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
209 TORTURE_SHUTDOWN_GRACE
=$2
213 checkarg
--torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuscale\|refscale\|scf\)$' '^--'
216 if test "$TORTURE_SUITE" = rcuscale ||
test "$TORTURE_SUITE" = refscale
218 # If you really want jitter for refscale or
219 # rcuscale, specify it after specifying the rcuscale
220 # or the refscale. (But why jitter in these cases?)
225 TORTURE_TRUST_MAKE
="y"
228 echo Unknown argument
$1
235 if test -z "$TORTURE_INITRD" || tools
/testing
/selftests
/rcutorture
/bin
/mkinitrd.sh
239 echo No initrd and unable to create one
, aborting
test >&2
243 CONFIGFRAG
=${KVM}/configs
/${TORTURE_SUITE}; export CONFIGFRAG
245 defaultconfigs
="`tr '\012' ' ' < $CONFIGFRAG/CFLIST`"
246 if test -z "$configs"
248 configs
=$defaultconfigs
256 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
261 [0-9]\
**|
[0-9][0-9]\
**|
[0-9][0-9][0-9]\
**)
262 config_reps
=`echo $CF | sed -e 's/\*.*$//'`
263 CF1
=`echo $CF | sed -e 's/^[^*]*\*//'`
270 for ((cur_rep
=0;cur_rep
<$config_reps;cur_rep
++))
272 configs_derep
="$configs_derep $CF1"
276 configs_derep
="`echo $configs_derep | sed -e "s
/\
<CFLIST\
>/$defaultconfigs/g
"`"
277 if test -n "$TORTURE_KCONFIG_GDB_ARG"
279 if test "`echo $configs_derep | wc -w`" -gt 1
281 echo "The --config list is: $configs_derep."
282 echo "Only one --config permitted with --gdb, terminating."
286 for CF1
in $configs_derep
288 if test -f "$CONFIGFRAG/$CF1"
290 cpu_count
=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
291 cpu_count
=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
292 cpu_count
=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
293 echo $CF1 $cpu_count >> $T/cfgcpu
295 echo "The --configs file $CF1 does not exist, terminating."
299 sort -k2nr $T/cfgcpu
-T="$T" > $T/cfgcpu.
sort
301 # Use a greedy bin-packing algorithm, sorting the list accordingly.
302 awk < $T/cfgcpu.
sort > $T/cfgcpu.pack
-v ncpus
=$cpus '
308 # Read file of tests and corresponding required numbers of CPUs.
318 # Each pass through the following loop creates on test batch
319 # that can be executed concurrently given ncpus. Note that a
320 # given test that requires more than the available CPUs will run in
321 # their own batch. Such tests just have to make do with what
323 while (nc != ncpus) {
327 # Each pass through the following loop considers one
328 # test for inclusion in the current batch.
329 for (i = 0; i < njobs; i++) {
331 continue; # Already part of a batch.
332 if (nc >= cpus[i] || nc == ncpus) {
334 # This test fits into the current batch.
338 break; # Too-big test in its own batch.
343 # Dump out the tests in batch order.
344 for (b = 1; b <= batch; b++)
345 for (i = 0; i < njobs; i++)
347 print cf[i], cpus[i];
350 # Generate a script to execute the tests in appropriate batches.
351 cat << ___EOF___ > $T/script
352 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
353 KVM="$KVM"; export KVM
354 PATH="$PATH"; export PATH
355 TORTURE_ALLOTED_CPUS="$TORTURE_ALLOTED_CPUS"; export TORTURE_ALLOTED_CPUS
356 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
357 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
358 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
359 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
360 TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG
361 TORTURE_KCONFIG_GDB_ARG="$TORTURE_KCONFIG_GDB_ARG"; export TORTURE_KCONFIG_GDB_ARG
362 TORTURE_BOOT_GDB_ARG="$TORTURE_BOOT_GDB_ARG"; export TORTURE_BOOT_GDB_ARG
363 TORTURE_QEMU_GDB_ARG="$TORTURE_QEMU_GDB_ARG"; export TORTURE_QEMU_GDB_ARG
364 TORTURE_KCONFIG_KASAN_ARG="$TORTURE_KCONFIG_KASAN_ARG"; export TORTURE_KCONFIG_KASAN_ARG
365 TORTURE_KCONFIG_KCSAN_ARG="$TORTURE_KCONFIG_KCSAN_ARG"; export TORTURE_KCONFIG_KCSAN_ARG
366 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
367 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
368 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
369 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
370 TORTURE_QEMU_MEM="$TORTURE_QEMU_MEM"; export TORTURE_QEMU_MEM
371 TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
372 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
373 TORTURE_TRUST_MAKE="$TORTURE_TRUST_MAKE"; export TORTURE_TRUST_MAKE
376 mkdir -p "$resdir" || :
379 TORTURE_RESDIR="$resdir/$ds"; export TORTURE_RESDIR
380 TORTURE_STOPFILE="$resdir/$ds/STOP"; export TORTURE_STOPFILE
381 echo Results directory: $resdir/$ds
382 echo $scriptname $args
383 touch $resdir/$ds/log
384 echo $scriptname $args >> $resdir/$ds/log
385 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
386 pwd > $resdir/$ds/testid.txt
389 git status >> $resdir/$ds/testid.txt
390 git rev-parse HEAD >> $resdir/$ds/testid.txt
391 git diff HEAD >> $resdir/$ds/testid.txt
394 awk < $T/cfgcpu.pack \
395 -v TORTURE_BUILDONLY
="$TORTURE_BUILDONLY" \
396 -v CONFIGDIR
="$CONFIGFRAG/" \
399 -v jitter
="$jitter" \
402 -v TORTURE_QEMU_ARG
="$TORTURE_QEMU_ARG" \
403 -v TORTURE_BOOTARGS
="$TORTURE_BOOTARGS" \
414 # Dump out the scripting required to run one test batch.
415 function dump(first, pastlast, batchnum)
417 print "echo ----Start batch " batchnum ": `date` | tee -a " rd "log";
420 for (j = first; j < pastlast; j++) {
421 builddir=KVM "/b" j - first + 1
423 if (cfrep[cf[j]] == "") {
428 cfr[jn] = cf[j] "." cfrep[cf[j]];
430 if (cpusr[jn] > ncpus && ncpus != 0)
434 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` | tee -a " rd "log";
435 print "rm -f " builddir ".*";
436 print "touch " builddir ".wait";
437 print "mkdir " rd cfr[jn] " || :";
438 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 &"
439 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` | tee -a " rd "log";
440 print "while test -f " builddir ".wait"
444 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` | tee -a " rd "log";
447 for (j = 1; j < jn; j++) {
449 print "rm -f " builddir ".ready"
450 print "if test -f \"" rd cfr[j] "/builtkernel\""
452 print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date` | tee -a " rd "log";
453 print "\tneedqemurun=1"
458 if (ja[1] == -1 && ncpus == 0)
460 else if (ja[1] == -1)
464 if (TORTURE_BUILDONLY && njitter != 0) {
466 print "echo Build-only run, so suppressing jitter | tee -a " rd "log"
468 if (TORTURE_BUILDONLY) {
471 print "if test -n \"$needqemurun\""
473 print "\techo ---- Starting kernels. `date` | tee -a " rd "log";
474 print "\techo > " rd "jitter_pids"
475 for (j = 0; j < njitter; j++) {
476 print "\tjitter.sh " j " " dur " " ja[2] " " ja[3] "&"
477 print "\techo $! >> " rd "jitter_pids"
480 print "\techo ---- All kernel runs complete. `date` | tee -a " rd "log";
483 print "\techo ---- No kernel runs. `date` | tee -a " rd "log";
485 for (j = 1; j < jn; j++) {
487 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: | tee -a " rd "log";
488 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out | tee -a " rd "log";
498 # Each pass through the following loop considers one test.
499 for (i = 0; i < njobs; i++) {
501 # Sequential test specified, each test its own batch.
502 dump(i, i + 1, batchnum);
505 } else if (nc < cpus[i] && i != 0) {
506 # Out of CPUs, dump out a batch.
507 dump(first, i, batchnum);
512 # Account for the CPUs needed by the current test.
515 # Dump the last batch.
517 dump(first, i, batchnum);
520 cat << ___EOF___ >> $T/script
523 echo " --- `date` Test summary:"
524 echo Results directory: $resdir/$ds
525 kcsan-collapse.sh $resdir/$ds
526 kvm-recheck.sh $resdir/$ds
529 if test "$dryrun" = script
533 elif test "$dryrun" = sched
535 # Extract the test run schedule from the script.
536 egrep 'Start batch|Starting build\.' $T/script |
538 sed -e 's/:.*$//' -e 's/^echo //'
541 # Not a dryrun, so run the script.
545 # 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
546 # Function-graph tracing: ftrace=function_graph ftrace_graph_filter=sched_setaffinity,migration_cpu_stop
547 # Also --kconfig "CONFIG_FUNCTION_TRACER=y CONFIG_FUNCTION_GRAPH_TRACER=y"
548 # Control buffer size: --bootargs trace_buf_size=3k
549 # Get trace-buffer dumps on all oopses: --bootargs ftrace_dump_on_oops
550 # Ditto, but dump only the oopsing CPU: --bootargs ftrace_dump_on_oops=orig_cpu
551 # Heavy-handed way to also dump on warnings: --bootargs panic_on_warn