Merge tag 'm68k-for-v5.15-tag1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / tools / testing / selftests / rcutorture / bin / kvm-test-1-run-batch.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
3 #
4 # Carry out a kvm-based run for the specified batch of scenarios, which
5 # might have been built by --build-only kvm.sh run.
6 #
7 # Usage: kvm-test-1-run-batch.sh SCENARIO [ SCENARIO ... ]
8 #
9 # Each SCENARIO is the name of a directory in the current directory
10 #       containing a ready-to-run qemu-cmd file.
11 #
12 # Copyright (C) 2021 Facebook, Inc.
13 #
14 # Authors: Paul E. McKenney <paulmck@kernel.org>
15
16 T=${TMPDIR-/tmp}/kvm-test-1-run-batch.sh.$$
17 trap 'rm -rf $T' 0
18 mkdir $T
19
20 echo ---- Running batch $*
21 # Check arguments
22 runfiles=
23 for i in "$@"
24 do
25         if ! echo $i | grep -q '^[^/.a-z]\+\(\.[0-9]\+\)\?$'
26         then
27                 echo Bad scenario name: \"$i\" 1>&2
28                 exit 1
29         fi
30         if ! test -d "$i"
31         then
32                 echo Scenario name not a directory: \"$i\" 1>&2
33                 exit 2
34         fi
35         if ! test -f "$i/qemu-cmd"
36         then
37                 echo Scenario lacks a command file: \"$i/qemu-cmd\" 1>&2
38                 exit 3
39         fi
40         rm -f $i/build.*
41         touch $i/build.run
42         runfiles="$runfiles $i/build.run"
43 done
44
45 # Extract settings from the qemu-cmd file.
46 grep '^#' $1/qemu-cmd | sed -e 's/^# //' > $T/qemu-cmd-settings
47 . $T/qemu-cmd-settings
48
49 # Start up jitter, start each scenario, wait, end jitter.
50 echo ---- System running test: `uname -a`
51 echo ---- Starting kernels. `date` | tee -a log
52 $TORTURE_JITTER_START
53 kvm-assign-cpus.sh /sys/devices/system/node > $T/cpuarray.awk
54 for i in "$@"
55 do
56         echo ---- System running test: `uname -a` > $i/kvm-test-1-run-qemu.sh.out
57         echo > $i/kvm-test-1-run-qemu.sh.out
58         export TORTURE_AFFINITY=
59         kvm-get-cpus-script.sh $T/cpuarray.awk $T/cpubatches.awk $T/cpustate
60         cat << '        ___EOF___' >> $T/cpubatches.awk
61         END {
62                 affinitylist = "";
63                 if (!gotcpus()) {
64                         print "echo No CPU-affinity information, so no taskset command.";
65                 } else if (cpu_count !~ /^[0-9][0-9]*$/) {
66                         print "echo " scenario ": Bogus number of CPUs (old qemu-cmd?), so no taskset command.";
67                 } else {
68                         affinitylist = nextcpus(cpu_count);
69                         if (!(affinitylist ~ /^[0-9,-][0-9,-]*$/))
70                                 print "echo " scenario ": Bogus CPU-affinity information, so no taskset command.";
71                         else if (!dumpcpustate())
72                                 print "echo " scenario ": Could not dump state, so no taskset command.";
73                         else
74                                 print "export TORTURE_AFFINITY=" affinitylist;
75                 }
76         }
77         ___EOF___
78         cpu_count="`grep '# TORTURE_CPU_COUNT=' $i/qemu-cmd | sed -e 's/^.*=//'`"
79         affinity_export="`awk -f $T/cpubatches.awk -v cpu_count="$cpu_count" -v scenario=$i < /dev/null`"
80         $affinity_export
81         kvm-test-1-run-qemu.sh $i >> $i/kvm-test-1-run-qemu.sh.out 2>&1 &
82 done
83 for i in $runfiles
84 do
85         while ls $i > /dev/null 2>&1
86         do
87                 :
88         done
89 done
90 echo ---- All kernel runs complete. `date` | tee -a log
91 $TORTURE_JITTER_STOP