]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - tools/testing/selftests/rcutorture/bin/kvm.sh
Merge tag 'leds-for-4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewsk...
[mirror_ubuntu-artful-kernel.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: 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_DEFCONFIG=defconfig
42 TORTURE_BOOT_IMAGE=""
43 TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD
44 TORTURE_KMAKE_ARG=""
45 TORTURE_SHUTDOWN_GRACE=180
46 TORTURE_SUITE=rcu
47 resdir=""
48 configs=""
49 cpus=0
50 ds=`date +%Y.%m.%d-%H:%M:%S`
51
52 . functions.sh
53
54 usage () {
55 echo "Usage: $scriptname optional arguments:"
56 echo " --bootargs kernel-boot-arguments"
57 echo " --bootimage relative-path-to-kernel-boot-image"
58 echo " --buildonly"
59 echo " --configs \"config-file list w/ repeat factor (3*TINY01)\""
60 echo " --cpus N"
61 echo " --datestamp string"
62 echo " --defconfig string"
63 echo " --dryrun sched|script"
64 echo " --duration minutes"
65 echo " --interactive"
66 echo " --kmake-arg kernel-make-arguments"
67 echo " --mac nn:nn:nn:nn:nn:nn"
68 echo " --no-initrd"
69 echo " --qemu-args qemu-system-..."
70 echo " --qemu-cmd qemu-system-..."
71 echo " --results absolute-pathname"
72 echo " --torture rcu"
73 exit 1
74 }
75
76 while test $# -gt 0
77 do
78 case "$1" in
79 --bootargs|--bootarg)
80 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
81 TORTURE_BOOTARGS="$2"
82 shift
83 ;;
84 --bootimage)
85 checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
86 TORTURE_BOOT_IMAGE="$2"
87 shift
88 ;;
89 --buildonly)
90 TORTURE_BUILDONLY=1
91 ;;
92 --configs|--config)
93 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
94 configs="$2"
95 shift
96 ;;
97 --cpus)
98 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
99 cpus=$2
100 shift
101 ;;
102 --datestamp)
103 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
104 ds=$2
105 shift
106 ;;
107 --defconfig)
108 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
109 TORTURE_DEFCONFIG=$2
110 shift
111 ;;
112 --dryrun)
113 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
114 dryrun=$2
115 shift
116 ;;
117 --duration)
118 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
119 dur=$2
120 shift
121 ;;
122 --interactive)
123 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
124 ;;
125 --kmake-arg)
126 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
127 TORTURE_KMAKE_ARG="$2"
128 shift
129 ;;
130 --mac)
131 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
132 TORTURE_QEMU_MAC=$2
133 shift
134 ;;
135 --no-initrd)
136 TORTURE_INITRD=""; export TORTURE_INITRD
137 ;;
138 --qemu-args|--qemu-arg)
139 checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
140 TORTURE_QEMU_ARG="$2"
141 shift
142 ;;
143 --qemu-cmd)
144 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
145 TORTURE_QEMU_CMD="$2"
146 shift
147 ;;
148 --results)
149 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
150 resdir=$2
151 shift
152 ;;
153 --shutdown-grace)
154 checkarg --shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
155 TORTURE_SHUTDOWN_GRACE=$2
156 shift
157 ;;
158 --torture)
159 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\)$' '^--'
160 TORTURE_SUITE=$2
161 shift
162 ;;
163 *)
164 echo Unknown argument $1
165 usage
166 ;;
167 esac
168 shift
169 done
170
171 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
172
173 if test -z "$configs"
174 then
175 configs="`cat $CONFIGFRAG/CFLIST`"
176 fi
177
178 if test -z "$resdir"
179 then
180 resdir=$KVM/res
181 fi
182
183 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
184 touch $T/cfgcpu
185 for CF in $configs
186 do
187 case $CF in
188 [0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**)
189 config_reps=`echo $CF | sed -e 's/\*.*$//'`
190 CF1=`echo $CF | sed -e 's/^[^*]*\*//'`
191 ;;
192 *)
193 config_reps=1
194 CF1=$CF
195 ;;
196 esac
197 if test -f "$CONFIGFRAG/$CF1"
198 then
199 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
200 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
201 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
202 do
203 echo $CF1 $cpu_count >> $T/cfgcpu
204 done
205 else
206 echo "The --configs file $CF1 does not exist, terminating."
207 exit 1
208 fi
209 done
210 sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
211
212 # Use a greedy bin-packing algorithm, sorting the list accordingly.
213 awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
214 BEGIN {
215 njobs = 0;
216 }
217
218 {
219 # Read file of tests and corresponding required numbers of CPUs.
220 cf[njobs] = $1;
221 cpus[njobs] = $2;
222 njobs++;
223 }
224
225 END {
226 alldone = 0;
227 batch = 0;
228 nc = -1;
229
230 # Each pass through the following loop creates on test batch
231 # that can be executed concurrently given ncpus. Note that a
232 # given test that requires more than the available CPUs will run in
233 # their own batch. Such tests just have to make do with what
234 # is available.
235 while (nc != ncpus) {
236 batch++;
237 nc = ncpus;
238
239 # Each pass through the following loop considers one
240 # test for inclusion in the current batch.
241 for (i = 0; i < njobs; i++) {
242 if (done[i])
243 continue; # Already part of a batch.
244 if (nc >= cpus[i] || nc == ncpus) {
245
246 # This test fits into the current batch.
247 done[i] = batch;
248 nc -= cpus[i];
249 if (nc <= 0)
250 break; # Too-big test in its own batch.
251 }
252 }
253 }
254
255 # Dump out the tests in batch order.
256 for (b = 1; b <= batch; b++)
257 for (i = 0; i < njobs; i++)
258 if (done[i] == b)
259 print cf[i], cpus[i];
260 }'
261
262 # Generate a script to execute the tests in appropriate batches.
263 cat << ___EOF___ > $T/script
264 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
265 KVM="$KVM"; export KVM
266 PATH="$PATH"; export PATH
267 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
268 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
269 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
270 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
271 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
272 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
273 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
274 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
275 TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
276 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
277 if ! test -e $resdir
278 then
279 mkdir -p "$resdir" || :
280 fi
281 mkdir $resdir/$ds
282 echo Results directory: $resdir/$ds
283 echo $scriptname $args
284 touch $resdir/$ds/log
285 echo $scriptname $args >> $resdir/$ds/log
286 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
287 pwd > $resdir/$ds/testid.txt
288 if test -d .git
289 then
290 git status >> $resdir/$ds/testid.txt
291 git rev-parse HEAD >> $resdir/$ds/testid.txt
292 if ! git diff HEAD > $T/git-diff 2>&1
293 then
294 cp $T/git-diff $resdir/$ds
295 fi
296 fi
297 ___EOF___
298 awk < $T/cfgcpu.pack \
299 -v CONFIGDIR="$CONFIGFRAG/" \
300 -v KVM="$KVM" \
301 -v ncpus=$cpus \
302 -v rd=$resdir/$ds/ \
303 -v dur=$dur \
304 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
305 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
306 'BEGIN {
307 i = 0;
308 }
309
310 {
311 cf[i] = $1;
312 cpus[i] = $2;
313 i++;
314 }
315
316 # Dump out the scripting required to run one test batch.
317 function dump(first, pastlast, batchnum)
318 {
319 print "echo ----Start batch " batchnum ": `date`";
320 print "echo ----Start batch " batchnum ": `date` >> " rd "/log";
321 jn=1
322 for (j = first; j < pastlast; j++) {
323 builddir=KVM "/b" jn
324 cpusr[jn] = cpus[j];
325 if (cfrep[cf[j]] == "") {
326 cfr[jn] = cf[j];
327 cfrep[cf[j]] = 1;
328 } else {
329 cfrep[cf[j]]++;
330 cfr[jn] = cf[j] "." cfrep[cf[j]];
331 }
332 if (cpusr[jn] > ncpus && ncpus != 0)
333 ovf = "-ovf";
334 else
335 ovf = "";
336 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
337 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
338 print "rm -f " builddir ".*";
339 print "touch " builddir ".wait";
340 print "mkdir " builddir " > /dev/null 2>&1 || :";
341 print "mkdir " rd cfr[jn] " || :";
342 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 &"
343 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
344 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
345 print "while test -f " builddir ".wait"
346 print "do"
347 print "\tsleep 1"
348 print "done"
349 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
350 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
351 jn++;
352 }
353 for (j = 1; j < jn; j++) {
354 builddir=KVM "/b" j
355 print "rm -f " builddir ".ready"
356 print "if test -z \"$TORTURE_BUILDONLY\""
357 print "then"
358 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`";
359 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log";
360 print "fi"
361 }
362 print "wait"
363 print "if test -z \"$TORTURE_BUILDONLY\""
364 print "then"
365 print "\techo ---- All kernel runs complete. `date`";
366 print "\techo ---- All kernel runs complete. `date` >> " rd "/log";
367 print "fi"
368 for (j = 1; j < jn; j++) {
369 builddir=KVM "/b" j
370 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
371 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
372 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
373 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
374 }
375 }
376
377 END {
378 njobs = i;
379 nc = ncpus;
380 first = 0;
381 batchnum = 1;
382
383 # Each pass through the following loop considers one test.
384 for (i = 0; i < njobs; i++) {
385 if (ncpus == 0) {
386 # Sequential test specified, each test its own batch.
387 dump(i, i + 1, batchnum);
388 first = i;
389 batchnum++;
390 } else if (nc < cpus[i] && i != 0) {
391 # Out of CPUs, dump out a batch.
392 dump(first, i, batchnum);
393 first = i;
394 nc = ncpus;
395 batchnum++;
396 }
397 # Account for the CPUs needed by the current test.
398 nc -= cpus[i];
399 }
400 # Dump the last batch.
401 if (ncpus != 0)
402 dump(first, i, batchnum);
403 }' >> $T/script
404
405 cat << ___EOF___ >> $T/script
406 echo
407 echo
408 echo " --- `date` Test summary:"
409 echo Results directory: $resdir/$ds
410 kvm-recheck.sh $resdir/$ds
411 ___EOF___
412
413 if test "$dryrun" = script
414 then
415 cat $T/script
416 exit 0
417 elif test "$dryrun" = sched
418 then
419 # Extract the test run schedule from the script.
420 egrep 'Start batch|Starting build\.' $T/script |
421 grep -v ">>" |
422 sed -e 's/:.*$//' -e 's/^echo //'
423 exit 0
424 else
425 # Not a dryrun, so run the script.
426 sh $T/script
427 fi
428
429 # 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