162306a36Sopenharmony_ci#!/bin/bash 262306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+ 362306a36Sopenharmony_ci# 462306a36Sopenharmony_ci# Run a kvm-based test of the specified tree on the specified configs. 562306a36Sopenharmony_ci# Fully automated run and error checking, no graphics console. 662306a36Sopenharmony_ci# 762306a36Sopenharmony_ci# Execute this in the source tree. Do not run it as a background task 862306a36Sopenharmony_ci# because qemu does not seem to like that much. 962306a36Sopenharmony_ci# 1062306a36Sopenharmony_ci# Usage: kvm-test-1-run.sh config resdir seconds qemu-args boot_args_in 1162306a36Sopenharmony_ci# 1262306a36Sopenharmony_ci# qemu-args defaults to "-enable-kvm -display none -no-reboot", along 1362306a36Sopenharmony_ci# with arguments specifying the number of CPUs 1462306a36Sopenharmony_ci# and other options generated from the underlying 1562306a36Sopenharmony_ci# CPU architecture. 1662306a36Sopenharmony_ci# boot_args_in defaults to value returned by the per_version_boot_params 1762306a36Sopenharmony_ci# shell function. 1862306a36Sopenharmony_ci# 1962306a36Sopenharmony_ci# Anything you specify for either qemu-args or boot_args_in is appended to 2062306a36Sopenharmony_ci# the default values. The "-smp" value is deduced from the contents of 2162306a36Sopenharmony_ci# the config fragment. 2262306a36Sopenharmony_ci# 2362306a36Sopenharmony_ci# More sophisticated argument parsing is clearly needed. 2462306a36Sopenharmony_ci# 2562306a36Sopenharmony_ci# Copyright (C) IBM Corporation, 2011 2662306a36Sopenharmony_ci# 2762306a36Sopenharmony_ci# Authors: Paul E. McKenney <paulmck@linux.ibm.com> 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ciT="`mktemp -d ${TMPDIR-/tmp}/kvm-test-1-run.sh.XXXXXX`" 3062306a36Sopenharmony_citrap 'rm -rf $T' 0 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci. functions.sh 3362306a36Sopenharmony_ci. $CONFIGFRAG/ver_functions.sh 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciconfig_template=${1} 3662306a36Sopenharmony_ciconfig_dir=`echo $config_template | sed -e 's,/[^/]*$,,'` 3762306a36Sopenharmony_cititle=`echo $config_template | sed -e 's/^.*\///'` 3862306a36Sopenharmony_ciresdir=${2} 3962306a36Sopenharmony_ciif test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir" 4062306a36Sopenharmony_cithen 4162306a36Sopenharmony_ci echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it" 4262306a36Sopenharmony_ci exit 1 4362306a36Sopenharmony_cifi 4462306a36Sopenharmony_ciecho ' ---' `date`: Starting build, PID $$ 4562306a36Sopenharmony_ciecho ' ---' Kconfig fragment at: $config_template >> $resdir/log 4662306a36Sopenharmony_citouch $resdir/ConfigFragment.input 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci# Combine additional Kconfig options into an existing set such that 4962306a36Sopenharmony_ci# newer options win. The first argument is the Kconfig source ID, the 5062306a36Sopenharmony_ci# second the to-be-updated file within $T, and the third and final the 5162306a36Sopenharmony_ci# list of additional Kconfig options. Note that a $2.tmp file is 5262306a36Sopenharmony_ci# created when doing the update. 5362306a36Sopenharmony_ciconfig_override_param () { 5462306a36Sopenharmony_ci if test -n "$3" 5562306a36Sopenharmony_ci then 5662306a36Sopenharmony_ci echo $3 | sed -e 's/^ *//' -e 's/ *$//' | tr -s " " "\012" > $T/Kconfig_args 5762306a36Sopenharmony_ci echo " --- $1" >> $resdir/ConfigFragment.input 5862306a36Sopenharmony_ci cat $T/Kconfig_args >> $resdir/ConfigFragment.input 5962306a36Sopenharmony_ci config_override.sh $T/$2 $T/Kconfig_args > $T/$2.tmp 6062306a36Sopenharmony_ci mv $T/$2.tmp $T/$2 6162306a36Sopenharmony_ci fi 6262306a36Sopenharmony_ci} 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ciecho > $T/KcList 6562306a36Sopenharmony_ciconfig_override_param "$config_dir/CFcommon" KcList "`cat $config_dir/CFcommon 2> /dev/null`" 6662306a36Sopenharmony_ciconfig_override_param "$config_template" KcList "`cat $config_template 2> /dev/null`" 6762306a36Sopenharmony_ciconfig_override_param "--gdb options" KcList "$TORTURE_KCONFIG_GDB_ARG" 6862306a36Sopenharmony_ciconfig_override_param "--kasan options" KcList "$TORTURE_KCONFIG_KASAN_ARG" 6962306a36Sopenharmony_ciconfig_override_param "--kcsan options" KcList "$TORTURE_KCONFIG_KCSAN_ARG" 7062306a36Sopenharmony_ciconfig_override_param "--kconfig argument" KcList "$TORTURE_KCONFIG_ARG" 7162306a36Sopenharmony_cicp $T/KcList $resdir/ConfigFragment 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_cibase_resdir=`echo $resdir | sed -e 's/\.[0-9]\+$//'` 7462306a36Sopenharmony_ciif test "$base_resdir" != "$resdir" && test -f $base_resdir/bzImage && test -f $base_resdir/vmlinux 7562306a36Sopenharmony_cithen 7662306a36Sopenharmony_ci # Rerunning previous test, so use that test's kernel. 7762306a36Sopenharmony_ci QEMU="`identify_qemu $base_resdir/vmlinux`" 7862306a36Sopenharmony_ci BOOT_IMAGE="`identify_boot_image $QEMU`" 7962306a36Sopenharmony_ci KERNEL=$base_resdir/${BOOT_IMAGE##*/} # use the last component of ${BOOT_IMAGE} 8062306a36Sopenharmony_ci ln -s $base_resdir/Make*.out $resdir # for kvm-recheck.sh 8162306a36Sopenharmony_ci ln -s $base_resdir/.config $resdir # for kvm-recheck.sh 8262306a36Sopenharmony_ci # Arch-independent indicator 8362306a36Sopenharmony_ci touch $resdir/builtkernel 8462306a36Sopenharmony_cielif test "$base_resdir" != "$resdir" 8562306a36Sopenharmony_cithen 8662306a36Sopenharmony_ci # Rerunning previous test for which build failed 8762306a36Sopenharmony_ci ln -s $base_resdir/Make*.out $resdir # for kvm-recheck.sh 8862306a36Sopenharmony_ci ln -s $base_resdir/.config $resdir # for kvm-recheck.sh 8962306a36Sopenharmony_ci echo Initial build failed, not running KVM, see $resdir. 9062306a36Sopenharmony_ci if test -f $resdir/build.wait 9162306a36Sopenharmony_ci then 9262306a36Sopenharmony_ci mv $resdir/build.wait $resdir/build.ready 9362306a36Sopenharmony_ci fi 9462306a36Sopenharmony_ci exit 1 9562306a36Sopenharmony_cielif kvm-build.sh $T/KcList $resdir 9662306a36Sopenharmony_cithen 9762306a36Sopenharmony_ci # Had to build a kernel for this test. 9862306a36Sopenharmony_ci QEMU="`identify_qemu vmlinux`" 9962306a36Sopenharmony_ci BOOT_IMAGE="`identify_boot_image $QEMU`" 10062306a36Sopenharmony_ci cp vmlinux $resdir 10162306a36Sopenharmony_ci cp .config $resdir 10262306a36Sopenharmony_ci cp Module.symvers $resdir > /dev/null || : 10362306a36Sopenharmony_ci cp System.map $resdir > /dev/null || : 10462306a36Sopenharmony_ci if test -n "$BOOT_IMAGE" 10562306a36Sopenharmony_ci then 10662306a36Sopenharmony_ci cp $BOOT_IMAGE $resdir 10762306a36Sopenharmony_ci KERNEL=$resdir/${BOOT_IMAGE##*/} 10862306a36Sopenharmony_ci # Arch-independent indicator 10962306a36Sopenharmony_ci touch $resdir/builtkernel 11062306a36Sopenharmony_ci else 11162306a36Sopenharmony_ci echo No identifiable boot image, not running KVM, see $resdir. 11262306a36Sopenharmony_ci echo Do the torture scripts know about your architecture? 11362306a36Sopenharmony_ci fi 11462306a36Sopenharmony_ci parse-build.sh $resdir/Make.out $title 11562306a36Sopenharmony_cielse 11662306a36Sopenharmony_ci # Build failed. 11762306a36Sopenharmony_ci cp .config $resdir || : 11862306a36Sopenharmony_ci echo Build failed, not running KVM, see $resdir. 11962306a36Sopenharmony_ci if test -f $resdir/build.wait 12062306a36Sopenharmony_ci then 12162306a36Sopenharmony_ci mv $resdir/build.wait $resdir/build.ready 12262306a36Sopenharmony_ci fi 12362306a36Sopenharmony_ci exit 1 12462306a36Sopenharmony_cifi 12562306a36Sopenharmony_ciif test -f $resdir/build.wait 12662306a36Sopenharmony_cithen 12762306a36Sopenharmony_ci mv $resdir/build.wait $resdir/build.ready 12862306a36Sopenharmony_cifi 12962306a36Sopenharmony_ciwhile test -f $resdir/build.ready 13062306a36Sopenharmony_cido 13162306a36Sopenharmony_ci sleep 1 13262306a36Sopenharmony_cidone 13362306a36Sopenharmony_ciseconds=$3 13462306a36Sopenharmony_ciqemu_args=$4 13562306a36Sopenharmony_ciboot_args_in=$5 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ciif test -z "$TORTURE_BUILDONLY" 13862306a36Sopenharmony_cithen 13962306a36Sopenharmony_ci echo ' ---' `date`: Starting kernel 14062306a36Sopenharmony_cifi 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci# Generate -smp qemu argument. 14362306a36Sopenharmony_ciqemu_args="-enable-kvm -display none -no-reboot $qemu_args" 14462306a36Sopenharmony_cicpu_count=`configNR_CPUS.sh $resdir/ConfigFragment` 14562306a36Sopenharmony_cicpu_count=`configfrag_boot_cpus "$boot_args_in" "$config_template" "$cpu_count"` 14662306a36Sopenharmony_ciif test "$cpu_count" -gt "$TORTURE_ALLOTED_CPUS" 14762306a36Sopenharmony_cithen 14862306a36Sopenharmony_ci echo CPU count limited from $cpu_count to $TORTURE_ALLOTED_CPUS | tee -a $resdir/Warnings 14962306a36Sopenharmony_ci cpu_count=$TORTURE_ALLOTED_CPUS 15062306a36Sopenharmony_cifi 15162306a36Sopenharmony_ciqemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`" 15262306a36Sopenharmony_ciqemu_args="`specify_qemu_net "$qemu_args"`" 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci# Generate architecture-specific and interaction-specific qemu arguments 15562306a36Sopenharmony_ciqemu_args="$qemu_args `identify_qemu_args "$QEMU" "$resdir/console.log"`" 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci# Generate qemu -append arguments 15862306a36Sopenharmony_ciqemu_append="`identify_qemu_append "$QEMU"`" 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci# Pull in Kconfig-fragment boot parameters 16162306a36Sopenharmony_ciboot_args="`configfrag_boot_params "$boot_args_in" "$config_template"`" 16262306a36Sopenharmony_ci# Generate kernel-version-specific boot parameters 16362306a36Sopenharmony_ciboot_args="`per_version_boot_params "$boot_args" $resdir/.config $seconds`" 16462306a36Sopenharmony_ciif test -n "$TORTURE_BOOT_GDB_ARG" 16562306a36Sopenharmony_cithen 16662306a36Sopenharmony_ci boot_args="$TORTURE_BOOT_GDB_ARG $boot_args" 16762306a36Sopenharmony_cifi 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci# Give bare-metal advice 17062306a36Sopenharmony_cimodprobe_args="`echo $boot_args | tr -s ' ' '\012' | grep "^$TORTURE_MOD\." | sed -e "s/$TORTURE_MOD\.//g"`" 17162306a36Sopenharmony_cikboot_args="`echo $boot_args | tr -s ' ' '\012' | grep -v "^$TORTURE_MOD\."`" 17262306a36Sopenharmony_citestid_txt="`dirname $resdir`/testid.txt" 17362306a36Sopenharmony_citouch $resdir/bare-metal 17462306a36Sopenharmony_ciecho To run this scenario on bare metal: >> $resdir/bare-metal 17562306a36Sopenharmony_ciecho >> $resdir/bare-metal 17662306a36Sopenharmony_ciecho " 1." Set your bare-metal build tree to the state shown in this file: >> $resdir/bare-metal 17762306a36Sopenharmony_ciecho " " $testid_txt >> $resdir/bare-metal 17862306a36Sopenharmony_ciecho " 2." Update your bare-metal build tree"'"s .config based on this file: >> $resdir/bare-metal 17962306a36Sopenharmony_ciecho " " $resdir/ConfigFragment >> $resdir/bare-metal 18062306a36Sopenharmony_ciecho " 3." Make the bare-metal kernel"'"s build system aware of your .config updates: >> $resdir/bare-metal 18162306a36Sopenharmony_ciecho " " $ 'yes "" | make oldconfig' >> $resdir/bare-metal 18262306a36Sopenharmony_ciecho " 4." Build your bare-metal kernel. >> $resdir/bare-metal 18362306a36Sopenharmony_ciecho " 5." Boot your bare-metal kernel with the following parameters: >> $resdir/bare-metal 18462306a36Sopenharmony_ciecho " " $kboot_args >> $resdir/bare-metal 18562306a36Sopenharmony_ciecho " 6." Start the test with the following command: >> $resdir/bare-metal 18662306a36Sopenharmony_ciecho " " $ modprobe $TORTURE_MOD $modprobe_args >> $resdir/bare-metal 18762306a36Sopenharmony_ciecho " 7." After some time, end the test with the following command: >> $resdir/bare-metal 18862306a36Sopenharmony_ciecho " " $ rmmod $TORTURE_MOD >> $resdir/bare-metal 18962306a36Sopenharmony_ciecho " 8." Copy your bare-metal kernel"'"s .config file, overwriting this file: >> $resdir/bare-metal 19062306a36Sopenharmony_ciecho " " $resdir/.config >> $resdir/bare-metal 19162306a36Sopenharmony_ciecho " 9." Copy the console output from just before the modprobe to just after >> $resdir/bare-metal 19262306a36Sopenharmony_ciecho " " the rmmod into this file: >> $resdir/bare-metal 19362306a36Sopenharmony_ciecho " " $resdir/console.log >> $resdir/bare-metal 19462306a36Sopenharmony_ciecho "10." Check for runtime errors using the following command: >> $resdir/bare-metal 19562306a36Sopenharmony_ciecho " " $ tools/testing/selftests/rcutorture/bin/kvm-recheck.sh `dirname $resdir` >> $resdir/bare-metal 19662306a36Sopenharmony_ciecho >> $resdir/bare-metal 19762306a36Sopenharmony_ciecho Some of the above steps may be skipped if you build your bare-metal >> $resdir/bare-metal 19862306a36Sopenharmony_ciecho kernel here: `head -n 1 $testid_txt | sed -e 's/^Build directory: //'` >> $resdir/bare-metal 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ciecho $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append \"$qemu_append $boot_args\" $TORTURE_QEMU_GDB_ARG > $resdir/qemu-cmd 20162306a36Sopenharmony_ciecho "# TORTURE_SHUTDOWN_GRACE=$TORTURE_SHUTDOWN_GRACE" >> $resdir/qemu-cmd 20262306a36Sopenharmony_ciecho "# seconds=$seconds" >> $resdir/qemu-cmd 20362306a36Sopenharmony_ciecho "# TORTURE_KCONFIG_GDB_ARG=\"$TORTURE_KCONFIG_GDB_ARG\"" >> $resdir/qemu-cmd 20462306a36Sopenharmony_ciecho "# TORTURE_JITTER_START=\"$TORTURE_JITTER_START\"" >> $resdir/qemu-cmd 20562306a36Sopenharmony_ciecho "# TORTURE_JITTER_STOP=\"$TORTURE_JITTER_STOP\"" >> $resdir/qemu-cmd 20662306a36Sopenharmony_ciecho "# TORTURE_TRUST_MAKE=\"$TORTURE_TRUST_MAKE\"; export TORTURE_TRUST_MAKE" >> $resdir/qemu-cmd 20762306a36Sopenharmony_ciecho "# TORTURE_CPU_COUNT=$cpu_count" >> $resdir/qemu-cmd 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ciif test -n "$TORTURE_BUILDONLY" 21062306a36Sopenharmony_cithen 21162306a36Sopenharmony_ci echo Build-only run specified, boot/test omitted. 21262306a36Sopenharmony_ci touch $resdir/buildonly 21362306a36Sopenharmony_ci exit 0 21462306a36Sopenharmony_cifi 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_cikvm-test-1-run-qemu.sh $resdir 21762306a36Sopenharmony_ciparse-console.sh $resdir/console.log $title 218