17cf86c0bSPaul E. McKenney#!/bin/bash 27cf86c0bSPaul E. McKenney# SPDX-License-Identifier: GPL-2.0+ 37cf86c0bSPaul E. McKenney# 47cf86c0bSPaul E. McKenney# Rerun a series of tests under KVM. 57cf86c0bSPaul E. McKenney# 67cf86c0bSPaul E. McKenney# Usage: kvm-again.sh /path/to/old/run [ options ] 77cf86c0bSPaul E. McKenney# 87cf86c0bSPaul E. McKenney# Copyright (C) 2021 Facebook, Inc. 97cf86c0bSPaul E. McKenney# 107cf86c0bSPaul E. McKenney# Authors: Paul E. McKenney <paulmck@kernel.org> 117cf86c0bSPaul E. McKenney 127cf86c0bSPaul E. McKenneyscriptname=$0 137cf86c0bSPaul E. McKenneyargs="$*" 147cf86c0bSPaul E. McKenney 157cf86c0bSPaul E. McKenneyT=${TMPDIR-/tmp}/kvm-again.sh.$$ 167cf86c0bSPaul E. McKenneytrap 'rm -rf $T' 0 177cf86c0bSPaul E. McKenneymkdir $T 187cf86c0bSPaul E. McKenney 197cf86c0bSPaul E. McKenneyif ! test -d tools/testing/selftests/rcutorture/bin 207cf86c0bSPaul E. McKenneythen 217cf86c0bSPaul E. McKenney echo $scriptname must be run from top-level directory of kernel source tree. 227cf86c0bSPaul E. McKenney exit 1 237cf86c0bSPaul E. McKenneyfi 247cf86c0bSPaul E. McKenney 257cf86c0bSPaul E. McKenneyoldrun=$1 267cf86c0bSPaul E. McKenneyshift 277cf86c0bSPaul E. McKenneyif ! test -d "$oldrun" 287cf86c0bSPaul E. McKenneythen 297cf86c0bSPaul E. McKenney echo "Usage: $scriptname /path/to/old/run [ options ]" 307cf86c0bSPaul E. McKenney exit 1 317cf86c0bSPaul E. McKenneyfi 327cf86c0bSPaul E. McKenneyif ! cp "$oldrun/batches" $T/batches.oldrun 337cf86c0bSPaul E. McKenneythen 347cf86c0bSPaul E. McKenney # Later on, can reconstitute this from console.log files. 357cf86c0bSPaul E. McKenney echo Prior run batches file does not exist: $oldrun/batches 367cf86c0bSPaul E. McKenney exit 1 377cf86c0bSPaul E. McKenneyfi 387cf86c0bSPaul E. McKenney 397cf86c0bSPaul E. McKenneyif test -f "$oldrun/torture_suite" 407cf86c0bSPaul E. McKenneythen 417cf86c0bSPaul E. McKenney torture_suite="`cat $oldrun/torture_suite`" 427cf86c0bSPaul E. McKenneyelif test -f "$oldrun/TORTURE_SUITE" 437cf86c0bSPaul E. McKenneythen 447cf86c0bSPaul E. McKenney torture_suite="`cat $oldrun/TORTURE_SUITE`" 457cf86c0bSPaul E. McKenneyelse 467cf86c0bSPaul E. McKenney echo "Prior run torture_suite file does not exist: $oldrun/{torture_suite,TORTURE_SUITE}" 477cf86c0bSPaul E. McKenney exit 1 487cf86c0bSPaul E. McKenneyfi 497cf86c0bSPaul E. McKenney 507cf86c0bSPaul E. McKenneyKVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM 517cf86c0bSPaul E. McKenneyPATH=${KVM}/bin:$PATH; export PATH 527cf86c0bSPaul E. McKenney. functions.sh 537cf86c0bSPaul E. McKenney 547cf86c0bSPaul E. McKenneydryrun= 5500505165SPaul E. McKenneydur= 567cf86c0bSPaul E. McKenneydefault_link="cp -R" 577cf86c0bSPaul E. McKenneyrundir="`pwd`/tools/testing/selftests/rcutorture/res/`date +%Y.%m.%d-%H.%M.%S-again`" 587cf86c0bSPaul E. McKenney 597cf86c0bSPaul E. McKenneystartdate="`date`" 607cf86c0bSPaul E. McKenneystarttime="`get_starttime`" 617cf86c0bSPaul E. McKenney 627cf86c0bSPaul E. McKenneyusage () { 637cf86c0bSPaul E. McKenney echo "Usage: $scriptname $oldrun [ arguments ]:" 647cf86c0bSPaul E. McKenney echo " --dryrun" 6500505165SPaul E. McKenney echo " --duration minutes | <seconds>s | <hours>h | <days>d" 667cf86c0bSPaul E. McKenney echo " --link hard|soft|copy" 677cf86c0bSPaul E. McKenney echo " --remote" 687cf86c0bSPaul E. McKenney echo " --rundir /new/res/path" 697cf86c0bSPaul E. McKenney exit 1 707cf86c0bSPaul E. McKenney} 717cf86c0bSPaul E. McKenney 727cf86c0bSPaul E. McKenneywhile test $# -gt 0 737cf86c0bSPaul E. McKenneydo 747cf86c0bSPaul E. McKenney case "$1" in 757cf86c0bSPaul E. McKenney --dryrun) 767cf86c0bSPaul E. McKenney dryrun=1 777cf86c0bSPaul E. McKenney ;; 7800505165SPaul E. McKenney --duration) 7900505165SPaul E. McKenney checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error' 8000505165SPaul E. McKenney mult=60 8100505165SPaul E. McKenney if echo "$2" | grep -q 's$' 8200505165SPaul E. McKenney then 8300505165SPaul E. McKenney mult=1 8400505165SPaul E. McKenney elif echo "$2" | grep -q 'h$' 8500505165SPaul E. McKenney then 8600505165SPaul E. McKenney mult=3600 8700505165SPaul E. McKenney elif echo "$2" | grep -q 'd$' 8800505165SPaul E. McKenney then 8900505165SPaul E. McKenney mult=86400 9000505165SPaul E. McKenney fi 9100505165SPaul E. McKenney ts=`echo $2 | sed -e 's/[smhd]$//'` 9200505165SPaul E. McKenney dur=$(($ts*mult)) 9300505165SPaul E. McKenney shift 9400505165SPaul E. McKenney ;; 957cf86c0bSPaul E. McKenney --link) 967cf86c0bSPaul E. McKenney checkarg --link "hard|soft|copy" "$#" "$2" 'hard\|soft\|copy' '^--' 977cf86c0bSPaul E. McKenney case "$2" in 987cf86c0bSPaul E. McKenney copy) 997cf86c0bSPaul E. McKenney arg_link="cp -R" 1007cf86c0bSPaul E. McKenney ;; 1017cf86c0bSPaul E. McKenney hard) 1027cf86c0bSPaul E. McKenney arg_link="cp -Rl" 1037cf86c0bSPaul E. McKenney ;; 1047cf86c0bSPaul E. McKenney soft) 1057cf86c0bSPaul E. McKenney arg_link="cp -Rs" 1067cf86c0bSPaul E. McKenney ;; 1077cf86c0bSPaul E. McKenney esac 1087cf86c0bSPaul E. McKenney shift 1097cf86c0bSPaul E. McKenney ;; 1107cf86c0bSPaul E. McKenney --remote) 1117cf86c0bSPaul E. McKenney arg_remote=1 1127cf86c0bSPaul E. McKenney default_link="cp -as" 1137cf86c0bSPaul E. McKenney ;; 1147cf86c0bSPaul E. McKenney --rundir) 1157cf86c0bSPaul E. McKenney checkarg --rundir "(absolute pathname)" "$#" "$2" '^/' '^error' 1167cf86c0bSPaul E. McKenney rundir=$2 1177cf86c0bSPaul E. McKenney if test -e "$rundir" 1187cf86c0bSPaul E. McKenney then 1197cf86c0bSPaul E. McKenney echo "--rundir $2: Already exists." 1207cf86c0bSPaul E. McKenney usage 1217cf86c0bSPaul E. McKenney fi 1227cf86c0bSPaul E. McKenney shift 1237cf86c0bSPaul E. McKenney ;; 1247cf86c0bSPaul E. McKenney *) 1257cf86c0bSPaul E. McKenney echo Unknown argument $1 1267cf86c0bSPaul E. McKenney usage 1277cf86c0bSPaul E. McKenney ;; 1287cf86c0bSPaul E. McKenney esac 1297cf86c0bSPaul E. McKenney shift 1307cf86c0bSPaul E. McKenneydone 1317cf86c0bSPaul E. McKenneyif test -z "$arg_link" 1327cf86c0bSPaul E. McKenneythen 1337cf86c0bSPaul E. McKenney arg_link="$default_link" 1347cf86c0bSPaul E. McKenneyfi 1357cf86c0bSPaul E. McKenney 1367cf86c0bSPaul E. McKenneyecho ---- Re-run results directory: $rundir 1377cf86c0bSPaul E. McKenney 1387cf86c0bSPaul E. McKenney# Copy old run directory tree over and adjust. 1397cf86c0bSPaul E. McKenneymkdir -p "`dirname "$rundir"`" 1407cf86c0bSPaul E. McKenneyif ! $arg_link "$oldrun" "$rundir" 1417cf86c0bSPaul E. McKenneythen 1427cf86c0bSPaul E. McKenney echo "Cannot copy from $oldrun to $rundir." 1437cf86c0bSPaul E. McKenney usage 1447cf86c0bSPaul E. McKenneyfi 1457cf86c0bSPaul 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 1467cf86c0bSPaul E. McKenneyecho $oldrun > "$rundir/re-run" 1477cf86c0bSPaul E. McKenneyif ! test -d "$rundir/../../bin" 1487cf86c0bSPaul E. McKenneythen 1497cf86c0bSPaul E. McKenney $arg_link "$oldrun/../../bin" "$rundir/../.." 1507cf86c0bSPaul E. McKenneyfi 1517cf86c0bSPaul E. McKenneyfor i in $rundir/*/qemu-cmd 1527cf86c0bSPaul E. McKenneydo 1537cf86c0bSPaul E. McKenney cp "$i" $T 1547cf86c0bSPaul E. McKenney qemu_cmd_dir="`dirname "$i"`" 1557cf86c0bSPaul E. McKenney kernel_dir="`echo $qemu_cmd_dir | sed -e 's/\.[0-9]\+$//'`" 156*018629e9SPaul E. McKenney jitter_dir="`dirname "$kernel_dir"`" 157*018629e9SPaul E. McKenney kvm-transform.sh "$kernel_dir/bzImage" "$qemu_cmd_dir/console.log" "$jitter_dir" $dur < $T/qemu-cmd > $i 15800505165SPaul E. McKenney if test -n "$dur" 15900505165SPaul E. McKenney then 16000505165SPaul E. McKenney echo "# seconds=$dur" >> $i 16100505165SPaul E. McKenney fi 1627cf86c0bSPaul E. McKenney echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i 1637cf86c0bSPaul E. McKenneydone 1647cf86c0bSPaul E. McKenneygrep -v '^#' $T/batches.oldrun | awk ' 1657cf86c0bSPaul E. McKenneyBEGIN { 1667cf86c0bSPaul E. McKenney oldbatch = 1; 1677cf86c0bSPaul E. McKenney} 1687cf86c0bSPaul E. McKenney 1697cf86c0bSPaul E. McKenney{ 1707cf86c0bSPaul E. McKenney if (oldbatch != $1) { 1717cf86c0bSPaul E. McKenney print "kvm-test-1-run-batch.sh" curbatch; 1727cf86c0bSPaul E. McKenney curbatch = ""; 1737cf86c0bSPaul E. McKenney oldbatch = $1; 1747cf86c0bSPaul E. McKenney } 1757cf86c0bSPaul E. McKenney curbatch = curbatch " " $2; 1767cf86c0bSPaul E. McKenney} 1777cf86c0bSPaul E. McKenney 1787cf86c0bSPaul E. McKenneyEND { 1797cf86c0bSPaul E. McKenney print "kvm-test-1-run-batch.sh" curbatch 1807cf86c0bSPaul E. McKenney}' > $T/runbatches.sh 1817cf86c0bSPaul E. McKenney 1827cf86c0bSPaul E. McKenneyif test -n "$dryrun" 1837cf86c0bSPaul E. McKenneythen 1847cf86c0bSPaul E. McKenney echo ---- Dryrun complete, directory: $rundir | tee -a "$rundir/log" 1857cf86c0bSPaul E. McKenneyelse 1867cf86c0bSPaul E. McKenney ( cd "$rundir"; sh $T/runbatches.sh ) 1877cf86c0bSPaul E. McKenney kcsan-collapse.sh "$rundir" | tee -a "$rundir/log" 1887cf86c0bSPaul E. McKenney echo | tee -a "$rundir/log" 1897cf86c0bSPaul E. McKenney echo ---- Results directory: $rundir | tee -a "$rundir/log" 1907cf86c0bSPaul E. McKenney kvm-recheck.sh "$rundir" > $T/kvm-recheck.sh.out 2>&1 1917cf86c0bSPaul E. McKenney ret=$? 1927cf86c0bSPaul E. McKenney cat $T/kvm-recheck.sh.out | tee -a "$rundir/log" 1937cf86c0bSPaul E. McKenney echo " --- Done at `date` (`get_starttime_duration $starttime`) exitcode $ret" | tee -a "$rundir/log" 1947cf86c0bSPaul E. McKenney exit $ret 1957cf86c0bSPaul E. McKenneyfi 196