brintos

brintos / linux-shallow public Read only

0
0
Text · 8.6 KiB · ad79784 Raw
220 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.0+3#4# Run a kvm-based test of the specified tree on the specified configs.5# Fully automated run and error checking, no graphics console.6#7# Execute this in the source tree.  Do not run it as a background task8# because qemu does not seem to like that much.9#10# Usage: kvm-test-1-run.sh config resdir seconds qemu-args boot_args_in11#12# qemu-args defaults to "-enable-kvm -display none -no-reboot", along13#			with arguments specifying the number of CPUs14#			and other options generated from the underlying15#			CPU architecture.16# boot_args_in defaults to value returned by the per_version_boot_params17#			shell function.18#19# Anything you specify for either qemu-args or boot_args_in is appended to20# the default values.  The "-smp" value is deduced from the contents of21# the config fragment.22#23# More sophisticated argument parsing is clearly needed.24#25# Copyright (C) IBM Corporation, 201126#27# Authors: Paul E. McKenney <paulmck@linux.ibm.com>28 29T="`mktemp -d ${TMPDIR-/tmp}/kvm-test-1-run.sh.XXXXXX`"30trap 'rm -rf $T' 031 32. functions.sh33. $CONFIGFRAG/ver_functions.sh34 35config_template=${1}36config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'`37title=`echo $config_template | sed -e 's/^.*\///'`38resdir=${2}39if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"40then41	echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it"42	exit 143fi44echo ' ---' `date`: Starting build, PID $$45echo ' ---' Kconfig fragment at: $config_template >> $resdir/log46touch $resdir/ConfigFragment.input47 48# Combine additional Kconfig options into an existing set such that49# newer options win.  The first argument is the Kconfig source ID, the50# second the to-be-updated file within $T, and the third and final the51# list of additional Kconfig options.  Note that a $2.tmp file is52# created when doing the update.53config_override_param () {54	if test -n "$3"55	then56		echo $3 | sed -e 's/^ *//' -e 's/ *$//' | tr -s " " "\012" > $T/Kconfig_args57		echo " --- $1" >> $resdir/ConfigFragment.input58		cat $T/Kconfig_args >> $resdir/ConfigFragment.input59		config_override.sh $T/$2 $T/Kconfig_args > $T/$2.tmp60		mv $T/$2.tmp $T/$261	fi62}63 64echo > $T/KcList65config_override_param "$config_dir/CFcommon" KcList "`cat $config_dir/CFcommon 2> /dev/null`"66config_override_param "$config_template" KcList "`cat $config_template 2> /dev/null`"67config_override_param "--gdb options" KcList "$TORTURE_KCONFIG_GDB_ARG"68config_override_param "--kasan options" KcList "$TORTURE_KCONFIG_KASAN_ARG"69config_override_param "--kcsan options" KcList "$TORTURE_KCONFIG_KCSAN_ARG"70config_override_param "--kconfig argument" KcList "$TORTURE_KCONFIG_ARG"71config_override_param "$config_dir/CFcommon.$(uname -m)" KcList \72		      "`cat $config_dir/CFcommon.$(uname -m) 2> /dev/null`"73cp $T/KcList $resdir/ConfigFragment74 75base_resdir=`echo $resdir | sed -e 's/\.[0-9]\+$//'`76if test "$base_resdir" != "$resdir" && test -f $base_resdir/bzImage && test -f $base_resdir/vmlinux77then78	# Rerunning previous test, so use that test's kernel.79	QEMU="`identify_qemu $base_resdir/vmlinux`"80	BOOT_IMAGE="`identify_boot_image $QEMU`"81	KERNEL=$base_resdir/${BOOT_IMAGE##*/} # use the last component of ${BOOT_IMAGE}82	ln -s $base_resdir/Make*.out $resdir  # for kvm-recheck.sh83	ln -s $base_resdir/.config $resdir  # for kvm-recheck.sh84	# Arch-independent indicator85	touch $resdir/builtkernel86elif test "$base_resdir" != "$resdir"87then88	# Rerunning previous test for which build failed89	ln -s $base_resdir/Make*.out $resdir  # for kvm-recheck.sh90	ln -s $base_resdir/.config $resdir  # for kvm-recheck.sh91	echo Initial build failed, not running KVM, see $resdir.92	if test -f $resdir/build.wait93	then94		mv $resdir/build.wait $resdir/build.ready95	fi96	exit 197elif kvm-build.sh $T/KcList $resdir98then99	# Had to build a kernel for this test.100	QEMU="`identify_qemu vmlinux`"101	BOOT_IMAGE="`identify_boot_image $QEMU`"102	cp vmlinux $resdir103	cp .config $resdir104	cp Module.symvers $resdir > /dev/null || :105	cp System.map $resdir > /dev/null || :106	if test -n "$BOOT_IMAGE"107	then108		cp $BOOT_IMAGE $resdir109		KERNEL=$resdir/${BOOT_IMAGE##*/}110		# Arch-independent indicator111		touch $resdir/builtkernel112	else113		echo No identifiable boot image, not running KVM, see $resdir.114		echo Do the torture scripts know about your architecture?115	fi116	parse-build.sh $resdir/Make.out $title117else118	# Build failed.119	cp .config $resdir || :120	echo Build failed, not running KVM, see $resdir.121	if test -f $resdir/build.wait122	then123		mv $resdir/build.wait $resdir/build.ready124	fi125	exit 1126fi127if test -f $resdir/build.wait128then129	mv $resdir/build.wait $resdir/build.ready130fi131while test -f $resdir/build.ready132do133	sleep 1134done135seconds=$3136qemu_args=$4137boot_args_in=$5138 139if test -z "$TORTURE_BUILDONLY"140then141	echo ' ---' `date`: Starting kernel142fi143 144# Generate -smp qemu argument.145qemu_args="-enable-kvm -display none -no-reboot $qemu_args"146cpu_count=`configNR_CPUS.sh $resdir/ConfigFragment`147cpu_count=`configfrag_boot_cpus "$boot_args_in" "$config_template" "$cpu_count"`148if test "$cpu_count" -gt "$TORTURE_ALLOTED_CPUS"149then150	echo CPU count limited from $cpu_count to $TORTURE_ALLOTED_CPUS | tee -a $resdir/Warnings151	cpu_count=$TORTURE_ALLOTED_CPUS152fi153qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"154qemu_args="`specify_qemu_net "$qemu_args"`"155 156# Generate architecture-specific and interaction-specific qemu arguments157qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$resdir/console.log"`"158 159# Generate qemu -append arguments160qemu_append="`identify_qemu_append "$QEMU"`"161 162# Pull in Kconfig-fragment boot parameters163boot_args="`configfrag_boot_params "$boot_args_in" "$config_template"`"164# Generate kernel-version-specific boot parameters165boot_args="`per_version_boot_params "$boot_args" $resdir/.config $seconds`"166if test -n "$TORTURE_BOOT_GDB_ARG"167then168	boot_args="$TORTURE_BOOT_GDB_ARG $boot_args"169fi170 171# Give bare-metal advice172modprobe_args="`echo $boot_args | tr -s ' ' '\012' | grep "^$TORTURE_MOD\." | sed -e "s/$TORTURE_MOD\.//g"`"173kboot_args="`echo $boot_args | tr -s ' ' '\012' | grep -v "^$TORTURE_MOD\."`"174testid_txt="`dirname $resdir`/testid.txt"175touch $resdir/bare-metal176echo To run this scenario on bare metal: >> $resdir/bare-metal177echo >> $resdir/bare-metal178echo " 1." Set your bare-metal build tree to the state shown in this file: >> $resdir/bare-metal179echo "   " $testid_txt >> $resdir/bare-metal180echo " 2." Update your bare-metal build tree"'"s .config based on this file: >> $resdir/bare-metal181echo "   " $resdir/ConfigFragment >> $resdir/bare-metal182echo " 3." Make the bare-metal kernel"'"s build system aware of your .config updates: >> $resdir/bare-metal183echo "   " $ 'yes "" | make oldconfig' >> $resdir/bare-metal184echo " 4." Build your bare-metal kernel. >> $resdir/bare-metal185echo " 5." Boot your bare-metal kernel with the following parameters: >> $resdir/bare-metal186echo "   " $kboot_args >> $resdir/bare-metal187echo " 6." Start the test with the following command: >> $resdir/bare-metal188echo "   " $ modprobe $TORTURE_MOD $modprobe_args >> $resdir/bare-metal189echo " 7." After some time, end the test with the following command: >> $resdir/bare-metal190echo "   " $ rmmod $TORTURE_MOD >> $resdir/bare-metal191echo " 8." Copy your bare-metal kernel"'"s .config file, overwriting this file: >> $resdir/bare-metal192echo "   " $resdir/.config >> $resdir/bare-metal193echo " 9." Copy the console output from just before the modprobe to just after >> $resdir/bare-metal194echo "   " the rmmod into this file: >> $resdir/bare-metal195echo "   " $resdir/console.log >> $resdir/bare-metal196echo "10." Check for runtime errors using the following command: >> $resdir/bare-metal197echo "   " $ tools/testing/selftests/rcutorture/bin/kvm-recheck.sh `dirname $resdir` >> $resdir/bare-metal198echo >> $resdir/bare-metal199echo Some of the above steps may be skipped if you build your bare-metal >> $resdir/bare-metal200echo kernel here: `head -n 1 $testid_txt | sed -e 's/^Build directory: //'`  >> $resdir/bare-metal201 202echo $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append \"$qemu_append $boot_args\" $TORTURE_QEMU_GDB_ARG > $resdir/qemu-cmd203echo "# TORTURE_SHUTDOWN_GRACE=$TORTURE_SHUTDOWN_GRACE" >> $resdir/qemu-cmd204echo "# seconds=$seconds" >> $resdir/qemu-cmd205echo "# TORTURE_KCONFIG_GDB_ARG=\"$TORTURE_KCONFIG_GDB_ARG\"" >> $resdir/qemu-cmd206echo "# TORTURE_JITTER_START=\"$TORTURE_JITTER_START\"" >> $resdir/qemu-cmd207echo "# TORTURE_JITTER_STOP=\"$TORTURE_JITTER_STOP\"" >> $resdir/qemu-cmd208echo "# TORTURE_TRUST_MAKE=\"$TORTURE_TRUST_MAKE\"; export TORTURE_TRUST_MAKE" >> $resdir/qemu-cmd209echo "# TORTURE_CPU_COUNT=$cpu_count" >> $resdir/qemu-cmd210 211if test -n "$TORTURE_BUILDONLY"212then213	echo Build-only run specified, boot/test omitted.214	touch $resdir/buildonly215	exit 0216fi217 218kvm-test-1-run-qemu.sh $resdir219parse-console.sh $resdir/console.log $title220