kvm-test-1-run.sh 8.1 KB
Newer Older
1 2 3 4 5 6 7 8
#!/bin/bash
#
# Run a kvm-based test of the specified tree on the specified configs.
# Fully automated run and error checking, no graphics console.
#
# Execute this in the source tree.  Do not run it as a background task
# because qemu does not seem to like that much.
#
9
# Usage: kvm-test-1-run.sh config builddir resdir seconds qemu-args boot_args
10
#
11 12 13
# qemu-args defaults to "-enable-kvm -nographic", along with arguments
#			specifying the number of CPUs and other options
#			generated from the underlying CPU architecture.
14 15
# boot_args defaults to value returned by the per_version_boot_params
#			shell function.
16
#
17
# Anything you specify for either qemu-args or boot_args is appended to
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
# the default values.  The "-smp" value is deduced from the contents of
# the config fragment.
#
# More sophisticated argument parsing is clearly needed.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
34 35
# along with this program; if not, you can access it online at
# http://www.gnu.org/licenses/gpl-2.0.html.
36 37 38 39 40
#
# Copyright (C) IBM Corporation, 2011
#
# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>

41
T=/tmp/kvm-test-1-run.sh.$$
42
trap 'rm -rf $T' 0
43
touch $T
44 45

. $KVM/bin/functions.sh
46
. $CONFIGFRAG/ver_functions.sh
47 48

config_template=${1}
49
config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'`
50 51 52 53
title=`echo $config_template | sed -e 's/^.*\///'`
builddir=${2}
if test -z "$builddir" -o ! -d "$builddir" -o ! -w "$builddir"
then
54
	echo "kvm-test-1-run.sh :$builddir: Not a writable directory, cannot build into it"
55 56 57 58 59
	exit 1
fi
resdir=${3}
if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"
then
60
	echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it"
61 62 63 64
	exit 1
fi
cp $config_template $resdir/ConfigFragment
echo ' ---' `date`: Starting build
65
echo ' ---' Kconfig fragment at: $config_template >> $resdir/log
66 67 68 69
if test -r "$config_dir/CFcommon"
then
	cat < $config_dir/CFcommon >> $T
fi
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
# Optimizations below this point
# CONFIG_USB=n
# CONFIG_SECURITY=n
# CONFIG_NFS_FS=n
# CONFIG_SOUND=n
# CONFIG_INPUT_JOYSTICK=n
# CONFIG_INPUT_TABLET=n
# CONFIG_INPUT_TOUCHSCREEN=n
# CONFIG_INPUT_MISC=n
# CONFIG_INPUT_MOUSE=n
# # CONFIG_NET=n # disables console access, so accept the slower build.
# CONFIG_SCSI=n
# CONFIG_ATA=n
# CONFIG_FAT_FS=n
# CONFIG_MSDOS_FS=n
# CONFIG_VFAT_FS=n
# CONFIG_ISO9660_FS=n
# CONFIG_QUOTA=n
# CONFIG_HID=n
# CONFIG_CRYPTO=n
# CONFIG_PCCARD=n
# CONFIG_PCMCIA=n
# CONFIG_CARDBUS=n
# CONFIG_YENTA=n
94 95
base_resdir=`echo $resdir | sed -e 's/\.[0-9]\+$//'`
if test "$base_resdir" != "$resdir" -a -f $base_resdir/bzImage -a -f $base_resdir/vmlinux
96
then
97 98
	# Rerunning previous test, so use that test's kernel.
	QEMU="`identify_qemu $base_resdir/vmlinux`"
