2 # SPDX-License-Identifier: GPL-2.0+
4 # Run a kvm-based test of the specified tree on the specified configs.
5 # Fully automated run and error checking, no graphics console.
7 # Execute this in the source tree. Do not run it as a background task
8 # because qemu does not seem to like that much.
10 # Usage: kvm-test-1-run.sh config builddir resdir seconds qemu-args boot_args
12 # qemu-args defaults to "-enable-kvm -nographic", along with arguments
13 # specifying the number of CPUs and other options
14 # generated from the underlying CPU architecture.
15 # boot_args defaults to value returned by the per_version_boot_params
18 # Anything you specify for either qemu-args or boot_args is appended to
19 # the default values. The "-smp" value is deduced from the contents of
20 # the config fragment.
22 # More sophisticated argument parsing is clearly needed.
24 # Copyright (C) IBM Corporation, 2011
26 # Authors: Paul E. McKenney <paulmck@linux.ibm.com>
28 T
=${TMPDIR-/tmp}/kvm-test-1-run.sh.$$
33 .
$CONFIGFRAG/ver_functions.sh
36 config_dir
=`echo $config_template | sed -e 's,/[^/]*$,,'`
37 title
=`echo $config_template | sed -e 's/^.*\///'`
40 if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"
42 echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it"
45 echo ' ---' `date`: Starting build
46 echo ' ---' Kconfig fragment
at: $config_template >> $resdir/log
47 touch $resdir/ConfigFragment.input
49 # Combine additional Kconfig options into an existing set such that
50 # newer options win. The first argument is the Kconfig source ID, the
51 # second the to-be-updated file within $T, and the third and final the
52 # list of additional Kconfig options. Note that a $2.tmp file is
53 # created when doing the update.
54 config_override_param
() {
57 echo $3 |
sed -e 's/^ *//' -e 's/ *$//' |
tr -s " " "\012" > $T/Kconfig_args
58 echo " --- $1" >> $resdir/ConfigFragment.input
59 cat $T/Kconfig_args
>> $resdir/ConfigFragment.input
60 config_override.sh
$T/$2 $T/Kconfig_args
> $T/$2.tmp
62 # Note that "#CHECK#" is not permitted on commandline.
67 config_override_param
"$config_dir/CFcommon" KcList
"`cat $config_dir/CFcommon 2> /dev/null`"
68 config_override_param
"$config_template" KcList
"`cat $config_template 2> /dev/null`"
69 config_override_param
"--kasan options" KcList
"$TORTURE_KCONFIG_KASAN_ARG"
70 config_override_param
"--kcsan options" KcList
"$TORTURE_KCONFIG_KCSAN_ARG"
71 config_override_param
"--kconfig argument" KcList
"$TORTURE_KCONFIG_ARG"
72 cp $T/KcList
$resdir/ConfigFragment
74 base_resdir
=`echo $resdir | sed -e 's/\.[0-9]\+$//'`
75 if test "$base_resdir" != "$resdir" -a -f $base_resdir/bzImage
-a -f $base_resdir/vmlinux
77 # Rerunning previous test, so use that test's kernel.
78 QEMU
="`identify_qemu $base_resdir/vmlinux`"
79 BOOT_IMAGE
="`identify_boot_image $QEMU`"
80 KERNEL
=$base_resdir/${BOOT_IMAGE##*/} # use the last component of ${BOOT_IMAGE}
81 ln -s $base_resdir/Make
*.out
$resdir # for kvm-recheck.sh
82 ln -s $base_resdir/.config
$resdir # for kvm-recheck.sh
83 # Arch-independent indicator
84 touch $resdir/builtkernel
85 elif kvm-build.sh
$T/KcList
$resdir
87 # Had to build a kernel for this test.
88 QEMU
="`identify_qemu vmlinux`"
89 BOOT_IMAGE
="`identify_boot_image $QEMU`"
92 cp Module.symvers
$resdir > /dev
/null ||
:
93 cp System.map
$resdir > /dev
/null ||
:
94 if test -n "$BOOT_IMAGE"
96 cp $BOOT_IMAGE $resdir
97 KERNEL
=$resdir/${BOOT_IMAGE##*/}
98 # Arch-independent indicator
99 touch $resdir/builtkernel
101 echo No identifiable boot image
, not running KVM
, see
$resdir.
102 echo Do the torture scripts know about your architecture?
104 parse-build.sh
$resdir/Make.out
$title
107 cp .config
$resdir ||
:
108 echo Build failed
, not running KVM
, see
$resdir.
109 if test -f $builddir.
wait
111 mv $builddir.
wait $builddir.ready
115 if test -f $builddir.
wait
117 mv $builddir.
wait $builddir.ready
119 while test -f $builddir.ready
128 kstarttime
=`gawk 'BEGIN { print systime() }' < /dev/null`
129 if test -z "$TORTURE_BUILDONLY"
131 echo ' ---' `date`: Starting kernel
134 # Generate -smp qemu argument.
135 qemu_args
="-enable-kvm -nographic $qemu_args"
136 cpu_count
=`configNR_CPUS.sh $resdir/ConfigFragment`
137 cpu_count
=`configfrag_boot_cpus "$boot_args" "$config_template" "$cpu_count"`
138 if test "$cpu_count" -gt "$TORTURE_ALLOTED_CPUS"
140 echo CPU count limited from
$cpu_count to
$TORTURE_ALLOTED_CPUS |
tee -a $resdir/Warnings
141 cpu_count
=$TORTURE_ALLOTED_CPUS
143 qemu_args
="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"
145 # Generate architecture-specific and interaction-specific qemu arguments
146 qemu_args
="$qemu_args `identify_qemu_args "$QEMU" "$resdir/console.log
"`"
148 # Generate qemu -append arguments
149 qemu_append
="`identify_qemu_append "$QEMU"`"
151 # Pull in Kconfig-fragment boot parameters
152 boot_args
="`configfrag_boot_params "$boot_args" "$config_template"`"
153 # Generate kernel-version-specific boot parameters
154 boot_args
="`per_version_boot_params "$boot_args" $resdir/.config $seconds`"
156 if test -n "$TORTURE_BUILDONLY"
158 echo Build-only run specified
, boot
/test omitted.
159 touch $resdir/buildonly
162 echo "NOTE: $QEMU either did not run or was interactive" > $resdir/console.log
163 echo $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd
164 ( $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append "$qemu_append $boot_args" > $resdir/qemu-output
2>&1 & echo $
! > $resdir/qemu_pid
; wait `cat $resdir/qemu_pid`; echo $?
> $resdir/qemu-retval
) &
166 sleep 10 # Give qemu's pid a chance to reach the file
167 if test -s "$resdir/qemu_pid"
169 qemu_pid
=`cat "$resdir/qemu_pid"`
170 echo Monitoring qemu job
at pid
$qemu_pid
173 echo Monitoring qemu job
at yet-as-unknown pid
177 if test -z "$qemu_pid" -a -s "$resdir/qemu_pid"
179 qemu_pid
=`cat "$resdir/qemu_pid"`
181 kruntime
=`gawk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
182 if test -z "$qemu_pid" ||
kill -0 "$qemu_pid" > /dev
/null
2>&1
184 if test $kruntime -ge $seconds
191 if test $kruntime -lt $seconds
193 echo Completed
in $kruntime vs.
$seconds >> $resdir/Warnings
2>&1
194 grep "^(qemu) qemu:" $resdir/kvm-test-1-run.sh.out
>> $resdir/Warnings
2>&1
195 killpid
="`sed -n "s
/^
(qemu
) qemu
: terminating on signal
[0-9]* from pid \
([0-9]*\
).
*$
/\
1/p
" $resdir/Warnings`"
196 if test -n "$killpid"
198 echo "ps -fp $killpid" >> $resdir/Warnings
2>&1
199 ps
-fp $killpid >> $resdir/Warnings
2>&1
202 echo ' ---' `date`: "Kernel done"
207 if test -z "$qemu_pid" -a -s "$resdir/qemu_pid"
209 qemu_pid
=`cat "$resdir/qemu_pid"`
211 if test $commandcompleted -eq 0 -a -n "$qemu_pid"
213 echo Grace period
for qemu job
at pid
$qemu_pid
214 oldline
="`tail $resdir/console.log`"
217 kruntime
=`gawk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
218 if kill -0 $qemu_pid > /dev
/null
2>&1
225 newline
="`tail $resdir/console.log`"
226 if test "$newline" != "$oldline" && echo $newline |
grep -q ' [0-9]\+us : '
230 last_ts
="`tail $resdir/console.log | grep '^\[ *[0-9]\+\.[0-9]\+]' | tail -1 | sed -e 's/^\[ *//' -e 's/\..*$//'`"
231 if test -z "$last_ts"
235 if test "$newline" != "$oldline" -a "$last_ts" -lt $
((seconds
+ $TORTURE_SHUTDOWN_GRACE))
239 if test $must_continue = no
-a $kruntime -ge $
((seconds
+ $TORTURE_SHUTDOWN_GRACE))
241 echo "!!! PID $qemu_pid hung at $kruntime vs. $seconds seconds" >> $resdir/Warnings
2>&1
248 elif test -z "$qemu_pid"
250 echo Unknown PID
, cannot
kill qemu
command
253 parse-console.sh
$resdir/console.log
$title