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 41grace=120 42 43T=/tmp/kvm-test-1-run.sh.$$ 44trap 'rm -rf $T' 0 45touch $T 46 47. $KVM/bin/functions.sh 48. $CONFIGFRAG/ver_functions.sh 49 50config_template=${1} 51config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'` 52title=`echo $config_template | sed -e 's/^.*\///'` 53builddir=${2} 54if test -z "$builddir" -o ! -d "$builddir" -o ! -w "$builddir" 55then 56 echo "kvm-test-1-run.sh :$builddir: Not a writable directory, cannot build into it" 57 exit 1 58fi 59resdir=${3} 60if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir" 61then 62 echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it" 63 exit 1 64fi 65cp $config_template $resdir/ConfigFragment 66echo ' ---' `date`: Starting build 67echo ' ---' Kconfig fragment at: $config_template >> $resdir/log 68if test -r "$config_dir/CFcommon" 69then 70 cat < $config_dir/CFcommon >> $T 71fi 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 96if kvm-build.sh $config_template $builddir $T 97then 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 114else 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 123fi 124while test -f $builddir.ready 125do 126 sleep 1 127done 128minutes=$4 129seconds=$(($minutes * 60)) 130qemu_args=$5 131boot_args=$6 132 133cd $KVM 134kstarttime=`awk 'BEGIN { print systime() }' < /dev/null` 135if test -z "$TORTURE_BUILDONLY" 136then 137 echo ' ---' `date`: Starting kernel 138fi 139 140# Generate -smp qemu argument. 141qemu_args="-enable-kvm -soundhw pcspk -nographic $qemu_args" 142cpu_count=`configNR_CPUS.sh $config_template` 143cpu_count=`configfrag_boot_cpus "$boot_args" "$config_template" "$cpu_count"` 144vcpus=`identify_qemu_vcpus` 145if test $cpu_count -gt $vcpus 146then 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 151fi 152qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`" 153 154# Generate architecture-specific and interaction-specific qemu arguments 155qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$builddir/console.log"`" 156 157# Generate qemu -append arguments 158qemu_append="`identify_qemu_append "$QEMU"`" 159 160# Pull in Kconfig-fragment boot parameters 161boot_args="`configfrag_boot_params "$boot_args" "$config_template"`" 162# Generate kernel-version-specific boot parameters 163boot_args="`per_version_boot_params "$boot_args" $builddir/.config $seconds`" 164 165if test -n "$TORTURE_BUILDONLY" 166then 167 echo Build-only run specified, boot/test omitted. 168 touch $resdir/buildonly 169 exit 0 170fi 171echo "NOTE: $QEMU either did not run or was interactive" > $builddir/console.log 172echo $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 ) & 174qemu_pid=$! 175commandcompleted=0 176echo Monitoring qemu job at pid $qemu_pid 177while : 178do 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 204done 205if test $commandcompleted -eq 0 206then 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 225fi 226 227cp $builddir/console.log $resdir 228parse-torture.sh $resdir/console.log $title 229parse-console.sh $resdir/console.log $title 230