-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
go.sh
executable file
·300 lines (234 loc) · 7.69 KB
/
go.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/bin/bash
#
# Simple autotest script.
#
#
# Install host dependencies
#
sudo apt install -y -qq jq expect sshpass nmap iperf3 &>/dev/null
#
# Create working directories
#
mkdir -p userconfig logs reports
# create sample configuration if id does not exits
LOCALREPO="apt.armbian.com"
if [[ ! -f userconfig/configuration.sh ]]; then
cp lib/configuration.sh userconfig/configuration.sh
echo "Setup finished. Edit userconfig/configuration.sh and run ./go.sh again!"
exit
fi
# load user configuration
source userconfig/configuration.sh
# Script parameters handling
while [[ $1 == *=* ]]; do
parameter=${1%%=*}
value=${1##*=}
shift
echo "Command line: setting $parameter to ${value:-(empty)}"
eval "$parameter=\"$value\""
scripted=true
done
# Display help
if [[ $1 == "--help" ]]; then
echo "Config options:"
echo ""
echo "DISPLAYHOSTS = yes # displays ip addresses and exit"
echo "PREPAREONLY = yes # run only initial board prepare"
echo "EMULATED = yes # don't run sbc-bench but use static data for debugging"
exit
fi
# start measuring executing time
START=$(date +%s)
# define absolute path
SRC="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
# report file name
REPORT="$(date +%Y-%m-%d_%H.%M.%S)"
REPORT_HTML=$(date "+%d. %b %Y %H:%M UTC")
# array declaration for storing tested families and branches
myfambran=()
# store pids in here
mytestids=()
# load libraries
source lib/functions.sh
# remove logs each time we ran the script. Need to be changed
rm -rf ${SRC}/logs/* ${SRC}/reports/data.out
if [[ -n $HOSTS ]]; then # read comma delimited IP address from HOSTS
IFS=', ' read -r -a hostarray <<< "$HOSTS"
elif [[ -n $SUBNET ]]; then # otherwise scan subnet if SUBNET is defined
# exclude IP addresses defined in EXCLUDE
[[ -n $EXCLUDE ]] && HOST_EXCLUDE="--exclude ${EXCLUDE}"
# include IP addresses defined in INCLUDE
[[ -n $INCLUDE ]] && IFS=', ' read -r -a includearray <<< "$INCLUDE"
readarray -t hostarray < <(nmap $HOST_EXCLUDE --open -sn ${SUBNET} 2> /dev/null \
| grep "ssh\|Nmap scan report" | grep -v "gateway" \
| grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
else # otherwise stops with an error
echo "\$HOST not defined. Exiting." && exit 1
fi
# merge HOSTS/SUBNET with INCLUDE
hostarray=("${includearray[@]}" "${hostarray[@]}")
if [[ $DISPLAYHOSTS == yes ]]; then
i=0
for each in "${hostarray[@]}"
do
i=$((i+1))
echo "$i. $each"
done
exit
fi
echo "Display config options:"
echo ""
echo "PASSES=$PASSES"
echo "SBCBENCHPASS=$SBCBENCHPASS"
echo "COMPARE=$COMPARE"
echo "PARALLEL=$PARALLEL"
echo "FRESH=$FRESH"
echo "BSPSWITCH=$BSPSWITCH"
echo "EMULATED=$EMULATED"
echo "LOCALREPO=$LOCALREPO"
echo ""
# cycle test cases and make a header row
#
# when DRY_RUN is set we cycle over test to basic information about tests, but do not run them
#
echo "Preparing tests"
DRY_RUN=true
readarray -t array < <(find $SRC/tests -maxdepth 2 -type f -name '*.bash' | sort)
COLOUMB=0
for u in "${array[@]}"
do
unset TEST_SKIP
. $u
if [[ $TEST_SKIP != "true" ]]; then
COLOUMB=$((COLOUMB+1))
if [[ COLOUMB -gt 5 ]]; then
row=2;
else
row=1;
fi
echo "- $TEST_TITLE"
HEADER_HTML+="<td align=center rowspan=$row>$TEST_ICON<br><small>$TEST_TITLE</small></td>"
fi
done
echo ""
# html report header
HEAD_HTML="<html>\n<head>\n<style type=\"text/css\">
\ntd, tr {
\n border: 1px solid #e0e3e6;
\n padding: 8px;
\n}
\ntable {
\n border-collapse: collapse;
\n background: #f6f8fa;
\n}
\n</style>\n<meta charset=\"UTF-8\">\n</head>\n<body><h1>Report ${REPORT_HTML}</h1>\
\n<table class=\"TFtable\" cellspacing=0 width=100% border=0>
\n<tr><td align=right rowspan=2>\
<img width=20 src=https://raw.githubusercontent.com/armbian/autotests/master/icons/hashtag.png>\
</td><td align=center colspan=2>Board</td>\n"
HEADER_HTML="${HEAD_HTML}${HEADER_HTML}</tr>\
<tr><td>Cycle</td><td>Version & kernel</td><td align=middle colspan=3>Iperf send/receive</td>
<td align=middle>copy / set</td><td align=middle>read / write</td></tr>\n"
unset DRY_RUN
# Read cached database from previous succesfull test run. Display / log error if this run is different.
# Some host might not returned after the test cycle
#
if [[ -f ${SRC}/reports/data.in ]]; then
i=0
while IFS="\n" read -r line; do
eval "declare -a a$i=($line)"
i=$((i+1))
done < ${SRC}/reports/data.in
fi
# Cycle hosts and see if they are alive, login/create username
# and read /etc/armbian-release and compare with previous run
x=0
waitlonger=0
for USER_HOST in "${hostarray[@]}"; do
readarray -t array < <(find $SRC/init -maxdepth 2 -type f -name '*.bash' | sort)
for u in "${array[@]}"
do
. $u
vara="a$x[0]"
varb="a$x[1]"
# creating data for next comparission
echo '"'$USER_HOST'" "'$BOARD_NAME'"' >> ${SRC}/reports/data.out
if [[ "${COMPARE}" == "yes" && $i -gt 1 && ("$USER_HOST" != "${!vara}" || "$BOARD_NAME" != "${!varb}") ]]; then
[[ -n $BOARD_NAME ]] && x=$((x+1))
display_alert "${x}. ${!varb} was expected on $(mask_ip "${!vara}")" "$(date +%R:%S)" "err"
fi
# switch to nightly
if [[ $FRESH == nightly ]]; then
display_alert "Switch to nightly builds, current branch" "$(date +%R:%S)" "wrn"
remote_exec "apt update; apt -y -qq install armbian-config; \
LANG=C armbian-config main=System selection=Nightly branch=$BOARD_BRANCH" "-t" &>/dev/null
write_uboot
fi
# switch to stable build, current branch from repository if not already there
#if [[ -n "$BOARD_IMAGE_TYPE" && "$BOARD_IMAGE_TYPE" != stable && $BOARD_BRANCH != current && $FRESH == yes ]]; then
if [[ -n "$BOARD_IMAGE_TYPE" && $FRESH == "stable" ]]; then
display_alert "Switch to stable builds" "$(date +%R:%S)" "wrn"
remote_exec "apt update; apt -y -qq install armbian-config; \
LANG=C armbian-config main=System selection=Stable branch=$BOARD_BRANCH" "-t" &>/dev/null
write_uboot
fi
x=$((x+1))
done
done
# show diff to previous build
display_alert "Diff to previous build" "added or removed" "info"
cat ${SRC}/reports/data.out | cut -d$'"' -f 4 | sed 's/.*/"&"/' | sort | uniq | awk -F"\"" '{print $2}' > ${SRC}/reports/data.out.txt
[[ -f ${SRC}/reports/data.in ]] && cat ${SRC}/reports/data.in ${SRC}/reports/data.out | cut -d$'"' -f 4 | sed 's/.*/"&"/' | sort | uniq | awk -F"\"" '{print $2}' | diff ${SRC}/reports/data.out.txt - | grep ">"
#cp ${SRC}/reports/data.out ${SRC}/reports/data.in
if [[ $PREPAREONLY == yes ]]; then
exit
fi
echo ""
# sleep in case upgrade and reboot was done
sleep $waitlonger
# Cycle boards and run tests
x=0
for USER_HOST in "${hostarray[@]}"; do
remote_exec "(sleep 60m; reboot) &" "-t" &>/dev/null # reboots the machine automatically after some time
if [[ $PARALLEL == "yes" ]]; then
run_tests &
else
run_tests
fi
mytestids+=($!)
#[[ $? -ne 0 ]] && display_alert "Host failed" "$(mask_ip "$USER_HOST")" "err"
x=$((x+1))
done
function disaster-condition
{
counter=0
for i in "${mytestids[@]}"
do
kill -0 $i > /dev/null 2>&1;
if [[ $? -eq 0 ]]; then
((counter++))
else
mytestids=( "${mytestids[@]/$i}" )
fi
done
[[ $counter -eq 0 ]] && return 0
}
while :
do
# echo "Tests running in the background ..."
# sleep 10
if (disaster-condition)
then break
fi
done
# close HTML file
HEADER_HTML+="$(ls -v ${SRC}/logs/*.html | xargs cat)</table></body>\n</html>\n"
echo -e $HEADER_HTML >> ${SRC}/reports/${REPORT}.html
# Show script run duration
echo "This whole procedure took "$((($(date +%s) - $START)/60))" minutes".
if [[ -n $UPLOAD_SERVER && -n $UPLOAD_LOCATION ]]; then
# upload report
rsync -arP --delete ${SRC}/reports/${REPORT}.html -e 'ssh -p 22' ${UPLOAD_SERVER}:${UPLOAD_LOCATION}"${REPORT}.html"
# set link to latest
ssh ${UPLOAD_SERVER} "cd ${UPLOAD_LOCATION} ; ln -sf ${REPORT}.html latest.html"
fi