Merge tag 'efi-urgent' of git://git.kernel.org/pub/scm/linux/kernel/git/mfleming...
[cascardo/linux.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: sh kvm-test-1-run.sh config builddir resdir minutes qemu-args boot_args
10 #
11 # qemu-args defaults to "-nographic", along with arguments specifying the
12 #                       number of CPUs and other options generated from
13 #                       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
46 . $KVM/bin/functions.sh
47 . $KVPATH/ver_functions.sh
48
49 config_template=${1}
50 config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'`
51 title=`echo $config_template | sed -e 's/^.*\///'`
52 builddir=${2}
53 if test -z "$builddir" -o ! -d "$builddir" -o ! -w "$builddir"
54 then
55         echo "kvm-test-1-run.sh :$builddir: Not a writable directory, cannot build into it"
56         exit 1
57 fi
58 resdir=${3}
59 if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"
60 then
61         echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it"
62         exit 1
63 fi
64 cp $config_template $resdir/ConfigFragment
65 echo ' ---' `date`: Starting build
66 echo ' ---' Kconfig fragment at: $config_template >> $resdir/log
67 if test -r "$config_dir/CFcommon"
68 then
69         cat < $config_dir/CFcommon >> $T
70 fi
71 # Optimizations below this point
72 # CONFIG_USB=n
73 # CONFIG_SECURITY=n
74 # CONFIG_NFS_FS=n
75 # CONFIG_SOUND=n
76 # CONFIG_INPUT_JOYSTICK=n
77 # CONFIG_INPUT_TABLET=n
78 # CONFIG_INPUT_TOUCHSCREEN=n
79 # CONFIG_INPUT_MISC=n
80 # CONFIG_INPUT_MOUSE=n
81 # # CONFIG_NET=n # disables console access, so accept the slower build.
82 # CONFIG_SCSI=n
83 # CONFIG_ATA=n
84 # CONFIG_FAT_FS=n
85 # CONFIG_MSDOS_FS=n
86 # CONFIG_VFAT_FS=n
87 # CONFIG_ISO9660_FS=n
88 # CONFIG_QUOTA=n
89 # CONFIG_HID=n
90 # CONFIG_CRYPTO=n
91 # CONFIG_PCCARD=n
92 # CONFIG_PCMCIA=n
93 # CONFIG_CARDBUS=n
94 # CONFIG_YENTA=n
95 if kvm-build.sh $config_template $builddir $T
96 then
97         cp $builddir/Make*.out $resdir
98         cp $builddir/.config $resdir
99         cp $builddir/arch/x86/boot/bzImage $resdir
100         parse-build.sh $resdir/Make.out $title
101         if test -f $builddir.wait
102         then
103                 mv $builddir.wait $builddir.ready
104         fi
105 else
106         cp $builddir/Make*.out $resdir
107         echo Build failed, not running KVM, see $resdir.
108         if test -f $builddir.wait
109         then
110                 mv $builddir.wait $builddir.ready
111         fi
112         exit 1
113 fi
114 while test -f $builddir.ready
115 do
116         sleep 1
117 done
118 minutes=$4
119 seconds=$(($minutes * 60))
120 qemu_args=$5
121 boot_args=$6
122
123 cd $KVM
124 kstarttime=`awk 'BEGIN { print systime() }' < /dev/null`
125 echo ' ---' `date`: Starting kernel
126
127 # Determine the appropriate flavor of qemu command.
128 QEMU="`identify_qemu $builddir/vmlinux`"
129
130 # Generate -smp qemu argument.
131 qemu_args="-nographic $qemu_args"
132 cpu_count=`configNR_CPUS.sh $config_template`
133 vcpus=`identify_qemu_vcpus`
134 if test $cpu_count -gt $vcpus
135 then
136         echo CPU count limited from $cpu_count to $vcpus
137         touch $resdir/Warnings
138         echo CPU count limited from $cpu_count to $vcpus >> $resdir/Warnings
139         cpu_count=$vcpus
140 fi
141 qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"
142
143 # Generate architecture-specific and interaction-specific qemu arguments
144 qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$builddir/console.log"`"
145
146 # Generate qemu -append arguments
147 qemu_append="`identify_qemu_append "$QEMU"`"
148
149 # Pull in Kconfig-fragment boot parameters
150 boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
151 # Generate kernel-version-specific boot parameters
152 boot_args="`per_version_boot_params "$boot_args" $builddir/.config $seconds`"
153
154 echo $QEMU $qemu_args -m 512 -kernel $builddir/arch/x86/boot/bzImage -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd
155 if test -n "$RCU_BUILDONLY"
156 then
157         echo Build-only run specified, boot/test omitted.
158         exit 0
159 fi
160 $QEMU $qemu_args -m 512 -kernel $builddir/arch/x86/boot/bzImage -append "$qemu_append $boot_args" &
161 qemu_pid=$!
162 commandcompleted=0
163 echo Monitoring qemu job at pid $qemu_pid
164 for ((i=0;i<$seconds;i++))
165 do
166         if kill -0 $qemu_pid > /dev/null 2>&1
167         then
168                 sleep 1
169         else
170                 commandcompleted=1
171                 kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
172                 if test $kruntime -lt $seconds
173                 then
174                         echo Completed in $kruntime vs. $seconds >> $resdir/Warnings 2>&1
175                 else
176                         echo ' ---' `date`: Kernel done
177                 fi
178                 break
179         fi
180 done
181 if test $commandcompleted -eq 0
182 then
183         echo Grace period for qemu job at pid $qemu_pid
184         for ((i=0;i<=$grace;i++))
185         do
186                 if kill -0 $qemu_pid > /dev/null 2>&1
187                 then
188                         sleep 1
189                 else
190                         break
191                 fi
192                 if test $i -eq $grace
193                 then
194                         kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }'`
195                         echo "!!! Hang at $kruntime vs. $seconds seconds" >> $resdir/Warnings 2>&1
196                         kill -KILL $qemu_pid
197                 fi
198         done
199 fi
200
201 cp $builddir/console.log $resdir
202 parse-${TORTURE_SUITE}torture.sh $resdir/console.log $title
203 parse-console.sh $resdir/console.log $title