1d3b1548aSPaul E. McKenney#!/bin/bash 2fef141f6SPaul E. McKenney# SPDX-License-Identifier: GPL-2.0+ 3d3b1548aSPaul E. McKenney# 4d3b1548aSPaul E. McKenney# Run a kvm-based test of the specified tree on the specified configs. 5d3b1548aSPaul E. McKenney# Fully automated run and error checking, no graphics console. 6d3b1548aSPaul E. McKenney# 7d3b1548aSPaul E. McKenney# Execute this in the source tree. Do not run it as a background task 8d3b1548aSPaul E. McKenney# because qemu does not seem to like that much. 9d3b1548aSPaul E. McKenney# 103c43ce53SPaul E. McKenney# Usage: kvm-test-1-run.sh config resdir seconds qemu-args boot_args_in 11d3b1548aSPaul E. McKenney# 121b2f48f2SBoqun Feng# qemu-args defaults to "-enable-kvm -nographic", along with arguments 131b2f48f2SBoqun Feng# specifying the number of CPUs and other options 141b2f48f2SBoqun Feng# generated from the underlying CPU architecture. 15a8dafbf3SPaul E. McKenney# boot_args_in defaults to value returned by the per_version_boot_params 16d3b1548aSPaul E. McKenney# shell function. 17d3b1548aSPaul E. McKenney# 18a8dafbf3SPaul E. McKenney# Anything you specify for either qemu-args or boot_args_in is appended to 19d3b1548aSPaul E. McKenney# the default values. The "-smp" value is deduced from the contents of 20d3b1548aSPaul E. McKenney# the config fragment. 21d3b1548aSPaul E. McKenney# 22d3b1548aSPaul E. McKenney# More sophisticated argument parsing is clearly needed. 23d3b1548aSPaul E. McKenney# 24d3b1548aSPaul E. McKenney# Copyright (C) IBM Corporation, 2011 25d3b1548aSPaul E. McKenney# 26fef141f6SPaul E. McKenney# Authors: Paul E. McKenney <paulmck@linux.ibm.com> 27d3b1548aSPaul E. McKenney 28b038c58bSPaul E. McKenneyT=${TMPDIR-/tmp}/kvm-test-1-run.sh.$$ 29d3b1548aSPaul E. McKenneytrap 'rm -rf $T' 0 30d62c9833SPaul E. McKenneymkdir $T 31d3b1548aSPaul E. McKenney 32feef2d28SSeongJae Park. functions.sh 33edae018dSPranith Kumar. $CONFIGFRAG/ver_functions.sh 34d3b1548aSPaul E. McKenney 35d3b1548aSPaul E. McKenneyconfig_template=${1} 36d3b1548aSPaul E. McKenneyconfig_dir=`echo $config_template | sed -e 's,/[^/]*$,,'` 37d3b1548aSPaul E. McKenneytitle=`echo $config_template | sed -e 's/^.*\///'` 383c43ce53SPaul E. McKenneyresdir=${2} 39d3b1548aSPaul E. McKenneyif test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir" 40d3b1548aSPaul E. McKenneythen 41d3b1548aSPaul E. McKenney echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it" 42d3b1548aSPaul E. McKenney exit 1 43d3b1548aSPaul E. McKenneyfi 44*cb1fa863SPaul E. McKenneyecho ' ---' `date`: Starting build, PID $$ 45d3b1548aSPaul E. McKenneyecho ' ---' Kconfig fragment at: $config_template >> $resdir/log 46b5744d3cSPaul E. McKenneytouch $resdir/ConfigFragment.input 476be63d7dSPaul E. McKenney 48409670aaSPaul E. McKenney# Combine additional Kconfig options into an existing set such that 49409670aaSPaul E. McKenney# newer options win. The first argument is the Kconfig source ID, the 50409670aaSPaul E. McKenney# second the to-be-updated file within $T, and the third and final the 51409670aaSPaul E. McKenney# list of additional Kconfig options. Note that a $2.tmp file is 52409670aaSPaul E. McKenney# created when doing the update. 536be63d7dSPaul E. McKenneyconfig_override_param () { 54409670aaSPaul E. McKenney if test -n "$3" 556be63d7dSPaul E. McKenney then 56409670aaSPaul E. McKenney echo $3 | sed -e 's/^ *//' -e 's/ *$//' | tr -s " " "\012" > $T/Kconfig_args 576be63d7dSPaul E. McKenney echo " --- $1" >> $resdir/ConfigFragment.input 586be63d7dSPaul E. McKenney cat $T/Kconfig_args >> $resdir/ConfigFragment.input 59409670aaSPaul E. McKenney config_override.sh $T/$2 $T/Kconfig_args > $T/$2.tmp 60409670aaSPaul E. McKenney mv $T/$2.tmp $T/$2 616be63d7dSPaul E. McKenney # Note that "#CHECK#" is not permitted on commandline. 626be63d7dSPaul E. McKenney fi 636be63d7dSPaul E. McKenney} 646be63d7dSPaul E. McKenney 65409670aaSPaul E. McKenneyecho > $T/KcList 66409670aaSPaul E. McKenneyconfig_override_param "$config_dir/CFcommon" KcList "`cat $config_dir/CFcommon 2> /dev/null`" 67409670aaSPaul E. McKenneyconfig_override_param "$config_template" KcList "`cat $config_template 2> /dev/null`" 68b67a9170SPaul E. McKenneyconfig_override_param "--gdb options" KcList "$TORTURE_KCONFIG_GDB_ARG" 6904dbcdb4SPaul E. McKenneyconfig_override_param "--kasan options" KcList "$TORTURE_KCONFIG_KASAN_ARG" 70409670aaSPaul E. McKenneyconfig_override_param "--kcsan options" KcList "$TORTURE_KCONFIG_KCSAN_ARG" 71409670aaSPaul E. McKenneyconfig_override_param "--kconfig argument" KcList "$TORTURE_KCONFIG_ARG" 72409670aaSPaul E. McKenneycp $T/KcList $resdir/ConfigFragment 73d62c9833SPaul E. McKenney 74acc1adf5SPaul E. McKenneybase_resdir=`echo $resdir | sed -e 's/\.[0-9]\+$//'` 75a519d214SPaul E. McKenneyif test "$base_resdir" != "$resdir" && test -f $base_resdir/bzImage && test -f $base_resdir/vmlinux 76d3b1548aSPaul E. McKenneythen 77acc1adf5SPaul E. McKenney # Rerunning previous test, so use that test's kernel. 78acc1adf5SPaul E. McKenney QEMU="`identify_qemu $base_resdir/vmlinux`" 791b900c6aSBoqun Feng BOOT_IMAGE="`identify_boot_image $QEMU`" 801b900c6aSBoqun Feng KERNEL=$base_resdir/${BOOT_IMAGE##*/} # use the last component of ${BOOT_IMAGE} 81acc1adf5SPaul E. McKenney ln -s $base_resdir/Make*.out $resdir # for kvm-recheck.sh 82acc1adf5SPaul E. McKenney ln -s $base_resdir/.config $resdir # for kvm-recheck.sh 8385ef2bd2SPaul E. McKenney # Arch-independent indicator 8485ef2bd2SPaul E. McKenney touch $resdir/builtkernel 85a519d214SPaul E. McKenneyelif test "$base_resdir" != "$resdir" 86a519d214SPaul E. McKenneythen 87a519d214SPaul E. McKenney # Rerunning previous test for which build failed 88a519d214SPaul E. McKenney ln -s $base_resdir/Make*.out $resdir # for kvm-recheck.sh 89a519d214SPaul E. McKenney ln -s $base_resdir/.config $resdir # for kvm-recheck.sh 90a519d214SPaul E. McKenney echo Initial build failed, not running KVM, see $resdir. 913c43ce53SPaul E. McKenney if test -f $resdir/build.wait 92a519d214SPaul E. McKenney then 933c43ce53SPaul E. McKenney mv $resdir/build.wait $resdir/build.ready 94a519d214SPaul E. McKenney fi 95a519d214SPaul E. McKenney exit 1 96409670aaSPaul E. McKenneyelif kvm-build.sh $T/KcList $resdir 97acc1adf5SPaul E. McKenneythen 98acc1adf5SPaul E. McKenney # Had to build a kernel for this test. 996dc82595SPaul E. McKenney QEMU="`identify_qemu vmlinux`" 100f189cc8cSPaul E. McKenney BOOT_IMAGE="`identify_boot_image $QEMU`" 1016dc82595SPaul E. McKenney cp vmlinux $resdir 1026dc82595SPaul E. McKenney cp .config $resdir 1036dc82595SPaul E. McKenney cp Module.symvers $resdir > /dev/null || : 1046dc82595SPaul E. McKenney cp System.map $resdir > /dev/null || : 105f189cc8cSPaul E. McKenney if test -n "$BOOT_IMAGE" 106f189cc8cSPaul E. McKenney then 1076dc82595SPaul E. McKenney cp $BOOT_IMAGE $resdir 1081b900c6aSBoqun Feng KERNEL=$resdir/${BOOT_IMAGE##*/} 10985ef2bd2SPaul E. McKenney # Arch-independent indicator 11085ef2bd2SPaul E. McKenney touch $resdir/builtkernel 111f189cc8cSPaul E. McKenney else 112f189cc8cSPaul E. McKenney echo No identifiable boot image, not running KVM, see $resdir. 113f189cc8cSPaul E. McKenney echo Do the torture scripts know about your architecture? 114f189cc8cSPaul E. McKenney fi 115d3b1548aSPaul E. McKenney parse-build.sh $resdir/Make.out $title 116d3b1548aSPaul E. McKenneyelse 117acc1adf5SPaul E. McKenney # Build failed. 1186dc82595SPaul E. McKenney cp .config $resdir || : 119d3b1548aSPaul E. McKenney echo Build failed, not running KVM, see $resdir. 1203c43ce53SPaul E. McKenney if test -f $resdir/build.wait 121d3b1548aSPaul E. McKenney then 1223c43ce53SPaul E. McKenney mv $resdir/build.wait $resdir/build.ready 123d3b1548aSPaul E. McKenney fi 124d3b1548aSPaul E. McKenney exit 1 125d3b1548aSPaul E. McKenneyfi 1263c43ce53SPaul E. McKenneyif test -f $resdir/build.wait 127acc1adf5SPaul E. McKenneythen 1283c43ce53SPaul E. McKenney mv $resdir/build.wait $resdir/build.ready 129acc1adf5SPaul E. McKenneyfi 1303c43ce53SPaul E. McKenneywhile test -f $resdir/build.ready 131d3b1548aSPaul E. McKenneydo 132d3b1548aSPaul E. McKenney sleep 1 133d3b1548aSPaul E. McKenneydone 1343c43ce53SPaul E. McKenneyseconds=$3 1353c43ce53SPaul E. McKenneyqemu_args=$4 1363c43ce53SPaul E. McKenneyboot_args_in=$5 137d3b1548aSPaul E. McKenney 1389bee2c6fSPaul E. McKenneyif test -z "$TORTURE_BUILDONLY" 1399bee2c6fSPaul E. McKenneythen 140d3b1548aSPaul E. McKenney echo ' ---' `date`: Starting kernel 1419bee2c6fSPaul E. McKenneyfi 142d3b1548aSPaul E. McKenney 143d3b1548aSPaul E. McKenney# Generate -smp qemu argument. 1441b2f48f2SBoqun Fengqemu_args="-enable-kvm -nographic $qemu_args" 145d62c9833SPaul E. McKenneycpu_count=`configNR_CPUS.sh $resdir/ConfigFragment` 146a8dafbf3SPaul E. McKenneycpu_count=`configfrag_boot_cpus "$boot_args_in" "$config_template" "$cpu_count"` 147b22eb7ceSPaul E. McKenneyif test "$cpu_count" -gt "$TORTURE_ALLOTED_CPUS" 148d3b1548aSPaul E. McKenneythen 149b22eb7ceSPaul E. McKenney echo CPU count limited from $cpu_count to $TORTURE_ALLOTED_CPUS | tee -a $resdir/Warnings 150b22eb7ceSPaul E. McKenney cpu_count=$TORTURE_ALLOTED_CPUS 151d3b1548aSPaul E. McKenneyfi 152d3b1548aSPaul E. McKenneyqemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`" 15388513ae5SPaul E. McKenneyqemu_args="`specify_qemu_net "$qemu_args"`" 154d3b1548aSPaul E. McKenney 155d3b1548aSPaul E. McKenney# Generate architecture-specific and interaction-specific qemu arguments 156c979ff99SPaul E. McKenneyqemu_args="$qemu_args `identify_qemu_args "$QEMU" "$resdir/console.log"`" 157d3b1548aSPaul E. McKenney 158d3b1548aSPaul E. McKenney# Generate qemu -append arguments 159d3b1548aSPaul E. McKenneyqemu_append="`identify_qemu_append "$QEMU"`" 160d3b1548aSPaul E. McKenney 161d3b1548aSPaul E. McKenney# Pull in Kconfig-fragment boot parameters 162a8dafbf3SPaul E. McKenneyboot_args="`configfrag_boot_params "$boot_args_in" "$config_template"`" 163d3b1548aSPaul E. McKenney# Generate kernel-version-specific boot parameters 1646bb7ff17SPaul E. McKenneyboot_args="`per_version_boot_params "$boot_args" $resdir/.config $seconds`" 165b67a9170SPaul E. McKenneyif test -n "$TORTURE_BOOT_GDB_ARG" 166b67a9170SPaul E. McKenneythen 167b67a9170SPaul E. McKenney boot_args="$boot_args $TORTURE_BOOT_GDB_ARG" 168b67a9170SPaul E. McKenneyfi 169a8dafbf3SPaul E. McKenney 170a8dafbf3SPaul E. McKenney# Give bare-metal advice 171a8dafbf3SPaul E. McKenneymodprobe_args="`echo $boot_args | tr -s ' ' '\012' | grep "^$TORTURE_MOD\." | sed -e "s/$TORTURE_MOD\.//g"`" 172a8dafbf3SPaul E. McKenneykboot_args="`echo $boot_args | tr -s ' ' '\012' | grep -v "^$TORTURE_MOD\."`" 173a8dafbf3SPaul E. McKenneytestid_txt="`dirname $resdir`/testid.txt" 174a8dafbf3SPaul E. McKenneytouch $resdir/bare-metal 175a8dafbf3SPaul E. McKenneyecho To run this scenario on bare metal: >> $resdir/bare-metal 176a8dafbf3SPaul E. McKenneyecho >> $resdir/bare-metal 177a8dafbf3SPaul E. McKenneyecho " 1." Set your bare-metal build tree to the state shown in this file: >> $resdir/bare-metal 178a8dafbf3SPaul E. McKenneyecho " " $testid_txt >> $resdir/bare-metal 179a8dafbf3SPaul E. McKenneyecho " 2." Update your bare-metal build tree"'"s .config based on this file: >> $resdir/bare-metal 180a8dafbf3SPaul E. McKenneyecho " " $resdir/ConfigFragment >> $resdir/bare-metal 181a8dafbf3SPaul E. McKenneyecho " 3." Make the bare-metal kernel"'"s build system aware of your .config updates: >> $resdir/bare-metal 182a8dafbf3SPaul E. McKenneyecho " " $ 'yes "" | make oldconfig' >> $resdir/bare-metal 183a8dafbf3SPaul E. McKenneyecho " 4." Build your bare-metal kernel. >> $resdir/bare-metal 184a8dafbf3SPaul E. McKenneyecho " 5." Boot your bare-metal kernel with the following parameters: >> $resdir/bare-metal 185a8dafbf3SPaul E. McKenneyecho " " $kboot_args >> $resdir/bare-metal 186a8dafbf3SPaul E. McKenneyecho " 6." Start the test with the following command: >> $resdir/bare-metal 187a8dafbf3SPaul E. McKenneyecho " " $ modprobe $TORTURE_MOD $modprobe_args >> $resdir/bare-metal 188a8dafbf3SPaul E. McKenneyecho " 7." After some time, end the test with the following command: >> $resdir/bare-metal 189a8dafbf3SPaul E. McKenneyecho " " $ rmmod $TORTURE_MOD >> $resdir/bare-metal 190a8dafbf3SPaul E. McKenneyecho " 8." Copy your bare-metal kernel"'"s .config file, overwriting this file: >> $resdir/bare-metal 191a8dafbf3SPaul E. McKenneyecho " " $resdir/.config >> $resdir/bare-metal 192a8dafbf3SPaul E. McKenneyecho " 9." Copy the console output from just before the modprobe to just after >> $resdir/bare-metal 193a8dafbf3SPaul E. McKenneyecho " " the rmmod into this file: >> $resdir/bare-metal 194a8dafbf3SPaul E. McKenneyecho " " $resdir/console.log >> $resdir/bare-metal 195a8dafbf3SPaul E. McKenneyecho "10." Check for runtime errors using the following command: >> $resdir/bare-metal 196a8dafbf3SPaul E. McKenneyecho " " $ tools/testing/selftests/rcutorture/bin/kvm-recheck.sh `dirname $resdir` >> $resdir/bare-metal 197a8dafbf3SPaul E. McKenneyecho >> $resdir/bare-metal 198a8dafbf3SPaul E. McKenneyecho Some of the above steps may be skipped if you build your bare-metal >> $resdir/bare-metal 199a8dafbf3SPaul E. McKenneyecho kernel here: `head -n 1 $testid_txt | sed -e 's/^Build directory: //'` >> $resdir/bare-metal 200a8dafbf3SPaul E. McKenney 201b67a9170SPaul E. McKenneyecho $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append \"$qemu_append $boot_args\" $TORTURE_QEMU_GDB_ARG > $resdir/qemu-cmd 202315957caSPaul E. McKenneyecho "# TORTURE_SHUTDOWN_GRACE=$TORTURE_SHUTDOWN_GRACE" >> $resdir/qemu-cmd 203315957caSPaul E. McKenneyecho "# seconds=$seconds" >> $resdir/qemu-cmd 204cc45716eSPaul E. McKenneyecho "# TORTURE_KCONFIG_GDB_ARG=\"$TORTURE_KCONFIG_GDB_ARG\"" >> $resdir/qemu-cmd 2057831b391SPaul E. McKenneyecho "# TORTURE_JITTER_START=\"$TORTURE_JITTER_START\"" >> $resdir/qemu-cmd 2067831b391SPaul E. McKenneyecho "# TORTURE_JITTER_STOP=\"$TORTURE_JITTER_STOP\"" >> $resdir/qemu-cmd 207d3b1548aSPaul E. McKenney 208805ffee2SPaul E. McKenneyif test -n "$TORTURE_BUILDONLY" 209d3b1548aSPaul E. McKenneythen 210d3b1548aSPaul E. McKenney echo Build-only run specified, boot/test omitted. 2119bee2c6fSPaul E. McKenney touch $resdir/buildonly 212d3b1548aSPaul E. McKenney exit 0 213d3b1548aSPaul E. McKenneyfi 214316db589SPaul E. McKenney 215d53f52d6SPaul E. McKenneykvm-test-1-run-qemu.sh $resdir 216