162306a36Sopenharmony_ci#!/bin/sh
262306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+
362306a36Sopenharmony_ci#
462306a36Sopenharmony_ci# Run a group of kvm.sh tests on the specified commits.  This currently
562306a36Sopenharmony_ci# unconditionally does three-minute runs on each scenario in CFLIST,
662306a36Sopenharmony_ci# taking advantage of all available CPUs and trusting the "make" utility.
762306a36Sopenharmony_ci# In the short term, adjustments can be made by editing this script and
862306a36Sopenharmony_ci# CFLIST.  If some adjustments appear to have ongoing value, this script
962306a36Sopenharmony_ci# might grow some command-line arguments.
1062306a36Sopenharmony_ci#
1162306a36Sopenharmony_ci# Usage: kvm-check-branches.sh commit1 commit2..commit3 commit4 ...
1262306a36Sopenharmony_ci#
1362306a36Sopenharmony_ci# This script considers its arguments one at a time.  If more elaborate
1462306a36Sopenharmony_ci# specification of commits is needed, please use "git rev-list" to
1562306a36Sopenharmony_ci# produce something that this simple script can understand.  The reason
1662306a36Sopenharmony_ci# for retaining the simplicity is that it allows the user to more easily
1762306a36Sopenharmony_ci# see which commit came from which branch.
1862306a36Sopenharmony_ci#
1962306a36Sopenharmony_ci# This script creates a yyyy.mm.dd-hh.mm.ss-group entry in the "res"
2062306a36Sopenharmony_ci# directory.  The calls to kvm.sh create the usual entries, but this script
2162306a36Sopenharmony_ci# moves them under the yyyy.mm.dd-hh.mm.ss-group entry, each in its own
2262306a36Sopenharmony_ci# directory numbered in run order, that is, "0001", "0002", and so on.
2362306a36Sopenharmony_ci# For successful runs, the large build artifacts are removed.  Doing this
2462306a36Sopenharmony_ci# reduces the disk space required by about two orders of magnitude for
2562306a36Sopenharmony_ci# successful runs.
2662306a36Sopenharmony_ci#
2762306a36Sopenharmony_ci# Copyright (C) Facebook, 2020
2862306a36Sopenharmony_ci#
2962306a36Sopenharmony_ci# Authors: Paul E. McKenney <paulmck@kernel.org>
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciif ! git status > /dev/null 2>&1
3262306a36Sopenharmony_cithen
3362306a36Sopenharmony_ci	echo '!!!' This script needs to run in a git archive. 1>&2
3462306a36Sopenharmony_ci	echo '!!!' Giving up. 1>&2
3562306a36Sopenharmony_ci	exit 1
3662306a36Sopenharmony_cifi
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci# Remember where we started so that we can get back at the end.
3962306a36Sopenharmony_cicurcommit="`git status | head -1 | awk '{ print $NF }'`"
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_cinfail=0
4262306a36Sopenharmony_cintry=0
4362306a36Sopenharmony_ciresdir="tools/testing/selftests/rcutorture/res"
4462306a36Sopenharmony_cids="`date +%Y.%m.%d-%H.%M.%S`-group"
4562306a36Sopenharmony_ciif ! test -e $resdir
4662306a36Sopenharmony_cithen
4762306a36Sopenharmony_ci	mkdir $resdir || :
4862306a36Sopenharmony_cifi
4962306a36Sopenharmony_cimkdir $resdir/$ds
5062306a36Sopenharmony_ciecho Results directory: $resdir/$ds
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ciRCUTORTURE="`pwd`/tools/testing/selftests/rcutorture"; export RCUTORTURE
5362306a36Sopenharmony_ciPATH=${RCUTORTURE}/bin:$PATH; export PATH
5462306a36Sopenharmony_ci. functions.sh
5562306a36Sopenharmony_ciecho Using all `identify_qemu_vcpus` CPUs.
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci# Each pass through this loop does one command-line argument.
5862306a36Sopenharmony_cifor gitbr in $@
5962306a36Sopenharmony_cido
6062306a36Sopenharmony_ci	echo ' --- git branch ' $gitbr
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci	# Each pass through this loop tests one commit.
6362306a36Sopenharmony_ci	for i in `git rev-list "$gitbr"`
6462306a36Sopenharmony_ci	do
6562306a36Sopenharmony_ci		ntry=`expr $ntry + 1`
6662306a36Sopenharmony_ci		idir=`awk -v ntry="$ntry" 'END { printf "%04d", ntry; }' < /dev/null`
6762306a36Sopenharmony_ci		echo ' --- commit ' $i from branch $gitbr
6862306a36Sopenharmony_ci		date
6962306a36Sopenharmony_ci		mkdir $resdir/$ds/$idir
7062306a36Sopenharmony_ci		echo $gitbr > $resdir/$ds/$idir/gitbr
7162306a36Sopenharmony_ci		echo $i >> $resdir/$ds/$idir/gitbr
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci		# Test the specified commit.
7462306a36Sopenharmony_ci		git checkout $i > $resdir/$ds/$idir/git-checkout.out 2>&1
7562306a36Sopenharmony_ci		echo git checkout return code: $? "(Commit $ntry: $i)"
7662306a36Sopenharmony_ci		kvm.sh --allcpus --duration 3 --trust-make --datestamp "$ds/$idir" > $resdir/$ds/$idir/kvm.sh.out 2>&1
7762306a36Sopenharmony_ci		ret=$?
7862306a36Sopenharmony_ci		echo kvm.sh return code $ret for commit $i from branch $gitbr
7962306a36Sopenharmony_ci		echo Run results: $resdir/$ds/$idir
8062306a36Sopenharmony_ci		if test "$ret" -ne 0
8162306a36Sopenharmony_ci		then
8262306a36Sopenharmony_ci			# Failure, so leave all evidence intact.
8362306a36Sopenharmony_ci			nfail=`expr $nfail + 1`
8462306a36Sopenharmony_ci		else
8562306a36Sopenharmony_ci			# Success, so remove large files to save about 1GB.
8662306a36Sopenharmony_ci			( cd $resdir/$ds/$idir/$rrd; rm -f */vmlinux */bzImage */System.map */Module.symvers )
8762306a36Sopenharmony_ci		fi
8862306a36Sopenharmony_ci	done
8962306a36Sopenharmony_cidone
9062306a36Sopenharmony_cidate
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci# Go back to the original commit.
9362306a36Sopenharmony_cigit checkout "$curcommit"
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ciif test $nfail -ne 0
9662306a36Sopenharmony_cithen
9762306a36Sopenharmony_ci	echo '!!! ' $nfail failures in $ntry 'runs!!!'
9862306a36Sopenharmony_ci	exit 1
9962306a36Sopenharmony_cielse
10062306a36Sopenharmony_ci	echo No failures in $ntry runs.
10162306a36Sopenharmony_ci	exit 0
10262306a36Sopenharmony_cifi
103