treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / testing / selftests / rcutorture / bin / kvm.sh
blob78d18ab8e95482dd18f32cef45833539f13d76e2
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_KMAKE_ARG=""
35 TORTURE_QEMU_MEM=512
36 TORTURE_SHUTDOWN_GRACE=180
37 TORTURE_SUITE=rcu
38 TORTURE_TRUST_MAKE=""
39 resdir=""
40 configs=""
41 cpus=0
42 ds=`date +%Y.%m.%d-%H:%M:%S`
43 jitter="-1"
45 usage () {
46 echo "Usage: $scriptname optional arguments:"
47 echo " --bootargs kernel-boot-arguments"
48 echo " --bootimage relative-path-to-kernel-boot-image"
49 echo " --buildonly"
50 echo " --configs \"config-file list w/ repeat factor (3*TINY01)\""
51 echo " --cpus N"
52 echo " --datestamp string"
53 echo " --defconfig string"
54 echo " --dryrun sched|script"
55 echo " --duration minutes"
56 echo " --interactive"
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"
62 echo " --no-initrd"
63 echo " --qemu-args qemu-arguments"
64 echo " --qemu-cmd qemu-system-..."
65 echo " --results absolute-pathname"
66 echo " --torture rcu"
67 echo " --trust-make"
68 exit 1
71 while test $# -gt 0
73 case "$1" in
74 --bootargs|--bootarg)
75 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
76 TORTURE_BOOTARGS="$2"
77 shift
79 --bootimage)
80 checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
81 TORTURE_BOOT_IMAGE="$2"
82 shift
84 --buildonly)
85 TORTURE_BUILDONLY=1
87 --configs|--config)
88 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
89 configs="$2"
90 shift
92 --cpus)
93 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
94 cpus=$2
95 TORTURE_ALLOTED_CPUS="$2"
96 max_cpus="`identify_qemu_vcpus`"
97 if test "$TORTURE_ALLOTED_CPUS" -gt "$max_cpus"
98 then
99 TORTURE_ALLOTED_CPUS=$max_cpus
101 shift
103 --datestamp)
104 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
105 ds=$2
106 shift
108 --defconfig)
109 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
110 TORTURE_DEFCONFIG=$2
111 shift
113 --dryrun)
114 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
115 dryrun=$2
116 shift
118 --duration)
119 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
120 dur=$(($2*60))
121 shift
123 --interactive)
124 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
126 --jitter)
127 checkarg --jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$'
128 jitter="$2"
129 shift
131 --kconfig)
132 checkarg --kconfig "(Kconfig options)" $# "$2" '^CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\( CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\)*$' '^error$'
133 TORTURE_KCONFIG_ARG="$2"
134 shift
136 --kmake-arg)
137 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
138 TORTURE_KMAKE_ARG="$2"
139 shift
141 --mac)
142 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
143 TORTURE_QEMU_MAC=$2
144 shift
146 --memory)
147 checkarg --memory "(memory size)" $# "$2" '^[0-9]\+[MG]\?$' error
148 TORTURE_QEMU_MEM=$2
149 shift
151 --no-initrd)
152 TORTURE_INITRD=""; export TORTURE_INITRD
154 --qemu-args|--qemu-arg)
155 checkarg --qemu-args "(qemu arguments)" $# "$2" '^-' '^error'
156 TORTURE_QEMU_ARG="$2"
157 shift
159 --qemu-cmd)
160 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
161 TORTURE_QEMU_CMD="$2"
162 shift
164 --results)
165 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
166 resdir=$2
167 shift
169 --shutdown-grace)
170 checkarg --shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
171 TORTURE_SHUTDOWN_GRACE=$2
172 shift
174 --torture)
175 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuperf\)$' '^--'
176 TORTURE_SUITE=$2
177 shift
178 if test "$TORTURE_SUITE" = rcuperf
179 then
180 # If you really want jitter for rcuperf, specify
181 # it after specifying rcuperf. (But why?)
182 jitter=0
185 --trust-make)
186 TORTURE_TRUST_MAKE="y"
189 echo Unknown argument $1
190 usage
192 esac
193 shift
194 done
196 if test -z "$TORTURE_INITRD" || tools/testing/selftests/rcutorture/bin/mkinitrd.sh
197 then
199 else
200 echo No initrd and unable to create one, aborting test >&2
201 exit 1
204 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
206 defaultconfigs="`tr '\012' ' ' < $CONFIGFRAG/CFLIST`"
207 if test -z "$configs"
208 then
209 configs=$defaultconfigs
212 if test -z "$resdir"
213 then
214 resdir=$KVM/res
217 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
218 configs_derep=
219 for CF in $configs
221 case $CF in
222 [0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**)
223 config_reps=`echo $CF | sed -e 's/\*.*$//'`
224 CF1=`echo $CF | sed -e 's/^[^*]*\*//'`
227 config_reps=1
228 CF1=$CF
230 esac
231 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
233 configs_derep="$configs_derep $CF1"
234 done
235 done
236 touch $T/cfgcpu
237 configs_derep="`echo $configs_derep | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`"
238 for CF1 in $configs_derep
240 if test -f "$CONFIGFRAG/$CF1"
241 then
242 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
243 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
244 cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
245 echo $CF1 $cpu_count >> $T/cfgcpu
246 else
247 echo "The --configs file $CF1 does not exist, terminating."
248 exit 1
250 done
251 sort -k2nr $T/cfgcpu -T="$T" > $T/cfgcpu.sort
253 # Use a greedy bin-packing algorithm, sorting the list accordingly.
254 awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
255 BEGIN {
256 njobs = 0;
260 # Read file of tests and corresponding required numbers of CPUs.
261 cf[njobs] = $1;
262 cpus[njobs] = $2;
263 njobs++;
266 END {
267 batch = 0;
268 nc = -1;
270 # Each pass through the following loop creates on test batch
271 # that can be executed concurrently given ncpus. Note that a
272 # given test that requires more than the available CPUs will run in
273 # their own batch. Such tests just have to make do with what
274 # is available.
275 while (nc != ncpus) {
276 batch++;
277 nc = ncpus;
279 # Each pass through the following loop considers one
280 # test for inclusion in the current batch.
281 for (i = 0; i < njobs; i++) {
282 if (done[i])
283 continue; # Already part of a batch.
284 if (nc >= cpus[i] || nc == ncpus) {
286 # This test fits into the current batch.
287 done[i] = batch;
288 nc -= cpus[i];
289 if (nc <= 0)
290 break; # Too-big test in its own batch.
295 # Dump out the tests in batch order.
296 for (b = 1; b <= batch; b++)
297 for (i = 0; i < njobs; i++)
298 if (done[i] == b)
299 print cf[i], cpus[i];
302 # Generate a script to execute the tests in appropriate batches.
303 cat << ___EOF___ > $T/script
304 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
305 KVM="$KVM"; export KVM
306 PATH="$PATH"; export PATH
307 TORTURE_ALLOTED_CPUS="$TORTURE_ALLOTED_CPUS"; export TORTURE_ALLOTED_CPUS
308 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
309 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
310 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
311 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
312 TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG
313 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
314 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
315 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
316 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
317 TORTURE_QEMU_MEM="$TORTURE_QEMU_MEM"; export TORTURE_QEMU_MEM
318 TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
319 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
320 TORTURE_TRUST_MAKE="$TORTURE_TRUST_MAKE"; export TORTURE_TRUST_MAKE
321 if ! test -e $resdir
322 then
323 mkdir -p "$resdir" || :
325 mkdir $resdir/$ds
326 echo Results directory: $resdir/$ds
327 echo $scriptname $args
328 touch $resdir/$ds/log
329 echo $scriptname $args >> $resdir/$ds/log
330 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
331 pwd > $resdir/$ds/testid.txt
332 if test -d .git
333 then
334 git status >> $resdir/$ds/testid.txt
335 git rev-parse HEAD >> $resdir/$ds/testid.txt
336 git diff HEAD >> $resdir/$ds/testid.txt
338 ___EOF___
339 awk < $T/cfgcpu.pack \
340 -v TORTURE_BUILDONLY="$TORTURE_BUILDONLY" \
341 -v CONFIGDIR="$CONFIGFRAG/" \
342 -v KVM="$KVM" \
343 -v ncpus=$cpus \
344 -v jitter="$jitter" \
345 -v rd=$resdir/$ds/ \
346 -v dur=$dur \
347 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
348 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
349 'BEGIN {
350 i = 0;
354 cf[i] = $1;
355 cpus[i] = $2;
356 i++;
359 # Dump out the scripting required to run one test batch.
360 function dump(first, pastlast, batchnum)
362 print "echo ----Start batch " batchnum ": `date` | tee -a " rd "log";
363 print "needqemurun="
364 jn=1
365 for (j = first; j < pastlast; j++) {
366 builddir=KVM "/b" j - first + 1
367 cpusr[jn] = cpus[j];
368 if (cfrep[cf[j]] == "") {
369 cfr[jn] = cf[j];
370 cfrep[cf[j]] = 1;
371 } else {
372 cfrep[cf[j]]++;
373 cfr[jn] = cf[j] "." cfrep[cf[j]];
375 if (cpusr[jn] > ncpus && ncpus != 0)
376 ovf = "-ovf";
377 else
378 ovf = "";
379 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` | tee -a " rd "log";
380 print "rm -f " builddir ".*";
381 print "touch " builddir ".wait";
382 print "mkdir " rd cfr[jn] " || :";
383 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 &"
384 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` | tee -a " rd "log";
385 print "while test -f " builddir ".wait"
386 print "do"
387 print "\tsleep 1"
388 print "done"
389 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` | tee -a " rd "log";
390 jn++;
392 for (j = 1; j < jn; j++) {
393 builddir=KVM "/b" j
394 print "rm -f " builddir ".ready"
395 print "if test -f \"" rd cfr[j] "/builtkernel\""
396 print "then"
397 print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date` | tee -a " rd "log";
398 print "\tneedqemurun=1"
399 print "fi"
401 njitter = 0;
402 split(jitter, ja);
403 if (ja[1] == -1 && ncpus == 0)
404 njitter = 1;
405 else if (ja[1] == -1)
406 njitter = ncpus;
407 else
408 njitter = ja[1];
409 if (TORTURE_BUILDONLY && njitter != 0) {
410 njitter = 0;
411 print "echo Build-only run, so suppressing jitter | tee -a " rd "log"
413 if (TORTURE_BUILDONLY) {
414 print "needqemurun="
416 print "if test -n \"$needqemurun\""
417 print "then"
418 print "\techo ---- Starting kernels. `date` | tee -a " rd "log";
419 for (j = 0; j < njitter; j++)
420 print "\tjitter.sh " j " " dur " " ja[2] " " ja[3] "&"
421 print "\twait"
422 print "\techo ---- All kernel runs complete. `date` | tee -a " rd "log";
423 print "else"
424 print "\twait"
425 print "\techo ---- No kernel runs. `date` | tee -a " rd "log";
426 print "fi"
427 for (j = 1; j < jn; j++) {
428 builddir=KVM "/b" j
429 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: | tee -a " rd "log";
430 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out | tee -a " rd "log";
434 END {
435 njobs = i;
436 nc = ncpus;
437 first = 0;
438 batchnum = 1;
440 # Each pass through the following loop considers one test.
441 for (i = 0; i < njobs; i++) {
442 if (ncpus == 0) {
443 # Sequential test specified, each test its own batch.
444 dump(i, i + 1, batchnum);
445 first = i;
446 batchnum++;
447 } else if (nc < cpus[i] && i != 0) {
448 # Out of CPUs, dump out a batch.
449 dump(first, i, batchnum);
450 first = i;
451 nc = ncpus;
452 batchnum++;
454 # Account for the CPUs needed by the current test.
455 nc -= cpus[i];
457 # Dump the last batch.
458 if (ncpus != 0)
459 dump(first, i, batchnum);
460 }' >> $T/script
462 cat << ___EOF___ >> $T/script
463 echo
464 echo
465 echo " --- `date` Test summary:"
466 echo Results directory: $resdir/$ds
467 kvm-recheck.sh $resdir/$ds
468 ___EOF___
470 if test "$dryrun" = script
471 then
472 cat $T/script
473 exit 0
474 elif test "$dryrun" = sched
475 then
476 # Extract the test run schedule from the script.
477 egrep 'Start batch|Starting build\.' $T/script |
478 grep -v ">>" |
479 sed -e 's/:.*$//' -e 's/^echo //'
480 exit 0
481 else
482 # Not a dryrun, so run the script.
483 sh $T/script
486 # 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
487 # Function-graph tracing: ftrace=function_graph ftrace_graph_filter=sched_setaffinity,migration_cpu_stop
488 # Also --kconfig "CONFIG_FUNCTION_TRACER=y CONFIG_FUNCTION_GRAPH_TRACER=y"