summaryrefslogtreecommitdiff
path: root/t/perf/perf-lib.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/perf/perf-lib.sh')
-rw-r--r--t/perf/perf-lib.sh145
1 files changed, 116 insertions, 29 deletions
diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh
index b58a43e..ab0c763 100644
--- a/t/perf/perf-lib.sh
+++ b/t/perf/perf-lib.sh
@@ -15,7 +15,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with this program. If not, see http://www.gnu.org/licenses/ .
+# along with this program. If not, see https://www.gnu.org/licenses/ .
# These variables must be set before the inclusion of test-lib.sh below,
# because it will change our working directory.
@@ -27,7 +27,11 @@ TEST_NO_MALLOC_CHECK=t
. ../test-lib.sh
-if test -n "$GIT_TEST_INSTALLED" -a -z "$PERF_SET_GIT_TEST_INSTALLED"
+unset GIT_CONFIG_NOSYSTEM
+GIT_CONFIG_SYSTEM="$TEST_DIRECTORY/perf/config"
+export GIT_CONFIG_SYSTEM
+
+if test -n "$GIT_TEST_INSTALLED" && test -z "$PERF_SET_GIT_TEST_INSTALLED"
then
error "Do not use GIT_TEST_INSTALLED with the perf tests.
@@ -45,7 +49,10 @@ export TEST_DIRECTORY TRASH_DIRECTORY GIT_BUILD_DIR GIT_TEST_CMP
MODERN_GIT=$GIT_BUILD_DIR/bin-wrappers/git
export MODERN_GIT
-perf_results_dir=$TEST_OUTPUT_DIRECTORY/test-results
+MODERN_SCALAR=$GIT_BUILD_DIR/bin-wrappers/scalar
+export MODERN_SCALAR
+
+perf_results_dir=$TEST_RESULTS_DIR
test -n "$GIT_PERF_SUBSECTION" && perf_results_dir="$perf_results_dir/$GIT_PERF_SUBSECTION"
mkdir -p "$perf_results_dir"
rm -f "$perf_results_dir"/$(basename "$0" .sh).subtests
@@ -70,6 +77,19 @@ test_perf_do_repo_symlink_config_ () {
test_have_prereq SYMLINKS || git config core.symlinks false
}
+test_perf_copy_repo_contents () {
+ for stuff in "$1"/*
+ do
+ case "$stuff" in
+ */objects|*/hooks|*/config|*/commondir|*/gitdir|*/worktrees|*/fsmonitor--daemon*)
+ ;;
+ *)
+ cp -R "$stuff" "$repo/.git/" || exit 1
+ ;;
+ esac
+ done
+}
+
test_perf_create_repo_from () {
test "$#" = 2 ||
BUG "not 2 parameters to test-create-repo"
@@ -77,20 +97,20 @@ test_perf_create_repo_from () {
source="$2"
source_git="$("$MODERN_GIT" -C "$source" rev-parse --git-dir)"
objects_dir="$("$MODERN_GIT" -C "$source" rev-parse --git-path objects)"
+ common_dir="$("$MODERN_GIT" -C "$source" rev-parse --git-common-dir)"
mkdir -p "$repo/.git"
(
cd "$source" &&
{ cp -Rl "$objects_dir" "$repo/.git/" 2>/dev/null ||
cp -R "$objects_dir" "$repo/.git/"; } &&
- for stuff in "$source_git"/*; do
- case "$stuff" in
- */objects|*/hooks|*/config|*/commondir)
- ;;
- *)
- cp -R "$stuff" "$repo/.git/" || exit 1
- ;;
- esac
- done
+
+ # common_dir must come first here, since we want source_git to
+ # take precedence and overwrite any overlapping files
+ test_perf_copy_repo_contents "$common_dir"
+ if test "$source_git" != "$common_dir"
+ then
+ test_perf_copy_repo_contents "$source_git"
+ fi
) &&
(
cd "$repo" &&
@@ -103,6 +123,10 @@ test_perf_create_repo_from () {
# status" due to a locked index. Since we have
# a copy it's fine to remove the lock.
rm .git/index.lock
+ fi &&
+ if test_bool_env GIT_PERF_USE_SCALAR false
+ then
+ "$MODERN_SCALAR" register
fi
) || error "failed to copy repository '$source' to '$repo'"
}
@@ -113,7 +137,11 @@ test_perf_fresh_repo () {
"$MODERN_GIT" init -q "$repo" &&
(
cd "$repo" &&
- test_perf_do_repo_symlink_config_
+ test_perf_do_repo_symlink_config_ &&
+ if test_bool_env GIT_PERF_USE_SCALAR false
+ then
+ "$MODERN_SCALAR" register
+ fi
)
}
@@ -144,17 +172,19 @@ test_run_perf_ () {
test_cleanup=:
test_export_="test_cleanup"
export test_cleanup test_export_
- "$GTIME" -f "%E %U %S" -o test_time.$i "$SHELL" -c '
+ "$GTIME" -f "%E %U %S" -o test_time.$i "$TEST_SHELL_PATH" -c '
. '"$TEST_DIRECTORY"/test-lib-functions.sh'
test_export () {
- [ $# != 0 ] || return 0
- test_export_="$test_export_\\|$1"
- shift
- test_export "$@"
+ test_export_="$test_export_ $*"
}
'"$1"'
ret=$?
-set | sed -n "s'"/'/'\\\\''/g"';s/^\\($test_export_\\)/export '"'&'"'/p" >test_vars
+needles=
+for v in $test_export_
+do
+ needles="$needles;s/^$v=/export $v=/p"
+done
+set | sed -n "s'"/'/'\\\\''/g"'$needles" >test_vars
exit $ret' >&3 2>&4
eval_ret=$?
@@ -170,19 +200,39 @@ exit $ret' >&3 2>&4
}
test_wrapper_ () {
- test_wrapper_func_=$1; shift
+ local test_wrapper_func_="$1"; shift
+ local test_title_="$1"; shift
test_start_
- test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
- test "$#" = 2 ||
- BUG "not 2 or 3 parameters to test-expect-success"
+ test_prereq=
+ test_perf_setup_=
+ while test $# != 0
+ do
+ case $1 in
+ --prereq)
+ test_prereq=$2
+ shift
+ ;;
+ --setup)
+ test_perf_setup_=$2
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+ done
+ test "$#" = 1 || BUG "test_wrapper_ needs 2 positional parameters"
export test_prereq
- if ! test_skip "$@"
+ export test_perf_setup_
+
+ if ! test_skip "$test_title_" "$@"
then
base=$(basename "$0" .sh)
echo "$test_count" >>"$perf_results_dir"/$base.subtests
- echo "$1" >"$perf_results_dir"/$base.$test_count.descr
+ echo "$test_title_" >"$perf_results_dir"/$base.$test_count.descr
base="$perf_results_dir"/"$PERF_RESULTS_PREFIX$(basename "$0" .sh)"."$test_count"
- "$test_wrapper_func_" "$@"
+ "$test_wrapper_func_" "$test_title_" "$@"
fi
test_finish_
@@ -195,6 +245,16 @@ test_perf_ () {
echo "perf $test_count - $1:"
fi
for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); do
+ if test -n "$test_perf_setup_"
+ then
+ say >&3 "setup: $test_perf_setup_"
+ if ! test_eval_ $test_perf_setup_
+ then
+ test_failure_ "$test_perf_setup_"
+ break
+ fi
+
+ fi
say >&3 "running: $2"
if test_run_perf_ "$2"
then
@@ -214,22 +274,44 @@ test_perf_ () {
else
test_ok_ "$1"
fi
- "$TEST_DIRECTORY"/perf/min_time.perl test_time.* >"$base".times
+ "$TEST_DIRECTORY"/perf/min_time.perl test_time.* >"$base".result
+ rm test_time.*
}
+# Usage: test_perf 'title' [options] 'perf-test'
+# Run the performance test script specified in perf-test with
+# optional prerequisite and setup steps.
+# Options:
+# --prereq prerequisites: Skip the test if prequisites aren't met
+# --setup "setup-steps": Run setup steps prior to each measured iteration
+#
test_perf () {
test_wrapper_ test_perf_ "$@"
}
test_size_ () {
+ if test -n "$test_perf_setup_"
+ then
+ say >&3 "setup: $test_perf_setup_"
+ test_eval_ $test_perf_setup_
+ fi
+
say >&3 "running: $2"
- if test_eval_ "$2" 3>"$base".size; then
+ if test_eval_ "$2" 3>"$base".result; then
test_ok_ "$1"
else
test_failure_ "$@"
fi
}
+# Usage: test_size 'title' [options] 'size-test'
+# Run the size test script specified in size-test with optional
+# prerequisites and setup steps. Returns the numeric value
+# returned by size-test.
+# Options:
+# --prereq prerequisites: Skip the test if prequisites aren't met
+# --setup "setup-steps": Run setup steps prior to the size measurement
+
test_size () {
test_wrapper_ test_size_ "$@"
}
@@ -238,10 +320,15 @@ test_size () {
# and does it after running everything)
test_at_end_hook_ () {
if test -z "$GIT_PERF_AGGREGATING_LATER"; then
- ( cd "$TEST_DIRECTORY"/perf && ./aggregate.perl $(basename "$0") )
+ (
+ cd "$TEST_DIRECTORY"/perf &&
+ ./aggregate.perl --results-dir="$TEST_RESULTS_DIR" $(basename "$0")
+ )
fi
}
test_export () {
export "$@"
}
+
+test_lazy_prereq PERF_EXTRA 'test_bool_env GIT_PERF_EXTRA false'