Merge branch 'for-4.5/drivers' of git://git.kernel.dk/linux-block
[linux-2.6-block.git] / tools / testing / selftests / rcutorture / bin / kvm-test-1-run.sh
1 #!/bin/bash
2 #
3 # Run a kvm-based test of the specified tree on the specified configs.
4 # Fully automated run and error checking, no graphics console.
5 #
6 # Execute this in the source tree.  Do not run it as a background task
7 # because qemu does not seem to like that much.
8 #
9 # Usage: kvm-test-1-run.sh config builddir resdir minutes qemu-args boot_args
10 #
11 # qemu-args defaults to "-enable-kvm -soundhw pcspk -nographic", along with
12 #                       arguments specifying the number of CPUs and other
13 #                       options generated from the underlying CPU architecture.
14 # boot_args defaults to value returned by the per_version_boot_params
15 #                       shell function.
16 #
17 # Anything you specify for either qemu-args or boot_args is appended to
18 # the default values.  The "-smp" value is deduced from the contents of
19 # the config fragment.
20 #
21 # More sophisticated argument parsing is clearly needed.
22 #
23 # This program is free software; you can redistribute it and/or modify
24 # it under the terms of the GNU General Public License as published by
25 # the Free Software Foundation; either version 2 of the License, or
26 # (at your option) any later version.
27 #
28 # This program is distributed in the hope that it will be useful,
29 # but WITHOUT ANY WARRANTY; without even the implied warranty of
30 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31 # GNU General Public License for more details.
32 #
33 # You should have received a copy of the GNU General Public License
34 # along with this program; if not, you can access it online at
35 # http://www.gnu.org/licenses/gpl-2.0.html.
36 #
37 # Copyright (C) IBM Corporation, 2011
38 #
39 # Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
40
41 T=/tmp/kvm-test-1-run.sh.$$
42 trap 'rm -rf $T' 0
43 touch $T
44
45 . $KVM/bin/functions.sh
46 . $CONFIGFRAG/ver_functions.sh
47
48 config_template=${1}
49 config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'`
50 title=`echo $config_template | sed -e 's/^.*\///'`
51 builddir=${2}
52 if test -z "$builddir" -o ! -d "$builddir" -o ! -w "$builddir"
53 then
54         echo "kvm-test-1-run.sh :$builddir: Not a writable directory, cannot build into it"
55         exit 1
56 fi
57 resdir=${3}
58 if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"
59 then
60         echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it"
61         exit 1
62 fi
63 cp $config_template $resdir/ConfigFragment
64 echo ' ---' `date`: Starting build
65 echo ' ---' Kconfig fragment at: $config_template >> $resdir/log
66 if test -r "$config_dir/CFcommon"
67 then
68         cat < $config_dir/CFcommon >> $T
69 fi
70 # Optimizations below this point
71 # CONFIG_USB=n
72 # CONFIG_SECURITY=n
73 # CONFIG_NFS_FS=n
74 # CONFIG_SOUND=n
75 # CONFIG_INPUT_JOYSTICK=n
76 # CONFIG_INPUT_TABLET=n
77 # CONFIG_INPUT_TOUCHSCREEN=n
78 # CONFIG_INPUT_MISC=n
79 # CONFIG_INPUT_MOUSE=n
80 # # CONFIG_NET=n # disables console access, so accept the slower build.
81 # CONFIG_SCSI=n
82 # CONFIG_ATA=n
83 # CONFIG_FAT_FS=n
84 # CONFIG_MSDOS_FS=n
85 # CONFIG_VFAT_FS=n
86 # CONFIG_ISO9660_FS=n
87 # CONFIG_QUOTA=n
88 # CONFIG_HID=n
89 # CONFIG_CRYPTO=n
90 # CONFIG_PCCARD=n
91 # CONFIG_PCMCIA=n
92 # CONFIG_CARDBUS=n
93 # CONFIG_YENTA=n
94 if kvm-build.sh $config_template $builddir $T
95 then
96         QEMU="`identify_qemu $builddir/vmlinux`"
97         BOOT_IMAGE="`identify_boot_image $QEMU`"
98         cp $builddir/Make*.out $resdir
99         cp $builddir/.config $resdir
100         if test -n "$BOOT_IMAGE"
101         then
102                 cp $builddir/$BOOT_IMAGE $resdir
103         else
104                 echo No identifiable boot image, not running KVM, see $resdir.
105                 echo Do the torture scripts know about your architecture?
106         fi
107         parse-build.sh $resdir/Make.out $title
108         if test -f $builddir.wait
109         then
110                 mv $builddir.wait $builddir.ready
111         fi
112 else
113         cp $builddir/Make*.out $resdir
114         cp $builddir/.config $resdir || :
115         echo Build failed, not running KVM, see $resdir.
116         if test -f $builddir.wait
117         then
118                 mv $builddir.wait $builddir.ready
119         fi
120         exit 1
121 fi
122 while test -f $builddir.ready
123 do
124         sleep 1
125 done
126 minutes=$4
127 seconds=$(($minutes * 60))
128 qemu_args=$5
129 boot_args=$6
130
131 cd $KVM
132 kstarttime=`awk 'BEGIN { print systime() }' < /dev/null`
133 if test -z "$TORTURE_BUILDONLY"
134 then
135         echo ' ---' `date`: Starting kernel
136 fi
137
138 # Generate -smp qemu argument.
139 qemu_args="-enable-kvm -soundhw pcspk -nographic $qemu_args"
140 cpu_count=`configNR_CPUS.sh $config_template`
141 cpu_count=`configfrag_boot_cpus "$boot_args" "$config_template" "$cpu_count"`
142 vcpus=`identify_qemu_vcpus`
143 if test $cpu_count -gt $vcpus
144 then
145         echo CPU count limited from $cpu_count to $vcpus
146         touch $resdir/Warnings
147         echo CPU count limited from $cpu_count to $vcpus >> $resdir/Warnings
148         cpu_count=$vcpus
149 fi
150 qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"
151
152 # Generate architecture-specific and interaction-specific qemu arguments
153 qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$resdir/console.log"`"
154
155 # Generate qemu -append arguments
156 qemu_append="`identify_qemu_append "$QEMU"`"
157
158 # Pull in Kconfig-fragment boot parameters
159 boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
160 # Generate kernel-version-specific boot parameters
161 boot_args="`per_version_boot_params "$boot_args" $builddir/.config $seconds`"
162
163 if test -n "$TORTURE_BUILDONLY"
164 then
165         echo Build-only run specified, boot/test omitted.
166         touch $resdir/buildonly
167         exit 0
168 fi
169 echo "NOTE: $QEMU either did not run or was interactive" > $resdir/console.log
170 echo $QEMU $qemu_args -m 512 -kernel $resdir/bzImage -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd
171 ( $QEMU $qemu_args -m 512 -kernel $resdir/bzImage -append "$qemu_append $boot_args"; echo $? > $resdir/qemu-retval ) &
172 qemu_pid=$!
173 commandcompleted=0
174 echo Monitoring qemu job at pid $qemu_pid
175 while :
176 do
177         kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
178         if kill -0 $qemu_pid > /dev/null 2>&1
179         then
180                 if test $kruntime -ge $seconds
181                 then
182                         break;
183                 fi
184                 sleep 1
185         else
186                 commandcompleted=1
187                 if test $kruntime -lt $seconds
188                 then
189                         echo Completed in $kruntime vs. $seconds >> $resdir/Warnings 2>&1
190                         grep "^(qemu) qemu:" $resdir/kvm-test-1-run.sh.out >> $resdir/Warnings 2>&1
191                         killpid="`sed -n "s/^(qemu) qemu: terminating on signal [0-9]* from pid \([0-9]*\).*$/\1/p" $resdir/Warnings`"
192                         if test -n "$killpid"
193                         then
194                                 echo "ps -fp $killpid" >> $resdir/Warnings 2>&1
195                                 ps -fp $killpid >> $resdir/Warnings 2>&1
196                         fi
197                 else
198                         echo ' ---' `date`: Kernel done
199                 fi
200                 break
201         fi
202 done
203 if test $commandcompleted -eq 0
204 then
205         echo Grace period for qemu job at pid $qemu_pid
206         while :
207         do
208                 kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
209                 if kill -0 $qemu_pid > /dev/null 2>&1
210                 then
211                         :
212                 else
213                         break
214                 fi
215                 if test $kruntime -ge $((seconds + $TORTURE_SHUTDOWN_GRACE))
216                 then
217                         echo "!!! PID $qemu_pid hung at $kruntime vs. $seconds seconds" >> $resdir/Warnings 2>&1
218                         kill -KILL $qemu_pid
219                         break
220                 fi
221                 sleep 1
222         done
223 fi
224
225 parse-torture.sh $resdir/console.log $title
226 parse-console.sh $resdir/console.log $title