Merge branch 'acpi-ec'
[linux-drm-fsl-dcu.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 grace=120
42
43 T=/tmp/kvm-test-1-run.sh.$$
44 trap 'rm -rf $T' 0
45 touch $T
46
47 . $KVM/bin/functions.sh
48 . $CONFIGFRAG/ver_functions.sh
49
50 config_template=${1}
51 config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'`
52 title=`echo $config_template | sed -e 's/^.*\///'`
53 builddir=${2}
54 if test -z "$builddir" -o ! -d "$builddir" -o ! -w "$builddir"
55 then
56         echo "kvm-test-1-run.sh :$builddir: Not a writable directory, cannot build into it"
57         exit 1
58 fi
59 resdir=${3}
60 if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"
61 then
62         echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it"
63         exit 1
64 fi
65 cp $config_template $resdir/ConfigFragment
66 echo ' ---' `date`: Starting build
67 echo ' ---' Kconfig fragment at: $config_template >> $resdir/log
68 if test -r "$config_dir/CFcommon"
69 then
70         cat < $config_dir/CFcommon >> $T
71 fi
72 # Optimizations below this point
73 # CONFIG_USB=n
74 # CONFIG_SECURITY=n
75 # CONFIG_NFS_FS=n
76 # CONFIG_SOUND=n
77 # CONFIG_INPUT_JOYSTICK=n
78 # CONFIG_INPUT_TABLET=n
79 # CONFIG_INPUT_TOUCHSCREEN=n
80 # CONFIG_INPUT_MISC=n
81 # CONFIG_INPUT_MOUSE=n
82 # # CONFIG_NET=n # disables console access, so accept the slower build.
83 # CONFIG_SCSI=n
84 # CONFIG_ATA=n
85 # CONFIG_FAT_FS=n
86 # CONFIG_MSDOS_FS=n
87 # CONFIG_VFAT_FS=n
88 # CONFIG_ISO9660_FS=n
89 # CONFIG_QUOTA=n
90 # CONFIG_HID=n
91 # CONFIG_CRYPTO=n
92 # CONFIG_PCCARD=n
93 # CONFIG_PCMCIA=n
94 # CONFIG_CARDBUS=n
95 # CONFIG_YENTA=n
96 if kvm-build.sh $config_template $builddir $T
97 then
98         QEMU="`identify_qemu $builddir/vmlinux`"
99         BOOT_IMAGE="`identify_boot_image $QEMU`"
100         cp $builddir/Make*.out $resdir
101         cp $builddir/.config $resdir
102         if test -n "$BOOT_IMAGE"
103         then
104                 cp $builddir/$BOOT_IMAGE $resdir
105         else
106                 echo No identifiable boot image, not running KVM, see $resdir.
107                 echo Do the torture scripts know about your architecture?
108         fi
109         parse-build.sh $resdir/Make.out $title
110         if test -f $builddir.wait
111         then
112                 mv $builddir.wait $builddir.ready
113         fi
114 else
115         cp $builddir/Make*.out $resdir
116         cp $builddir/.config $resdir || :
117         echo Build failed, not running KVM, see $resdir.
118         if test -f $builddir.wait
119         then
120                 mv $builddir.wait $builddir.ready
121         fi
122         exit 1
123 fi
124 while test -f $builddir.ready
125 do
126         sleep 1
127 done
128 minutes=$4
129 seconds=$(($minutes * 60))
130 qemu_args=$5
131 boot_args=$6
132
133 cd $KVM
134 kstarttime=`awk 'BEGIN { print systime() }' < /dev/null`
135 if test -z "$TORTURE_BUILDONLY"
136 then
137         echo ' ---' `date`: Starting kernel
138 fi
139
140 # Generate -smp qemu argument.
141 qemu_args="-enable-kvm -soundhw pcspk -nographic $qemu_args"
142 cpu_count=`configNR_CPUS.sh $config_template`
143 cpu_count=`configfrag_boot_cpus "$boot_args" "$config_template" "$cpu_count"`
144 vcpus=`identify_qemu_vcpus`
145 if test $cpu_count -gt $vcpus
146 then
147         echo CPU count limited from $cpu_count to $vcpus
148         touch $resdir/Warnings
149         echo CPU count limited from $cpu_count to $vcpus >> $resdir/Warnings
150         cpu_count=$vcpus
151 fi
152 qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"
153
154 # Generate architecture-specific and interaction-specific qemu arguments
155 qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$builddir/console.log"`"
156
157 # Generate qemu -append arguments
158 qemu_append="`identify_qemu_append "$QEMU"`"
159
160 # Pull in Kconfig-fragment boot parameters
161 boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
162 # Generate kernel-version-specific boot parameters
163 boot_args="`per_version_boot_params "$boot_args" $builddir/.config $seconds`"
164
165 if test -n "$TORTURE_BUILDONLY"
166 then
167         echo Build-only run specified, boot/test omitted.
168         touch $resdir/buildonly
169         exit 0
170 fi
171 echo "NOTE: $QEMU either did not run or was interactive" > $builddir/console.log
172 echo $QEMU $qemu_args -m 512 -kernel $resdir/bzImage -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd
173 ( $QEMU $qemu_args -m 512 -kernel $resdir/bzImage -append "$qemu_append $boot_args"; echo $? > $resdir/qemu-retval ) &
174 qemu_pid=$!
175 commandcompleted=0
176 echo Monitoring qemu job at pid $qemu_pid
177 while :
178 do
179         kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
180         if kill -0 $qemu_pid > /dev/null 2>&1
181         then
182                 if test $kruntime -ge $seconds
183                 then
184                         break;
185                 fi
186                 sleep 1
187         else
188                 commandcompleted=1
189                 if test $kruntime -lt $seconds
190                 then
191                         echo Completed in $kruntime vs. $seconds >> $resdir/Warnings 2>&1
192                         grep "^(qemu) qemu:" $resdir/kvm-test-1-run.sh.out >> $resdir/Warnings 2>&1
193                         killpid="`sed -n "s/^(qemu) qemu: terminating on signal [0-9]* from pid \([0-9]*\).*$/\1/p" $resdir/Warnings`"
194                         if test -n "$killpid"
195                         then
196                                 echo "ps -fp $killpid" >> $resdir/Warnings 2>&1
197                                 ps -fp $killpid >> $resdir/Warnings 2>&1
198                         fi
199                 else
200                         echo ' ---' `date`: Kernel done
201                 fi
202                 break
203         fi
204 done
205 if test $commandcompleted -eq 0
206 then
207         echo Grace period for qemu job at pid $qemu_pid
208         while :
209         do
210                 kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
211                 if kill -0 $qemu_pid > /dev/null 2>&1
212                 then
213                         :
214                 else
215                         break
216                 fi
217                 if test $kruntime -ge $((seconds + grace))
218                 then
219                         echo "!!! PID $qemu_pid hung at $kruntime vs. $seconds seconds" >> $resdir/Warnings 2>&1
220                         kill -KILL $qemu_pid
221                         break
222                 fi
223                 sleep 1
224         done
225 fi
226
227 cp $builddir/console.log $resdir
228 parse-torture.sh $resdir/console.log $title
229 parse-console.sh $resdir/console.log $title