0a7c8744abef1f7c1719285227e98843c5df3a0f
1#!/bin/sh
2
3die () {
4 echo >&2 "error: $*"
5 exit 1
6}
7
8while [ $# -gt 0 ]; do
9 arg="$1"
10 case "$arg" in
11 --)
12 break ;;
13 --help)
14 echo "usage: $0 [--config file] [--subsection subsec] [other_git_tree...] [--] [test_scripts]"
15 exit 0 ;;
16 --config)
17 shift
18 GIT_PERF_CONFIG_FILE=$(cd "$(dirname "$1")"; pwd)/$(basename "$1")
19 export GIT_PERF_CONFIG_FILE
20 shift ;;
21 --subsection)
22 shift
23 GIT_PERF_SUBSECTION="$1"
24 export GIT_PERF_SUBSECTION
25 shift ;;
26 --*)
27 die "unrecognised option: '$arg'" ;;
28 *)
29 break ;;
30 esac
31done
32
33run_one_dir () {
34 if test $# -eq 0; then
35 set -- p????-*.sh
36 fi
37 echo "=== Running $# tests in ${GIT_TEST_INSTALLED:-this tree} ==="
38 for t in "$@"; do
39 ./$t $GIT_TEST_OPTS
40 done
41}
42
43unpack_git_rev () {
44 rev=$1
45 echo "=== Unpacking $rev in build/$rev ==="
46 mkdir -p build/$rev
47 (cd "$(git rev-parse --show-cdup)" && git archive --format=tar $rev) |
48 (cd build/$rev && tar x)
49}
50
51build_git_rev () {
52 rev=$1
53 name="$2"
54 for config in config.mak config.mak.autogen config.status
55 do
56 if test -e "../../$config"
57 then
58 cp "../../$config" "build/$rev/"
59 fi
60 done
61 echo "=== Building $rev ($name) ==="
62 (
63 cd build/$rev &&
64 if test -n "$GIT_PERF_MAKE_COMMAND"
65 then
66 sh -c "$GIT_PERF_MAKE_COMMAND"
67 else
68 make $GIT_PERF_MAKE_OPTS
69 fi
70 ) || die "failed to build revision '$mydir'"
71}
72
73run_dirs_helper () {
74 mydir=${1%/}
75 shift
76 while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
77 shift
78 done
79 if test $# -gt 0 -a "$1" = --; then
80 shift
81 fi
82 if [ ! -d "$mydir" ]; then
83 rev=$(git rev-parse --verify "$mydir" 2>/dev/null) ||
84 die "'$mydir' is neither a directory nor a valid revision"
85 if [ ! -d build/$rev ]; then
86 unpack_git_rev $rev
87 fi
88 build_git_rev $rev "$mydir"
89 mydir=build/$rev
90 fi
91 if test "$mydir" = .; then
92 unset GIT_TEST_INSTALLED
93 else
94 GIT_PERF_DIR_MYDIR_REL=$mydir
95 GIT_PERF_DIR_MYDIR_ABS=$(cd $mydir && pwd)
96 export GIT_PERF_DIR_MYDIR_REL GIT_PERF_DIR_MYDIR_ABS
97
98 GIT_TEST_INSTALLED="$GIT_PERF_DIR_MYDIR_ABS/bin-wrappers"
99 # Older versions of git lacked bin-wrappers; fallback to the
100 # files in the root.
101 test -d "$GIT_TEST_INSTALLED" || GIT_TEST_INSTALLED=$GIT_PERF_DIR_MYDIR_ABS
102 export GIT_TEST_INSTALLED
103 fi
104 run_one_dir "$@"
105}
106
107run_dirs () {
108 while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
109 run_dirs_helper "$@"
110 shift
111 done
112}
113
114get_subsections () {
115 section="$1"
116 test -z "$GIT_PERF_CONFIG_FILE" && return
117 git config -f "$GIT_PERF_CONFIG_FILE" --name-only --get-regex "$section\..*\.[^.]+" |
118 sed -e "s/$section\.\(.*\)\..*/\1/" | sort | uniq
119}
120
121get_var_from_env_or_config () {
122 env_var="$1"
123 conf_sec="$2"
124 conf_var="$3"
125 conf_opts="$4" # optional
126
127 # Do nothing if the env variable is already set
128 eval "test -z \"\${$env_var+x}\"" || return
129
130 test -z "$GIT_PERF_CONFIG_FILE" && return
131
132 # Check if the variable is in the config file
133 if test -n "$GIT_PERF_SUBSECTION"
134 then
135 var="$conf_sec.$GIT_PERF_SUBSECTION.$conf_var"
136 conf_value=$(git config $conf_opts -f "$GIT_PERF_CONFIG_FILE" "$var") &&
137 eval "$env_var=\"$conf_value\"" && return
138 fi
139 var="$conf_sec.$conf_var"
140 conf_value=$(git config $conf_opts -f "$GIT_PERF_CONFIG_FILE" "$var") &&
141 eval "$env_var=\"$conf_value\""
142}
143
144run_subsection () {
145 get_var_from_env_or_config "GIT_PERF_REPEAT_COUNT" "perf" "repeatCount" "--int"
146 : ${GIT_PERF_REPEAT_COUNT:=3}
147 export GIT_PERF_REPEAT_COUNT
148
149 get_var_from_env_or_config "GIT_PERF_DIRS_OR_REVS" "perf" "dirsOrRevs"
150 set -- $GIT_PERF_DIRS_OR_REVS "$@"
151
152 get_var_from_env_or_config "GIT_PERF_MAKE_COMMAND" "perf" "makeCommand"
153 get_var_from_env_or_config "GIT_PERF_MAKE_OPTS" "perf" "makeOpts"
154
155 get_var_from_env_or_config "GIT_PERF_REPO_NAME" "perf" "repoName"
156 export GIT_PERF_REPO_NAME
157
158 GIT_PERF_AGGREGATING_LATER=t
159 export GIT_PERF_AGGREGATING_LATER
160
161 if test $# = 0 -o "$1" = -- -o -f "$1"; then
162 set -- . "$@"
163 fi
164
165 codespeed_opt=
166 test "$GIT_PERF_CODESPEED_OUTPUT" = "true" && codespeed_opt="--codespeed"
167
168 run_dirs "$@"
169
170 if test -z "$GIT_PERF_SEND_TO_CODESPEED"
171 then
172 ./aggregate.perl $codespeed_opt "$@"
173 else
174 json_res_file="test-results/$GIT_PERF_SUBSECTION/aggregate.json"
175 ./aggregate.perl --codespeed "$@" | tee "$json_res_file"
176 send_data_url="$GIT_PERF_SEND_TO_CODESPEED/result/add/json/"
177 curl -v --request POST --data-urlencode "json=$(cat "$json_res_file")" "$send_data_url"
178 fi
179}
180
181get_var_from_env_or_config "GIT_PERF_CODESPEED_OUTPUT" "perf" "codespeedOutput" "--bool"
182get_var_from_env_or_config "GIT_PERF_SEND_TO_CODESPEED" "perf" "sendToCodespeed"
183
184cd "$(dirname $0)"
185. ../../GIT-BUILD-OPTIONS
186
187mkdir -p test-results
188get_subsections "perf" >test-results/run_subsections.names
189
190if test $(wc -l <test-results/run_subsections.names) -eq 0
191then
192 if test -n "$GIT_PERF_SUBSECTION"
193 then
194 if test -n "$GIT_PERF_CONFIG_FILE"
195 then
196 die "no subsections are defined in config file '$GIT_PERF_CONFIG_FILE'"
197 else
198 die "subsection '$GIT_PERF_SUBSECTION' defined without a config file"
199 fi
200 fi
201 (
202 run_subsection "$@"
203 )
204elif test -n "$GIT_PERF_SUBSECTION"
205then
206 egrep "^$GIT_PERF_SUBSECTION\$" test-results/run_subsections.names >/dev/null ||
207 die "subsection '$GIT_PERF_SUBSECTION' not found in '$GIT_PERF_CONFIG_FILE'"
208
209 egrep "^$GIT_PERF_SUBSECTION\$" test-results/run_subsections.names | while read -r subsec
210 do
211 (
212 GIT_PERF_SUBSECTION="$subsec"
213 export GIT_PERF_SUBSECTION
214 echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========"
215 run_subsection "$@"
216 )
217 done
218else
219 while read -r subsec
220 do
221 (
222 GIT_PERF_SUBSECTION="$subsec"
223 export GIT_PERF_SUBSECTION
224 echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========"
225 run_subsection "$@"
226 )
227 done <test-results/run_subsections.names
228fi