99 100
	BOOT_IMAGE="`identify_boot_image $QEMU`"
	KERNEL=$base_resdir/${BOOT_IMAGE##*/} # use the last component of ${BOOT_IMAGE}
101 102 103 104 105
	ln -s $base_resdir/Make*.out $resdir  # for kvm-recheck.sh
	ln -s $base_resdir/.config $resdir  # for kvm-recheck.sh
elif kvm-build.sh $config_template $builddir $T
then
	# Had to build a kernel for this test.
106 107
	QEMU="`identify_qemu $builddir/vmlinux`"
	BOOT_IMAGE="`identify_boot_image $QEMU`"
108
	cp $builddir/Make*.out $resdir
109
	cp $builddir/vmlinux $resdir
110
	cp $builddir/.config $resdir
111 112 113
	if test -n "$BOOT_IMAGE"
	then
		cp $builddir/$BOOT_IMAGE $resdir
114
		KERNEL=$resdir/${BOOT_IMAGE##*/}
115 116 117 118
	else
		echo No identifiable boot image, not running KVM, see $resdir.
		echo Do the torture scripts know about your architecture?
	fi
119 120
	parse-build.sh $resdir/Make.out $title
else
121
	# Build failed.
122
	cp $builddir/Make*.out $resdir
123
	cp $builddir/.config $resdir || :
124
	echo Build failed, not running KVM, see $resdir.
125 126 127 128
	if test -f $builddir.wait
	then
		mv $builddir.wait $builddir.ready
	fi
129 130
	exit 1
fi
131 132 133 134
if test -f $builddir.wait
then
	mv $builddir.wait $builddir.ready
fi
135 136 137 138
while test -f $builddir.ready
do
	sleep 1
done
139
seconds=$4
140 141 142 143 144
qemu_args=$5
boot_args=$6

cd $KVM
kstarttime=`awk 'BEGIN { print systime() }' < /dev/null`
145 146 147 148
if test -z "$TORTURE_BUILDONLY"
then
	echo ' ---' `date`: Starting kernel
fi
149

150
# Generate -smp qemu argument.
151
qemu_args="-enable-kvm -nographic $qemu_args"
152
cpu_count=`configNR_CPUS.sh $config_template`
153
cpu_count=`configfrag_boot_cpus "$boot_args" "$config_template" "$cpu_count"`
154 155
vcpus=`identify_qemu_vcpus`
if test $cpu_count -gt $vcpus
156
then
157
	echo CPU count limited from $cpu_count to $vcpus
158
	touch $resdir/Warnings
159 160
	echo CPU count limited from $cpu_count to $vcpus >> $resdir/Warnings
	cpu_count=$vcpus
161
fi
162 163 164
qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"

# Generate architecture-specific and interaction-specific qemu arguments
165
qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$resdir/console.log"`"
166 167 168

# Generate qemu -append arguments
qemu_append="`identify_qemu_append "$QEMU"`"
169

170 171
# Pull in Kconfig-fragment boot parameters
boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
172 173
# Generate kernel-version-specific boot parameters
boot_args="`per_version_boot_params "$boot_args" $builddir/.config $seconds`"
174

175
if test -n "$TORTURE_BUILDONLY"
176 177
then
	echo Build-only run specified, boot/test omitted.
178
	touch $resdir/buildonly
179 180
	exit 0
fi
181
echo "NOTE: $QEMU either did not run or was interactive" > $resdir/console.log
182 183
echo $QEMU $qemu_args -m 512 -kernel $KERNEL -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd
( $QEMU $qemu_args -m 512 -kernel $KERNEL -append "$qemu_append $boot_args"& echo $! > $resdir/qemu_pid; wait `cat  $resdir/qemu_pid`; echo $? > $resdir/qemu-retval ) &
184
commandcompleted=0
185 186 187 188 189 190 191 192 193
sleep 10 # Give qemu's pid a chance to reach the file
if test -s "$resdir/qemu_pid"
then
	qemu_pid=`cat "$resdir/qemu_pid"`
	echo Monitoring qemu job at pid $qemu_pid
else
	qemu_pid=""
	echo Monitoring qemu job at yet-as-unknown pid
fi
194
while :
195
do
196 197 198 199
	if test -z "$qemu_pid" -a -s "$resdir/qemu_pid"
	then
		qemu_pid=`cat "$resdir/qemu_pid"`
	fi
200
	kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
201
	if test -z "$qemu_pid" || kill -0 "$qemu_pid" > /dev/null 2>&1
202
	then
203 204 205 206
		if test $kruntime -ge $seconds
		then
			break;
		fi
207 208 209 210 211 212
		sleep 1
	else
		commandcompleted=1
		if test $kruntime -lt $seconds
		then
			echo Completed in $kruntime vs. $seconds >> $resdir/Warnings 2>&1
213 214 215 216 217 218 219
			grep "^(qemu) qemu:" $resdir/kvm-test-1-run.sh.out >> $resdir/Warnings 2>&1
			killpid="`sed -n "s/^(qemu) qemu: terminating on signal [0-9]* from pid \([0-9]*\).*$/\1/p" $resdir/Warnings`"
			if test -n "$killpid"
			then
				echo "ps -fp $killpid" >> $resdir/Warnings 2>&1
				ps -fp $killpid >> $resdir/Warnings 2>&1
			fi
220
		else
221
			echo ' ---' `date`: "Kernel done"
222 223 224 225
		fi
		break
	fi
done
226 227 228 229 230
if test -z "$qemu_pid" -a -s "$resdir/qemu_pid"
then
	qemu_pid=`cat "$resdir/qemu_pid"`
fi
if test $commandcompleted -eq 0 -a -n "$qemu_pid"
231 232
then
	echo Grace period for qemu job at pid $qemu_pid
233
	oldline="`tail $resdir/console.log`"
234
	while :
235
	do
236
		kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
237 238
		if kill -0 $qemu_pid > /dev/null 2>&1
		then
239
			:
240 241 242
		else
			break
		fi
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
		must_continue=no
		newline="`tail $resdir/console.log`"
		if test "$newline" != "$oldline" && echo $newline | grep -q ' [0-9]\+us : '
		then
			must_continue=yes
		fi
		last_ts="`tail $resdir/console.log | grep '^\[ *[0-9]\+\.[0-9]\+]' | tail -1 | sed -e 's/^\[ *//' -e 's/\..*$//'`"
		if test -z "last_ts"
		then
			last_ts=0
		fi
		if test "$newline" != "$oldline" -a "$last_ts" -lt $((seconds + $TORTURE_SHUTDOWN_GRACE))
		then
			must_continue=yes
		fi
		if test $must_continue = no -a $kruntime -ge $((seconds + $TORTURE_SHUTDOWN_GRACE))
259
		then
260
			echo "!!! PID $qemu_pid hung at $kruntime vs. $seconds seconds" >> $resdir/Warnings 2>&1
261
			kill -KILL $qemu_pid
262
			break
263
		fi
264 265
		oldline=$newline
		sleep 10
266
	done
267 268 269
elif test -z "$qemu_pid"
then
	echo Unknown PID, cannot kill qemu command
270 271
fi

272
parse-torture.sh $resdir/console.log $title
273
parse-console.sh $resdir/console.log $title