t/perf: factor boilerplate out of test_perf

About half of test_perf() is boilerplate preparing to run _any_ test, and the other half is specifically running a timing test. Let's split it into two functions, so that we can reuse the boilerplate in future commits. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 17, 2018 at 16:55 UTC 968e77a5f87c1a50983323f15296a6dda53a1098
1 file changed +35 -26
t/perf/perf-lib.sh
+35 -26
@@ -179,8 +179,8 @@ exit $ret' >&3 2>&4
179 return "$eval_ret"
180 }
181
182 -
183 -test_perf () {
182 +test_wrapper_ () {
183 + test_wrapper_func_=$1; shift
184 test_start_
185 test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
186 test "$#" = 2 ||
@@ -191,35 +191,44 @@ test_perf () {
191 base=$(basename "$0" .sh)
192 echo "$test_count" >>"$perf_results_dir"/$base.subtests
193 echo "$1" >"$perf_results_dir"/$base.$test_count.descr
194 - if test -z "$verbose"; then
195 - printf "%s" "perf $test_count - $1:"
196 - else
197 - echo "perf $test_count - $1:"
198 - fi
199 - for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); do
200 - say >&3 "running: $2"
201 - if test_run_perf_ "$2"
202 - then
203 - if test -z "$verbose"; then
204 - printf " %s" "$i"
205 - else
206 - echo "* timing run $i/$GIT_PERF_REPEAT_COUNT:"
207 - fi
194 + base="$perf_results_dir"/"$perf_results_prefix$(basename "$0" .sh)"."$test_count"
195 + "$test_wrapper_func_" "$@"
196 + fi
197 +
198 + test_finish_
199 +}
200 +
201 +test_perf_ () {
202 + if test -z "$verbose"; then
203 + printf "%s" "perf $test_count - $1:"
204 + else
205 + echo "perf $test_count - $1:"
206 + fi
207 + for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); do
208 + say >&3 "running: $2"
209 + if test_run_perf_ "$2"
210 + then
211 + if test -z "$verbose"; then
212 + printf " %s" "$i"
213 else
209 - test -z "$verbose" && echo
210 - test_failure_ "$@"
211 - break
214 + echo "* timing run $i/$GIT_PERF_REPEAT_COUNT:"
215 fi
213 - done
214 - if test -z "$verbose"; then
215 - echo " ok"
216 else
217 - test_ok_ "$1"
217 + test -z "$verbose" && echo
218 + test_failure_ "$@"
219 + break
220 fi
219 - base="$perf_results_dir"/"$perf_results_prefix$(basename "$0" .sh)"."$test_count"
220 - "$TEST_DIRECTORY"/perf/min_time.perl test_time.* >"$base".times
221 + done
222 + if test -z "$verbose"; then
223 + echo " ok"
224 + else
225 + test_ok_ "$1"
226 fi
222 - test_finish_
227 + "$TEST_DIRECTORY"/perf/min_time.perl test_time.* >"$base".times
228 +}
229 +
230 +test_perf () {
231 + test_wrapper_ test_perf_ "$@"
232 }
233
234 # We extend test_done to print timings at the end (./run disables this