blob: a472fb04f7cb22f3a51c3c5bec43b326b17973be (
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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
#!/bin/bash
set -e
export LANG=C
# some defaults
GIT_REF_DIR=`pwd`/ref-snapshots/
ABE_BRANCH=
ABE_PATH="" # if empty, then it gets a local checkout below
DISPLAY_REPORT=false
DISPLAY_SUMMARY=false
QUIET=false
ONLY_CHECK_REFERENCE=false
BUILD_TARGET=aarch64-linux-gnu
validate_path()
{
if ! readlink -e $1; then
echo "Path $1 does not exist" >&2
exit 1
fi
}
read_var()
{
local artifact_list=$1
local var=$2
grep "^${var}=" "${artifact_list}" | cut -d = -f 2-
}
# parse command line options
while [[ $# -gt 0 ]]; do
OPT=$1
shift
case "$OPT" in
--abe-path) ABE_PATH="`validate_path $1`"; shift;;
--ref-snapshots) GIT_REF_DIR="`validate_path $1`"; shift;;
--abe-branch) ABE_BRANCH=$1; shift;;
--abe-flags) ABE_FLAGS=$1; shift;;
--abe-configure-flags) ABE_CONF_FLAGS=$1; shift;;
--target) BUILD_TARGET=$1; shift;;
--display[_-]report) DISPLAY_REPORT=true;;
--display[_-]summary) DISPLAY_SUMMARY=true;;
--only-check-reference) ONLY_CHECK_REFERENCE=true;;
--quiet) QUIET=true;;
--debug) set -x;;
*) echo "Unrecognised option: $OPT" >&2; exit 1;;
esac
done
# find the location of the abe-tests directory
ABE_TESTS_PATH=`perl -e 'use File::Basename; use Cwd q(abs_path); print dirname(abs_path(shift))' "$0"`
# suppress return code of 1 when there are no matches, to avoid spurious shell
# aborts due to set -e
xgrep()
{
(
set +e
grep "$@"
RESULT=$?
if [ $? -lt 2 ]; then
exit 0
else
exit 2
fi
)
}
# if --quiet was used, then we hide most of the output of abe using this
# function.
log_to_file()
{
if $QUIET; then
tee "$1" | grep --line-buffered -P '^(NOTE|WARNING|ERROR|FIXME):'
else
tee "$1"
fi
}
# if the date rolls over during the test, we can end up with log differences
# because the timestamp is used in filenames. Assuming that this test takes
# less than 24 hours, we can just convert tomorrow's date to today's date to
# hide log differences when this happens.
TODAY="`date +%Y%m%d`"
TOMORROW="`date -d tomorrow +%Y%m%d`"
postprocess_log()
{
DIRNAME=$1
sed -e 's@/'"$DIRNAME"'/@/<builddir>/@g' | sed -e 's@\(/[^ ./]*.git\)[^ /]*@\1<stuff>@g; s@builds/tmp.[0-9]*\>@builds/tmp.<pid>@g; '"s/$TODAY/<date>/g; s/$TOMORROW/<date>/g"
}
result_pass()
{
echo PASSED: "$*" | tee --append $TOP/results_summary.txt $TOP/results_report.txt
}
result_fail()
{
EXTRA_FILE=$1
shift
echo FAILED: "$* See $(basename $EXTRA_FILE)." | tee --append $TOP/results_summary.txt $TOP/results_report.txt
sed -e 's/^/>>> /' "$EXTRA_FILE" >> $TOP/results_report.txt
}
result_fail_no_file()
{
echo FAILED: "$*" | tee --append $TOP/results_summary.txt $TOP/results_report.txt
}
extract_run()
{
FILE=$1
DIRNAME=$2
LINE=$(grep -n '^NOTE: Checkout all took' "$FILE" | head -n 1 | cut -f1 -d:)
# we can ignore the manifest files warning here because the comparison is
# less sophisticated than the one in this test and reports false positives
if [ -z "$LINE" ]; then LINE=1; fi
tail -n "+$LINE" "$FILE" | xgrep -E '^(DRYRUN:|RUN:|ERROR[ (]|FIXME\(|WARNING:) ' | postprocess_log "$DIRNAME" | xgrep -v '^WARNING: Manifest files are different'
}
compare_run_lines()
{
FILE1=$1
FILE2=$2
OUTPUT=$3
(
set +e
diff -u "$FILE1" "$FILE2" > "$OUTPUT"
if [ $? -eq 0 ]; then
result_pass run lines diff.
else
result_fail "$OUTPUT" run lines diff.
fi
)
}
extract_revisions()
{
FILE=$1
perl -e 'while (<>) { if (m/^NOTE: Configuring (.*?) *$/) { $component = $1; } if (m@^(?:DRY)?RUN:.*/bin/bash ('"$SNAPSHOTS"'/([^/]+\.git)[^ ]+/)configure SHELL=/bin/bash@) { print "$component: $2 "; system("cd $1 && git rev-parse HEAD") } }' "$FILE"
}
compare_revisions()
{
FILE1=$1
FILE2=$2
OUTPUT=$3
WHEN=$3
(
set +e
diff -u "$FILE1" "$FILE2" > "$OUTPUT"
if [ $? -eq 0 ]; then
result_pass revisions diff.
else
result_fail "$OUTPUT" "revisions list differs $WHEN".
fi
)
}
add_extra_revisions()
{
FILE=$1
perl -e 'while (<>) { if (m@^RUN:.*/bin/bash ('"$SNAPSHOTS"'/([^/]+\.git)[^ ]+/)configure SHELL=/bin/bash@) { print "$2: "; system(qq(cd $1 && touch abe-test-dummy && git add abe-test-dummy && git -c user.name="ABE Tests" commit -m dummy)); } }' "$FILE"
}
check_revisions_in_manifest()
{
PHASE=$1
REVISIONS=$2
MANI=$3
REPORT=$4
FAILED=false
while read; do
# We get input in the form:
# COMPONENT[optional SUBCOMPONENT]: REPO.git SHA1
# Extract COMPONENT:
COMPONENT=`echo "$REPLY" | sed -e 's/:.*//; s/ .*//'`
REV=`echo $REPLY | sed -e 's/.* //'`
if ! grep -q "${COMPONENT}_revision=$REV" "$MANI"; then
FAILED=true
echo "${COMPONENT}_revision=$REV not found in $(basename $MANI)" >> "$REPORT" 2>&1
fi
done < "$REVISIONS"
if $FAILED; then
result_fail "$REPORT" "Build revisions did not match manifest revisions in phase $PHASE."
else
result_pass "Build revisions matched manifest revisions in phase $PHASE."
fi
}
strip_unused_content_from_manifest()
{
IN="$1"
OUT="$2"
grep -B1000000 -F -x ' # Everything below this line is only for informational purposes for developers' <"$IN" >"$OUT"
}
scan_manifest_for_build_dir()
{
FILE=$1
BUILDDIR=$2
PHASE=$3
DIR_REFS=$TOP/scan_builddir$PHASE.txt
if grep -F "$BUILDDIR" "$FILE" > $DIR_REFS; then
result_fail $TOP/$DIR_REFS Phase $PHASE manifest contains reference to build dir.
else
result_pass Phase $PHASE manifest does not contain references to build dir.
fi
}
wrap_abe()
{
PHASE=$1
ABE_LOG_FILE=$2
shift 2
(
export ORIG_PATH="$PATH"
# we handle errors explicitly here
set +e
set -o pipefail
PATH="$ABE_TESTS_PATH/wrappers:$PATH"
export REPORT_FILE_TEMPLATE=$TOP/wrap-failures-$PHASE/
mkdir -p "$REPORT_FILE_TEMPLATE"
"$@" 2>&1 | log_to_file "$ABE_LOG_FILE"
if [ $? -eq 0 ]; then
result_pass Phase $PHASE abe succeeded.
else
tail -n 100 "$ABE_LOG_FILE" > "$ABE_LOG_FILE".tail
result_fail "$ABE_LOG_FILE".tail Phase $PHASE abe returned non-zero exit status.
fi
)
}
check_wrap_fails()
{
PHASE=$1
echo "======= CHECKING FOR FAILURES IN WRAPPED COMMANDS (PHASE $PHASE)"
(
FAILED=0
shopt -s nullglob
for i in $TOP/wrap-failures-$PHASE/*; do
if [ -f "$i" ]; then
cmd=`basename $i`
result_fail_no_file "Phase $PHASE use of $cmd resulted in non-zero return code."
FAILED=1
fi
done
if [ $FAILED -eq 0 ]; then
result_pass "Phase $PHASE monitored commands did not fail."
fi
)
}
check_log()
{
PHASE=$1
PATTERN=$2
INFILE=$3
OUTFILE=$4
MSG_FAIL=$5
MSG_PASS=$6
(
set +e
grep "$PATTERN" "$INFILE" > "$OUTFILE"
if [ $? -ne 1 ]; then
result_fail $OUTFILE Phase $PHASE $MSG_FAIL.
else
result_pass Phase $PHASE $MSG_PASS
fi
)
}
check_artifacts()
{
local PHASE=$1
local ARTIFACTS=$2
local error
error=0
while read; do
local object=$(echo "${REPLY}" | cut -d = -f 1)
local path=$(echo "${REPLY}" | cut -d = -f 2-)
if [ "${path:0:1}" != "/" ]; then
error=1
echo "Artifact '${object}' has relative path '${path}'" >> $TOP/artifact-errors$PHASE.txt
fi
if [ ! -f ${path} ]; then
error=1
echo "Artifact '${object}' has non-existent path '${path}'" >> $TOP/artifact-errors$PHASE.txt
fi
done < "${ARTIFACTS}"
if [ "${error}" -eq 0 ]; then
result_pass Phase $PHASE Artifacts.
else
result_fail $TOP/artifact-errors$PHASE.txt Phase $PHASE Artifacts are invalid.
fi
}
if [ -d "$GIT_REF_DIR" ]; then
GIT_REF_OPT=--with-git-reference-dir=$GIT_REF_DIR
echo "======= FOUND GIT REFERENCE DIR $GIT_REF_DIR"
else
unset GIT_REF_OPT
fi
rm -Rf full-manifest-test
mkdir -p full-manifest-test
cd full-manifest-test
TOP="`pwd`"
SNAPSHOTS="$TOP/snapshots"
# for speed when making tarballs
export XZ_OPT=-0
# make sure that some failure is reported if set -e kills the script.
trap '{
if [ -z "$REACHED_THE_END" ]; then
result_fail_no_file Abe-tests encountered unhandled error condition.
fi
}' EXIT
if [[ -z "$ABE_PATH" ]]; then
git clone git://git.linaro.org/toolchain/abe
ABE_PATH=$TOP/abe
(cd $ABE_PATH && git checkout "${ABE_BRANCH:-master}")
else
if [[ ! -z "$ABE_BRANCH" ]]; then
echo "--abe-branch and --abe-path cannot be used together" >&1
exit 1
fi
fi
if ! $ONLY_CHECK_REFERENCE; then
echo ======= MANIFEST TEST PHASE 1
mkdir -p build
pushd build
echo "======= CONFIGURE ABE (PHASE 1)"
$ABE_PATH/configure ${GIT_REF_OPT:+"$GIT_REF_OPT"} ${ABE_CONF_FLAGS:+$ABE_CONF_FLAGS}
echo "======= BUILD TOOLCHAIN (PHASE 1)"
wrap_abe 1 $TOP/test-mani-build1.txt \
$ABE_PATH/abe.sh --snapshots $SNAPSHOTS \
--list-artifacts "artifacts1.txt" \
--target "$BUILD_TARGET" \
--build all \
${ABE_FLAGS:+$ABE_FLAGS} \
--tarbin
popd
echo "======= TOOLCHAIN BUILD COMPLETE (PHASE 1)"
echo "======= FINDING GIT REVISIONS (PHASE 1)"
extract_revisions $TOP/test-mani-build1.txt > $TOP/revisions1.txt
echo "======= ADDING EXTRA REVISIONS (PHASE 1)"
add_extra_revisions $TOP/test-mani-build1.txt
echo "======= VALIDATING ARTIFACTS (PHASE 1)"
check_artifacts 1 $TOP/build/artifacts1.txt
echo "======= FINDING MANIFEST FROM PHASE 1"
mkdir -p test
pushd test
TARBALL="$(read_var $TOP/build/artifacts1.txt toolchain)"
tar axf "$TARBALL"
MANIFEST="$(read_var $TOP/build/artifacts1.txt manifest)"
cp "$MANIFEST" "$TOP/orig-manifest1.txt"
popd
echo "======= FOUND MANIFEST AT $MANIFEST (PHASE 1)"
echo "======= RENAMING BUILD DIRECTORY"
mv build build.orig
echo "======= VALIDATING MANIFEST FORMAT (PHASE 1)"
if $ABE_TESTS_PATH/validate-manifest.pl "$TOP/orig-manifest1.txt" &> "$TOP/validate1.txt"; then
result_pass phase 1 manifest validated successfully.
else
result_fail "$TOP/validate1.txt" phase 1 manifest did not validate.
fi
echo "======= CREATING STRIPPED MANIFEST (PHASE 1)"
strip_unused_content_from_manifest "$TOP/orig-manifest1.txt" "$TOP/stripped-manifest1.txt"
echo "======= MANIFEST TEST PHASE 2"
mkdir -p build2
pushd build2
echo "======= CONFIGURE ABE (PHASE 2)"
$ABE_PATH/configure ${GIT_REF_OPT:+"$GIT_REF_OPT"} ${ABE_CONF_FLAGS:+$ABE_CONF_FLAGS}
echo "======= BUILD TOOLCHAIN (PHASE 2)"
wrap_abe 2 $TOP/test-mani-build2.txt \
$ABE_PATH/abe.sh --disable update --snapshots $SNAPSHOTS \
--list-artifacts "artifacts2.txt" \
--manifest "$TOP/stripped-manifest1.txt" \
--build all --tarbin
popd
echo "======= TOOLCHAIN BUILD COMPLETE (PHASE 2)"
echo "======= FINDING GIT REVISIONS (PHASE 2)"
extract_revisions $TOP/test-mani-build2.txt > $TOP/revisions2.txt
echo "======= COMPARING GIT REVISIONS"
compare_revisions revisions1.txt revisions2.txt "$TOP/revisions_diff.txt" "between phase 1 and phase 2 builds"
echo "======= ANALYSING BUILD COMMANDS"
extract_run test-mani-build1.txt build >$TOP/run_lines_1.txt
extract_run test-mani-build2.txt build2 >$TOP/run_lines_2.txt
compare_run_lines $TOP/run_lines_1.txt $TOP/run_lines_2.txt $TOP/run_lines_diff.txt
echo "======= VALIDATING ARTIFACTS (PHASE 2)"
check_artifacts 2 $TOP/build2/artifacts2.txt
echo "======= FINDING MANIFESTS FROM PHASE 2"
mkdir -p test2
pushd test2
TARBALL2="$(read_var $TOP/build2/artifacts2.txt toolchain)"
tar axf "$TARBALL2"
MANIFEST2="$(read_var $TOP/build2/artifacts2.txt manifest)"
cp "$MANIFEST2" "$TOP/orig-manifest2.txt"
echo "======= VALIDATING MANIFEST FORMAT (PHASE 2)"
if $ABE_TESTS_PATH/validate-manifest.pl "$TOP/orig-manifest2.txt" &> "$TOP/validate2.txt"; then
result_pass phase 2 manifest validated successfully.
else
result_fail "$TOP/validate2.txt" phase 2 manifest did not validate.
fi
echo "======= CREATING STRIPPED MANIFEST (PHASE 2)"
strip_unused_content_from_manifest "$TOP/orig-manifest2.txt" "$TOP/stripped-manifest2.txt"
echo "======= CHECKING MANIFESTS"
scan_manifest_for_build_dir "$TOP/stripped-manifest1.txt" "$TOP/build" 1
scan_manifest_for_build_dir "$TOP/stripped-manifest2.txt" "$TOP/build" 2
scan_manifest_for_build_dir "$TOP/stripped-manifest2.txt" "$TOP/build2" 2
(
set +e
diff -u "$TOP/stripped-manifest1.txt" "$TOP/stripped-manifest2.txt" > $TOP/strict_mani_diff.txt
if [ $? -eq 0 ]; then
result_pass strict manifest diff.
else
result_fail $TOP/strict_mani_diff.txt strict manifest diff.
fi
diff -u <(sort "$TOP/stripped-manifest1.txt") <(sort "$TOP/stripped-manifest2.txt") > $TOP/relaxed_mani_diff.txt
if [ $? -eq 0 ]; then
result_pass relaxed manifest diff.
else
result_fail $TOP/relaxed_mani_diff.txt relaxed manifest diff.
fi
diff -u <(sort -u "$TOP/stripped-manifest1.txt") <(sort -u "$TOP/stripped-manifest2.txt") > $TOP/super_relaxed_mani_diff.txt
if [ $? -eq 0 ]; then
result_pass super relaxed manifest diff.
else
result_fail $TOP/super_relaxed_mani_diff.txt super relaxed manifest diff.
fi
)
echo "======= CHECKING REVISIONS IN MANIFEST FILES"
check_revisions_in_manifest 1 \
"$TOP/revisions1.txt" \
"$TOP/stripped-manifest1.txt" \
"$TOP/revisions-report1.txt"
check_revisions_in_manifest 2 \
"$TOP/revisions2.txt" \
"$TOP/stripped-manifest2.txt" \
"$TOP/revisions-report2.txt"
echo "======= CHECKING BUILD LOGS"
check_log 1 '^ERROR ' $TOP/test-mani-build1.txt $TOP/error_list_1.txt 'found Abe ERRORs' 'no errors reported in build'
check_log 2 '^ERROR ' $TOP/test-mani-build2.txt $TOP/error_list_2.txt 'found Abe ERRORs' 'no errors reported in build'
check_log 1 '\.sh: line [0-9]\+' $TOP/test-mani-build1.txt $TOP/shell_error_1.txt 'found shell errors' 'no shell errors found'
check_log 2 '\.sh: line [0-9]\+' $TOP/test-mani-build2.txt $TOP/shell_error_2.txt 'found shell errors' 'no shell errors found'
echo "======= CHECKING FILE LISTS"
(cd $TOP/test; find . | sort > $TOP/files_1.txt)
(cd $TOP/test2; find . | sort > $TOP/files_2.txt)
(
set +e
diff -u <(sed -e "s/$TODAY/<date>/g; s/$TOMORROW/<date>/g" $TOP/files_1.txt) <(sed -e "s/$TODAY/<date>/g; s/$TOMORROW/<date>/g" $TOP/files_2.txt) > $TOP/files_diff.txt
if [ $? -eq 0 ]; then
result_pass files list diff.
else
result_fail $TOP/files_diff.txt files list diff.
fi
)
check_wrap_fails 1
check_wrap_fails 2
fi
echo "======= TESTING ARCHIVED MANIFESTS"
ARCHIVE_TOP="$ABE_TESTS_PATH/test-data/ref-1.1/"
mkdir -p build.archive1
pushd build.archive1
echo "======= CONFIGURE ABE (ARCHIVE 1)"
$ABE_PATH/configure ${GIT_REF_OPT:+"$GIT_REF_OPT"} ${ABE_CONF_FLAGS:+$ABE_CONF_FLAGS}
echo "======= BUILD TOOLCHAIN (ARCHIVE 1)"
wrap_abe archive1 $TOP/test-mani-checkout-archive1.txt \
$ABE_PATH/abe.sh --snapshots $SNAPSHOTS \
--list-artifacts "artifacts-checkout-archive1.txt" \
--manifest "$ARCHIVE_TOP/orig-manifest1.txt" \
--checkout all
wrap_abe archive1 $TOP/test-mani-build-archive1.txt \
$ABE_PATH/abe.sh --disable update --snapshots $SNAPSHOTS \
--list-artifacts "artifacts-build-archive1.txt" \
--manifest "$ARCHIVE_TOP/orig-manifest1.txt" \
--build all --tarbin --dryrun
popd
echo "======= ANALYSING BUILD COMMANDS"
# only look at configure lines for now
extract_run $TOP/test-mani-build-archive1.txt build.archive1 |sed -e 's/^DRYRUN:/RUN:/' | xgrep configure >$TOP/run_lines_archive1.txt
xgrep configure "$ARCHIVE_TOP/run_lines_1.txt" > $TOP/run_lines_ref_archive1.txt
# too many paths in here, disabled for now
#compare_run_lines $TOP/run_lines_ref_archive1.txt $TOP/run_lines_archive1.txt $TOP/run_lines_diff-archive1.txt
extract_revisions $TOP/test-mani-build-archive1.txt > $TOP/revisions-archive1.txt
compare_revisions "$ARCHIVE_TOP/revisions1.txt" $TOP/revisions-archive1.txt "$TOP/revisions_diff-archive1.txt" "in archive1 build."
#check_revisions_in_manifest archive1 \
# "$TOP/revisions-archive1.txt" \
# "$ARCHIVE_TOP/orig-manifest1.txt" \
# "$TOP/revisions-report-archive1.txt"
# from here, we don't need debug, and it just messes up the output anyway
set +x
echo "======= TESTS COMPLETE"
echo
echo " ==============================="
echo " ======= RESULTS SUMMARY ======="
echo " ==============================="
echo
num_fails="`xgrep -c ^FAILED $TOP/results_summary.txt`"
num_tests="`xgrep -c ^ $TOP/results_summary.txt`"
echo
echo "Summary of results in $TOP/results_summary.txt"
echo "Full report in in $TOP/results_report.txt"
echo
if $DISPLAY_SUMMARY; then
echo "Summary follows:"
cat "$TOP/results_summary.txt"
fi
if $DISPLAY_REPORT; then
echo "Report follows:"
cat "$TOP/results_report.txt"
fi
REACHED_THE_END=1
echo
if [[ $num_fails -gt 0 ]]; then
echo "Failed $num_fails/$num_tests tests."
exit 1
else
echo "Passed $num_tests tests."
exit 0
fi
|