Skip to content

Commit 4f40bd9

Browse files
committed
benchmark: show helpful errors w/o local repo
When running without a local test repository, show a helpful error message.
1 parent d564cc1 commit 4f40bd9

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

tests/benchmarks/benchmark_helpers.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ else
2121
OUTPUT_STYLE="auto"
2222
fi
2323

24+
HELP_GIT_REMOTE="https://github.com/git/git"
25+
HELP_LINUX_REMOTE="https://github.com/torvalds/linux"
26+
2427
#
2528
# parse the arguments to the outer script that's including us; these are arguments that
2629
# the `benchmark.sh` passes (or that a user could specify when running an individual test)
@@ -384,3 +387,27 @@ gitbench() {
384387
hyperfine "${ARGUMENTS[@]}"
385388
rm -rf "${SANDBOX_DIR:?}"
386389
}
390+
391+
# helper script to give useful error messages about configuration
392+
needs_repo() {
393+
REPO="${1}"
394+
395+
if [ "${REPO}" = "" ]; then
396+
echo "usage: needs_repo <repo>" 1>&2
397+
exit 1
398+
fi
399+
400+
REPO_UPPER=$(echo "${1}" | tr '[:lower:]' '[:upper:]')
401+
REPO_URL=$(eval echo "\${BENCHMARK_${REPO_UPPER}_REPOSITORY}")
402+
REPO_REMOTE_URL=$(eval echo "\${HELP_${REPO_UPPER}_REMOTE}")
403+
404+
if [ "${REPO_URL}" = "" ]; then
405+
echo "$0: '${REPO}' repository not configured" 1>&2
406+
echo "" 1>&2
407+
echo "This benchmark needs an on-disk '${REPO}' repository. First, clone the" 1>&2
408+
echo "remote repository ('${REPO_REMOTE_URL}') locally then set," 1>&2
409+
echo "the 'BENCHMARK_${REPO_UPPER}_REPOSITORY' environment variable to the path that" 1>&2
410+
echo "contains the repository locally, then run this benchmark again." 1>&2
411+
exit 1
412+
fi
413+
}

tests/benchmarks/blame__git_cached

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
. "$(dirname "$0")/benchmark_helpers.sh"
44

5+
needs_repo git
6+
57
gitbench --prepare "clone_repo git && cd git && git reset --hard v2.45.0" \
68
--warmup 5 \
79
--chdir "git" \

tests/benchmarks/blame__linux_cached

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
. "$(dirname "$0")/benchmark_helpers.sh"
44

5+
needs_repo linux
6+
57
gitbench --prepare "clone_repo linux && cd linux && git reset --hard v6.9" \
68
--warmup 5 \
79
--chdir "linux" \

0 commit comments

Comments
 (0)