aboutsummaryrefslogtreecommitdiff
path: root/testsuite/test.sh
blob: a1700288562157c350d54f474cd3fd5107a88ea7 (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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
#!/bin/bash

# common.sh loads all the files of library functions.
if test x"`echo \`dirname "$0"\` | sed 's:^\./::'`" != x"testsuite"; then
    echo "WARNING: Should be run from top abe dir" > /dev/stderr
    topdir="`readlink -e \`dirname $0\`/..`"
else
    topdir=$PWD
fi

test_sources_conf="${topdir}/testsuite/test_sources.conf"
# configure generates host.conf from host.conf.in.
if test -e "${PWD}/host.conf"; then
    . "${PWD}/host.conf"
    . "${topdir}/lib/common.sh" || exit 1
else
    build="`sh ${topdir}/config.guess`"
    . "${topdir}/lib/common.sh" || exit 1
    warning "no host.conf file!  Synthesizing a framework for testing."

    remote_snapshots="${remote_snapshots:-/snapshots-ref}"
    wget_bin=/usr/bin/wget
    NEWWORKDIR=/usr/local/bin/git-new-workdir
    sources_conf=${topdir}/testsuite/test_sources.conf
fi
echo "Testsuite using ${sources_conf}"

# Use wget -q in the testsuite
wget_quiet=yes

# We always override $local_snapshots so that we don't damage or move the
# local_snapshots directory of an existing build.
local_abe_tmp="`mktemp -d /tmp/abe.$$.XXX`"
local_snapshots="${local_abe_tmp}/snapshots"

# If this isn't being run in an existing build dir, create one in our
# temp directory.
if test ! -d "${local_builds}"; then
    local_builds="${local_abe_tmp}/builds"
    out="`mkdir -p ${local_builds}`"
    if test "$?" -gt 1; then
	error "Couldn't create local_builds dir ${local_builds}"
	exit 1
    fi
fi

# Let's make sure that the snapshots portion of the directory is created before
# we use it just to be safe.
out="`mkdir -p ${local_snapshots}`"
if test "$?" -gt 1; then
    error "Couldn't create local_snapshots dir ${local_snapshots}"
    exit 1
fi

# Let's make sure that the build portion of the directory is created before
# we use it just to be safe.
out="`mkdir -p ${local_snapshots}`"


# Since we're testing, we don't load the host.conf file, instead
# we create false values that stay consistent.
abe_top=/build/abe/test
hostname=test.foobar.org
target=x86_64-linux-gnu

if test x"$1" = x"-v"; then
    debug=yes
fi

fixme()
{
    if test x"${debug}" = x"yes"; then
	echo "($BASH_LINENO): $*" 1>&2
    fi
}

passes=0
pass()
{
    echo "PASS: $1"
    passes="`expr ${passes} + 1`"
}

xpasses=0
xpass()
{
    echo "XPASS: $1"
    xpasses="`expr ${xpasses} + 1`"
}

untested=0
untested()
{
    echo "UNTESTED: $1"
    untested="`expr ${untested} + 1`"
}

failures=0
fail()
{
    echo "FAIL: $1"
    failures="`expr ${failures} + 1`"
}

xfailures=0
xfail()
{
    echo "XFAIL: $1"
    xfailures="`expr ${xfailures} + 1`"
}

totals()
{
    echo ""
    echo "Total test results:"
    echo "	Passes: ${passes}"
    echo "	Failures: ${failures}"
    if test ${xpasses} -gt 0; then
	echo "	Unexpected Passes: ${xpasses}"
    fi
    if test ${xfailures} -gt 0; then
	echo "	Expected Failures: ${xfailures}"
    fi
    if test ${untested} -gt 0; then
	echo "	Untested: ${untested}"
    fi
}

#
# common.sh tests
#
# Pretty much everything uses the git parser so test it first.
. "${topdir}/testsuite/git-parser-tests.sh"
. "${topdir}/testsuite/stamp-tests.sh"
#. "${topdir}/testsuite/normalize-tests.sh"
. "${topdir}/testsuite/dryrun-tests.sh"
#. "${topdir}/testsuite/report-tests.sh"

# ----------------------------------------------------------------------------------

echo "=========== is_package_in_runtests() tests ============="


# test the package at the beginning of the list
in_runtests="glibc gdb gcc binutils"
testing="is_package_in_runtests \"${in_runtests}\" glibc"
in_package="glibc"
out="`is_package_in_runtests "${in_runtests}" ${in_package}`"
ret=$?
if test ${ret} -eq 0; then
    pass "${testing}"
else
    fail "${testing}"
    fixme "is_package_in_runtests \"${in_runtests}\" ${in_package} resulted in '${ret}'"
fi

# test the package at the end of the list
in_runtests="glibc gdb gcc binutils"
testing="is_package_in_runtests \"${in_runtests}\" binutils"
in_package="binutils"
out="`is_package_in_runtests "${in_runtests}" ${in_package}`"
ret=$?
if test ${ret} -eq 0; then
    pass "${testing}"
else
    fail "${testing}"
    fixme "is_package_in_runtests \"${in_runtests}\" ${in_package} resulted in '${ret}'"
fi

# test the package in the middle of the list
in_runtests="glibc gdb gcc binutils"
testing="is_package_in_runtests \"${in_runtests}\" gdb"
in_package="gdb"
out="`is_package_in_runtests "${in_runtests}" ${in_package}`"
ret=$?
if test ${ret} -eq 0; then
    pass "${testing}"
else
    fail "${testing}"
    fixme "is_package_in_runtests \"${in_runtests}\" ${in_package} resulted in '${ret}'"
fi

# test a package not in the list
in_runtests="glibc gdb gcc binutils"
testing="is_package_in_runtests \"${in_runtests}\" foo"
in_package="foo"
out="`is_package_in_runtests "${in_runtests}" ${in_package}`"
ret=$?
if test ${ret} -eq 1; then
    pass "${testing}"
else
    fail "${testing}"
    fixme "is_package_in_runtests \"${in_runtests}\" ${in_package} resulted in '${ret}' expected '1'"
fi

# test a partial package name
in_runtests="glibc gdb gcc binutils"
testing="is_package_in_runtests \"${in_runtests}\" gd"
in_package="gd"
out="`is_package_in_runtests "${in_runtests}" ${in_package}`"
ret=$?
if test ${ret} -eq 1; then
    pass "${testing}"
else
    fail "${testing}"
    fixme "is_package_in_runtests \"${in_runtests}\" ${in_package} resulted in '${ret}' expected '1'"
fi

# test that unquoted $runtests fails
in_runtests="glibc gdb gcc binutils"
testing="is_package_in_runtests ${in_runtests} glibc (unquoted \${in_runtests})"
in_package="glibc"
out="`is_package_in_runtests ${in_runtests} ${in_package}`"
ret=$?
if test ${ret} -eq 1; then
    pass "${testing}"
else
    fail "${testing}"
    fixme "is_package_in_runtests ${in_runtests} ${in_package} resulted in '${ret}'"
fi

# ----------------------------------------------------------------------------------
echo "============= fetch_http() tests ================"

collect_data gmp

# Download the first time without force.
out="`fetch_http gmp 2>/dev/null`"
if test $? -eq 0 -a -e ${local_snapshots}/gmp-6.1.0.tar.xz; then
    pass "fetch_http gmp"
else
    fail "fetch_http gmp"
fi

# Get the timestamp of the file.
gmp_stamp1=`stat -c %X ${local_snapshots}/gmp-6.1.0.tar.xz`

# Download it again
out="`fetch_http gmp 2>/dev/null`"
ret=$?

# Get the timestamp of the file after another fetch.
gmp_stamp2=`stat -c %X ${local_snapshots}/gmp-6.1.0.tar.xz`

# They should be the same timestamp.
if test $ret -eq 0 -a ${gmp_stamp1} -eq ${gmp_stamp2}; then
    pass "fetch_http gmp didn't update as expected (force=no)"
else
    fail "fetch_http gmp updated unexpectedly (force=no)"
fi

# If the two operations happen within the same second then their timestamps will
# be equivalent.  This sleep operation forces the timestamps apart.
sleep 2s

# Now try it with force on
out="`force=yes fetch_http gmp 2>/dev/null`"
if test $? -gt 0; then
    fail "fetch_http gmp with \${force}=yes when source exists"
else
    pass "fetch_http gmp with \${force}=yes when source exists"
fi

# Get the timestamp of the file after another fetch.
gmp_stamp3=`stat -c %X ${local_snapshots}/gmp-6.1.0.tar.xz`

if test ${gmp_stamp1} -eq ${gmp_stamp3}; then
    fail "fetch_http gmp with \${force}=yes has unexpected matching timestamps"
else
    pass "fetch_http gmp with \${force}=yes has unmatching timestamps as expected."
fi

# Make sure force doesn't get in the way of a clean download.
rm ${local_snapshots}/gmp-6.1.0.tar.xz

# force should override supdate and this should download for the first time.
out="`force=yes fetch_http gmp 2>/dev/null`"
if test $? -gt 0; then
    fail "fetch_http gmp with \${force}=yes and sources don't exist"
else
    pass "fetch_http gmp with \${force}=yes and sources don't exist"
fi

# Test the case where wget_bin isn't set.
rm ${local_snapshots}/gmp-6.1.0.tar.xz

out="`unset wget_bin; fetch_http gmp 2>/dev/null`"
if test $? -gt 0; then
    pass "unset wget_bin; fetch_http gmp should fail."
else
    fail "unset wget_bin; fetch_http gmp should fail."
fi

# Verify that '1' is returned when a non-existent file is requested.
out="`fetch_http no_such_file 2>/dev/null`"
if test $? -gt 0; then
    pass "fetch_http no_such_file (implicit \${supdate}=yes) should fail."
else
    fail "fetch_http no_such_file (implicit \${supdate}=yes) should fail."
fi

echo "============= fetch() tests ================"

# Fetch with no file name should error.
out="`fetch 2>/dev/null`"
if test $? -gt 0; then
    pass "fetch <with no filename should error>"
else
    fail "fetch <with no filename should error>"
fi

# Create a git_reference_dir
local_refdir="${local_snapshots}/../refdir"
mkdir -p ${local_refdir}
# We need a way to differentiate the refdir version.
cp ${local_snapshots}/gmp-* ${local_refdir}/
rm -f ${local_snapshots}/gmp-* &>/dev/null

rm -f ${local_snapshots}/gmp-* &>/dev/null
# Use fetch that goes to a reference dir using a longname
out="`git_reference_dir=${local_refdir} fetch gmp &>/dev/null`"
if test $? -gt 0 -o ! -e "${local_snapshots}/gmp-6.1.0.tar.xz"; then
    fail "fetch gmp (with full name) from reference dir failed unexpectedly."
else
    pass "fetch gmp (with full name) from reference dir passed as expected."
fi

rm -f ${local_snapshots}/gmp-* &>/dev/null

# Replace with a marked version so we can tell if it's copied the reference
# versions erroneously.
rm -f ${local_refdir}/gmp-6.1.0.tar.xz
echo "DEADBEEF" > ${local_refdir}/gmp-6.1.0.tar.xz

# Use fetch that finds a git reference dir but is forced to use the server.
out="`force=yes git_reference_dir=${local_refdir} fetch gmp 2>/dev/null`"
if test $? -gt 0; then
    fail "fetch gmp (with full name) from reference dir failed unexpectedly."
elif test x"$(grep DEADBEEF ${local_snapshots}/gmp-6.1.0.tar.xz)" != x""; then
    fail "fetch gmp pulled from reference dir instead of server."
else
    pass "fetch gmp (with full name) from reference dir passed as expected."
fi

# Make sure supdate=no where source doesn't exist fails
rm ${local_snapshots}/gmp-6.1.0.tar.xz
rm ${local_refdir}/gmp-6.1.0.tar.xz
out="`supdate=no fetch gmp 2>/dev/null`"
if test $? -gt 0; then
    pass "fetch gmp --supdate=no failed as expected when there's no source downloaded."
else
    fail "fetch gmp --supdate=no passed unexpectedly when there's no source downloaded."
fi

# Make sure supdate=no --force=yes where source doesn't exist passes by forcing
# a download
rm ${local_snapshots}/gmp-6.1.0.tar.xz &>/dev/null
rm ${local_refdir}/gmp-6.1.0.tar.xz &>/dev/null
out="`force=yes supdate=no fetch gmp 2>/dev/null`"
if test $? -eq 0 -a -e "${local_snapshots}/gmp-6.1.0.tar.xz"; then
    pass "fetch gmp --supdate=no --force=yes passed as expected when there's no source downloaded."
else
    fail "fetch gmp --supdate=no --force=yes failed unexpectedly when there's no source downloaded."
fi

# Make sure supdate=no where source does exist passes
out="`supdate=no fetch gmp 2>/dev/null`"
if test $? -eq 0 -a -e "${local_snapshots}/gmp-6.1.0.tar.xz"; then
    pass "fetch gmp --supdate=no --force=yes passed as expected because the source already exists."
else
    fail "fetch gmp --supdate=no --force=yes failed unexpectedly when the source exists."
fi

cp ${local_snapshots}/gmp-6.1.0.tar.xz ${local_refdir}/ &>/dev/null

# Download a clean/new copy for the check_md5sum tests
rm ${local_snapshots}/gmp-6.1.0.tar.xz* &>/dev/null
fetch_http gmp 2>/dev/null

out="`check_md5sum 'gmp' 2>/dev/null`"
if test $? -gt 0; then
    fail "check_md5sum failed for 'gmp"
else
    pass "check_md5sum passed for 'gmp"
fi

# Test with a non-infrastructure file
out="`check_md5sum 'foo' 2>/dev/null`"
if test $? -gt 0; then
    pass "check_md5sum failed as expected for 'foo"
else
    fail "check_md5sum passed as expected for 'foo"
fi

mv ${local_snapshots}/gmp-6.1.0.tar.xz ${local_snapshots}/gmp-6.1.0.tar.xz.back
echo "empty file" > ${local_snapshots}/gmp-6.1.0.tar.xz

# Test an expected failure case.
out="`check_md5sum 'gmp' 2>/dev/null`"
if test $? -gt 0; then
    pass "check_md5sum failed as expected for nonmatching 'gmp file"
else
    fail "check_md5sum passed unexpectedly for nonmatching 'gmp file"
fi

mv ${local_snapshots}/gmp-6.1.0.tar.xz.back ${local_snapshots}/gmp-6.1.0.tar.xz

echo "============= extract() tests ================"

# use correct md5sum
set_component_md5sum gmp a9868ef2556ad6a2909babcd1428f3c7

if extract gmp 2>/dev/null; then
    pass "extract passed with valid md5sum"
else
    fail "extract failed with valid md5sum"
fi

# use incorrect md5sum
set_component_md5sum gmp aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

if extract gmp 2>/dev/null; then
    fail "extract succeeded, but should have failed due to incorrect md5sum"
else
    pass "extract failed as expected due to incorrect md5sum"
fi

# unset md5sum so that the remainder of the testsuite is unaffected
set_component_md5sum gmp ""

# ----------------------------------------------------------------------------------
#
# Test package building

# dryrun=yes
# #gcc_version=linaro-4.8-2013.09
# gcc_version=git://git.linaro.org/toolchain/gcc.git/fsf-gcc-4_8-branch

# out="`binary_toolchain 2>&1 | tee xx |grep "DRYRUN:.*Jcvf"`"

# ----------------------------------------------------------------------------------

echo "========= create_release_tag() tests ============"

mkdir -p ${local_abe_tmp}/builds/gcc
echo "5.1.1" > ${local_abe_tmp}/builds/gcc/BASE-VER
component_init gcc BRANCH="aa" REVISION="a1b2c3d4e5f6" SRCDIR="${local_abe_tmp}/builds"

testing="create_release_tag: GCC repository without release string set"
date="`date +%Y%m%d`"
out="`create_release_tag gcc | grep -v TRACE`"
toolname="`echo ${out} | cut -d '~' -f 1`"
branch="`echo ${out} | cut -d '~' -f 2 | cut -d '@' -f 1`"
revision="`echo ${out} | cut -d '@' -f 2`"
if test x"${out}" = x"gcc-linaro-5.1.1~aa@a1b2c3d4-${date}"; then
    pass "${testing}"
else
    fail "${testing}"
    fixme "create_release_tag returned ${out}"
fi

echo "#define RELEASE \"development\""  > ${local_abe_tmp}/builds/version.h
echo "#define VERSION \"2.22.90\"" >> ${local_abe_tmp}/builds/version.h
component_init glibc BRANCH="aa/bb/cc" REVISION="1a2b3c4d5e6f" SRCDIR="${local_abe_tmp}/builds"

testing="create_release_tag: GLIBC repository without release string set"
date="`date +%Y%m%d`"
out="`create_release_tag glibc | grep -v TRACE`"
toolname="`echo ${out} | cut -d '~' -f 1`"
branch="`echo ${out} | cut -d '~' -f 2 | cut -d '@' -f 1`"
revision="`echo ${out} | cut -d '@' -f 2`"
if test x"${out}" = x"glibc-linaro-2.22.90~aa-bb-cc@1a2b3c4d-${date}"; then
    pass "${testing}"
else
    fail "${testing}"
    fixme "create_release_tag returned ${out}"
fi

mkdir -p ${local_abe_tmp}/builds
release=foobar
testing="create_release_tag: GCC repository with release string set"
out="`create_release_tag gcc | grep -v TRACE`"
if test x"${out}" = x"gcc-linaro-5.1.1-${release}"; then
    pass "${testing}"
else
    fail "${testing}"
    fixme "create_release_tag returned ${out}"
fi

# rm ${local_abe_tmp}/builds/BASE-VER

export release="2015.08-rc1"
testing="create_release_tag: release candidate tarball with release"
in="gcc-linaro-5.1.1-2015.08-rc1.tar.xz"
out="`create_release_tag ${in} | grep -v TRACE`"
toolname="`echo ${out} | cut -d ' ' -f 1`"
branch="`echo ${out} | cut -d ' ' -f 2`"
revision="`echo ${out} | cut -d ' ' -f 3`"
if test x"${out}" = x"gcc-linaro-5.1.1-2015.08-rc1"; then
    pass "${testing}"
else
    fail "${testing}"
    fixme "create_release_tag returned ${out}"
fi

export release="2015.08-2-rc1"
testing="create_release_tag: release candidate tarball with release"
in="gcc-linaro-5.1.1-2015.08-2-rc1.tar.xz"
out="`create_release_tag ${in} | grep -v TRACE`"
toolname="`echo ${out} | cut -d ' ' -f 1`"
branch="`echo ${out} | cut -d ' ' -f 2`"
revision="`echo ${out} | cut -d ' ' -f 3`"
if test x"${out}" = x"gcc-linaro-5.1.1-2015.08-2-rc1"; then
    pass "${testing}"
else
    fail "${testing}"
    fixme "create_release_tag returned ${out}"
fi

# ----------------------------------------------------------------------------------
echo "============= checkout () tests ================"
echo "  Checking out sources into ${local_snapshots}"
echo "  Please be patient while sources are checked out...."
echo "================================================"

# These can be painfully slow so test small repos.

component_init abe TOOL=abe URL=http://git.linaro.org/toolchain FILESPEC=abe.git SRCDIR=${local_snapshots}/abe.git BRANCH=master

# confirm that checkout works with raw URLs
rm -rf "${local_snapshots}"/*.git*
testing="http://abe.git@git.linaro.org/git/toolchain/abe.git"
in="abe"
if test x"${debug}" = xyes; then
  out="`cd ${local_snapshots} && checkout ${in}`"
else
  out="`cd ${local_snapshots} && checkout ${in} 2>/dev/null`"
fi
if test $? -eq 0; then
  pass "${testing}"
else
  fail "${testing}"
fi

# confirm that checkout fails approriately with a range of bad services in raw URLs
for service in "foomatic://" "http:" "http:/fake.git" "http/" "http//" ""; do
  rm -rf "${local_snapshots}"/*.git*
  url="${service}abe.git@git.linaro.org/git/toolchain"
  set_component_url abe ${url}
  in="abe"
  testing="checkout: ${in} should fail with 'proper URL required' message for ${service}."
  if test x"${debug}" = xyes; then
    out="`cd ${local_snapshots} && checkout ${in} 2> >(tee /dev/stderr)`"
  else
    out="`cd ${local_snapshots} && checkout ${in} 2>&1`"
  fi
  if test $? -eq 0; then
    fail "${testing}"
  else
    if echo "${out}" | grep -q "^ERROR.*: checkout (proper URL required)"; then
      pass "${testing}"
    else
      fail "${testing}"
    fi
  fi
done

# only find one suitable input
rm -rf "${local_snapshots}"/*.git*
set_component_url abe "http://"
in="abe"
testing="checkout: ${in} should fail with 'Malformed input' message."
if test x"${debug}" = xyes; then
  out="`cd ${local_snapshots} && checkout ${in} 2> >(tee /dev/stderr)`"
else
  out="`cd ${local_snapshots} && checkout ${in} 2>&1`"
fi
if test $? -eq 0; then
  fail "${testing}"
else
  if echo "${out}" | grep -q "^ERROR.*: checkout (proper URL required)"; then
    pass "${testing}"
  else
    fail "${testing}"
  fi
fi

# Reset the URL
set_component_url abe "http://git.linaro.org/toolchain"

test_checkout ()
{
    local should="$1"
    local testing="$2"
    local package="$3"
    local branch="$4"
    local revision="$5"
    local ret=
    local out=
    
    # Make sure there's no hanging state relating to this test before it runs
    rm -rf ${local_snapshots}/${package}*

    set_component_branch ${package} ${branch}
    set_component_revision ${package} ${revision}
    set_component_srcdir abe ${local_snapshots}/abe.git~${branch}

    if test x"${revision}" != x; then
    set_component_srcdir abe ${local_snapshots}/abe.git_rev_${revision}
    fi

    if test x"${debug}" = x"yes"; then
	out="`(cd ${local_snapshots} && checkout ${package})`"
	ret=$?
	if test ${ret} -eq 0 -a x"${should}" = x"pass"; then
	    pass "function ${testing}"
	fi
	if test ${ret} -eq 0 -a x"${should}" = x"fail"; then
	    fail "function ${testing}"
	fi
	if test ${ret} -eq 1 -a x"${should}" = x"pass"; then
	    fail "function ${testing}"
	fi
	if test ${ret} -eq 1 -a x"${should}" = x"fail"; then
	    pass "function ${testing}"
	fi
    else
	out="`(cd ${local_snapshots} && checkout ${package})`"
	local ret=$?
	if test ${ret} -eq 0 -a x"${should}" = x"pass"; then
	    pass "function ${testing}"
	fi
	if test ${ret} -eq 0 -a x"${should}" = x"fail"; then
	    fail "function ${testing}"
	fi
	if test ${ret} -eq 1 -a x"${should}" = x"pass"; then
	    fail "function ${testing}"
	fi
	if test ${ret} -eq 1 -a x"${should}" = x"fail"; then
	    pass "function ${testing}"
	fi
    fi

    set_component_branch ${package} ""
    set_component_revision ${package} ""

    local srcdir="`get_component_srcdir ${package}`"
    local branch_test=0
    if test -d ${srcdir}; then
	if test x"${branch}" = x -a x"${revision}" = x; then
            branch_test=`(cd ${srcdir} && git branch -a | egrep -c "^\* (local_HEAD|master)$")`
	elif test x"${revision}" = x; then
            branch_test=`(cd ${srcdir} && git branch -a | grep -c "^\* ${branch}$")`
	else
            branch_test=`(cd ${srcdir} && git branch -a | grep -c "^\* local_${revision}$")`
	fi
    else
	untested "${testing}"
	return 1
    fi

    # Make sure we leave no hanging state
    rm -rf "${local_snapshots}/${package}"*
    case ${should} in
	*pass)
	    if test "${branch_test}" -gt 0; then
		pass "${testing}"
		return 0
	    fi
	    fail "${testing}"
	    return 1
	    ;;
	*fail)
	    if test "${branch_test}" -eq 0; then
		pass "${testing}"
		return 0
	    fi
	    fail "${testing}"
	    return 1
	    ;;
	*)
	    fail "${testing}"
	    return 1
	    ;;
    esac
}

testing="checkout: http://git@<url>/<repo>.git"
package="abe"
branch=''
revision=''
should="pass"
test_checkout "${should}" "${testing}" "${package}" "${branch}" "${revision}"

testing="checkout: http://git@<url>/<repo>.git/<branch>"
package="abe"
branch="stable"
revision=''
should="pass"
test_checkout "${should}" "${testing}" "${package}" "${branch}" "${revision}"

testing="checkout: http://git@<url>/<repo>.git@<revision>"
package="abe"
branch='master'
revision="9bcced554dfc"
should="pass"
test_checkout "${should}" "${testing}" "${package}" "${branch}" "${revision}"

testing="checkout: http://git@<url>/<repo>.git/unusedbranchname@<revision>"
package="abe.git"
branch="unusedbranchname"
revision="9bcced554dfc"
should="pass"
test_checkout "${should}" "${testing}" "${package}" "${branch}" "${revision}"

# This should fail because it's an unknown repository
component_init foo TOOL=foo

testing="checkout: git://testingrepository/foo should fail with 'clone failed' message."
package="foo.git"
branch=''
revision=''
should="fail"
test_checkout "${should}" "${testing}" "${package}" "${branch}" "${revision}"

# This should fail because an unknown branch is specified
testing="checkout: http://git@<url>/<repo>.git/<nonexistentbranch> should fail with 'branch does not exist' message."
package="abe.git"
branch="nonexistentbranch"
revision=''
should="fail"
test_checkout "${should}" "${testing}" "${package}" "${branch}" "${revision}"

# This should fail because an unknown revision is specified
testing="checkout: http://git@<url>/<repo>.git@<nonexistentrevision> should fail with 'revision does not exist' message."
package="abe.git"
branch=''
revision="123456bogusbranch"
should="fail"
test_checkout "${should}" "${testing}" "${package}" "${branch}" "${revision}"

testing="checkout: http://git@<url>/<repo>.git~<branch> should pass with appropriate notice"
package="abe.git"
branch='staging'
revision=""
should="pass"
test_checkout "${should}" "${testing}" "${package}" "${branch}" "${revision}"

rm -rf "${local_snapshots}"/*.git*

echo "============= misc tests ================"
testing="pipefail"
out="`false | tee /dev/null`"
if test $? -ne 0; then
    pass "${testing}"
else
    fail "${testing}"
fi

# Do not pollute env
testing="source_config"
depends="`depends= && source_config isl && echo ${depends}`"
static_link="`static_link= && source_config isl && echo ${static_link}`"
default_configure_flags="`default_configure_flags= && source_config isl && echo ${default_configure_flags}`"
if test x"${depends}" != xgmp; then
  fail "${testing}"
elif test x"${static_link}" != xyes; then
  fail "${testing}"
elif test x"${default_configure_flags}" != x"--with-gmp-prefix=${PWD}/${hostname}/${build}/depends"; then
  fail "${testing}"
else
  pass "${testing}"
fi
depends=
default_configure_flags=
static_link=

testing="postfix make args (make_install)"
cmp_makeflags="`echo ${cmp_makeflags} | sed -e 's:\ball-:install-:g'`"
if test x"${cmp_makeflags}" = x; then
  untested "${testing}" #implies that the config for this tool no longer contains default_makeflags
else
  out="`. ${topdir}/config/${tool}.conf && make_install ${tool}.git 2>&1`"
  if test x"${debug}" = x"yes"; then
    echo "${out}"
  fi
  echo "${out}" | grep -- "${cmp_makeflags}" > /dev/null 2>&1
  if test $? -eq 0; then
    pass "${testing}"
  else
    fail "${testing}"
  fi
fi
cmp_makeflags=

component_init dejagnu TOOL=dejagnu BRANCH=linaro SRCDIR=${local_snapshots}/dejagnu.git~linaro BUILDDIR=${local_builds}/dejagnu.git~linaro FILESPEC=dejagnu.git URL=http://git.linaro.org/git/toolchain

checkout dejagnu
if test $? -eq 0; then
    pass "Checking out Dejagnu for configure test"
else
    fail "Checking out Dejagnu for configure test"
fi

testing="configure"
tool="dejagnu"
configure="`grep ^configure= ${topdir}/config/${tool}.conf | cut -d '\"' -f 2`"
if test x"${configure}" = xno; then
    untested "${testing}"
else
    out=`configure_build ${tool} 2>&1`
    ret=$?
    if test x"${debug}" = x"yes"; then
	echo "${out}"
    fi
    if test -f ${local_builds}/dejagnu.git~linaro/config.log -a ${ret} -eq 0; then
	pass "${testing}"
    else
	fail "${testing}"
    fi
fi

# TODO: Test checkout directly with a non URL.
# TODO: Test checkout with a multi-/ branch

#testing="checkout: http://git@<url>/<repo>.git~multi/part/branch."
#package="glibc.git"
#branch='release/2.18/master'
#revision=""
#should="pass"
#test_checkout "${should}" "${testing}" "${package}" "${branch}" "${revision}"

# ----------------------------------------------------------------------------------
# print the total of test results
totals

# We can't just return ${failures} or it could overflow to 0 (success)
if test ${failures} -gt 0; then
    exit 1
fi
exit 0