1#!/bin/sh
2
3case "$1" in
4 --help)
5 echo "usage: $0 [--config file] [other_git_tree...] [--] [test_scripts]"
6 exit 0
7 ;;
8 --config)
9 shift
10 GIT_PERF_CONFIG_FILE=$(cd "$(dirname "$1")"; pwd)/$(basename "$1")
11 export GIT_PERF_CONFIG_FILE
12 shift ;;
13esac
14
15die () {
16 echo >&2 "error: $*"
17 exit 1
18}
19
20run_one_dir () {
21 if test $# -eq 0; then
22 set -- p????-*.sh
23 fi
24 echo "=== Running $# tests in ${GIT_TEST_INSTALLED:-this tree} ==="
25 for t in "$@"; do
26 ./$t $GIT_TEST_OPTS
27 done
28}
29
30unpack_git_rev () {
31 rev=$1
32 echo "=== Unpacking $rev in build/$rev ==="
33 mkdir -p build/$rev
34 (cd "$(git rev-parse --show-cdup)" && git archive --format=tar $rev) |
35 (cd build/$rev && tar x)
36}
37
38build_git_rev () {
39 rev=$1
40 for config in config.mak config.mak.autogen config.status
41 do
42 if test -e "../../$config"
43 then
44 cp "../../$config" "build/$rev/"
45 fi
46 done
47 echo "=== Building $rev ==="
48 (
49 cd build/$rev &&
50 if test -n "$GIT_PERF_MAKE_COMMAND"
51 then
52 sh -c "$GIT_PERF_MAKE_COMMAND"
53 else
54 make $GIT_PERF_MAKE_OPTS
55 fi
56 ) || die "failed to build revision '$mydir'"
57}
58
59run_dirs_helper () {
60 mydir=${1%/}
61 shift
62 while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
63 shift
64 done
65 if test $# -gt 0 -a "$1" = --; then
66 shift
67 fi
68 if [ ! -d "$mydir" ]; then
69 rev=$(git rev-parse --verify "$mydir" 2>/dev/null) ||
70 die "'$mydir' is neither a directory nor a valid revision"
71 if [ ! -d build/$rev ]; then
72 unpack_git_rev $rev
73 fi
74 build_git_rev $rev
75 mydir=build/$rev
76 fi
77 if test "$mydir" = .; then
78 unset GIT_TEST_INSTALLED
79 else
80 GIT_TEST_INSTALLED="$mydir/bin-wrappers"
81 # Older versions of git lacked bin-wrappers; fallback to the
82 # files in the root.
83 test -d "$GIT_TEST_INSTALLED" || GIT_TEST_INSTALLED=$mydir
84 export GIT_TEST_INSTALLED
85 fi
86 run_one_dir "$@"
87}
88
89run_dirs () {
90 while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
91 run_dirs_helper "$@"
92 shift
93 done
94}
95
96get_subsections () {
97 section="$1"
98 test -z "$GIT_PERF_CONFIG_FILE" && return
99 git config -f "$GIT_PERF_CONFIG_FILE" --name-only --get-regex "$section\..*\.[^.]+" |
100 sed -e "s/$section\.\(.*\)\..*/\1/" | sort | uniq
101}
102
103get_var_from_env_or_config () {
104 env_var="$1"
105 conf_sec="$2"
106 conf_var="$3"
107 # $4 can be set to a default value
108
109 # Do nothing if the env variable is already set
110 eval "test -z \"\${$env_var+x}\"" || return
111
112 test -z "$GIT_PERF_CONFIG_FILE" && return
113
114 # Check if the variable is in the config file
115 if test -n "$GIT_PERF_SUBSECTION"
116 then
117 var="$conf_sec.$GIT_PERF_SUBSECTION.$conf_var"
118 conf_value=$(git config -f "$GIT_PERF_CONFIG_FILE" "$var") &&
119 eval "$env_var=\"$conf_value\"" && return
120 fi
121 var="$conf_sec.$conf_var"
122 conf_value=$(git config -f "$GIT_PERF_CONFIG_FILE" "$var") &&
123 eval "$env_var=\"$conf_value\"" && return
124
125 test -n "${4+x}" && eval "$env_var=\"$4\""
126}
127
128run_subsection () {
129 get_var_from_env_or_config "GIT_PERF_REPEAT_COUNT" "perf" "repeatCount" 3
130 export GIT_PERF_REPEAT_COUNT
131
132 get_var_from_env_or_config "GIT_PERF_DIRS_OR_REVS" "perf" "dirsOrRevs"
133 set -- $GIT_PERF_DIRS_OR_REVS "$@"
134
135 get_var_from_env_or_config "GIT_PERF_MAKE_COMMAND" "perf" "makeCommand"
136 get_var_from_env_or_config "GIT_PERF_MAKE_OPTS" "perf" "makeOpts"
137
138 GIT_PERF_AGGREGATING_LATER=t
139 export GIT_PERF_AGGREGATING_LATER
140
141 if test $# = 0 -o "$1" = -- -o -f "$1"; then
142 set -- . "$@"
143 fi
144
145 run_dirs "$@"
146 ./aggregate.perl "$@"
147}
148
149cd "$(dirname $0)"
150. ../../GIT-BUILD-OPTIONS
151
152mkdir -p test-results
153get_subsections "perf" >test-results/run_subsections.names
154
155if test $(wc -l <test-results/run_subsections.names) -eq 0
156then
157 (
158 run_subsection "$@"
159 )
160else
161 while read -r subsec
162 do
163 (
164 GIT_PERF_SUBSECTION="$subsec"
165 export GIT_PERF_SUBSECTION
166 echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========"
167 run_subsection "$@"
168 )
169 done <test-results/run_subsections.names
170fi