blob: 86e6ffe6df45dfa472d3072915c67937cec3fa5c [file] [log] [blame]
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -07001#!/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#
Paul E. McKenneyd3b15482014-02-06 20:35:41 -08009# Usage: sh kvm-test-1-run.sh config builddir resdir minutes qemu-args boot_args
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070010#
Paul E. McKenneyd3b15482014-02-06 20:35:41 -080011# 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.
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070016#
Paul E. McKenney4a261db2014-01-13 22:57:48 -080017# Anything you specify for either qemu-args or boot_args is appended to
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070018# 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
Paul E. McKenney0e342a82013-12-03 09:54:18 -080034# along with this program; if not, you can access it online at
35# http://www.gnu.org/licenses/gpl-2.0.html.
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070036#
37# Copyright (C) IBM Corporation, 2011
38#
39# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
40
41grace=120
42
Paul E. McKenneyd3b15482014-02-06 20:35:41 -080043T=/tmp/kvm-test-1-run.sh.$$
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070044trap 'rm -rf $T' 0
45
46. $KVM/bin/functions.sh
Paul E. McKenney4275be82013-09-29 11:13:46 -070047. $KVPATH/ver_functions.sh
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070048
49config_template=${1}
Paul E. McKenneyd2ebf7e2014-02-06 11:54:32 -080050config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'`
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070051title=`echo $config_template | sed -e 's/^.*\///'`
52builddir=${2}
53if test -z "$builddir" -o ! -d "$builddir" -o ! -w "$builddir"
54then
Paul E. McKenneyd3b15482014-02-06 20:35:41 -080055 echo "kvm-test-1-run.sh :$builddir: Not a writable directory, cannot build into it"
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070056 exit 1
57fi
58resdir=${3}
59if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"
60then
Paul E. McKenneyd3b15482014-02-06 20:35:41 -080061 echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it"
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070062 exit 1
63fi
64cp $config_template $resdir/ConfigFragment
65echo ' ---' `date`: Starting build
Paul E. McKenney330a76f2013-09-30 14:49:43 -070066echo ' ---' Kconfig fragment at: $config_template >> $resdir/log
Paul E. McKenneyd2ebf7e2014-02-06 11:54:32 -080067if test -r "$config_dir/CFcommon"
68then
69 cat < $config_dir/CFcommon >> $T
70fi
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070071# 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
95if kvm-build.sh $config_template $builddir $T
96then
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
Paul E. McKenneybad80442014-01-13 23:16:55 -0800101 if test -f $builddir.wait
102 then
103 mv $builddir.wait $builddir.ready
104 fi
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700105else
106 cp $builddir/Make*.out $resdir
107 echo Build failed, not running KVM, see $resdir.
Paul E. McKenneybad80442014-01-13 23:16:55 -0800108 if test -f $builddir.wait
109 then
110 mv $builddir.wait $builddir.ready
111 fi
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700112 exit 1
113fi
Paul E. McKenneybad80442014-01-13 23:16:55 -0800114while test -f $builddir.ready
115do
116 sleep 1
117done
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700118minutes=$4
119seconds=$(($minutes * 60))
120qemu_args=$5
121boot_args=$6
122
123cd $KVM
124kstarttime=`awk 'BEGIN { print systime() }' < /dev/null`
125echo ' ---' `date`: Starting kernel
Paul E. McKenney4f8a0312013-09-30 17:17:57 -0700126
127# Determine the appropriate flavor of qemu command.
Paul E. McKenney43e38ab2014-01-15 15:48:41 -0800128QEMU="`identify_qemu $builddir/vmlinux`"
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700129
130# Generate -smp qemu argument.
Paul E. McKenney16d301c2014-01-14 21:28:57 -0800131qemu_args="-nographic $qemu_args"
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700132cpu_count=`configNR_CPUS.sh $config_template`
Paul E. McKenney315c5402013-10-04 13:15:55 -0700133vcpus=`identify_qemu_vcpus`
134if test $cpu_count -gt $vcpus
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700135then
Paul E. McKenney315c5402013-10-04 13:15:55 -0700136 echo CPU count limited from $cpu_count to $vcpus
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700137 touch $resdir/Warnings
Paul E. McKenney315c5402013-10-04 13:15:55 -0700138 echo CPU count limited from $cpu_count to $vcpus >> $resdir/Warnings
139 cpu_count=$vcpus
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700140fi
Paul E. McKenney315c5402013-10-04 13:15:55 -0700141qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"
142
143# Generate architecture-specific and interaction-specific qemu arguments
144qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$builddir/console.log"`"
145
146# Generate qemu -append arguments
147qemu_append="`identify_qemu_append "$QEMU"`"
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700148
Paul E. McKenneybe70a732013-10-09 11:02:00 -0700149# Pull in Kconfig-fragment boot parameters
150boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
Paul E. McKenneya5afdeb2014-02-06 17:50:32 -0800151# Generate kernel-version-specific boot parameters
152boot_args="`per_version_boot_params "$boot_args" $builddir/.config $seconds`"
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700153
Paul E. McKenneybe70a732013-10-09 11:02:00 -0700154echo $QEMU $qemu_args -m 512 -kernel $builddir/arch/x86/boot/bzImage -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd
Paul E. McKenney805ffee2014-02-26 15:39:41 -0800155if test -n "$TORTURE_BUILDONLY"
Paul E. McKenney11274812013-10-10 14:52:07 -0700156then
157 echo Build-only run specified, boot/test omitted.
158 exit 0
159fi
Paul E. McKenneybe70a732013-10-09 11:02:00 -0700160$QEMU $qemu_args -m 512 -kernel $builddir/arch/x86/boot/bzImage -append "$qemu_append $boot_args" &
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700161qemu_pid=$!
162commandcompleted=0
163echo Monitoring qemu job at pid $qemu_pid
164for ((i=0;i<$seconds;i++))
165do
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
180done
181if test $commandcompleted -eq 0
182then
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
199fi
200
201cp $builddir/console.log $resdir
Paul E. McKenney4074b512014-02-26 10:57:04 -0800202parse-torture.sh $resdir/console.log $title
Paul E. McKenney6d40cc02013-10-28 06:34:22 -0700203parse-console.sh $resdir/console.log $title