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