torture: Rename RCU_INITRD to TORTURE_INITRD
[deliverable/linux.git] / tools / testing / selftests / rcutorture / bin / kvm.sh
1 #!/bin/bash
2 #
3 # Run a series of 14 tests under KVM. These are not particularly
4 # well-selected or well-tuned, but are the current set. Run from the
5 # top level of the source tree.
6 #
7 # Edit the definitions below to set the locations of the various directories,
8 # as well as the test duration.
9 #
10 # Usage: sh kvm.sh [ options ]
11 #
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, you can access it online at
24 # http://www.gnu.org/licenses/gpl-2.0.html.
25 #
26 # Copyright (C) IBM Corporation, 2011
27 #
28 # Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
29
30 scriptname=$0
31 args="$*"
32
33 T=/tmp/kvm.sh.$$
34 trap 'rm -rf $T' 0
35 mkdir $T
36
37 dur=30
38 dryrun=""
39 KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
40 PATH=${KVM}/bin:$PATH; export PATH
41 TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD
42 RCU_KMAKE_ARG=""; export RCU_KMAKE_ARG
43 TORTURE_SUITE=rcu
44 resdir=""
45 configs=""
46 cpus=0
47 ds=`date +%Y.%m.%d-%H:%M:%S`
48 kversion=""
49
50 . functions.sh
51
52 usage () {
53 echo "Usage: $scriptname optional arguments:"
54 echo " --bootargs kernel-boot-arguments"
55 echo " --buildonly"
56 echo " --configs \"config-file list\""
57 echo " --cpus N"
58 echo " --datestamp string"
59 echo " --dryrun sched|script"
60 echo " --duration minutes"
61 echo " --interactive"
62 echo " --kmake-arg kernel-make-arguments"
63 echo " --kversion vN.NN"
64 echo " --mac nn:nn:nn:nn:nn:nn"
65 echo " --no-initrd"
66 echo " --qemu-args qemu-system-..."
67 echo " --qemu-cmd qemu-system-..."
68 echo " --results absolute-pathname"
69 echo " --torture rcu"
70 exit 1
71 }
72
73 while test $# -gt 0
74 do
75 case "$1" in
76 --bootargs)
77 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
78 RCU_BOOTARGS="$2"
79 shift
80 ;;
81 --buildonly)
82 RCU_BUILDONLY=1; export RCU_BUILDONLY
83 ;;
84 --configs)
85 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
86 configs="$2"
87 shift
88 ;;
89 --cpus)
90 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
91 cpus=$2
92 shift
93 ;;
94 --datestamp)
95 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
96 ds=$2
97 shift
98 ;;
99 --dryrun)
100 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
101 dryrun=$2
102 shift
103 ;;
104 --duration)
105 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
106 dur=$2
107 shift
108 ;;
109 --interactive)
110 RCU_QEMU_INTERACTIVE=1; export RCU_QEMU_INTERACTIVE
111 ;;
112 --kmake-arg)
113 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
114 RCU_KMAKE_ARG="$2"; export RCU_KMAKE_ARG
115 shift
116 ;;
117 --kversion)
118 checkarg --kversion "(kernel version)" $# "$2" '^v[0-9.]*$' '^error'
119 kversion=$2
120 shift
121 ;;
122 --mac)
123 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
124 RCU_QEMU_MAC=$2; export RCU_QEMU_MAC
125 shift
126 ;;
127 --no-initrd)
128 TORTURE_INITRD=""; export TORTURE_INITRD
129 ;;
130 --qemu-args)
131 checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
132 RCU_QEMU_ARG="$2"
133 shift
134 ;;
135 --qemu-cmd)
136 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
137 RCU_QEMU_CMD="$2"; export RCU_QEMU_CMD
138 shift
139 ;;
140 --results)
141 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
142 resdir=$2
143 shift
144 ;;
145 --torture)
146 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\)$' '^--'
147 TORTURE_SUITE=$2
148 shift
149 ;;
150 *)
151 echo Unknown argument $1
152 usage
153 ;;
154 esac
155 shift
156 done
157
158 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
159 KVPATH=${CONFIGFRAG}/$kversion; export KVPATH
160
161 if test -z "$configs"
162 then
163 configs="`cat $CONFIGFRAG/$kversion/CFLIST`"
164 fi
165
166 if test -z "$resdir"
167 then
168 resdir=$KVM/res
169 fi
170
171 if test "$dryrun" = ""
172 then
173 if ! test -e $resdir
174 then
175 mkdir -p "$resdir" || :
176 fi
177 mkdir $resdir/$ds
178
179 # Be noisy only if running the script.
180 echo Results directory: $resdir/$ds
181 echo $scriptname $args
182
183 touch $resdir/$ds/log
184 echo $scriptname $args >> $resdir/$ds/log
185 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
186
187 pwd > $resdir/$ds/testid.txt
188 if test -d .git
189 then
190 git status >> $resdir/$ds/testid.txt
191 git rev-parse HEAD >> $resdir/$ds/testid.txt
192 fi
193 fi
194
195 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
196 touch $T/cfgcpu
197 for CF in $configs
198 do
199 if test -f "$CONFIGFRAG/$kversion/$CF"
200 then
201 echo $CF `configNR_CPUS.sh $CONFIGFRAG/$kversion/$CF` >> $T/cfgcpu
202 else
203 echo "The --configs file $CF does not exist, terminating."
204 exit 1
205 fi
206 done
207 sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
208
209 # Use a greedy bin-packing algorithm, sorting the list accordingly.
210 awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
211 BEGIN {
212 njobs = 0;
213 }
214
215 {
216 # Read file of tests and corresponding required numbers of CPUs.
217 cf[njobs] = $1;
218 cpus[njobs] = $2;
219 njobs++;
220 }
221
222 END {
223 alldone = 0;
224 batch = 0;
225 nc = -1;
226
227 # Each pass through the following loop creates on test batch
228 # that can be executed concurrently given ncpus. Note that a
229 # given test that requires more than the available CPUs will run in
230 # their own batch. Such tests just have to make do with what
231 # is available.
232 while (nc != ncpus) {
233 batch++;
234 nc = ncpus;
235
236 # Each pass through the following loop considers one
237 # test for inclusion in the current batch.
238 for (i = 0; i < njobs; i++) {
239 if (done[i])
240 continue; # Already part of a batch.
241 if (nc >= cpus[i] || nc == ncpus) {
242
243 # This test fits into the current batch.
244 done[i] = batch;
245 nc -= cpus[i];
246 if (nc <= 0)
247 break; # Too-big test in its own batch.
248 }
249 }
250 }
251
252 # Dump out the tests in batch order.
253 for (b = 1; b <= batch; b++)
254 for (i = 0; i < njobs; i++)
255 if (done[i] == b)
256 print cf[i], cpus[i];
257 }'
258
259 # Generate a script to execute the tests in appropriate batches.
260 cat << ___EOF___ > $T/script
261 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
262 ___EOF___
263 awk < $T/cfgcpu.pack \
264 -v CONFIGDIR="$CONFIGFRAG/$kversion/" \
265 -v KVM="$KVM" \
266 -v ncpus=$cpus \
267 -v rd=$resdir/$ds/ \
268 -v dur=$dur \
269 -v RCU_QEMU_ARG=$RCU_QEMU_ARG \
270 -v RCU_BOOTARGS=$RCU_BOOTARGS \
271 'BEGIN {
272 i = 0;
273 }
274
275 {
276 cf[i] = $1;
277 cpus[i] = $2;
278 i++;
279 }
280
281 # Dump out the scripting required to run one test batch.
282 function dump(first, pastlast)
283 {
284 print "echo ----Start batch: `date`";
285 print "echo ----Start batch: `date` >> " rd "/log";
286 jn=1
287 for (j = first; j < pastlast; j++) {
288 builddir=KVM "/b" jn
289 cpusr[jn] = cpus[j];
290 if (cfrep[cf[j]] == "") {
291 cfr[jn] = cf[j];
292 cfrep[cf[j]] = 1;
293 } else {
294 cfrep[cf[j]]++;
295 cfr[jn] = cf[j] "." cfrep[cf[j]];
296 }
297 if (cpusr[jn] > ncpus && ncpus != 0)
298 ovf = "(!)";
299 else
300 ovf = "";
301 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
302 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
303 print "rm -f " builddir ".*";
304 print "touch " builddir ".wait";
305 print "mkdir " builddir " > /dev/null 2>&1 || :";
306 print "mkdir " rd cfr[jn] " || :";
307 print "kvm-test-1-run.sh " CONFIGDIR cf[j], builddir, rd cfr[jn], dur " \"" RCU_QEMU_ARG "\" \"" RCU_BOOTARGS "\" > " rd cfr[jn] "/kvm-test-1-run.sh.out 2>&1 &"
308 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
309 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
310 print "while test -f " builddir ".wait"
311 print "do"
312 print "\tsleep 1"
313 print "done"
314 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
315 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
316 jn++;
317 }
318 for (j = 1; j < jn; j++) {
319 builddir=KVM "/b" j
320 print "rm -f " builddir ".ready"
321 print "echo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`";
322 print "echo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log";
323 }
324 print "wait"
325 print "echo ---- All kernel runs complete. `date`";
326 print "echo ---- All kernel runs complete. `date` >> " rd "/log";
327 for (j = 1; j < jn; j++) {
328 builddir=KVM "/b" j
329 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
330 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
331 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
332 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
333 }
334 }
335
336 END {
337 njobs = i;
338 nc = ncpus;
339 first = 0;
340
341 # Each pass through the following loop considers one test.
342 for (i = 0; i < njobs; i++) {
343 if (ncpus == 0) {
344 # Sequential test specified, each test its own batch.
345 dump(i, i + 1);
346 first = i;
347 } else if (nc < cpus[i] && i != 0) {
348 # Out of CPUs, dump out a batch.
349 dump(first, i);
350 first = i;
351 nc = ncpus;
352 }
353 # Account for the CPUs needed by the current test.
354 nc -= cpus[i];
355 }
356 # Dump the last batch.
357 if (ncpus != 0)
358 dump(first, i);
359 }' >> $T/script
360
361 if test "$dryrun" = script
362 then
363 # Dump out the script, but define the environment variables that
364 # it needs to run standalone.
365 echo CONFIGFRAG="$CONFIGFRAG; export CONFIGFRAG"
366 echo KVM="$KVM; export KVM"
367 echo KVPATH="$KVPATH; export KVPATH"
368 echo PATH="$PATH; export PATH"
369 echo RCU_BUILDONLY="$RCU_BUILDONLY; export RCU_BUILDONLY"
370 echo TORTURE_INITRD="$TORTURE_INITRD; export TORTURE_INITRD"
371 echo RCU_KMAKE_ARG="$RCU_KMAKE_ARG; export RCU_KMAKE_ARG"
372 echo RCU_QEMU_CMD="$RCU_QEMU_CMD; export RCU_QEMU_CMD"
373 echo RCU_QEMU_INTERACTIVE="$RCU_QEMU_INTERACTIVE; export RCU_QEMU_INTERACTIVE"
374 echo RCU_QEMU_MAC="$RCU_QEMU_MAC; export RCU_QEMU_MAC"
375 echo "mkdir -p "$resdir" || :"
376 echo "mkdir $resdir/$ds"
377 cat $T/script
378 exit 0
379 elif test "$dryrun" = sched
380 then
381 # Extract the test run schedule from the script.
382 egrep 'Start batch|Starting build\.' $T/script |
383 grep -v ">>" |
384 sed -e 's/:.*$//' -e 's/^echo //'
385 exit 0
386 else
387 # Not a dryru, so run the script.
388 sh $T/script
389 fi
390
391 # 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
392
393 echo
394 echo
395 echo " --- `date` Test summary:"
396 echo Results directory: $resdir/$ds
397 kvm-recheck.sh $resdir/$ds
This page took 0.042452 seconds and 6 git commands to generate.