brintos

brintos / linux-shallow public Read only

0
0
Text · 4.8 KiB · 88ca4e3 Raw
222 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.0+3#4# Rerun a series of tests under KVM.5#6# Usage: kvm-again.sh /path/to/old/run [ options ]7#8# Copyright (C) 2021 Facebook, Inc.9#10# Authors: Paul E. McKenney <paulmck@kernel.org>11 12scriptname=$013args="$*"14 15T="`mktemp -d ${TMPDIR-/tmp}/kvm-again.sh.XXXXXX`"16trap 'rm -rf $T' 017 18if ! test -d tools/testing/selftests/rcutorture/bin19then20	echo $scriptname must be run from top-level directory of kernel source tree.21	exit 122fi23 24oldrun=$125shift26if ! test -d "$oldrun"27then28	echo "Usage: $scriptname /path/to/old/run [ options ]"29	exit 130fi31if ! cp "$oldrun/scenarios" $T/scenarios.oldrun32then33	# Later on, can reconstitute this from console.log files.34	echo Prior run batches file does not exist: $oldrun/batches35	exit 136fi37 38if test -f "$oldrun/torture_suite"39then40	torture_suite="`cat $oldrun/torture_suite`"41elif test -f "$oldrun/TORTURE_SUITE"42then43	torture_suite="`cat $oldrun/TORTURE_SUITE`"44else45	echo "Prior run torture_suite file does not exist: $oldrun/{torture_suite,TORTURE_SUITE}"46	exit 147fi48 49RCUTORTURE="`pwd`/tools/testing/selftests/rcutorture"; export RCUTORTURE50PATH=${RCUTORTURE}/bin:$PATH; export PATH51. functions.sh52 53bootargs=54dryrun=55dur=56default_link="cp -R"57resdir="`pwd`/tools/testing/selftests/rcutorture/res"58rundir="$resdir/`date +%Y.%m.%d-%H.%M.%S-again`"59got_datestamp=60got_rundir=61 62startdate="`date`"63starttime="`get_starttime`"64 65usage () {66	echo "Usage: $scriptname $oldrun [ arguments ]:"67	echo "       --bootargs kernel-boot-arguments"68	echo "       --datestamp string"69	echo "       --dryrun"70	echo "       --duration minutes | <seconds>s | <hours>h | <days>d"71	echo "       --link hard|soft|copy"72	echo "       --remote"73	echo "       --rundir /new/res/path"74	echo "Command line: $scriptname $args"75	exit 176}77 78while test $# -gt 079do80	case "$1" in81	--bootargs|--bootarg)82		checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'83		bootargs="$bootargs $2"84		shift85		;;86	--datestamp)87		checkarg --datestamp "(relative pathname)" "$#" "$2" '^[a-zA-Z0-9._/-]*$' '^--'88		if test -n "$got_rundir" || test -n "$got_datestamp"89		then90			echo Only one of --datestamp or --rundir may be specified91			usage92		fi93		got_datestamp=y94		ds=$295		rundir="$resdir/$ds"96		if test -e "$rundir"97		then98			echo "--datestamp $2: Already exists."99			usage100		fi101		shift102		;;103	--dryrun)104		dryrun=1105		;;106	--duration)107		checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'108		mult=60109		if echo "$2" | grep -q 's$'110		then111			mult=1112		elif echo "$2" | grep -q 'h$'113		then114			mult=3600115		elif echo "$2" | grep -q 'd$'116		then117			mult=86400118		fi119		ts=`echo $2 | sed -e 's/[smhd]$//'`120		dur=$(($ts*mult))121		shift122		;;123	--link)124		checkarg --link "hard|soft|copy" "$#" "$2" 'hard\|soft\|copy' '^--'125		case "$2" in126		copy)127			arg_link="cp -R"128			;;129		hard)130			arg_link="cp -Rl"131			;;132		soft)133			arg_link="cp -Rs"134			;;135		esac136		shift137		;;138	--remote)139		arg_remote=1140		default_link="cp -as"141		;;142	--rundir)143		checkarg --rundir "(absolute pathname)" "$#" "$2" '^/' '^error'144		if test -n "$got_rundir" || test -n "$got_datestamp"145		then146			echo Only one of --datestamp or --rundir may be specified147			usage148		fi149		got_rundir=y150		rundir=$2151		if test -e "$rundir"152		then153			echo "--rundir $2: Already exists."154			usage155		fi156		shift157		;;158	*)159		if test -n "$1"160		then161			echo Unknown argument $1162			usage163		fi164		;;165	esac166	shift167done168if test -z "$arg_link"169then170	arg_link="$default_link"171fi172 173echo ---- Re-run results directory: $rundir174 175# Copy old run directory tree over and adjust.176mkdir -p "`dirname "$rundir"`"177if ! $arg_link "$oldrun" "$rundir"178then179	echo "Cannot copy from $oldrun to $rundir."180	usage181fi182rm -f "$rundir"/*/{console.log,console.log.diags,qemu_pid,qemu-pid,qemu-retval,Warnings,kvm-test-1-run.sh.out,kvm-test-1-run-qemu.sh.out,vmlinux} "$rundir"/log183touch "$rundir/log"184echo $scriptname $args | tee -a "$rundir/log"185echo $oldrun > "$rundir/re-run"186if ! test -d "$rundir/../../bin"187then188	$arg_link "$oldrun/../../bin" "$rundir/../.."189fi190for i in $rundir/*/qemu-cmd191do192	cp "$i" $T193	qemu_cmd_dir="`dirname "$i"`"194	kernel_dir="`echo $qemu_cmd_dir | sed -e 's/\.[0-9]\+$//'`"195	jitter_dir="`dirname "$kernel_dir"`"196	kvm-transform.sh "$kernel_dir/bzImage" "$qemu_cmd_dir/console.log" "$jitter_dir" "$dur" "$bootargs" < $T/qemu-cmd > $i197	if test -n "$arg_remote"198	then199		echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i200	fi201done202 203# Extract settings from the last qemu-cmd file transformed above.204grep '^#' $i | sed -e 's/^# //' > $T/qemu-cmd-settings205. $T/qemu-cmd-settings206 207grep -v '^#' $T/scenarios.oldrun | awk '208{209	curbatch = "";210	for (i = 2; i <= NF; i++)211		curbatch = curbatch " " $i;212	print "kvm-test-1-run-batch.sh" curbatch;213}' > $T/runbatches.sh214 215if test -n "$dryrun"216then217	echo ---- Dryrun complete, directory: $rundir | tee -a "$rundir/log"218else219	( cd "$rundir"; sh $T/runbatches.sh ) | tee -a "$rundir/log"220	kvm-end-run-stats.sh "$rundir" "$starttime"221fi222