t / perf / runon commit Merge branch 'dl/difftool-mergetool' (85ac27e)
   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        PERF_SET_GIT_TEST_INSTALLED=true
  88        export PERF_SET_GIT_TEST_INSTALLED
  89}
  90
  91run_dirs_helper () {
  92        mydir=${1%/}
  93        shift
  94        while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
  95                shift
  96        done
  97        if test $# -gt 0 -a "$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
 126run_dirs () {
 127        while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
 128                run_dirs_helper "$@"
 129                shift
 130        done
 131}
 132
 133get_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
 140get_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
 163run_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_REPO_NAME" "perf" "repoName"
 175        export GIT_PERF_REPO_NAME
 176
 177        GIT_PERF_AGGREGATING_LATER=t
 178        export GIT_PERF_AGGREGATING_LATER
 179
 180        if test $# = 0 -o "$1" = -- -o -f "$1"; then
 181                set -- . "$@"
 182        fi
 183
 184        codespeed_opt=
 185        test "$GIT_PERF_CODESPEED_OUTPUT" = "true" && codespeed_opt="--codespeed"
 186
 187        run_dirs "$@"
 188
 189        if test -z "$GIT_PERF_SEND_TO_CODESPEED"
 190        then
 191                ./aggregate.perl $codespeed_opt "$@"
 192        else
 193                json_res_file="test-results/$GIT_PERF_SUBSECTION/aggregate.json"
 194                ./aggregate.perl --codespeed "$@" | tee "$json_res_file"
 195                send_data_url="$GIT_PERF_SEND_TO_CODESPEED/result/add/json/"
 196                curl -v --request POST --data-urlencode "json=$(cat "$json_res_file")" "$send_data_url"
 197        fi
 198}
 199
 200get_var_from_env_or_config "GIT_PERF_CODESPEED_OUTPUT" "perf" "codespeedOutput" "--bool"
 201get_var_from_env_or_config "GIT_PERF_SEND_TO_CODESPEED" "perf" "sendToCodespeed"
 202
 203cd "$(dirname $0)"
 204. ../../GIT-BUILD-OPTIONS
 205
 206mkdir -p test-results
 207get_subsections "perf" >test-results/run_subsections.names
 208
 209if test $(wc -l <test-results/run_subsections.names) -eq 0
 210then
 211        if test -n "$GIT_PERF_SUBSECTION"
 212        then
 213                if test -n "$GIT_PERF_CONFIG_FILE"
 214                then
 215                        die "no subsections are defined in config file '$GIT_PERF_CONFIG_FILE'"
 216                else
 217                        die "subsection '$GIT_PERF_SUBSECTION' defined without a config file"
 218                fi
 219        fi
 220        (
 221                run_subsection "$@"
 222        )
 223elif test -n "$GIT_PERF_SUBSECTION"
 224then
 225        egrep "^$GIT_PERF_SUBSECTION\$" test-results/run_subsections.names >/dev/null ||
 226                die "subsection '$GIT_PERF_SUBSECTION' not found in '$GIT_PERF_CONFIG_FILE'"
 227
 228        egrep "^$GIT_PERF_SUBSECTION\$" test-results/run_subsections.names | while read -r subsec
 229        do
 230                (
 231                        GIT_PERF_SUBSECTION="$subsec"
 232                        export GIT_PERF_SUBSECTION
 233                        echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========"
 234                        run_subsection "$@"
 235                )
 236        done
 237else
 238        while read -r subsec
 239        do
 240                (
 241                        GIT_PERF_SUBSECTION="$subsec"
 242                        export GIT_PERF_SUBSECTION
 243                        echo "======== Run for subsection '$GIT_PERF_SUBSECTION' ========"
 244                        run_subsection "$@"
 245                )
 246        done <test-results/run_subsections.names
 247fi