WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / rcutorture / bin / kvm.sh
blob45d07b7b69f5954fae076e82403fb112b95136ec
1 #!/bin/bash
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>
14 scriptname=$0
15 args="$*"
17 T=${TMPDIR-/tmp}/kvm.sh.$$
18 trap 'rm -rf $T' 0
19 mkdir $T
21 cd `dirname $scriptname`/../../../../../
23 dur=$((30*60))
24 dryrun=""
25 KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
26 PATH=${KVM}/bin:$PATH; export PATH
27 . functions.sh
29 TORTURE_ALLOTED_CPUS="`identify_qemu_vcpus`"
30 TORTURE_DEFCONFIG=defconfig
31 TORTURE_BOOT_IMAGE=""
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=""
39 TORTURE_KMAKE_ARG=""
40 TORTURE_QEMU_MEM=512
41 TORTURE_SHUTDOWN_GRACE=180
42 TORTURE_SUITE=rcu
43 TORTURE_TRUST_MAKE=""
44 resdir=""
45 configs=""
46 cpus=0
47 ds=`date +%Y.%m.%d-%H.%M.%S`
48 jitter="-1"
50 usage () {
51 echo "Usage: $scriptname optional arguments:"
52 echo " --allcpus"
53 echo " --bootargs kernel-boot-arguments"
54 echo " --bootimage relative-path-to-kernel-boot-image"
55 echo " --buildonly"
56 echo " --configs \"config-file list w/ repeat factor (3*TINY01)\""
57 echo " --cpus N"
58 echo " --datestamp string"
59 echo " --defconfig string"
60 echo " --dryrun sched|script"
61 echo " --duration minutes | <seconds>s | <hours>h | <days>d"
62 echo " --gdb"
63 echo " --help"
64 echo " --interactive"
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"
70 echo " --no-initrd"
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"
75 echo " --trust-make"
76 exit 1
79 while test $# -gt 0
81 case "$1" in
82 --allcpus)
83 cpus=$TORTURE_ALLOTED_CPUS
84 max_cpus=$TORTURE_ALLOTED_CPUS
86 --bootargs|--bootarg)
87 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
88 TORTURE_BOOTARGS="$2"
89 shift
91 --bootimage)
92 checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
93 TORTURE_BOOT_IMAGE="$2"
94 shift
96 --buildonly|--build-only)
97 TORTURE_BUILDONLY=1
99 --configs|--config)
100 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
101 configs="$2"
102 shift
104 --cpus)
105 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
106 cpus=$2
107 TORTURE_ALLOTED_CPUS="$2"
108 max_cpus="`identify_qemu_vcpus`"
109 if test "$TORTURE_ALLOTED_CPUS" -gt "$max_cpus"
110 then
111 TORTURE_ALLOTED_CPUS=$max_cpus
113 shift
115 --datestamp)
116 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
117 ds=$2
118 shift
120 --defconfig)
121 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
122 TORTURE_DEFCONFIG=$2
123 shift
125 --dryrun)
126 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
127 dryrun=$2
128 shift
130 --duration)
131 checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'
132 mult=60
133 if echo "$2" | grep -q 's$'
134 then
135 mult=1
136 elif echo "$2" | grep -q 'h$'
137 then
138 mult=3600
139 elif echo "$2" | grep -q 'd$'
140 then
141 mult=86400
143 ts=`echo $2 | sed -e 's/[smhd]$//'`
144 dur=$(($ts*mult))
145 shift
147 --gdb)
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
152 --help|-h)
153 usage
155 --interactive)
156 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
158 --jitter)
159 checkarg --jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$'
160 jitter="$2"
161 shift
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"
166 shift
168 --kasan)
169 TORTURE_KCONFIG_KASAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KASAN=y"; export TORTURE_KCONFIG_KASAN_ARG
171 --kcsan)
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"
177 shift
179 --mac)
180 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
181 TORTURE_QEMU_MAC=$2
182 shift
184 --memory)
185 checkarg --memory "(memory size)" $# "$2" '^[0-9]\+[MG]\?$' error
186 TORTURE_QEMU_MEM=$2
187 shift
189 --no-initrd)
190 TORTURE_INITRD=""; export TORTURE_INITRD
192 --qemu-args|--qemu-arg)
193 checkarg --qemu-args "(qemu arguments)" $# "$2" '^-' '^error'
194 TORTURE_QEMU_ARG="$2"
195 shift
197 --qemu-cmd)
198 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
199 TORTURE_QEMU_CMD="$2"
200 shift
202 --results)
203 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
204 resdir=$2
205 shift
207 --shutdown-grace)
208 checkarg --shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
209 TORTURE_SHUTDOWN_GRACE=$2
210 shift
212 --torture)
213 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuscale\|refscale\|scf\)$' '^--'
214 TORTURE_SUITE=$2
215 shift
216 if test "$TORTURE_SUITE" = rcuscale || test "$TORTURE_SUITE" = refscale
217 then
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?)
221 jitter=0
224 --trust-make)
225 TORTURE_TRUST_MAKE="y"
228 echo Unknown argument $1
229 usage
231 esac
232 shift
233 done
235 if test -z "$TORTURE_INITRD" || tools/testing/selftests/rcutorture/bin/mkinitrd.sh
236 then
238 else
239 echo No initrd and unable to create one, aborting test >&2
240 exit 1
243 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
245 defaultconfigs="`tr '\012' ' ' < $CONFIGFRAG/CFLIST`"
246 if test -z "$configs"
247 then
248 configs=$defaultconfigs
251 if test -z "$resdir"
252 then
253 resdir=$KVM/res
256 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
257 configs_derep=
258 for CF in $configs
260 case $CF in
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/^[^*]*\*//'`
266 config_reps=1
267 CF1=$CF
269 esac
270 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
272 configs_derep="$configs_derep $CF1"
273 done
274 done
275 touch $T/cfgcpu
276 configs_derep="`echo $configs_derep | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`"
277 if test -n "$TORTURE_KCONFIG_GDB_ARG"
278 then
279 if test "`echo $configs_derep | wc -w`" -gt 1
280 then
281 echo "The --config list is: $configs_derep."
282 echo "Only one --config permitted with --gdb, terminating."
283 exit 1
286 for CF1 in $configs_derep
288 if test -f "$CONFIGFRAG/$CF1"
289 then
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
294 else
295 echo "The --configs file $CF1 does not exist, terminating."
296 exit 1
298 done
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 '
303 BEGIN {
304 njobs = 0;
308 # Read file of tests and corresponding required numbers of CPUs.
309 cf[njobs] = $1;
310 cpus[njobs] = $2;
311 njobs++;
314 END {
315 batch = 0;
316 nc = -1;
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
322 # is available.
323 while (nc != ncpus) {
324 batch++;
325 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++) {
330 if (done[i])
331 continue; # Already part of a batch.
332 if (nc >= cpus[i] || nc == ncpus) {
334 # This test fits into the current batch.
335 done[i] = batch;
336 nc -= cpus[i];
337 if (nc <= 0)
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++)
346 if (done[i] == b)
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
374 if ! test -e $resdir
375 then
376 mkdir -p "$resdir" || :
378 mkdir $resdir/$ds
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
387 if test -d .git
388 then
389 git status >> $resdir/$ds/testid.txt
390 git rev-parse HEAD >> $resdir/$ds/testid.txt
391 git diff HEAD >> $resdir/$ds/testid.txt
393 ___EOF___
394 awk < $T/cfgcpu.pack \
395 -v TORTURE_BUILDONLY="$TORTURE_BUILDONLY" \
396 -v CONFIGDIR="$CONFIGFRAG/" \
397 -v KVM="$KVM" \
398 -v ncpus=$cpus \
399 -v jitter="$jitter" \
400 -v rd=$resdir/$ds/ \
401 -v dur=$dur \
402 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
403 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
404 'BEGIN {
405 i = 0;
409 cf[i] = $1;
410 cpus[i] = $2;
411 i++;
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";
418 print "needqemurun="
419 jn=1
420 for (j = first; j < pastlast; j++) {
421 builddir=KVM "/b" j - first + 1
422 cpusr[jn] = cpus[j];
423 if (cfrep[cf[j]] == "") {
424 cfr[jn] = cf[j];
425 cfrep[cf[j]] = 1;
426 } else {
427 cfrep[cf[j]]++;
428 cfr[jn] = cf[j] "." cfrep[cf[j]];
430 if (cpusr[jn] > ncpus && ncpus != 0)
431 ovf = "-ovf";
432 else
433 ovf = "";
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"
441 print "do"
442 print "\tsleep 1"
443 print "done"
444 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` | tee -a " rd "log";
445 jn++;
447 for (j = 1; j < jn; j++) {
448 builddir=KVM "/b" j
449 print "rm -f " builddir ".ready"
450 print "if test -f \"" rd cfr[j] "/builtkernel\""
451 print "then"
452 print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date` | tee -a " rd "log";
453 print "\tneedqemurun=1"
454 print "fi"
456 njitter = 0;
457 split(jitter, ja);
458 if (ja[1] == -1 && ncpus == 0)
459 njitter = 1;
460 else if (ja[1] == -1)
461 njitter = ncpus;
462 else
463 njitter = ja[1];
464 if (TORTURE_BUILDONLY && njitter != 0) {
465 njitter = 0;
466 print "echo Build-only run, so suppressing jitter | tee -a " rd "log"
468 if (TORTURE_BUILDONLY) {
469 print "needqemurun="
471 print "if test -n \"$needqemurun\""
472 print "then"
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"
479 print "\twait"
480 print "\techo ---- All kernel runs complete. `date` | tee -a " rd "log";
481 print "else"
482 print "\twait"
483 print "\techo ---- No kernel runs. `date` | tee -a " rd "log";
484 print "fi"
485 for (j = 1; j < jn; j++) {
486 builddir=KVM "/b" 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";
492 END {
493 njobs = i;
494 nc = ncpus;
495 first = 0;
496 batchnum = 1;
498 # Each pass through the following loop considers one test.
499 for (i = 0; i < njobs; i++) {
500 if (ncpus == 0) {
501 # Sequential test specified, each test its own batch.
502 dump(i, i + 1, batchnum);
503 first = i;
504 batchnum++;
505 } else if (nc < cpus[i] && i != 0) {
506 # Out of CPUs, dump out a batch.
507 dump(first, i, batchnum);
508 first = i;
509 nc = ncpus;
510 batchnum++;
512 # Account for the CPUs needed by the current test.
513 nc -= cpus[i];
515 # Dump the last batch.
516 if (ncpus != 0)
517 dump(first, i, batchnum);
518 }' >> $T/script
520 cat << ___EOF___ >> $T/script
521 echo
522 echo
523 echo " --- `date` Test summary:"
524 echo Results directory: $resdir/$ds
525 kcsan-collapse.sh $resdir/$ds
526 kvm-recheck.sh $resdir/$ds
527 ___EOF___
529 if test "$dryrun" = script
530 then
531 cat $T/script
532 exit 0
533 elif test "$dryrun" = sched
534 then
535 # Extract the test run schedule from the script.
536 egrep 'Start batch|Starting build\.' $T/script |
537 grep -v ">>" |
538 sed -e 's/:.*$//' -e 's/^echo //'
539 exit 0
540 else
541 # Not a dryrun, so run the script.
542 sh $T/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