kvm-again.sh 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0+
#
# Rerun a series of tests under KVM.
#
# Usage: kvm-again.sh /path/to/old/run [ options ]
#
# Copyright (C) 2021 Facebook, Inc.
#
# Authors: Paul E. McKenney <paulmck@kernel.org>

scriptname=$0
args="$*"

T=${TMPDIR-/tmp}/kvm-again.sh.$$
trap 'rm -rf $T' 0
mkdir $T

if ! test -d tools/testing/selftests/rcutorture/bin
then
	echo $scriptname must be run from top-level directory of kernel source tree.
	exit 1
fi

oldrun=$1
shift
if ! test -d "$oldrun"
then
	echo "Usage: $scriptname /path/to/old/run [ options ]"
	exit 1
fi
32
if ! cp "$oldrun/scenarios" $T/scenarios.oldrun
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
then
	# Later on, can reconstitute this from console.log files.
	echo Prior run batches file does not exist: $oldrun/batches
	exit 1
fi

if test -f "$oldrun/torture_suite"
then
	torture_suite="`cat $oldrun/torture_suite`"
elif test -f "$oldrun/TORTURE_SUITE"
then
	torture_suite="`cat $oldrun/TORTURE_SUITE`"
else
	echo "Prior run torture_suite file does not exist: $oldrun/{torture_suite,TORTURE_SUITE}"
	exit 1
fi

KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
PATH=${KVM}/bin:$PATH; export PATH
. functions.sh

dryrun=
55
dur=
56 57 58 59 60 61 62 63 64
default_link="cp -R"
rundir="`pwd`/tools/testing/selftests/rcutorture/res/`date +%Y.%m.%d-%H.%M.%S-again`"

startdate="`date`"
starttime="`get_starttime`"

usage () {
	echo "Usage: $scriptname $oldrun [ arguments ]:"
	echo "       --dryrun"
65
	echo "       --duration minutes | <seconds>s | <hours>h | <days>d"
66 67 68 69 70 71 72 73 74 75 76 77
	echo "       --link hard|soft|copy"
	echo "       --remote"
	echo "       --rundir /new/res/path"
	exit 1
}

while test $# -gt 0
do
	case "$1" in
	--dryrun)
		dryrun=1
		;;
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
	--duration)
		checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'
		mult=60
		if echo "$2" | grep -q 's$'
		then
			mult=1
		elif echo "$2" | grep -q 'h$'
		then
			mult=3600
		elif echo "$2" | grep -q 'd$'
		then
			mult=86400
		fi
		ts=`echo $2 | sed -e 's/[smhd]$//'`
		dur=$(($ts*mult))
		shift
		;;
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
	--link)
		checkarg --link "hard|soft|copy" "$#" "$2" 'hard\|soft\|copy' '^--'
		case "$2" in
		copy)
			arg_link="cp -R"
			;;
		hard)
			arg_link="cp -Rl"
			;;
		soft)
			arg_link="cp -Rs"
			;;
		esac
		shift
		;;
	--remote)
		arg_remote=1
		default_link="cp -as"
		;;
	--rundir)
		checkarg --rundir "(absolute pathname)" "$#" "$2" '^/' '^error'
		rundir=$2
		if test -e "$rundir"
		then
			echo "--rundir $2: Already exists."
			usage
		fi
		shift
		;;
	*)
		echo Unknown argument $1
		usage
		;;
	esac
	shift
done
if test -z "$arg_link"
then
	arg_link="$default_link"
fi

echo ---- Re-run results directory: $rundir

# Copy old run directory tree over and adjust.
mkdir -p "`dirname "$rundir"`"
if ! $arg_link "$oldrun" "$rundir"
then
	echo "Cannot copy from $oldrun to $rundir."
	usage
fi
rm -f "$rundir"/*/{console.log,console.log.diags,qemu_pid,qemu-retval,Warnings,kvm-test-1-run.sh.out,kvm-test-1-run-qemu.sh.out,vmlinux} "$rundir"/log
146 147
touch "$rundir/log"
echo $scriptname $args | tee -a "$rundir/log"
148 149 150 151 152 153 154 155 156 157
echo $oldrun > "$rundir/re-run"
if ! test -d "$rundir/../../bin"
then
	$arg_link "$oldrun/../../bin" "$rundir/../.."
fi
for i in $rundir/*/qemu-cmd
do
	cp "$i" $T
	qemu_cmd_dir="`dirname "$i"`"
	kernel_dir="`echo $qemu_cmd_dir | sed -e 's/\.[0-9]\+$//'`"
158 159
	jitter_dir="`dirname "$kernel_dir"`"
	kvm-transform.sh "$kernel_dir/bzImage" "$qemu_cmd_dir/console.log" "$jitter_dir" $dur < $T/qemu-cmd > $i
160 161 162 163
	if test -n "$arg_remote"
	then
		echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i
	fi
164
done
165 166 167 168 169

# Extract settings from the last qemu-cmd file transformed above.
grep '^#' $i | sed -e 's/^# //' > $T/qemu-cmd-settings
. $T/qemu-cmd-settings

170
grep -v '^#' $T/scenarios.oldrun | awk '
171
{
172 173 174 175
	curbatch = "";
	for (i = 2; i <= NF; i++)
		curbatch = curbatch " " $i;
	print "kvm-test-1-run-batch.sh" curbatch;
176 177 178 179 180 181 182
}' > $T/runbatches.sh

if test -n "$dryrun"
then
	echo ---- Dryrun complete, directory: $rundir | tee -a "$rundir/log"
else
	( cd "$rundir"; sh $T/runbatches.sh )
183
	kvm-end-run-stats.sh "$rundir" "$starttime"
184
fi
新手
引导
客服 返回
顶部