1#!/bin/sh 2# 3# Copyright (c) 2011 Thomas Rast 4# 5# This program is free software: you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation, either version 2 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see http://www.gnu.org/licenses/ . 17 18# do the --tee work early; it otherwise confuses our careful 19# GIT_BUILD_DIR mangling 20case"$GIT_TEST_TEE_STARTED, $* "in 21done,*) 22# do not redirect again 23;; 24*' --tee '*|*' --va'*) 25mkdir-p test-results 26 BASE=test-results/$(basename "$0" .sh) 27(GIT_TEST_TEE_STARTED=done${SHELL-sh}"$0""$@"2>&1; 28echo $? >$BASE.exit) |tee$BASE.out 29test"$(cat $BASE.exit)"=0 30exit 31;; 32esac 33 34TEST_DIRECTORY=$(pwd)/.. 35TEST_OUTPUT_DIRECTORY=$(pwd) 36iftest -z"$GIT_TEST_INSTALLED";then 37 perf_results_prefix= 38else 39 perf_results_prefix=$(printf "%s" "${GIT_TEST_INSTALLED%/bin-wrappers}" | tr -c "[a-zA-Z0-9]" "[_*]")"." 40# make the tested dir absolute 41 GIT_TEST_INSTALLED=$(cd "$GIT_TEST_INSTALLED" && pwd) 42fi 43 44TEST_NO_CREATE_REPO=t 45 46. ../test-lib.sh 47 48# Variables from test-lib that are normally internal to the tests; we 49# need to export them for test_perf subshells 50export TEST_DIRECTORY TRASH_DIRECTORY GIT_BUILD_DIR GIT_TEST_CMP 51 52perf_results_dir=$TEST_OUTPUT_DIRECTORY/test-results 53mkdir-p"$perf_results_dir" 54rm-f"$perf_results_dir"/$(basename "$0" .sh).subtests 55 56iftest -z"$GIT_PERF_REPEAT_COUNT";then 57 GIT_PERF_REPEAT_COUNT=3 58fi 59die_if_build_dir_not_repo () { 60if! (cd"$TEST_DIRECTORY/.."&& 61 git rev-parse --build-dir>/dev/null 2>&1);then 62 error "No$1defined, and your build directory is not a repo" 63fi 64} 65 66iftest -z"$GIT_PERF_REPO";then 67 die_if_build_dir_not_repo '$GIT_PERF_REPO' 68 GIT_PERF_REPO=$TEST_DIRECTORY/.. 69fi 70iftest -z"$GIT_PERF_LARGE_REPO";then 71 die_if_build_dir_not_repo '$GIT_PERF_LARGE_REPO' 72 GIT_PERF_LARGE_REPO=$TEST_DIRECTORY/.. 73fi 74 75test_perf_create_repo_from () { 76test"$#"=2|| 77 error "bug in the test script: not 2 parameters to test-create-repo" 78 repo="$1" 79source="$2" 80 source_git=$source/$(cd "$source" && git rev-parse --git-dir) 81mkdir-p"$repo/.git" 82( 83cd"$repo/.git"&& 84{cp-Rl"$source_git/objects" . 2>/dev/null || 85cp-R"$source_git/objects" .; } && 86for stuff in"$source_git"/*;do 87case"$stuff"in 88*/objects|*/hooks|*/config) 89;; 90*) 91cp-R"$stuff" . ||break 92;; 93esac 94done&& 95cd .. && 96 git init -q&& 97mv .git/hooks .git/hooks-disabled2>/dev/null 98) || error "failed to copy repository '$source' to '$repo'" 99} 100 101# call at least one of these to establish an appropriately-sized repository 102test_perf_default_repo () { 103 test_perf_create_repo_from "${1:-$TRASH_DIRECTORY}""$GIT_PERF_REPO" 104} 105test_perf_large_repo () { 106iftest"$GIT_PERF_LARGE_REPO"="$GIT_BUILD_DIR";then 107echo"warning: \$GIT_PERF_LARGE_REPOis \$GIT_BUILD_DIR.">&2 108echo"warning: This will work, but may not be a sufficiently large repo">&2 109echo"warning: for representative measurements.">&2 110fi 111 test_perf_create_repo_from "${1:-$TRASH_DIRECTORY}""$GIT_PERF_LARGE_REPO" 112} 113test_checkout_worktree () { 114 git checkout-index -u -a|| 115 error "git checkout-index failed" 116} 117 118# Performance tests should never fail. If they do, stop immediately 119immediate=t 120 121test_run_perf_ () { 122 test_cleanup=: 123 test_export_="test_cleanup" 124export test_cleanup test_export_ 125/usr/bin/time-f"%E %U %S"-o test_time.$i"$SHELL"-c' 126. '"$TEST_DIRECTORY"/test-lib-functions.sh' 127test_export () { 128 [$#!= 0 ] || return 0 129 test_export_="$test_export_\\|$1" 130 shift 131 test_export "$@" 132} 133'"$1"' 134ret=$? 135set | sed -n "s'"/'/'\\\\''/g"';s/^\\($test_export_\\)/export '"'&'"'/p" >test_vars 136exit$ret'>&3 2>&4 137 eval_ret=$? 138 139iftest$eval_ret=0||test -n"$expecting_failure" 140then 141 test_eval_ "$test_cleanup" 142 . ./test_vars || error "failed to load updated environment" 143fi 144iftest"$verbose"="t"&&test -n"$HARNESS_ACTIVE";then 145echo"" 146fi 147return"$eval_ret" 148} 149 150 151test_perf () { 152test"$#"=3&& { test_prereq=$1;shift; } || test_prereq= 153test"$#"=2|| 154 error "bug in the test script: not 2 or 3 parameters to test-expect-success" 155export test_prereq 156if! test_skip "$@" 157then 158 base=$(basename "$0" .sh) 159echo"$test_count">>"$perf_results_dir"/$base.subtests 160echo"$1">"$perf_results_dir"/$base.$test_count.descr 161iftest -z"$verbose";then 162echo -n"perf$test_count-$1:" 163else 164echo"perf$test_count-$1:" 165fi 166for i in$(test_seq 1 $GIT_PERF_REPEAT_COUNT);do 167 say >&3"running:$2" 168if test_run_perf_ "$2" 169then 170iftest -z"$verbose";then 171echo -n"$i" 172else 173echo"* timing run$i/$GIT_PERF_REPEAT_COUNT:" 174fi 175else 176test -z"$verbose"&&echo 177 test_failure_ "$@" 178break 179fi 180done 181iftest -z"$verbose";then 182echo" ok" 183else 184 test_ok_ "$1" 185fi 186 base="$perf_results_dir"/"$perf_results_prefix$(basename "$0" .sh)"."$test_count" 187"$TEST_DIRECTORY"/perf/min_time.perl test_time.* >"$base".times 188fi 189echo>&3"" 190} 191 192# We extend test_done to print timings at the end (./run disables this 193# and does it after running everything) 194test_at_end_hook_ () { 195iftest -z"$GIT_PERF_AGGREGATING_LATER";then 196(cd"$TEST_DIRECTORY"/perf && ./aggregate.perl $(basename "$0")) 197fi 198} 199 200test_export () { 201export"$@" 202}