-
Notifications
You must be signed in to change notification settings - Fork 6
/
driver-v5.sh
executable file
·286 lines (259 loc) · 8.17 KB
/
driver-v5.sh
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/usr/bin/env bash
# set -x
shopt -s extglob
# get_runnable_master_run.ghtml?os=## --> new run id, optional addition: force=1
# start_master_test.ghtml?runid=##&type=##" --> new test id
# finish_master_test.ghtml?testid=7&rc=100 --> nothing
# finish_master_run.ghtml?runid=## --> nothing
# $1 == api
# $2 == arguments
function callcurl
{
if [ "$runid" == "test" ]; then
echo "test"
return
fi
trycount=0
sleepdur=1
rc=1
while [ $rc -ne 0 ]; do
curloutput=`timelimit -q -p -t 30 curl --silent --fail "https://auto-tester.puremagic.com/addv2/$1?clientver=5&$2"`
rc=$?
if [ $rc -ne 0 -o "x${curloutput:0:13}" == "xunauthorized:" ]; then
echo -e "\tcurl failed, rc=$rc, 1=$1, 2=$2, curloutput=$curloutput, retrying in $sleepdur seconds..." 1>&2
sleep $sleepdur
trycount=$(expr $trycount + 1)
sleepdur=$(expr $sleepdur \* 2)
if [ $sleepdur -gt 120 ]; then
sleepdur=120
fi
fi
done
if [ -n "$curloutput" ]; then
echo "$curloutput"
fi
}
# $1 == testid
# $2 == rundir
# $3 == file
# $4 == runmode
function uploadlog
{
if [ "$runid" == "test" ]; then
return
fi
trycount=0
sleepdur=1
rc=1
while [ $rc -ne 0 ]; do
curloutput=`timelimit -q -p -t 30 curl --silent --fail -T $2/$3 "https://auto-tester.puremagic.com/addv2/upload_$4?clientver=5&testid=$1"`
rc=$?
if [ $rc -ne 0 -o "x${curloutput:0:13}" == "xunauthorized:" ]; then
echo -e "\tcurl failed, rc=$rc, 1=$1, 2=$2, 3=$3, 4=$4, curloutput=$curloutput, retrying in $sleepdur seconds..." 1>&2
sleep $sleepdur
trycount=$(expr $trycount + 1)
sleepdur=$(expr $sleepdur \* 2)
if [ $sleepdur -gt 120 ]; then
sleepdur=120
fi
fi
done
if [ -n "$curloutput" ]; then
echo "$curloutput"
fi
}
function detectos
{
foo=`uname`
case "$foo" in
Linux|Darwin|FreeBSD)
OS=$foo
;;
CYGWIN_NT-*)
OS=Win
;;
*)
echo "unknown os ($foo), aborting"
exit 1
;;
esac
foo=`uname -m`
case "$foo" in
i[3456]86)
OS=${OS}_32
;;
x86_64|amd64)
OS=${OS}_64_64
;;
*)
echo "unknown machine ($foo), aborting"
exit 1
esac
echo $OS
}
# $1 == rundir
# $2 == OS
# $3 == owner
# $4 == repository
# $5 == branch
function checkoutRepeat
{
rc=1
while [ $rc -ne 0 ]; do
timelimit -q -p -t $TESTER_TIMEOUT src/do_checkout.sh "$1" "$2" "$3" "$4" "$5"
rc=$?
if [ $rc -ne 0 ]; then
sleep 60
fi
done
}
# $1 == null or "test" or "force"
# null: allow the service to determine if the test should run
# test: do a local only test run
# force: tell the service to execute a run even if there haven't been changes
# -- force has no meaning for runmode == pull right now
function runtests
{
if [ "$1" == "test-DMD" ]; then
OS=$(detectos)
data=("test" "master" "1" "$OS")
data=("${data[@]}" "3")
data=("${data[@]}" "1" "dlang" "dmd" "master")
data=("${data[@]}" "2" "dlang" "druntime" "master")
data=("${data[@]}" "3" "dlang" "phobos" "master")
data=("${data[@]}" 1 0)
#if [ "$runmode" == "pull" ]; then
# data=("${data[@]}" 17 0 "https://github.com/yebblies/dmd.git" "issue4923")
#fi
data=("${data[@]}" 15 0)
data=("${data[@]}" 15 1)
data=("${data[@]}" 15 2)
data=("${data[@]}" 16 0)
data=("${data[@]}" 16 1)
data=("${data[@]}" 16 2)
elif [ "$1" == "test-GDC" ]; then
OS=$(detectos)
data=("test" "master" "2" "$OS")
data=("${data[@]}" "1")
data=("${data[@]}" "13" "D-Programming-GDC" "GDC" "master")
data=("${data[@]}" 1 0)
#if [ "$runmode" == "pull" ]; then
# # fix
# data=("${data[@]}" 17 0 "https://github.com/yebblies/dmd.git" "issue4923")
#fi
data=("${data[@]}" 15 0)
data=("${data[@]}" 16 0)
else
data=($(callcurl get_runnable_pull "hostname=`hostname`$extraargs"))
fi
runid="${data[0]}"
if [[ ! ( $runid =~ ^(-?[0-9]+|test)$ ) ]]; then
if [ $runid != "skip" ]; then
echo "Unexpected output from get_runnable_pull, runid: $runid, data: ${data[@]}"
fi
echo -e -n "Skipping run...\r"
run_rc=2
return
fi
runmode="${data[1]}"
projecttype="${data[2]}"
OS="${data[3]}"
data=("${data[@]:4}")
num_rbs=${data[0]}
# sets of (repoid owner name branch)
repobranches=(${data[@]:1:4*$num_rbs})
steps=(${data[@]:1+4*$num_rbs})
rundir=$runmode-$runid-$OS
pretest
# add project when that data is available
echo -e "\nStarting $runmode run $runid, platform: $OS"
if [ ! -d "$rundir" ]; then
mkdir "$rundir"
fi
run_rc=0
while [ $run_rc -eq 0 -a ${#steps[@]} -gt 0 ]; do
repoid=${repobranches[${steps[1]}*4]}
reponame=${repobranches[${steps[1]}*4 + 2]}
testid=$(callcurl start_${runmode}_test "runid=$runid&type=${steps[0]}&repoid=$repoid")
if [[ ! ( $testid =~ ^(-?[0-9]+|test)$ ) ]]; then
if [ "x${testid:0:5}" != "xabort" ]; then
echo "Unexpected output from start_${runmode}_test, aborting: $testid"
fi
run_rc=3
break
fi
case ${steps[0]} in
1) # checkout
x=("${repobranches[@]}")
while [ ${#x[@]} -gt 0 ]; do
checkoutRepeat "$rundir" "$OS" "${x[1]}" "${x[2]}" "${x[3]}"
x=(${x[@]:4})
done
src/do_fixup.sh "$rundir" "$OS" "$projecttype"
step_rc=$?
logname=checkout.log
;;
15)
timelimit -q -p -t $TESTER_TIMEOUT src/do_build_${reponame}.sh "$rundir" "$OS"
step_rc=$?
logname=${reponame}-build.log
;;
16)
timelimit -q -p -t $TESTER_TIMEOUT src/do_test_${reponame}.sh "$rundir" "$OS" "$runmode"
step_rc=$?
logname=${reponame}-unittest.log
;;
17)
timelimit -q -p -t $TESTER_TIMEOUT src/do_pull.sh "$rundir" "$OS" "$reponame" "${steps[2]}" "${steps[3]}"
step_rc=$?
logname=${reponame}-merge.log
steps=(${steps[@]:2}) # trim extra fields
;;
18)
src/do_daily_maintenance.sh
;;
esac
if [ $step_rc -gt 1 ]; then
echo "timed out after $TESTER_TIMEOUT seconds, step failed" >> $rundir/$logname
step_rc=1
fi
steps=(${steps[@]:2})
uploadlog $testid $rundir $logname $runmode
curlrc=$(callcurl finish_${runmode}_test "testid=$testid&rc=$step_rc")
if [ "$runmode" == "pull" -a $step_rc -ne 0 ]; then
run_rc=1
elif [ "x$curlrc" != "xok" -a "x$curlrc" != "xtest" ]; then
if [ "x${curlrc:0:5}" != "xabort" ]; then
echo "Unexpected output from finish_${runmode}_test, aborting: $curlrc"
fi
run_rc=3
fi
done
#testid=$(callcurl start_${runmode}_test "runid=$runid&type=8")
#src/do_html_phobos.sh "$rundir" "$OS"
#html_dmd_rc=$?
#uploadlog $testid $rundir phobos-html.log
# todo: should be condition on test mode
#rsync --archive --compress --delete $rundir/phobos/web/2.0 dwebsite:/home/dwebsite/test-results/docs/$OS
#callcurl finish_${runmode}_test "testid=$testid&rc=$html_dmd_rc"
callcurl finish_${runmode}_run "runid=$runid"
echo -e "\trun_rc=$run_rc"
if [ -d "$rundir" -a "$runid" != "test" ]; then
rm -rf "$rundir"
if [ -d /cores ]; then rm -f /cores/*; fi
fi
}
TESTER_TIMEOUT=3600
function pretest
{
return
}
if [ -f configs/`hostname` ]; then
. configs/`hostname`
fi
rc=2
runtests $1
if [ $run_rc -ne 2 ]; then
rc=0
fi
exit $rc