]>
Commit | Line | Data |
---|---|---|
342e9ef2 TR |
1 | #!/bin/sh |
2 | ||
8796b307 CC |
3 | die () { |
4 | echo >&2 "error: $*" | |
5 | exit 1 | |
6 | } | |
7 | ||
8 | while [ $# -gt 0 ]; do | |
9 | arg="$1" | |
10 | case "$arg" in | |
11 | --) | |
12 | break ;; | |
342e9ef2 | 13 | --help) |
8796b307 CC |
14 | echo "usage: $0 [--config file] [--subsection subsec] [other_git_tree...] [--] [test_scripts]" |
15 | exit 0 ;; | |
e3d5e120 CC |
16 | --config) |
17 | shift | |
18 | GIT_PERF_CONFIG_FILE=$(cd "$(dirname "$1")"; pwd)/$(basename "$1") | |
19 | export GIT_PERF_CONFIG_FILE | |
20 | shift ;; | |
8796b307 CC |
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 | |
31 | done | |
342e9ef2 TR |
32 | |
33 | run_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 | ||
43 | unpack_git_rev () { | |
44 | rev=$1 | |
b11ad029 | 45 | echo "=== Unpacking $rev in build/$rev ===" |
342e9ef2 TR |
46 | mkdir -p build/$rev |
47 | (cd "$(git rev-parse --show-cdup)" && git archive --format=tar $rev) | | |
48 | (cd build/$rev && tar x) | |
49 | } | |
e6b71539 | 50 | |
342e9ef2 TR |
51 | build_git_rev () { |
52 | rev=$1 | |
ffdd0107 | 53 | name="$2" |
cd5c2812 KS |
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 | |
ffdd0107 | 61 | echo "=== Building $rev ($name) ===" |
88b6197d ÆAB |
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'" | |
342e9ef2 TR |
71 | } |
72 | ||
73 | run_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 | |
ffdd0107 | 88 | build_git_rev $rev "$mydir" |
342e9ef2 TR |
89 | mydir=build/$rev |
90 | fi | |
91 | if test "$mydir" = .; then | |
92 | unset GIT_TEST_INSTALLED | |
93 | else | |
94 | GIT_TEST_INSTALLED="$mydir/bin-wrappers" | |
28e1fb54 JK |
95 | # Older versions of git lacked bin-wrappers; fallback to the |
96 | # files in the root. | |
97 | test -d "$GIT_TEST_INSTALLED" || GIT_TEST_INSTALLED=$mydir | |
342e9ef2 TR |
98 | export GIT_TEST_INSTALLED |
99 | fi | |
100 | run_one_dir "$@" | |
101 | } | |
102 | ||
103 | run_dirs () { | |
104 | while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do | |
105 | run_dirs_helper "$@" | |
106 | shift | |
107 | done | |
108 | } | |
109 | ||
2638441e CC |
110 | get_subsections () { |
111 | section="$1" | |
112 | test -z "$GIT_PERF_CONFIG_FILE" && return | |
113 | git config -f "$GIT_PERF_CONFIG_FILE" --name-only --get-regex "$section\..*\.[^.]+" | | |
114 | sed -e "s/$section\.\(.*\)\..*/\1/" | sort | uniq | |
115 | } | |
116 | ||
e6b71539 CC |
117 | get_var_from_env_or_config () { |
118 | env_var="$1" | |
9ba95ed2 CC |
119 | conf_sec="$2" |
120 | conf_var="$3" | |
3ae7d2b0 | 121 | conf_opts="$4" # optional |
e6b71539 CC |
122 | |
123 | # Do nothing if the env variable is already set | |
124 | eval "test -z \"\${$env_var+x}\"" || return | |
125 | ||
9ba95ed2 CC |
126 | test -z "$GIT_PERF_CONFIG_FILE" && return |
127 | ||
e6b71539 | 128 | # Check if the variable is in the config file |
9ba95ed2 CC |
129 | if test -n "$GIT_PERF_SUBSECTION" |
130 | then | |
131 | var="$conf_sec.$GIT_PERF_SUBSECTION.$conf_var" | |
3ae7d2b0 | 132 | conf_value=$(git config $conf_opts -f "$GIT_PERF_CONFIG_FILE" "$var") && |
9ba95ed2 CC |
133 | eval "$env_var=\"$conf_value\"" && return |
134 | fi | |
135 | var="$conf_sec.$conf_var" | |
3ae7d2b0 | 136 | conf_value=$(git config $conf_opts -f "$GIT_PERF_CONFIG_FILE" "$var") && |
53ba2c79 | 137 | eval "$env_var=\"$conf_value\"" |
e6b71539 CC |
138 | } |
139 | ||
afda85c2 | 140 | run_subsection () { |
53ba2c79 RS |
141 | get_var_from_env_or_config "GIT_PERF_REPEAT_COUNT" "perf" "repeatCount" "--int" |
142 | : ${GIT_PERF_REPEAT_COUNT:=3} | |
afda85c2 | 143 | export GIT_PERF_REPEAT_COUNT |
e6b71539 | 144 | |
afda85c2 CC |
145 | get_var_from_env_or_config "GIT_PERF_DIRS_OR_REVS" "perf" "dirsOrRevs" |
146 | set -- $GIT_PERF_DIRS_OR_REVS "$@" | |
91c4339e | 147 | |
afda85c2 CC |
148 | get_var_from_env_or_config "GIT_PERF_MAKE_COMMAND" "perf" "makeCommand" |
149 | get_var_from_env_or_config "GIT_PERF_MAKE_OPTS" "perf" "makeOpts" | |
948e22e2 | 150 | |
19cf57a9 CC |
151 | get_var_from_env_or_config "GIT_PERF_REPO_NAME" "perf" "repoName" |
152 | export GIT_PERF_REPO_NAME | |
153 | ||
afda85c2 CC |
154 | GIT_PERF_AGGREGATING_LATER=t |
155 | export GIT_PERF_AGGREGATING_LATER | |
156 | ||
157 | if test $# = 0 -o "$1" = -- -o -f "$1"; then | |
158 | set -- . "$@" | |
159 | fi | |
160 | ||
5d6bb930 CC |
161 | codespeed_opt= |
162 | test "$GIT_PERF_CODESPEED_OUTPUT" = "true" && codespeed_opt="--codespeed" | |
163 | ||
afda85c2 | 164 | run_dirs "$@" |
fccec20f CC |
165 | |
166 | if test -z "$GIT_PERF_SEND_TO_CODESPEED" | |
167 | then | |
168 | ./aggregate.perl $codespeed_opt "$@" | |
169 | else | |
170 | json_res_file="test-results/$GIT_PERF_SUBSECTION/aggregate.json" | |
171 | ./aggregate.perl --codespeed "$@" | tee "$json_res_file" | |
172 | send_data_url="$GIT_PERF_SEND_TO_CODESPEED/result/add/json/" | |
173 | curl -v --request POST --data-urlencode "json=$(cat "$json_res_file")" "$send_data_url" | |
174 | fi | |
afda85c2 | 175 | } |
342e9ef2 | 176 | |
5d6bb930 | 177 | get_var_from_env_or_config "GIT_PERF_CODESPEED_OUTPUT" "perf" "codespeedOutput" "--bool" |
fccec20f | 178 | get_var_from_env_or_config "GIT_PERF_SEND_TO_CODESPEED" "perf" "sendToCodespeed" |
5d6bb930 | 179 | |
342e9ef2 TR |
180 | cd "$(dirname $0)" |
181 | . ../../GIT-BUILD-OPTIONS | |
182 | ||
afda85c2 CC |
183 | mkdir -p test-results |
184 | get_subsections "perf" >test-results/run_subsections.names | |
185 | ||
186 | if test $(wc -l <test-results/run_subsections.names) -eq 0 | |
187 | then | |
8796b307 CC |
188 | if test -n "$GIT_PERF_SUBSECTION" |
189 | then | |
190 | if test -n "$GIT_PERF_CONFIG_FILE" | |
191 | then | |
192 | die "no subsections are defined in config file '$GIT_PERF_CONFIG_FILE'" | |
193 | else | |
194 | die "subsection '$GIT_PERF_SUBSECTION' defined without a config file" | |
195 | fi | |
196 | fi | |
afda85c2 CC |
197 | ( |
198 | run_subsection "$@" | |
199 | ) | |
8796b307 CC |
200 | elif test -n "$GIT_PERF_SUBSECTION" |
201 | then | |
202 | egrep "^$GIT_PERF_SUBSECTION\$" test-results/run_subsections.names >/dev/null || | |
203 | die "subsection '$GIT_PERF_SUBSECTION' not found in '$GIT_PERF_CONFIG_FILE'" | |
204 | ||
205 | egrep "^$GIT_PERF_SUBSECTION\$" test-results/run_subsections.names | while read -r subsec | |
206 | do | |
207 | ( | |
208 | GIT_PERF_SUBSECTION="$subsec" | |
209 | export GIT_PERF_SUBSECTION | |
210 | echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========" | |
211 | run_subsection "$@" | |
212 | ) | |
213 | done | |
afda85c2 CC |
214 | else |
215 | while read -r subsec | |
216 | do | |
217 | ( | |
218 | GIT_PERF_SUBSECTION="$subsec" | |
219 | export GIT_PERF_SUBSECTION | |
220 | echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========" | |
221 | run_subsection "$@" | |
222 | ) | |
223 | done <test-results/run_subsections.names | |
342e9ef2 | 224 | fi |