| 1 | #!/bin/sh |
| 2 | |
| 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 ;; |
| 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 |
| 31 | done |
| 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 |
| 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 | |
| 51 | build_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 | |
| 73 | set_git_test_installed () { |
| 74 | mydir=$1 |
| 75 | |
| 76 | mydir_abs=$(cd $mydir && pwd) |
| 77 | mydir_abs_wrappers="$mydir_abs/bin-wrappers" |
| 78 | if test -d "$mydir_abs_wrappers" |
| 79 | then |
| 80 | GIT_TEST_INSTALLED=$mydir_abs_wrappers |
| 81 | else |
| 82 | # Older versions of git lacked bin-wrappers; |
| 83 | # fallback to the files in the root. |
| 84 | GIT_TEST_INSTALLED=$mydir_abs |
| 85 | fi |
| 86 | export GIT_TEST_INSTALLED |
| 87 | PERF_SET_GIT_TEST_INSTALLED=true |
| 88 | export PERF_SET_GIT_TEST_INSTALLED |
| 89 | } |
| 90 | |
| 91 | run_dirs_helper () { |
| 92 | mydir=${1%/} |
| 93 | shift |
| 94 | while test $# -gt 0 && test "$1" != -- && test ! -f "$1"; do |
| 95 | shift |
| 96 | done |
| 97 | if test $# -gt 0 && test "$1" = --; then |
| 98 | shift |
| 99 | fi |
| 100 | |
| 101 | PERF_RESULTS_PREFIX= |
| 102 | if test "$mydir" = "." |
| 103 | then |
| 104 | unset GIT_TEST_INSTALLED |
| 105 | elif test -d "$mydir" |
| 106 | then |
| 107 | PERF_RESULTS_PREFIX=bindir$(cd $mydir && printf "%s" "$(pwd)" | tr -c "[a-zA-Z0-9]" "_"). |
| 108 | set_git_test_installed "$mydir" |
| 109 | else |
| 110 | rev=$(git rev-parse --verify "$mydir" 2>/dev/null) || |
| 111 | die "'$mydir' is neither a directory nor a valid revision" |
| 112 | if [ ! -d build/$rev ]; then |
| 113 | unpack_git_rev $rev |
| 114 | fi |
| 115 | build_git_rev $rev "$mydir" |
| 116 | mydir=build/$rev |
| 117 | |
| 118 | PERF_RESULTS_PREFIX=build_$rev. |
| 119 | set_git_test_installed "$mydir" |
| 120 | fi |
| 121 | export PERF_RESULTS_PREFIX |
| 122 | |
| 123 | run_one_dir "$@" |
| 124 | } |
| 125 | |
| 126 | run_dirs () { |
| 127 | while test $# -gt 0 && test "$1" != -- && test ! -f "$1"; do |
| 128 | run_dirs_helper "$@" |
| 129 | shift |
| 130 | done |
| 131 | } |
| 132 | |
| 133 | get_subsections () { |
| 134 | section="$1" |
| 135 | test -z "$GIT_PERF_CONFIG_FILE" && return |
| 136 | git config -f "$GIT_PERF_CONFIG_FILE" --name-only --get-regex "$section\..*\.[^.]+" | |
| 137 | sed -e "s/$section\.\(.*\)\..*/\1/" | sort | uniq |
| 138 | } |
| 139 | |
| 140 | get_var_from_env_or_config () { |
| 141 | env_var="$1" |
| 142 | conf_sec="$2" |
| 143 | conf_var="$3" |
| 144 | conf_opts="$4" # optional |
| 145 | |
| 146 | # Do nothing if the env variable is already set |
| 147 | eval "test -z \"\${$env_var+x}\"" || return |
| 148 | |
| 149 | test -z "$GIT_PERF_CONFIG_FILE" && return |
| 150 | |
| 151 | # Check if the variable is in the config file |
| 152 | if test -n "$GIT_PERF_SUBSECTION" |
| 153 | then |
| 154 | var="$conf_sec.$GIT_PERF_SUBSECTION.$conf_var" |
| 155 | conf_value=$(git config $conf_opts -f "$GIT_PERF_CONFIG_FILE" "$var") && |
| 156 | eval "$env_var=\"$conf_value\"" && return |
| 157 | fi |
| 158 | var="$conf_sec.$conf_var" |
| 159 | conf_value=$(git config $conf_opts -f "$GIT_PERF_CONFIG_FILE" "$var") && |
| 160 | eval "$env_var=\"$conf_value\"" |
| 161 | } |
| 162 | |
| 163 | run_subsection () { |
| 164 | get_var_from_env_or_config "GIT_PERF_REPEAT_COUNT" "perf" "repeatCount" "--int" |
| 165 | : ${GIT_PERF_REPEAT_COUNT:=3} |
| 166 | export GIT_PERF_REPEAT_COUNT |
| 167 | |
| 168 | get_var_from_env_or_config "GIT_PERF_DIRS_OR_REVS" "perf" "dirsOrRevs" |
| 169 | set -- $GIT_PERF_DIRS_OR_REVS "$@" |
| 170 | |
| 171 | get_var_from_env_or_config "GIT_PERF_MAKE_COMMAND" "perf" "makeCommand" |
| 172 | get_var_from_env_or_config "GIT_PERF_MAKE_OPTS" "perf" "makeOpts" |
| 173 | |
| 174 | get_var_from_env_or_config "GIT_PERF_USE_SCALAR" "perf" "useScalar" "--bool" |
| 175 | export GIT_PERF_USE_SCALAR |
| 176 | |
| 177 | get_var_from_env_or_config "GIT_PERF_REPO_NAME" "perf" "repoName" |
| 178 | export GIT_PERF_REPO_NAME |
| 179 | |
| 180 | GIT_PERF_AGGREGATING_LATER=t |
| 181 | export GIT_PERF_AGGREGATING_LATER |
| 182 | |
| 183 | if test $# = 0 || test "$1" = -- || test -f "$1" |
| 184 | then |
| 185 | set -- . "$@" |
| 186 | fi |
| 187 | |
| 188 | codespeed_opt= |
| 189 | test "$GIT_PERF_CODESPEED_OUTPUT" = "true" && codespeed_opt="--codespeed" |
| 190 | |
| 191 | run_dirs "$@" |
| 192 | |
| 193 | if test -z "$GIT_PERF_SEND_TO_CODESPEED" |
| 194 | then |
| 195 | "$PERL_PATH" ./aggregate.perl --results-dir="$TEST_RESULTS_DIR" $codespeed_opt "$@" |
| 196 | else |
| 197 | json_res_file=""$TEST_RESULTS_DIR"/$GIT_PERF_SUBSECTION/aggregate.json" |
| 198 | "$PERL_PATH" ./aggregate.perl --results-dir="$TEST_RESULTS_DIR" --codespeed "$@" | tee "$json_res_file" |
| 199 | send_data_url="$GIT_PERF_SEND_TO_CODESPEED/result/add/json/" |
| 200 | curl -v --request POST --data-urlencode "json=$(cat "$json_res_file")" "$send_data_url" |
| 201 | fi |
| 202 | } |
| 203 | |
| 204 | get_var_from_env_or_config "GIT_PERF_CODESPEED_OUTPUT" "perf" "codespeedOutput" "--bool" |
| 205 | get_var_from_env_or_config "GIT_PERF_SEND_TO_CODESPEED" "perf" "sendToCodespeed" |
| 206 | |
| 207 | # Preserve GIT_PERF settings from the environment when loading |
| 208 | # GIT-BUILD-OPTIONS; see the similar hack in perf-lib.sh. |
| 209 | git_perf_settings="$(env | |
| 210 | sed -n "/^GIT_PERF_/{ |
| 211 | # escape all single-quotes in the value |
| 212 | s/'/'\\\\''/g |
| 213 | # turn this into an eval-able assignment |
| 214 | s/^\\([^=]*=\\)\\(.*\\)/\\1'\\2'/p |
| 215 | }")" |
| 216 | cd "$(dirname $0)" |
| 217 | . ../../GIT-BUILD-OPTIONS |
| 218 | eval "$git_perf_settings" |
| 219 | |
| 220 | if test -n "$TEST_OUTPUT_DIRECTORY" |
| 221 | then |
| 222 | TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results" |
| 223 | else |
| 224 | TEST_RESULTS_DIR=test-results |
| 225 | fi |
| 226 | |
| 227 | mkdir -p "$TEST_RESULTS_DIR" |
| 228 | get_subsections "perf" >"$TEST_RESULTS_DIR"/run_subsections.names |
| 229 | |
| 230 | if test $(wc -l <"$TEST_RESULTS_DIR"/run_subsections.names) -eq 0 |
| 231 | then |
| 232 | if test -n "$GIT_PERF_SUBSECTION" |
| 233 | then |
| 234 | if test -n "$GIT_PERF_CONFIG_FILE" |
| 235 | then |
| 236 | die "no subsections are defined in config file '$GIT_PERF_CONFIG_FILE'" |
| 237 | else |
| 238 | die "subsection '$GIT_PERF_SUBSECTION' defined without a config file" |
| 239 | fi |
| 240 | fi |
| 241 | ( |
| 242 | run_subsection "$@" |
| 243 | ) |
| 244 | elif test -n "$GIT_PERF_SUBSECTION" |
| 245 | then |
| 246 | grep -E "^$GIT_PERF_SUBSECTION\$" "$TEST_RESULTS_DIR"/run_subsections.names >/dev/null || |
| 247 | die "subsection '$GIT_PERF_SUBSECTION' not found in '$GIT_PERF_CONFIG_FILE'" |
| 248 | |
| 249 | grep -E "^$GIT_PERF_SUBSECTION\$" "$TEST_RESULTS_DIR"/run_subsections.names | while read -r subsec |
| 250 | do |
| 251 | ( |
| 252 | GIT_PERF_SUBSECTION="$subsec" |
| 253 | export GIT_PERF_SUBSECTION |
| 254 | echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========" |
| 255 | run_subsection "$@" |
| 256 | ) |
| 257 | done |
| 258 | else |
| 259 | while read -r subsec |
| 260 | do |
| 261 | ( |
| 262 | GIT_PERF_SUBSECTION="$subsec" |
| 263 | export GIT_PERF_SUBSECTION |
| 264 | echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========" |
| 265 | run_subsection "$@" |
| 266 | ) |
| 267 | done <"$TEST_RESULTS_DIR"/run_subsections.names |
| 268 | fi |