blob: 5236e073919d2e508e6073d201fa157670a8688e [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#
Pranith Kumar3327d922014-07-11 19:47:35 -04009# Usage: kvm-test-1-run.sh config builddir resdir minutes qemu-args boot_args
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070010#
Paul E. McKenney16c77ea2014-12-10 17:43:58 -080011# 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.
Paul E. McKenneyd3b15482014-02-06 20:35:41 -080014# 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
Paul E. McKenney57e60d02014-04-19 11:00:04 -070045touch $T
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070046
47. $KVM/bin/functions.sh
Pranith Kumaredae0182014-10-04 13:04:15 -040048. $CONFIGFRAG/ver_functions.sh
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070049
50config_template=${1}
Paul E. McKenneyd2ebf7e2014-02-06 11:54:32 -080051config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'`
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070052title=`echo $config_template | sed -e 's/^.*\///'`
53builddir=${2}
54if test -z "$builddir" -o ! -d "$builddir" -o ! -w "$builddir"
55then
Paul E. McKenneyd3b15482014-02-06 20:35:41 -080056 echo "kvm-test-1-run.sh :$builddir: Not a writable directory, cannot build into it"
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070057 exit 1
58fi
59resdir=${3}
60if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"
61then
Paul E. McKenneyd3b15482014-02-06 20:35:41 -080062 echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it"
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070063 exit 1
64fi
65cp $config_template $resdir/ConfigFragment
66echo ' ---' `date`: Starting build
Paul E. McKenney330a76f2013-09-30 14:49:43 -070067echo ' ---' Kconfig fragment at: $config_template >> $resdir/log
Paul E. McKenneyd2ebf7e2014-02-06 11:54:32 -080068if test -r "$config_dir/CFcommon"
69then
70 cat < $config_dir/CFcommon >> $T
71fi
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -070072# 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
Paul E. McKenneyf189cc82014-03-06 14:44:46 -080098 QEMU="`identify_qemu $builddir/vmlinux`"
99 BOOT_IMAGE="`identify_boot_image $QEMU`"
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700100 cp $builddir/Make*.out $resdir
101 cp $builddir/.config $resdir
Paul E. McKenneyf189cc82014-03-06 14:44:46 -0800102 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
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700109 parse-build.sh $resdir/Make.out $title
Paul E. McKenneybad80442014-01-13 23:16:55 -0800110 if test -f $builddir.wait
111 then
112 mv $builddir.wait $builddir.ready
113 fi
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700114else
115 cp $builddir/Make*.out $resdir
Paul E. McKenney9eb97fe2014-03-17 13:42:33 -0700116 cp $builddir/.config $resdir || :
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700117 echo Build failed, not running KVM, see $resdir.
Paul E. McKenneybad80442014-01-13 23:16:55 -0800118 if test -f $builddir.wait
119 then
120 mv $builddir.wait $builddir.ready
121 fi
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700122 exit 1
123fi
Paul E. McKenneybad80442014-01-13 23:16:55 -0800124while test -f $builddir.ready
125do
126 sleep 1
127done
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700128minutes=$4
129seconds=$(($minutes * 60))
130qemu_args=$5
131boot_args=$6
132
133cd $KVM
134kstarttime=`awk 'BEGIN { print systime() }' < /dev/null`
Paul E. McKenney9bee2c62014-04-29 09:53:34 -0700135if test -z "$TORTURE_BUILDONLY"
136then
137 echo ' ---' `date`: Starting kernel
138fi
Paul E. McKenney4f8a0312013-09-30 17:17:57 -0700139
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700140# Generate -smp qemu argument.
Paul E. McKenney16c77ea2014-12-10 17:43:58 -0800141qemu_args="-enable-kvm -soundhw pcspk -nographic $qemu_args"
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700142cpu_count=`configNR_CPUS.sh $config_template`
Paul E. McKenneyae867ff2014-07-21 13:35:10 -0700143cpu_count=`configfrag_boot_cpus "$boot_args" "$config_template" "$cpu_count"`
Paul E. McKenney315c5402013-10-04 13:15:55 -0700144vcpus=`identify_qemu_vcpus`
145if test $cpu_count -gt $vcpus
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700146then
Paul E. McKenney315c5402013-10-04 13:15:55 -0700147 echo CPU count limited from $cpu_count to $vcpus
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700148 touch $resdir/Warnings
Paul E. McKenney315c5402013-10-04 13:15:55 -0700149 echo CPU count limited from $cpu_count to $vcpus >> $resdir/Warnings
150 cpu_count=$vcpus
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700151fi
Paul E. McKenney315c5402013-10-04 13:15:55 -0700152qemu_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"`"
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700159
Paul E. McKenneybe70a732013-10-09 11:02:00 -0700160# Pull in Kconfig-fragment boot parameters
161boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
Paul E. McKenneya5afdeb2014-02-06 17:50:32 -0800162# Generate kernel-version-specific boot parameters
163boot_args="`per_version_boot_params "$boot_args" $builddir/.config $seconds`"
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700164
Paul E. McKenney805ffee2014-02-26 15:39:41 -0800165if test -n "$TORTURE_BUILDONLY"
Paul E. McKenney11274812013-10-10 14:52:07 -0700166then
167 echo Build-only run specified, boot/test omitted.
Paul E. McKenney9bee2c62014-04-29 09:53:34 -0700168 touch $resdir/buildonly
Paul E. McKenney11274812013-10-10 14:52:07 -0700169 exit 0
170fi
Paul E. McKenneyd2f74b52014-12-11 10:50:22 -0800171echo "NOTE: $QEMU either did not run or was interactive" > $builddir/console.log
Paul E. McKenney2f3fd492014-08-27 14:17:53 -0700172echo $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 ) &
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700174qemu_pid=$!
175commandcompleted=0
176echo Monitoring qemu job at pid $qemu_pid
Paul E. McKenney0bca7c32014-03-18 10:34:18 -0700177while :
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700178do
Paul E. McKenney0bca7c32014-03-18 10:34:18 -0700179 kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700180 if kill -0 $qemu_pid > /dev/null 2>&1
181 then
Paul E. McKenney0bca7c32014-03-18 10:34:18 -0700182 if test $kruntime -ge $seconds
183 then
184 break;
185 fi
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700186 sleep 1
187 else
188 commandcompleted=1
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700189 if test $kruntime -lt $seconds
190 then
191 echo Completed in $kruntime vs. $seconds >> $resdir/Warnings 2>&1
Paul E. McKenneyfff35c42014-03-04 09:06:40 -0800192 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
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700199 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
Paul E. McKenney0bca7c32014-03-18 10:34:18 -0700208 while :
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700209 do
Paul E. McKenney0bca7c32014-03-18 10:34:18 -0700210 kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700211 if kill -0 $qemu_pid > /dev/null 2>&1
212 then
Paul E. McKenney0bca7c32014-03-18 10:34:18 -0700213 :
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700214 else
215 break
216 fi
Paul E. McKenney0bca7c32014-03-18 10:34:18 -0700217 if test $kruntime -ge $((seconds + grace))
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700218 then
Paul E. McKenneyb7659242014-08-25 20:41:47 -0700219 echo "!!! PID $qemu_pid hung at $kruntime vs. $seconds seconds" >> $resdir/Warnings 2>&1
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700220 kill -KILL $qemu_pid
Paul E. McKenney0bca7c32014-03-18 10:34:18 -0700221 break
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700222 fi
Paul E. McKenney0bca7c32014-03-18 10:34:18 -0700223 sleep 1
Paul E. McKenneyc87b9c62013-09-28 14:12:21 -0700224 done
225fi
226
227cp $builddir/console.log $resdir
Paul E. McKenney4074b512014-02-26 10:57:04 -0800228parse-torture.sh $resdir/console.log $title
Paul E. McKenney6d40cc02013-10-28 06:34:22 -0700229parse-console.sh $resdir/console.log $title