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