summaryrefslogtreecommitdiff
path: root/tcwg_bmk-build.sh
blob: 809c097c56e64d50ac8e836d710ce2a027fd0c30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash

set -euf -o pipefail

scripts=$(dirname $0)
. $scripts/jenkins-helpers.sh

convert_args_to_variables "$@"

obligatory_variables rr[ci_config] \
		     BUILD_NUMBER ssh_host ssh_port

# Execution mode: baseline, bisect, continue, jenkins-full
rr[mode]="${rr[mode]-baseline}"

case "${rr[mode]}" in
    "jenkins-full")
	obligatory_variables rr[current_project] rr[current_branch]
	;;
esac

# Set custom revision for one of the projects, and use baseline revisions
# for all other projects.
rr[ci_project]="${rr[ci_project]-tcwg_bmk}"
rr[baseline_branch]="${rr[baseline_branch]-linaro-local/ci/${rr[ci_project]}/${rr[ci_config]}}"
rr[current_branch]="${rr[current_branch]-default}"
rr[current_project]="${rr[current_project]-none}"
rr[reset_baseline]="${rr[reset_baseline]-false}"
rr[top_artifacts]="${rr[top_artifacts]-$(pwd)/artifacts}"

# {toolchain_name}-{toolchain_ver}-{target}-{bmk}-{cflags}
IFS=- read -a ci_config <<EOF
${rr[ci_config]}
EOF
rr[toolchain_name]=${rr[toolchain_name]-${ci_config[0]}}
rr[target]=${rr[target]-${ci_config[2]}}
cflags=${cflags-${ci_config[4]}}

start_at="${start_at-default}"
finish_at="${finish_at-default}"
verbose="${verbose-true}"
verbose2="${verbose2-false}"

results_id="tx1/${rr[ci_project]}/${rr[ci_config]}-$BUILD_NUMBER"

if $verbose2; then set -x; fi

trap "eval \"echo ERROR at \${FUNCNAME[0]}:\${BASH_LINENO[0]}\"" EXIT

# Set start and finish steps for different modes.
default_start_at=""
default_finish_at=""
base_artifacts_opt="base-artifacts"
case "${rr[mode]}" in
    "baseline")
	default_finish_at="update_baseline"
	;;
    "bisect")
	case "${rr[toolchain]}:${rr[current_project]}" in
	    gnu:binutils) default_start_at="build_abe-binutils" ;;
	    gnu:gcc) default_start_at="build_abe-stage1" ;;
	    llvm:llvm) default_start_at="build_llvm" ;;
	esac
	default_finish_at="check_regression"
	;;
    "continue")
	# Developer mode.
	case "${rr[toolchain]}" in
	    "gnu") default_start_at="prepare_abe" ;;
	    "llvm") default_start_at="build_llvm" ;;
	esac
	base_artifacts_opt=""
	;;
    "jenkins-full") ;;
esac
if [ x"$start_at" = x"default" ]; then
    start_at="$default_start_at"
fi
if [ x"$finish_at" = x"default" ]; then
    finish_at="$default_finish_at"
fi

run_step_init "$start_at" "$finish_at" "${rr[top_artifacts]}" "$base_artifacts_opt" "$verbose"

. $scripts/round-robin.sh

benchmark ()
{
    (
    set -euf -o pipefail

    rm -rf $(pwd)/bin
    mkdir $(pwd)/bin

    local bin cc

    bin="$(pwd)/abe/builds/destdir/x86_64-unknown-linux-gnu/bin"
    cc="$bin/$(print_gnu_target ${rr[target]})-"

    local hw
    case "${rr[target]}" in
	arm*) hw=tk1 ;;
	*) hw=tx1 ;;
    esac

    local bmk_flags
    bmk_flags="$(echo _$cflags | sed -e "s/_/ -/g")"
    case "$cflags" in
	"Os*") bmk_flags="$bmk_flags -static" ;;
    esac
    
    ssh -p2222 -l $USER@linaro.org ci.linaro.org build tcwg-benchmark -s -v \
	-p bench_list=all \
	-p cflags="$bmk_flags" \
	-p displaytag=${rr[ci_config]} \
	-p toolchain_url=ssh://$ssh_host:$ssh_port:$cc \
	-p sysroot=ssh://$ssh_host:$ssh_port:$(pwd)/abe/sysroots/$(print_gnu_target ${rr[target]}) \
	-p results_id="$results_id" \
	-p scripts_branch="$scripts_branch" \
	-p bmk_branch="$bmk_branch"

    echo "$results_id" > "${rr[top_artifacts]}/results_id"
    cat >> ${rr[top_artifacts]}/results <<EOF
Succesful benchmark run: $results_id
0
EOF
    )
}

# Exit with code 0 if no regression compared to base-artifacts/results.
no_regression_p ()
{
    (
    set -euf -o pipefail

    if ! [ -f base-artifacts/results ]; then
	return 0
    fi
    
    local build_result_ref build_result_new
    build_result_ref=$(tail -n1 base-artifacts/results)
    build_result_new=$(tail -n1 ${rr[top_artifacts]}/results)

    if [ $build_result_new -lt $build_result_ref ]; then
	return 1
    fi

    if ! [ -f base-artifacts/results_id ]; then
	return 0
    fi

    local results_ref
    results_ref=$(cat base-artifacts/results_id)

    $scripts/tcwg-benchmark-results.sh --results_ref $results_ref --results_id $results_id --top_artifacts "${rr[top_artifacts]}" --verbose $verbose

    while IFS=, read -r bmk symbol speed size; do
	if [ "$size" -gt 100 ]; then
	    return 1
	fi
    done < ${rr[top_artifacts]}/results.csv
    )
}

run_step stop_on_fail -10 reset_artifacts
case "${rr[toolchain]}" in
    gnu)
	run_step stop_on_fail x prepare_abe
	run_step skip_on_fail -9 build_abe binutils
	run_step skip_on_fail -8 build_abe stage1
	run_step skip_on_fail -7 build_abe linux
	run_step skip_on_fail -6 build_abe glibc
	run_step skip_on_fail -5 build_abe stage2
	;;
    llvm)
	run_step skip_on_fail -1 build_llvm
	;;
esac
run_step skip_on_fail x benchmark
run_step reset_on_fail x check_regression
run_step stop_on_fail x update_baseline
run_step stop_on_fail x push_baseline

trap "" EXIT