Skip to content

Commit e407276

Browse files
neerajsi-msftGit for Windows Build Agent
authored andcommitted
t/perf: add iteration setup mechanism to perf-lib
Tests that affect the repo in stateful ways are easier to write if we can run setup steps outside of the measured portion of perf iteration. This change adds a "--setup 'setup-script'" parameter to test_perf. To make invocations easier to understand, I also moved the prerequisites to a new --prereq parameter. The setup facility will be used in the upcoming perf tests for batch mode, but it already helps in some existing tests, like t5302 and t7820. Signed-off-by: Neeraj Singh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 15db312 commit e407276

File tree

6 files changed

+75
-34
lines changed

6 files changed

+75
-34
lines changed

t/perf/p4220-log-grep-engines.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ do
3636
else
3737
prereq=""
3838
fi
39-
test_perf $prereq "$engine log$GIT_PERF_4220_LOG_OPTS --grep='$pattern'" "
39+
test_perf "$engine log$GIT_PERF_4220_LOG_OPTS --grep='$pattern'" \
40+
--prereq "$prereq" "
4041
git -c grep.patternType=$engine log --pretty=format:%h$GIT_PERF_4220_LOG_OPTS --grep='$pattern' >'out.$engine' || :
4142
"
4243
done

t/perf/p4221-log-grep-engines-fixed.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ do
2626
else
2727
prereq=""
2828
fi
29-
test_perf $prereq "$engine log$GIT_PERF_4221_LOG_OPTS --grep='$pattern'" "
29+
test_perf "$engine log$GIT_PERF_4221_LOG_OPTS --grep='$pattern'" \
30+
--prereq "$prereq" "
3031
git -c grep.patternType=$engine log --pretty=format:%h$GIT_PERF_4221_LOG_OPTS --grep='$pattern' >'out.$engine' || :
3132
"
3233
done

t/perf/p5302-pack-index.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,24 @@ test_expect_success 'set up thread-counting tests' '
2626
done
2727
'
2828

29-
test_perf PERF_EXTRA 'index-pack 0 threads' '
30-
rm -rf repo.git &&
31-
git init --bare repo.git &&
29+
test_perf 'index-pack 0 threads' --prereq PERF_EXTRA \
30+
--setup 'rm -rf repo.git && git init --bare repo.git' '
3231
GIT_DIR=repo.git git index-pack --threads=1 --stdin < $PACK
3332
'
3433

3534
for t in $threads
3635
do
3736
THREADS=$t
3837
export THREADS
39-
test_perf PERF_EXTRA "index-pack $t threads" '
40-
rm -rf repo.git &&
41-
git init --bare repo.git &&
38+
test_perf "index-pack $t threads" --prereq PERF_EXTRA \
39+
--setup 'rm -rf repo.git && git init --bare repo.git' '
4240
GIT_DIR=repo.git GIT_FORCE_THREADS=1 \
4341
git index-pack --threads=$THREADS --stdin <$PACK
4442
'
4543
done
4644

47-
test_perf 'index-pack default number of threads' '
48-
rm -rf repo.git &&
49-
git init --bare repo.git &&
45+
test_perf 'index-pack default number of threads' \
46+
--setup 'rm -rf repo.git && git init --bare repo.git' '
5047
GIT_DIR=repo.git git index-pack --stdin < $PACK
5148
'
5249

t/perf/p7519-fsmonitor.sh

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,7 @@ then
6060
esac
6161
fi
6262

