1*7cf86c0bSPaul E. McKenney#!/bin/bash 2*7cf86c0bSPaul E. McKenney# SPDX-License-Identifier: GPL-2.0+ 3*7cf86c0bSPaul E. McKenney# 4*7cf86c0bSPaul E. McKenney# Rerun a series of tests under KVM. 5*7cf86c0bSPaul E. McKenney# 6*7cf86c0bSPaul E. McKenney# Usage: kvm-again.sh /path/to/old/run [ options ] 7*7cf86c0bSPaul E. McKenney# 8*7cf86c0bSPaul E. McKenney# Copyright (C) 2021 Facebook, Inc. 9*7cf86c0bSPaul E. McKenney# 10*7cf86c0bSPaul E. McKenney# Authors: Paul E. McKenney <paulmck@kernel.org> 11*7cf86c0bSPaul E. McKenney 12*7cf86c0bSPaul E. McKenneyscriptname=$0 13*7cf86c0bSPaul E. McKenneyargs="$*" 14*7cf86c0bSPaul E. McKenney 15*7cf86c0bSPaul E. McKenneyT=${TMPDIR-/tmp}/kvm-again.sh.$$ 16*7cf86c0bSPaul E. McKenneytrap 'rm -rf $T' 0 17*7cf86c0bSPaul E. McKenneymkdir $T 18*7cf86c0bSPaul E. McKenney 19*7cf86c0bSPaul E. McKenneyif ! test -d tools/testing/selftests/rcutorture/bin 20*7cf86c0bSPaul E. McKenneythen 21*7cf86c0bSPaul E. McKenney echo $scriptname must be run from top-level directory of kernel source tree. 22*7cf86c0bSPaul E. McKenney exit 1 23*7cf86c0bSPaul E. McKenneyfi 24*7cf86c0bSPaul E. McKenney 25*7cf86c0bSPaul E. McKenneyoldrun=$1 26*7cf86c0bSPaul E. McKenneyshift 27*7cf86c0bSPaul E. McKenneyif ! test -d "$oldrun" 28*7cf86c0bSPaul E. McKenneythen 29*7cf86c0bSPaul E. McKenney echo "Usage: $scriptname /path/to/old/run [ options ]" 30*7cf86c0bSPaul E. McKenney exit 1 31*7cf86c0bSPaul E. McKenneyfi 32*7cf86c0bSPaul E. McKenneyif ! cp "$oldrun/batches" $T/batches.oldrun 33*7cf86c0bSPaul E. McKenneythen 34*7cf86c0bSPaul E. McKenney # Later on, can reconstitute this from console.log files. 35*7cf86c0bSPaul E. McKenney echo Prior run batches file does not exist: $oldrun/batches 36*7cf86c0bSPaul E. McKenney exit 1 37*7cf86c0bSPaul E. McKenneyfi 38*7cf86c0bSPaul E. McKenney 39*7cf86c0bSPaul E. McKenneyif test -f "$oldrun/torture_suite" 40*7cf86c0bSPaul E. McKenneythen 41*7cf86c0bSPaul E. McKenney torture_suite="`cat $oldrun/torture_suite`" 42*7cf86c0bSPaul E. McKenneyelif test -f "$oldrun/TORTURE_SUITE" 43*7cf86c0bSPaul E. McKenneythen 44*7cf86c0bSPaul E. McKenney torture_suite="`cat $oldrun/TORTURE_SUITE`" 45*7cf86c0bSPaul E. McKenneyelse 46*7cf86c0bSPaul E. McKenney echo "Prior run torture_suite file does not exist: $oldrun/{torture_suite,TORTURE_SUITE}" 47*7cf86c0bSPaul E. McKenney exit 1 48*7cf86c0bSPaul E. McKenneyfi 49*7cf86c0bSPaul E. McKenney 50*7cf86c0bSPaul E. McKenneyKVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM 51*7cf86c0bSPaul E. McKenneyPATH=${KVM}/bin:$PATH; export PATH 52*7cf86c0bSPaul E. McKenney. functions.sh 53*7cf86c0bSPaul E. McKenney 54*7cf86c0bSPaul E. McKenneydryrun= 55*7cf86c0bSPaul E. McKenneydefault_link="cp -R" 56*7cf86c0bSPaul E. McKenneyrundir="`pwd`/tools/testing/selftests/rcutorture/res/`date +%Y.%m.%d-%H.%M.%S-again`" 57*7cf86c0bSPaul E. McKenney 58*7cf86c0bSPaul E. McKenneystartdate="`date`" 59*7cf86c0bSPaul E. McKenneystarttime="`get_starttime`" 60*7cf86c0bSPaul E. McKenney 61*7cf86c0bSPaul E. McKenneyusage () { 62*7cf86c0bSPaul E. McKenney echo "Usage: $scriptname $oldrun [ arguments ]:" 63*7cf86c0bSPaul E. McKenney echo " --dryrun" 64*7cf86c0bSPaul E. McKenney echo " --link hard|soft|copy" 65*7cf86c0bSPaul E. McKenney echo " --remote" 66*7cf86c0bSPaul E. McKenney echo " --rundir /new/res/path" 67*7cf86c0bSPaul E. McKenney exit 1 68*7cf86c0bSPaul E. McKenney} 69*7cf86c0bSPaul E. McKenney 70*7cf86c0bSPaul E. McKenneywhile test $# -gt 0 71*7cf86c0bSPaul E. McKenneydo 72*7cf86c0bSPaul E. McKenney case "$1" in 73*7cf86c0bSPaul E. McKenney --dryrun) 74*7cf86c0bSPaul E. McKenney dryrun=1 75*7cf86c0bSPaul E. McKenney ;; 76*7cf86c0bSPaul E. McKenney --link) 77*7cf86c0bSPaul E. McKenney checkarg --link "hard|soft|copy" "$#" "$2" 'hard\|soft\|copy' '^--' 78*7cf86c0bSPaul E. McKenney case "$2" in 79*7cf86c0bSPaul E. McKenney copy) 80*7cf86c0bSPaul E. McKenney arg_link="cp -R" 81*7cf86c0bSPaul E. McKenney ;; 82*7cf86c0bSPaul E. McKenney hard) 83*7cf86c0bSPaul E. McKenney arg_link="cp -Rl" 84*7cf86c0bSPaul E. McKenney ;; 85*7cf86c0bSPaul E. McKenney soft) 86*7cf86c0bSPaul E. McKenney arg_link="cp -Rs" 87*7cf86c0bSPaul E. McKenney ;; 88*7cf86c0bSPaul E. McKenney esac 89*7cf86c0bSPaul E. McKenney shift 90*7cf86c0bSPaul E. McKenney ;; 91*7cf86c0bSPaul E. McKenney --remote) 92*7cf86c0bSPaul E. McKenney arg_remote=1 93*7cf86c0bSPaul E. McKenney default_link="cp -as" 94*7cf86c0bSPaul E. McKenney ;; 95*7cf86c0bSPaul E. McKenney --rundir) 96*7cf86c0bSPaul E. McKenney checkarg --rundir "(absolute pathname)" "$#" "$2" '^/' '^error' 97*7cf86c0bSPaul E. McKenney rundir=$2 98*7cf86c0bSPaul E. McKenney if test -e "$rundir" 99*7cf86c0bSPaul E. McKenney then 100*7cf86c0bSPaul E. McKenney echo "--rundir $2: Already exists." 101*7cf86c0bSPaul E. McKenney usage 102*7cf86c0bSPaul E. McKenney fi 103*7cf86c0bSPaul E. McKenney shift 104*7cf86c0bSPaul E. McKenney ;; 105*7cf86c0bSPaul E. McKenney *) 106*7cf86c0bSPaul E. McKenney echo Unknown argument $1 107*7cf86c0bSPaul E. McKenney usage 108*7cf86c0bSPaul E. McKenney ;; 109*7cf86c0bSPaul E. McKenney esac 110*7cf86c0bSPaul E. McKenney shift 111*7cf86c0bSPaul E. McKenneydone 112*7cf86c0bSPaul E. McKenneyif test -z "$arg_link" 113*7cf86c0bSPaul E. McKenneythen 114*7cf86c0bSPaul E. McKenney arg_link="$default_link" 115*7cf86c0bSPaul E. McKenneyfi 116*7cf86c0bSPaul E. McKenney 117*7cf86c0bSPaul E. McKenneyecho ---- Re-run results directory: $rundir 118*7cf86c0bSPaul E. McKenney 119*7cf86c0bSPaul E. McKenney# Copy old run directory tree over and adjust. 120*7cf86c0bSPaul E. McKenneymkdir -p "`dirname "$rundir"`" 121*7cf86c0bSPaul E. McKenneyif ! $arg_link "$oldrun" "$rundir" 122*7cf86c0bSPaul E. McKenneythen 123*7cf86c0bSPaul E. McKenney echo "Cannot copy from $oldrun to $rundir." 124*7cf86c0bSPaul E. McKenney usage 125*7cf86c0bSPaul E. McKenneyfi 126*7cf86c0bSPaul E. McKenneyrm -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 127*7cf86c0bSPaul E. McKenneyecho $oldrun > "$rundir/re-run" 128*7cf86c0bSPaul E. McKenneyif ! test -d "$rundir/../../bin" 129*7cf86c0bSPaul E. McKenneythen 130*7cf86c0bSPaul E. McKenney $arg_link "$oldrun/../../bin" "$rundir/../.." 131*7cf86c0bSPaul E. McKenneyfi 132*7cf86c0bSPaul E. McKenneyfor i in $rundir/*/qemu-cmd 133*7cf86c0bSPaul E. McKenneydo 134*7cf86c0bSPaul E. McKenney cp "$i" $T 135*7cf86c0bSPaul E. McKenney qemu_cmd_dir="`dirname "$i"`" 136*7cf86c0bSPaul E. McKenney kernel_dir="`echo $qemu_cmd_dir | sed -e 's/\.[0-9]\+$//'`" 137*7cf86c0bSPaul E. McKenney kvm-transform.sh $kernel_dir/bzImage $qemu_cmd_dir/console.log < $T/qemu-cmd > $i 138*7cf86c0bSPaul E. McKenney echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i 139*7cf86c0bSPaul E. McKenneydone 140*7cf86c0bSPaul E. McKenneygrep -v '^#' $T/batches.oldrun | awk ' 141*7cf86c0bSPaul E. McKenneyBEGIN { 142*7cf86c0bSPaul E. McKenney oldbatch = 1; 143*7cf86c0bSPaul E. McKenney} 144*7cf86c0bSPaul E. McKenney 145*7cf86c0bSPaul E. McKenney{ 146*7cf86c0bSPaul E. McKenney if (oldbatch != $1) { 147*7cf86c0bSPaul E. McKenney print "kvm-test-1-run-batch.sh" curbatch; 148*7cf86c0bSPaul E. McKenney curbatch = ""; 149*7cf86c0bSPaul E. McKenney oldbatch = $1; 150*7cf86c0bSPaul E. McKenney } 151*7cf86c0bSPaul E. McKenney curbatch = curbatch " " $2; 152*7cf86c0bSPaul E. McKenney} 153*7cf86c0bSPaul E. McKenney 154*7cf86c0bSPaul E. McKenneyEND { 155*7cf86c0bSPaul E. McKenney print "kvm-test-1-run-batch.sh" curbatch 156*7cf86c0bSPaul E. McKenney}' > $T/runbatches.sh 157*7cf86c0bSPaul E. McKenney 158*7cf86c0bSPaul E. McKenneyif test -n "$dryrun" 159*7cf86c0bSPaul E. McKenneythen 160*7cf86c0bSPaul E. McKenney echo ---- Dryrun complete, directory: $rundir | tee -a "$rundir/log" 161*7cf86c0bSPaul E. McKenneyelse 162*7cf86c0bSPaul E. McKenney ( cd "$rundir"; sh $T/runbatches.sh ) 163*7cf86c0bSPaul E. McKenney kcsan-collapse.sh "$rundir" | tee -a "$rundir/log" 164*7cf86c0bSPaul E. McKenney echo | tee -a "$rundir/log" 165*7cf86c0bSPaul E. McKenney echo ---- Results directory: $rundir | tee -a "$rundir/log" 166*7cf86c0bSPaul E. McKenney kvm-recheck.sh "$rundir" > $T/kvm-recheck.sh.out 2>&1 167*7cf86c0bSPaul E. McKenney ret=$? 168*7cf86c0bSPaul E. McKenney cat $T/kvm-recheck.sh.out | tee -a "$rundir/log" 169*7cf86c0bSPaul E. McKenney echo " --- Done at `date` (`get_starttime_duration $starttime`) exitcode $ret" | tee -a "$rundir/log" 170*7cf86c0bSPaul E. McKenney exit $ret 171*7cf86c0bSPaul E. McKenneyfi 172