Fix a really bad regression in0baf78e7bc("perf-lib.sh: rely on test-lib.sh for --tee handling", 2019-03-15). Since that change all runs of different <revisions> of git have used the git found in the user's $PATH, e.g. /usr/bin/git instead of the <revision> we just built and wanted to performance test. The problem starts with GIT_TEST_INSTALLED not working like our non-perf tests with the "run" script. I.e. you can't run performance tests against a given installed git. Instead we expect to use it ourselves to point GIT_TEST_INSTALLED to the <revision> we just built. However, we had been relying on '$(cd "$GIT_TEST_INSTALLED" && pwd)' to resolve that relative $GIT_TEST_INSTALLED to an absolute path *before* test-lib.sh was loaded, in cases where it was e.g. "build/<rev>/bin-wrappers" and we wanted "<abs_path>build/...". This change post-dates another proposed solution by a few days[1], I didn't notice that version when I initially wrote this. I'm doing the most minimal thing to solve the regression here, a follow-up change will move this result prefix selection logic entirely into the "run" script. This makes e.g. these cases all work: ./run . $PWD/../../ origin/master origin/next HEAD -- <tests> As well as just a plain one-off: ./run <tests> And, since we're passing down the new GIT_PERF_DIR_MYDIR_REL we make sure the bug relating to aggregate.perl not finding our files as described in0baf78e7bcdoesn't happen again. What *doesn't* work is setting GIT_TEST_INSTALLED to a relative path, this will subtly fail in test-lib.sh. This has always been the case even before0baf78e7bc, and as documented in t/README the GIT_TEST_INSTALLED variable should be set to an absolute path (needs to be set "to the bindir", which is always absolute), and the "perf" framework expects to munge it itself. Perhaps that should be dealt with in the future to allow manually setting GIT_TEST_INSTALLED, but as a preceding commit showed the user can just use the "run" script, which'll also pick the right output directory for the test results as expected by aggregate.perl. 1. https://public-inbox.org/git/20190502222409.GA15631@sigill.intra.peff.net/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
229 lines
5.5 KiB
Bash
Executable File
229 lines
5.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
die () {
|
|
echo >&2 "error: $*"
|
|
exit 1
|
|
}
|
|
|
|
while [ $# -gt 0 ]; do
|
|
arg="$1"
|
|
case "$arg" in
|
|
--)
|
|
break ;;
|
|
--help)
|
|
echo "usage: $0 [--config file] [--subsection subsec] [other_git_tree...] [--] [test_scripts]"
|
|
exit 0 ;;
|
|
--config)
|
|
shift
|
|
GIT_PERF_CONFIG_FILE=$(cd "$(dirname "$1")"; pwd)/$(basename "$1")
|
|
export GIT_PERF_CONFIG_FILE
|
|
shift ;;
|
|
--subsection)
|
|
shift
|
|
GIT_PERF_SUBSECTION="$1"
|
|
export GIT_PERF_SUBSECTION
|
|
shift ;;
|
|
--*)
|
|
die "unrecognised option: '$arg'" ;;
|
|
*)
|
|
break ;;
|
|
esac
|
|
done
|
|
|
|
run_one_dir () {
|
|
if test $# -eq 0; then
|
|
set -- p????-*.sh
|
|
fi
|
|
echo "=== Running $# tests in ${GIT_TEST_INSTALLED:-this tree} ==="
|
|
for t in "$@"; do
|
|
./$t $GIT_TEST_OPTS
|
|
done
|
|
}
|
|
|
|
unpack_git_rev () {
|
|
rev=$1
|
|
echo "=== Unpacking $rev in build/$rev ==="
|
|
mkdir -p build/$rev
|
|
(cd "$(git rev-parse --show-cdup)" && git archive --format=tar $rev) |
|
|
(cd build/$rev && tar x)
|
|
}
|
|
|
|
build_git_rev () {
|
|
rev=$1
|
|
name="$2"
|
|
for config in config.mak config.mak.autogen config.status
|
|
do
|
|
if test -e "../../$config"
|
|
then
|
|
cp "../../$config" "build/$rev/"
|
|
fi
|
|
done
|
|
echo "=== Building $rev ($name) ==="
|
|
(
|
|
cd build/$rev &&
|
|
if test -n "$GIT_PERF_MAKE_COMMAND"
|
|
then
|
|
sh -c "$GIT_PERF_MAKE_COMMAND"
|
|
else
|
|
make $GIT_PERF_MAKE_OPTS
|
|
fi
|
|
) || die "failed to build revision '$mydir'"
|
|
}
|
|
|
|
run_dirs_helper () {
|
|
mydir=${1%/}
|
|
shift
|
|
while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
|
|
shift
|
|
done
|
|
if test $# -gt 0 -a "$1" = --; then
|
|
shift
|
|
fi
|
|
if [ ! -d "$mydir" ]; then
|
|
rev=$(git rev-parse --verify "$mydir" 2>/dev/null) ||
|
|
die "'$mydir' is neither a directory nor a valid revision"
|
|
if [ ! -d build/$rev ]; then
|
|
unpack_git_rev $rev
|
|
fi
|
|
build_git_rev $rev "$mydir"
|
|
mydir=build/$rev
|
|
fi
|
|
if test "$mydir" = .; then
|
|
unset GIT_TEST_INSTALLED
|
|
else
|
|
GIT_PERF_DIR_MYDIR_REL=$mydir
|
|
GIT_PERF_DIR_MYDIR_ABS=$(cd $mydir && pwd)
|
|
export GIT_PERF_DIR_MYDIR_REL GIT_PERF_DIR_MYDIR_ABS
|
|
|
|
GIT_TEST_INSTALLED="$GIT_PERF_DIR_MYDIR_ABS/bin-wrappers"
|
|
# Older versions of git lacked bin-wrappers; fallback to the
|
|
# files in the root.
|
|
test -d "$GIT_TEST_INSTALLED" || GIT_TEST_INSTALLED=$GIT_PERF_DIR_MYDIR_ABS
|
|
export GIT_TEST_INSTALLED
|
|
fi
|
|
run_one_dir "$@"
|
|
}
|
|
|
|
run_dirs () {
|
|
while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
|
|
run_dirs_helper "$@"
|
|
shift
|
|
done
|
|
}
|
|
|
|
get_subsections () {
|
|
section="$1"
|
|
test -z "$GIT_PERF_CONFIG_FILE" && return
|
|
git config -f "$GIT_PERF_CONFIG_FILE" --name-only --get-regex "$section\..*\.[^.]+" |
|
|
sed -e "s/$section\.\(.*\)\..*/\1/" | sort | uniq
|
|
}
|
|
|
|
get_var_from_env_or_config () {
|
|
env_var="$1"
|
|
conf_sec="$2"
|
|
conf_var="$3"
|
|
conf_opts="$4" # optional
|
|
|
|
# Do nothing if the env variable is already set
|
|
eval "test -z \"\${$env_var+x}\"" || return
|
|
|
|
test -z "$GIT_PERF_CONFIG_FILE" && return
|
|
|
|
# Check if the variable is in the config file
|
|
if test -n "$GIT_PERF_SUBSECTION"
|
|
then
|
|
var="$conf_sec.$GIT_PERF_SUBSECTION.$conf_var"
|
|
conf_value=$(git config $conf_opts -f "$GIT_PERF_CONFIG_FILE" "$var") &&
|
|
eval "$env_var=\"$conf_value\"" && return
|
|
fi
|
|
var="$conf_sec.$conf_var"
|
|
conf_value=$(git config $conf_opts -f "$GIT_PERF_CONFIG_FILE" "$var") &&
|
|
eval "$env_var=\"$conf_value\""
|
|
}
|
|
|
|
run_subsection () {
|
|
get_var_from_env_or_config "GIT_PERF_REPEAT_COUNT" "perf" "repeatCount" "--int"
|
|
: ${GIT_PERF_REPEAT_COUNT:=3}
|
|
export GIT_PERF_REPEAT_COUNT
|
|
|
|
get_var_from_env_or_config "GIT_PERF_DIRS_OR_REVS" "perf" "dirsOrRevs"
|
|
set -- $GIT_PERF_DIRS_OR_REVS "$@"
|
|
|
|
get_var_from_env_or_config "GIT_PERF_MAKE_COMMAND" "perf" "makeCommand"
|
|
get_var_from_env_or_config "GIT_PERF_MAKE_OPTS" "perf" "makeOpts"
|
|
|
|
get_var_from_env_or_config "GIT_PERF_REPO_NAME" "perf" "repoName"
|
|
export GIT_PERF_REPO_NAME
|
|
|
|
GIT_PERF_AGGREGATING_LATER=t
|
|
export GIT_PERF_AGGREGATING_LATER
|
|
|
|
if test $# = 0 -o "$1" = -- -o -f "$1"; then
|
|
set -- . "$@"
|
|
fi
|
|
|
|
codespeed_opt=
|
|
test "$GIT_PERF_CODESPEED_OUTPUT" = "true" && codespeed_opt="--codespeed"
|
|
|
|
run_dirs "$@"
|
|
|
|
if test -z "$GIT_PERF_SEND_TO_CODESPEED"
|
|
then
|
|
./aggregate.perl $codespeed_opt "$@"
|
|
else
|
|
json_res_file="test-results/$GIT_PERF_SUBSECTION/aggregate.json"
|
|
./aggregate.perl --codespeed "$@" | tee "$json_res_file"
|
|
send_data_url="$GIT_PERF_SEND_TO_CODESPEED/result/add/json/"
|
|
curl -v --request POST --data-urlencode "json=$(cat "$json_res_file")" "$send_data_url"
|
|
fi
|
|
}
|
|
|
|
get_var_from_env_or_config "GIT_PERF_CODESPEED_OUTPUT" "perf" "codespeedOutput" "--bool"
|
|
get_var_from_env_or_config "GIT_PERF_SEND_TO_CODESPEED" "perf" "sendToCodespeed"
|
|
|
|
cd "$(dirname $0)"
|
|
. ../../GIT-BUILD-OPTIONS
|
|
|
|
mkdir -p test-results
|
|
get_subsections "perf" >test-results/run_subsections.names
|
|
|
|
if test $(wc -l <test-results/run_subsections.names) -eq 0
|
|
then
|
|
if test -n "$GIT_PERF_SUBSECTION"
|
|
then
|
|
if test -n "$GIT_PERF_CONFIG_FILE"
|
|
then
|
|
die "no subsections are defined in config file '$GIT_PERF_CONFIG_FILE'"
|
|
else
|
|
die "subsection '$GIT_PERF_SUBSECTION' defined without a config file"
|
|
fi
|
|
fi
|
|
(
|
|
run_subsection "$@"
|
|
)
|
|
elif test -n "$GIT_PERF_SUBSECTION"
|
|
then
|
|
egrep "^$GIT_PERF_SUBSECTION\$" test-results/run_subsections.names >/dev/null ||
|
|
die "subsection '$GIT_PERF_SUBSECTION' not found in '$GIT_PERF_CONFIG_FILE'"
|
|
|
|
egrep "^$GIT_PERF_SUBSECTION\$" test-results/run_subsections.names | while read -r subsec
|
|
do
|
|
(
|
|
GIT_PERF_SUBSECTION="$subsec"
|
|
export GIT_PERF_SUBSECTION
|
|
echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========"
|
|
run_subsection "$@"
|
|
)
|
|
done
|
|
else
|
|
while read -r subsec
|
|
do
|
|
(
|
|
GIT_PERF_SUBSECTION="$subsec"
|
|
export GIT_PERF_SUBSECTION
|
|
echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========"
|
|
run_subsection "$@"
|
|
)
|
|
done <test-results/run_subsections.names
|
|
fi
|