From 421fe3d641b6ed1c89a1c7c760b57208171e0f6f Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Thu, 30 Jul 2015 16:32:04 +0200 Subject: [PATCH] Tools: add git-regtest. This is a tool to run regression tests over a whole series of commits. Typical usage: git checkout tools/git-regtest experimental This runs 'make regressiontest' for every single commit between experimental and HEAD of the topic branch. Very convenient to make sure not a single commit introduces regressions. If there are regressions, the tools stops at the commit bringing in the regression, so you immediately know where to look. --- tools/git-regtest | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 tools/git-regtest diff --git a/tools/git-regtest b/tools/git-regtest new file mode 100755 index 0000000..a71bc52 --- /dev/null +++ b/tools/git-regtest @@ -0,0 +1,66 @@ +#!/bin/bash + +if [ $# -ne 1 -o "$1" = "-h" -o "$1" = "--help" ]; then + echo "Usage: $(basename $0) " + echo + echo "Example: $(basename $0) master" + echo + echo "This tool runs a regression test on every single commit since the" + echo "start commit, up to the current commit. Use it to make sure no" + echo "single commit introduces a regression. Can also be used to find out" + echo "which commit introduces the regression. Bisecting is fine for the" + echo "latter goal as well and may be faster, but also requires more thinking" + echo "of the user." + echo + echo "The tool stops as soon as a regression was detected." + echo + echo "IMPORTANT: the command to test for a regression is" + echo + echo " make regressiontest" + echo + echo "... so this command must be available." + echo + echo "Manual equivalent of this tool would be something like this:" + echo + echo " git checkout ~20" + echo " make regresssiontest" + echo " git checkout ~19" + echo " make regresssiontest" + echo " git checkout ~18" + echo " make regresssiontest" + echo " ..." + + exit 1 +fi + +BASE_BRANCH=${1} +CURRENT_BRANCH=$(git status | awk '/^On branch/ { print $3; exit; } + /^HEAD detached/ { print $4; exit; }') + +PARENTS=$(git log --oneline --ancestry-path \ + ${BASE_BRANCH}..${CURRENT_BRANCH} | wc -l) +let PARENTS1=${PARENTS}+1 +echo "${PARENTS1} commits to go." + +trap "echo -n \"Current commit is \" + git log HEAD^..HEAD | head -5 | tail -1" 0 + +while [ ${PARENTS} -ge 0 ]; do + echo "Next: ${CURRENT_BRANCH}~${PARENTS}" + sleep 3 + + # master and master~0 are different. Checking out the latter leads to a + # detached head state. This is confusing, avoid it. + if [ ${PARENTS} -eq 0 ]; then + git checkout ${CURRENT_BRANCH} + else + # The normal thing. + git checkout ${CURRENT_BRANCH}~${PARENTS} + fi + + make regressiontests || exit 1 + + let PARENTS=${PARENTS}-1 +done + +echo "All commits ran regression tests successfully."