Skip to content

Commit 0baf78e

Browse files
peffgitster
authored andcommitted
perf-lib.sh: rely on test-lib.sh for --tee handling
Since its inception, the perf-lib.sh script has manually handled the "--tee" option (and other options which imply it, like "--valgrind") with a cut-and-pasted block from test-lib.sh. That block has grown stale over the years, and has at least three problems: 1. It uses $SHELL to re-exec the script, whereas the version in test-lib.sh learned to use $TEST_SHELL_PATH. 2. It does an ad-hoc search of the "$*" string, whereas test-lib.sh learned to carefully parse the arguments left to right. 3. It never learned about --verbose-log (which also implies --tee), so it would not trigger for that option. This last one was especially annoying, because t/perf/run uses the GIT_TEST_OPTS from your config.mak to run the perf scripts. So if you've set, say, "-x --verbose-log" there, it will be passed as part of most perf runs. And while this script doesn't recognize the option, the test-lib.sh that we source _does_, and the behavior ends up being much more annoying: - as the comment at the top of the block says, we have to run this tee code early, before we start munging variables (it says GIT_BUILD_DIR, but the problematic variable is actually GIT_TEST_INSTALLED). - since we don't recognize --verbose-log, we don't trigger the block. We go on to munge GIT_TEST_INSTALLED, converting it from a relative to an absolute path. - then we source test-lib.sh, which _does_ recognize --verbose-log. It re-execs the script, which runs again. But this time with an absolute version of GIT_TEST_INSTALLED. - As a result, we copy the absolute version of GIT_TEST_INSTALLED into perf_results_prefix. Instead of writing our results to the expected "test-results/build_1234abcd.p1234-whatever.times", we instead write them to "test-results/_full_path_to_repo_t_perf_build_1234...". The aggregate.perl script doesn't expect this, and so it prints "<missing>" for each result (even though it spent considerable time running the tests!). We can solve all of these in one blow by just deleting our custom handling, and relying on the inclusion of test-lib.sh to handle --tee, --verbose-log, etc. There's one catch, though. We want to handle GIT_TEST_INSTALLED after we've included test-lib.sh, since we want it un-munged in the re-exec'd version of the script. But if we want to convert it from a relative to an absolute path, we must do so before we load test-lib.sh, since it will change our working directory. So we compute the absolute directory first, store it away, then include test-lib.sh, and finally assign to GIT_TEST_INSTALLED as appropriate. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0e94f7a commit 0baf78e

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

t/perf/perf-lib.sh

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,25 @@
1717
# You should have received a copy of the GNU General Public License
1818
# along with this program. If not, see http://www.gnu.org/licenses/ .
1919

20-
# do the --tee work early; it otherwise confuses our careful
21-
# GIT_BUILD_DIR mangling
22-
case "$GIT_TEST_TEE_STARTED, $* " in
23-
done,*)
24-
# do not redirect again
25-
;;
26-
*' --tee '*|*' --va'*)
27-
mkdir -p test-results
28-
BASE=test-results/$(basename "$0" .sh)
29-
(GIT_TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1;
30-
echo $? > $BASE.exit) | tee $BASE.out
31-
test "$(cat $BASE.exit)" = 0
32-
exit
33-
;;
34-
esac
35-
20+
# These variables must be set before the inclusion of test-lib.sh below,
21+
# because it will change our working directory.
3622
TEST_DIRECTORY=$(pwd)/..
3723
TEST_OUTPUT_DIRECTORY=$(pwd)
38-
if test -z "$GIT_TEST_INSTALLED"; then
39-
perf_results_prefix=
40-
else
41-
perf_results_prefix=$(printf "%s" "${GIT_TEST_INSTALLED%/bin-wrappers}" | tr -c "[a-zA-Z0-9]" "[_*]")"."
42-
# make the tested dir absolute
43-
GIT_TEST_INSTALLED=$(cd "$GIT_TEST_INSTALLED" && pwd)
44-
fi
24+
ABSOLUTE_GIT_TEST_INSTALLED=$(
25+
test -n "$GIT_TEST_INSTALLED" && cd "$GIT_TEST_INSTALLED" && pwd)
4526

4627
TEST_NO_CREATE_REPO=t
4728
TEST_NO_MALLOC_CHECK=t
4829

4930
. ../test-lib.sh
5031

32+
if test -z "$GIT_TEST_INSTALLED"; then
33+
perf_results_prefix=
34+
else
35+
perf_results_prefix=$(printf "%s" "${GIT_TEST_INSTALLED%/bin-wrappers}" | tr -c "[a-zA-Z0-9]" "[_*]")"."
36+
GIT_TEST_INSTALLED=$ABSOLUTE_GIT_TEST_INSTALLED
37+
fi
38+
5139
# Variables from test-lib that are normally internal to the tests; we
5240
# need to export them for test_perf subshells
5341
export TEST_DIRECTORY TRASH_DIRECTORY GIT_BUILD_DIR GIT_TEST_CMP

0 commit comments

Comments
 (0)