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# 12*93a556b8SPaul E. McKenney# qemu-args defaults to "-enable-kvm -display none -no-reboot", along 13*93a556b8SPaul E. McKenney# with arguments specifying the number of CPUs 14*93a556b8SPaul E. McKenney# and other options generated from the underlying 1510f84c2cSPaul E. McKenney# CPU architecture. 16a8dafbf3SPaul E. McKenney# boot_args_in defaults to value returned by the per_version_boot_params 17d3b1548aSPaul E. McKenney# shell function. 18d3b1548aSPaul E. McKenney# 19a8dafbf3SPaul E. McKenney# Anything you specify for either qemu-args or boot_args_in is appended to 20d3b1548aSPaul E. McKenney# the default values. The "-smp" value is deduced from the contents of 21d3b1548aSPaul E. McKenney# the config fragment. 22d3b1548aSPaul E. McKenney# 23d3b1548aSPaul E. McKenney# More sophisticated argument parsing is clearly needed. 24d3b1548aSPaul E. McKenney# 25d3b1548aSPaul E. McKenney# Copyright (C) IBM Corporation, 2011 26d3b1548aSPaul E. McKenney# 27fef141f6SPaul E. McKenney# Authors: Paul E. McKenney <paulmck@linux.ibm.com> 28d3b1548aSPaul E. McKenney 29c211ae9cSPaul E. McKenneyT="`mktemp -d ${TMPDIR-/tmp}/kvm-test-1-run.sh.XXXXXX`" 30d3b1548aSPaul E. McKenneytrap 'rm -rf $T' 0 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 44cb1fa863SPaul 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 fi 626be63d7dSPaul E. McKenney} 636be63d7dSPaul E. McKenney 64409670aaSPaul E. McKenneyecho > $T/KcList 65409670aaSPaul E. McKenneyconfig_override_param "$config_dir/CFcommon" KcList "`cat $config_dir/CFcommon 2> /dev/null`" 66409670aaSPaul E. McKenneyconfig_override_param "$config_template" KcList "`cat $config_template 2> /dev/null`" 67b67a9170SPaul E. McKenneyconfig_override_param "--gdb options" KcList "$TORTURE_KCONFIG_GDB_ARG" 6804dbcdb4SPaul E. McKenneyconfig_override_param "--kasan options" KcList "$TORTURE_KCONFIG_KASAN_ARG" 69409670aaSPaul E. McKenneyconfig_override_param "--kcsan options" KcList "$TORTURE_KCONFIG_KCSAN_ARG" 70409670aaSPaul E. McKenneyconfig_override_param "--kconfig argument" KcList "$TORTURE_KCONFIG_ARG" 71409670aaSPaul E. McKenneycp $T/KcList $resdir/ConfigFragment 72d62c9833SPaul E. McKenney 73acc1adf5SPaul E. McKenneybase_resdir=`echo $resdir | sed -e 's/\.[0-9]\+$//'` 74a519d214SPaul E. McKenneyif test "$base_resdir" != "$resdir" && test -f $base_resdir/bzImage && test -f $base_resdir/vmlinux 75d3b1548aSPaul E. McKenneythen 76acc1adf5SPaul E. McKenney # Rerunning previous test, so use that test's kernel. 77acc1adf5SPaul E. McKenney QEMU="`identify_qemu $base_resdir/vmlinux`" 781b900c6aSBoqun Feng BOOT_IMAGE="`identify_boot_image $QEMU`" 791b900c6aSBoqun Feng KERNEL=$base_resdir/${BOOT_IMAGE##*/} # use the last component of ${BOOT_IMAGE} 80acc1adf5SPaul E. McKenney ln -s $base_resdir/Make*.out $resdir # for kvm-recheck.sh 81acc1adf5SPaul E. McKenney ln -s $base_resdir/.config $resdir # for kvm-recheck.sh 8285ef2bd2SPaul E. McKenney # Arch-independent indicator 8385ef2bd2SPaul E. McKenney touch $resdir/builtkernel 84a519d214SPaul E. McKenneyelif test "$base_resdir" != "$resdir" 85a519d214SPaul E. McKenneythen 86a519d214SPaul E. McKenney # Rerunning previous test for which build failed 87a519d214SPaul E. McKenney ln -s $base_resdir/Make*.out $resdir # for kvm-recheck.sh 88a519d214SPaul E. McKenney ln -s $base_resdir/.config $resdir # for kvm-recheck.sh 89a519d214SPaul E. McKenney echo Initial build failed, not running KVM, see $resdir. 903c43ce53SPaul E. McKenney if test -f $resdir/build.wait 91a519d214SPaul E. McKenney then 923c43ce53SPaul E. McKenney mv $resdir/build.wait $resdir/build.ready 93a519d214SPaul E. McKenney fi 94a519d214SPaul E. McKenney exit 1 95409670aaSPaul E. McKenneyelif kvm-build.sh $T/KcList $resdir 96acc1adf5SPaul E. McKenneythen 97acc1adf5SPaul E. McKenney # Had to build a kernel for this test. 986dc82595SPaul E. McKenney QEMU="`identify_qemu vmlinux`" 99f189cc8cSPaul E. McKenney BOOT_IMAGE="`identify_boot_image $QEMU`" 1006dc82595SPaul E. McKenney cp vmlinux $resdir 1016dc82595SPaul E. McKenney cp .config $resdir 1026dc82595SPaul E. McKenney cp Module.symvers $resdir > /dev/null || : 1036dc82595SPaul E. McKenney cp System.map $resdir > /dev/null || : 104f189cc8cSPaul E. McKenney if test -n "$BOOT_IMAGE" 105f189cc8cSPaul E. McKenney then 1066dc82595SPaul E. McKenney cp $BOOT_IMAGE $resdir 1071b900c6aSBoqun Feng KERNEL=$resdir/${BOOT_IMAGE##*/} 10885ef2bd2SPaul E. McKenney # Arch-independent indicator 10985ef2bd2SPaul E. McKenney touch $resdir/builtkernel 110f189cc8cSPaul E. McKenney else 111f189cc8cSPaul E. McKenney echo No identifiable boot image, not running KVM, see $resdir. 112f189cc8cSPaul E. McKenney echo Do the torture scripts know about your architecture? 113f189cc8cSPaul E. McKenney fi 114d3b1548aSPaul E. McKenney parse-build.sh $resdir/Make.out $title 115d3b1548aSPaul E. McKenneyelse 116acc1adf5SPaul E. McKenney # Build failed. 1176dc82595SPaul E. McKenney cp .config $resdir || : 118d3b1548aSPaul E. McKenney echo Build failed, not running KVM, see $resdir. 1193c43ce53SPaul E. McKenney if test -f $resdir/build.wait 120d3b1548aSPaul E. McKenney then 1213c43ce53SPaul E. McKenney mv $resdir/build.wait $resdir/build.ready 122d3b1548aSPaul E. McKenney fi 123d3b1548aSPaul E. McKenney exit 1 124d3b1548aSPaul E. McKenneyfi 1253c43ce53SPaul E. McKenneyif test -f $resdir/build.wait 126acc1adf5SPaul E. McKenneythen 1273c43ce53SPaul E. McKenney mv $resdir/build.wait $resdir/build.ready 128acc1adf5SPaul E. McKenneyfi 1293c43ce53SPaul E. McKenneywhile test -f $resdir/build.ready 130d3b1548aSPaul E. McKenneydo 131d3b1548aSPaul E. McKenney sleep 1 132d3b1548aSPaul E. McKenneydone 1333c43ce53SPaul E. McKenneyseconds=$3 1343c43ce53SPaul E. McKenneyqemu_args=$4 1353c43ce53SPaul E. McKenneyboot_args_in=$5 136d3b1548aSPaul E. McKenney 1379bee2c6fSPaul E. McKenneyif test -z "$TORTURE_BUILDONLY" 1389bee2c6fSPaul E. McKenneythen 139d3b1548aSPaul E. McKenney echo ' ---' `date`: Starting kernel 1409bee2c6fSPaul E. McKenneyfi 141d3b1548aSPaul E. McKenney 142d3b1548aSPaul E. McKenney# Generate -smp qemu argument. 143*93a556b8SPaul E. McKenneyqemu_args="-enable-kvm -display none -no-reboot $qemu_args" 144d62c9833SPaul E. McKenneycpu_count=`configNR_CPUS.sh $resdir/ConfigFragment` 145a8dafbf3SPaul E. McKenneycpu_count=`configfrag_boot_cpus "$boot_args_in" "$config_template" "$cpu_count"` 146b22eb7ceSPaul E. McKenneyif test "$cpu_count" -gt "$TORTURE_ALLOTED_CPUS" 147d3b1548aSPaul E. McKenneythen 148b22eb7ceSPaul E. McKenney echo CPU count limited from $cpu_count to $TORTURE_ALLOTED_CPUS | tee -a $resdir/Warnings 149b22eb7ceSPaul E. McKenney cpu_count=$TORTURE_ALLOTED_CPUS 150d3b1548aSPaul E. McKenneyfi 151d3b1548aSPaul E. McKenneyqemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`" 15288513ae5SPaul E. McKenneyqemu_args="`specify_qemu_net "$qemu_args"`" 153d3b1548aSPaul E. McKenney 154d3b1548aSPaul E. McKenney# Generate architecture-specific and interaction-specific qemu arguments 155c979ff99SPaul E. McKenneyqemu_args="$qemu_args `identify_qemu_args "$QEMU" "$resdir/console.log"`" 156d3b1548aSPaul E. McKenney 157d3b1548aSPaul E. McKenney# Generate qemu -append arguments 158d3b1548aSPaul E. McKenneyqemu_append="`identify_qemu_append "$QEMU"`" 159d3b1548aSPaul E. McKenney 160d3b1548aSPaul E. McKenney# Pull in Kconfig-fragment boot parameters 161a8dafbf3SPaul E. McKenneyboot_args="`configfrag_boot_params "$boot_args_in" "$config_template"`" 162d3b1548aSPaul E. McKenney# Generate kernel-version-specific boot parameters 1636bb7ff17SPaul E. McKenneyboot_args="`per_version_boot_params "$boot_args" $resdir/.config $seconds`" 164b67a9170SPaul E. McKenneyif test -n "$TORTURE_BOOT_GDB_ARG" 165b67a9170SPaul E. McKenneythen 166171cfa01SPaul E. McKenney boot_args="$TORTURE_BOOT_GDB_ARG $boot_args" 167b67a9170SPaul E. McKenneyfi 168a8dafbf3SPaul E. McKenney 169a8dafbf3SPaul E. McKenney# Give bare-metal advice 170a8dafbf3SPaul E. McKenneymodprobe_args="`echo $boot_args | tr -s ' ' '\012' | grep "^$TORTURE_MOD\." | sed -e "s/$TORTURE_MOD\.//g"`" 171a8dafbf3SPaul E. McKenneykboot_args="`echo $boot_args | tr -s ' ' '\012' | grep -v "^$TORTURE_MOD\."`" 172a8dafbf3SPaul E. McKenneytestid_txt="`dirname $resdir`/testid.txt" 173a8dafbf3SPaul E. McKenneytouch $resdir/bare-metal 174a8dafbf3SPaul E. McKenneyecho To run this scenario on bare metal: >> $resdir/bare-metal 175a8dafbf3SPaul E. McKenneyecho >> $resdir/bare-metal 176a8dafbf3SPaul E. McKenneyecho " 1." Set your bare-metal build tree to the state shown in this file: >> $resdir/bare-metal 177a8dafbf3SPaul E. McKenneyecho " " $testid_txt >> $resdir/bare-metal 178a8dafbf3SPaul E. McKenneyecho " 2." Update your bare-metal build tree"'"s .config based on this file: >> $resdir/bare-metal 179a8dafbf3SPaul E. McKenneyecho " " $resdir/ConfigFragment >> $resdir/bare-metal 180a8dafbf3SPaul E. McKenneyecho " 3." Make the bare-metal kernel"'"s build system aware of your .config updates: >> $resdir/bare-metal 181a8dafbf3SPaul E. McKenneyecho " " $ 'yes "" | make oldconfig' >> $resdir/bare-metal 182a8dafbf3SPaul E. McKenneyecho " 4." Build your bare-metal kernel. >> $resdir/bare-metal 183a8dafbf3SPaul E. McKenneyecho " 5." Boot your bare-metal kernel with the following parameters: >> $resdir/bare-metal 184a8dafbf3SPaul E. McKenneyecho " " $kboot_args >> $resdir/bare-metal 185a8dafbf3SPaul E. McKenneyecho " 6." Start the test with the following command: >> $resdir/bare-metal 186a8dafbf3SPaul E. McKenneyecho " " $ modprobe $TORTURE_MOD $modprobe_args >> $resdir/bare-metal 187a8dafbf3SPaul E. McKenneyecho " 7." After some time, end the test with the following command: >> $resdir/bare-metal 188a8dafbf3SPaul E. McKenneyecho " " $ rmmod $TORTURE_MOD >> $resdir/bare-metal 189a8dafbf3SPaul E. McKenneyecho " 8." Copy your bare-metal kernel"'"s .config file, overwriting this file: >> $resdir/bare-metal 190a8dafbf3SPaul E. McKenneyecho " " $resdir/.config >> $resdir/bare-metal 191a8dafbf3SPaul E. McKenneyecho " 9." Copy the console output from just before the modprobe to just after >> $resdir/bare-metal 192a8dafbf3SPaul E. McKenneyecho " " the rmmod into this file: >> $resdir/bare-metal 193a8dafbf3SPaul E. McKenneyecho " " $resdir/console.log >> $resdir/bare-metal 194a8dafbf3SPaul E. McKenneyecho "10." Check for runtime errors using the following command: >> $resdir/bare-metal 195a8dafbf3SPaul E. McKenneyecho " " $ tools/testing/selftests/rcutorture/bin/kvm-recheck.sh `dirname $resdir` >> $resdir/bare-metal 196a8dafbf3SPaul E. McKenneyecho >> $resdir/bare-metal 197a8dafbf3SPaul E. McKenneyecho Some of the above steps may be skipped if you build your bare-metal >> $resdir/bare-metal 198a8dafbf3SPaul E. McKenneyecho kernel here: `head -n 1 $testid_txt | sed -e 's/^Build directory: //'` >> $resdir/bare-metal 199a8dafbf3SPaul E. McKenney 200b67a9170SPaul E. McKenneyecho $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append \"$qemu_append $boot_args\" $TORTURE_QEMU_GDB_ARG > $resdir/qemu-cmd 201315957caSPaul E. McKenneyecho "# TORTURE_SHUTDOWN_GRACE=$TORTURE_SHUTDOWN_GRACE" >> $resdir/qemu-cmd 202315957caSPaul E. McKenneyecho "# seconds=$seconds" >> $resdir/qemu-cmd 203cc45716eSPaul E. McKenneyecho "# TORTURE_KCONFIG_GDB_ARG=\"$TORTURE_KCONFIG_GDB_ARG\"" >> $resdir/qemu-cmd 2047831b391SPaul E. McKenneyecho "# TORTURE_JITTER_START=\"$TORTURE_JITTER_START\"" >> $resdir/qemu-cmd 2057831b391SPaul E. McKenneyecho "# TORTURE_JITTER_STOP=\"$TORTURE_JITTER_STOP\"" >> $resdir/qemu-cmd 206a5dbe252SPaul E. McKenneyecho "# TORTURE_TRUST_MAKE=\"$TORTURE_TRUST_MAKE\"; export TORTURE_TRUST_MAKE" >> $resdir/qemu-cmd 207a5202e17SPaul E. McKenneyecho "# TORTURE_CPU_COUNT=$cpu_count" >> $resdir/qemu-cmd 208d3b1548aSPaul E. McKenney 209805ffee2SPaul E. McKenneyif test -n "$TORTURE_BUILDONLY" 210d3b1548aSPaul E. McKenneythen 211d3b1548aSPaul E. McKenney echo Build-only run specified, boot/test omitted. 2129bee2c6fSPaul E. McKenney touch $resdir/buildonly 213d3b1548aSPaul E. McKenney exit 0 214d3b1548aSPaul E. McKenneyfi 215316db589SPaul E. McKenney 216d53f52d6SPaul E. McKenneykvm-test-1-run-qemu.sh $resdir 217d4b54d2dSPaul E. McKenneyparse-console.sh $resdir/console.log $title 218