63-
if test -n "$GIT_PERF_7519_DROP_CACHE"
64-
then
65-
# When using GIT_PERF_7519_DROP_CACHE, GIT_PERF_REPEAT_COUNT must be 1 to
66-
# generate valid results. Otherwise the caching that happens for the nth
67-
# run will negate the validity of the comparisons.
68-
if test "$GIT_PERF_REPEAT_COUNT" -ne 1
69-
then
70-
echo "warning: Setting GIT_PERF_REPEAT_COUNT=1" >&2
71-
GIT_PERF_REPEAT_COUNT=1
72-
fi
73-
fi
74-
75-
trace_start () {
63+
trace_start() {
7664
if test -n "$GIT_PERF_7519_TRACE"
7765
then
7866
name="$1"
@@ -175,10 +163,10 @@ setup_for_fsmonitor_hook () {
175163

176164
test_perf_w_drop_caches () {
177165
if test -n "$GIT_PERF_7519_DROP_CACHE"; then
178-
test-tool drop-caches
166+
test_perf "$1" --setup "test-tool drop-caches" "$2"
167+
else
168+
test_perf "$@"
179169
fi
180-
181-
test_perf "$@"
182170
}
183171

184172
test_fsmonitor_suite () {

t/perf/p7820-grep-engines.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ do
4949
fi
5050
if ! test_have_prereq PERF_GREP_ENGINES_THREADS
5151
then
52-
test_perf $prereq "$engine grep$GIT_PERF_7820_GREP_OPTS '$pattern'" "
52+
test_perf "$engine grep$GIT_PERF_7820_GREP_OPTS '$pattern'" \
53+
--prereq "$prereq" "
5354
git -c grep.patternType=$engine grep$GIT_PERF_7820_GREP_OPTS -- '$pattern' >'out.$engine' || :
5455
"
5556
else
5657
for threads in $GIT_PERF_GREP_THREADS
5758
do
58-
test_perf PTHREADS,$prereq "$engine grep$GIT_PERF_7820_GREP_OPTS '$pattern' with $threads threads" "
59+
test_perf "$engine grep$GIT_PERF_7820_GREP_OPTS '$pattern' with $threads threads"
60+
--prereq PTHREADS,$prereq "
5961
git -c grep.patternType=$engine -c grep.threads=$threads grep$GIT_PERF_7820_GREP_OPTS -- '$pattern' >'out.$engine.$threads' || :
6062
"
6163
done

t/perf/perf-lib.sh

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,40 @@ exit $ret' >&3 2>&4
189189
}
190190

191191
test_wrapper_ () {
192+
local test_wrapper_func_ test_title_
192193
test_wrapper_func_=$1; shift
194+
test_title_=$1; shift
193195
test_start_
194-
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
195-
test "$#" = 2 ||
196-
BUG "not 2 or 3 parameters to test-expect-success"
196+
test_prereq=
197+
test_perf_setup_=
198+
while test $# != 0
199+
do
200+
case $1 in
201+
--prereq)
202+
test_prereq=$2
203+
shift
204+
;;
205+
--setup)
206+
test_perf_setup_=$2
207+
shift
208+
;;
209+
*)
210+
break
211+
;;
212+
esac
213+
shift
214+
done
215+
test "$#" = 1 || BUG "test_wrapper_ needs 2 positional parameters"
197216
export test_prereq
198-
if ! test_skip "$@"
217+
export test_perf_setup_
218+
219+
if ! test_skip "$test_title_" "$@"
199220
then
200221
base=$(basename "$0" .sh)
201222
echo "$test_count" >>"$perf_results_dir"/$base.subtests
202223
echo "$1" >"$perf_results_dir"/$base.$test_count.descr
203224
base="$perf_results_dir"/"$PERF_RESULTS_PREFIX$(basename "$0" .sh)"."$test_count"
204-
"$test_wrapper_func_" "$@"
225+
"$test_wrapper_func_" "$test_title_" "$@"
205226
fi
206227

207228
test_finish_
@@ -214,6 +235,16 @@ test_perf_ () {
214235
echo "perf $test_count - $1:"
215236
fi
216237
for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); do
238+
if test -n "$test_perf_setup_"
239+
then
240+
say >&3 "setup: $test_perf_setup_"
241+
if ! test_eval_ $test_perf_setup_
242+
then
243+
test_failure_ "$test_perf_setup_"
244+
break
245+
fi
246+
247+
fi
217248
say >&3 "running: $2"
218249
if test_run_perf_ "$2"
219250
then
@@ -237,11 +268,24 @@ test_perf_ () {
237268
rm test_time.*
238269
}
239270

271+
# Usage: test_perf 'title' [options] 'perf-test'
272+
# Run the performance test script specified in perf-test with
273+
# optional prerequisite and setup steps.
274+
# Options:
275+
# --prereq prerequisites: Skip the test if prequisites aren't met
276+
# --setup "setup-steps": Run setup steps prior to each measured iteration
277+
#
240278
test_perf () {
241279
test_wrapper_ test_perf_ "$@"
242280
}
243281

244282
test_size_ () {
283+
if test -n "$test_perf_setup_"
284+
then
285+
say >&3 "setup: $test_perf_setup_"
286+
test_eval_ $test_perf_setup_
287+
fi
288+
245289
say >&3 "running: $2"
246290
if test_eval_ "$2" 3>"$base".result; then
247291
test_ok_ "$1"
@@ -250,6 +294,14 @@ test_size_ () {
250294
fi
251295
}
252296

297+
# Usage: test_size 'title' [options] 'size-test'
298+
# Run the size test script specified in size-test with optional
299+
# prerequisites and setup steps. Returns the numeric value
300+
# returned by size-test.
301+
# Options:
302+
# --prereq prerequisites: Skip the test if prequisites aren't met
303+
# --setup "setup-steps": Run setup steps prior to the size measurement
304+
253305
test_size () {
254306
test_wrapper_ test_size_ "$@"
255307
}

0 commit comments

Comments
 (0)