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 45touch $T 46 47. $KVM/bin/functions.sh 48. $KVPATH/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="-nographic $qemu_args" 142cpu_count=`configNR_CPUS.sh $config_template` 143vcpus=`identify_qemu_vcpus` 144if test $cpu_count -gt $vcpus 145then 146 echo CPU count limited from $cpu_count to $vcpus 147 touch $resdir/Warnings 148 echo CPU count limited from $cpu_count to $vcpus >> $resdir/Warnings 149 cpu_count=$vcpus 150fi 151qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`" 152 153# Generate architecture-specific and interaction-specific qemu arguments 154qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$builddir/console.log"`" 155 156# Generate qemu -append arguments 157qemu_append="`identify_qemu_append "$QEMU"`" 158 159# Pull in Kconfig-fragment boot parameters 160boot_args="`configfrag_boot_params "$boot_args" "$config_template"`" 161# Generate kernel-version-specific boot parameters 162boot_args="`per_version_boot_params "$boot_args" $builddir/.config $seconds`" 163 164if test -n "$TORTURE_BUILDONLY" 165then 166 echo Build-only run specified, boot/test omitted. 167 touch $resdir/buildonly 168 exit 0 169fi 170echo $QEMU $qemu_args -m 512 -kernel $builddir/$BOOT_IMAGE -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd 171( $QEMU $qemu_args -m 512 -kernel $builddir/$BOOT_IMAGE -append "$qemu_append $boot_args"; echo $? > $resdir/qemu-retval ) & 172qemu_pid=$! 173commandcompleted=0 174echo Monitoring qemu job at pid $qemu_pid 175while : 176do 177 kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null` 178 if kill -0 $qemu_pid > /dev/null 2>&1 179 then 180 if test $kruntime -ge $seconds 181 then 182 break; 183 fi 184 sleep 1 185 else 186 commandcompleted=1 187 if test $kruntime -lt $seconds 188 then 189 echo Completed in $kruntime vs. $seconds >> $resdir/Warnings 2>&1 190 grep "^(qemu) qemu:" $resdir/kvm-test-1-run.sh.out >> $resdir/Warnings 2>&1 191 killpid="`sed -n "s/^(qemu) qemu: terminating on signal [0-9]* from pid \([0-9]*\).*$/\1/p" $resdir/Warnings`" 192 if test -n "$killpid" 193 then 194 echo "ps -fp $killpid" >> $resdir/Warnings 2>&1 195 ps -fp $killpid >> $resdir/Warnings 2>&1 196 fi 197 else 198 echo ' ---' `date`: Kernel done 199 fi 200 break 201 fi 202done 203if test $commandcompleted -eq 0 204then 205 echo Grace period for qemu job at pid $qemu_pid 206 while : 207 do 208 kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null` 209 if kill -0 $qemu_pid > /dev/null 2>&1 210 then 211 : 212 else 213 break 214 fi 215 if test $kruntime -ge $((seconds + grace)) 216 then 217 echo "!!! Hang at $kruntime vs. $seconds seconds" >> $resdir/Warnings 2>&1 218 kill -KILL $qemu_pid 219 break 220 fi 221 sleep 1 222 done 223fi 224 225cp $builddir/console.log $resdir 226parse-torture.sh $resdir/console.log $title 227parse-console.sh $resdir/console.log $title 228