aboutsummaryrefslogtreecommitdiff
path: root/test.sh
blob: eb886ee90d64b715f7a258edebe38bd927a056c2 (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
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
#!/bin/bash

# Improve debug logs
PRGNAME=`basename $0`
PS4='+ $PRGNAME: ${FUNCNAME+"$FUNCNAME : "}$LINENO: '

testabe="`basename $0`"
topdir=`dirname $0`
abe_path=`readlink -f ${topdir}`
export abe_path

# Source common.sh for some common utilities.
. ${abe_path}/lib/common.sh || exit 1

# We use a tmp/ directory for the builddir in order that we don't pollute the
# srcdir or an existing builddir.
tmpdir=`mktemp -d /tmp/abe.$$.XXX`
if test "$?" -gt 0; then
    error "mktemp of ${tmpdir} failed."
    exit 1
fi

# Log files for abe test runs are dumped here.
testlogs=${tmpdir}/testlogs
mkdir -p ${testlogs}
if test "$?" -gt 0; then
    error "couldn't create '${testlogs}' directory."
    exit 1
fi

runintmpdir=
# If the current working directory has a host.conf in it we assume it's an
# existing build dir, otherwise we're in the srcdir so we need to run
# configure in the tmpdir and run the tests from there.
if test ! -e "${PWD}/host.conf"; then
    (cd ${tmpdir} && ${abe_path}/configure --with-sources-conf=${abe_path}/testsuite/test_sources.conf --with-remote-snapshots=snapshots-ref)
    # Run it once outside of dryrun mode so that we pull the md5sums file.
    (cd ${tmpdir} && ${abe_path}/abe.sh --space 4096)
    runintmpdir=yes
else
    # copy the md5sums file from the existing snapshots directory to the new local_snapshots directory.

    # Override $local_snapshots so that the local_snapshots directory of an
    # existing build is not moved or damaged.  This affects all called
    # instances of abe.sh below.
    export local_snapshots="${tmpdir}/snapshots"
    out="`mkdir -p ${local_snapshots}`"
    if test "$?" -gt 0; then
        error "couldn't create '${local_snapshots}' directory."
        exit 1
    fi
    # Override the existing sources_conf setting in host.conf.
    export sources_conf=${abe_path}testsuite/test_sources.conf
fi

export wget_quiet=yes

usage()
{
    echo "  ${testabe} [--debug|-v]"
    echo "                 [--md5sums <path/to/alternative/snapshots/md5sums>]"
    echo ""
    echo "  ${testabe} is the abe frontend command conformance test."
    echo ""
    echo " ${testabe} should be run from the source directory."
}

passes=0

pass()
{
    local testlineno=$1
    if test x"${debug}" = x"yes"; then
	echo -n "($testlineno) " 1>&2
    fi
    echo "PASS: '$2'"
    passes="`expr ${passes} + 1`"
}

failures=0
fail()
{
    local testlineno=$1
    if test x"${debug}" = x"yes"; then
	echo -n "($testlineno) " 1>&2
    fi
    echo "FAIL: '$2'"
    failures="`expr ${failures} + 1`"
}

totals()
{
    echo ""
    echo "Total test results:"
    echo "	Passes: ${passes}"
    echo "	Failures: ${failures}"
}



cbtest()
{
    local testlineno=$1
    if test x"${debug}" = x"yes"; then
	echo "($testlineno) out: $2" 1>&2
    fi

    case "$2" in
	*$3*)
	    pass ${testlineno} "$4"
	    ;;
	*)
	    fail ${testlineno} "$4"
	    ;;
    esac

    if test x"${debug}" = x"yes"; then
	echo "-----------" 1>&2
    fi
}

m5sums=
debug=
while test $# -gt 0; do
    case "$1" in
	--h*|-h)
	    usage
	    exit 1
	    ;;
	--deb*|-deb|-v)
	    debug="yes"
	    ;;
	--md5*|-md5*)
	    if test `echo $1 | grep -c "\-md5.*="` -gt 0; then
		error "A '=' is invalid after --md5sums. A space is expected."
		exit 1;
	    fi
	    if test -z $2; then
		error "--md5sums requires a path to an md5sums file."
		exit 1;
	    fi 
	    md5sums=$2
	    if test ! -e "$md5sums"; then
		error "Path to md5sums is invalid."
		exit 1;
	    fi
	    echo "Copying ${md5sums} to ${local_snapshots} for snapshots file."
	    cp ${md5sums} ${local_snapshots}
	    ;; 
	*)
	    ;;
    esac

    if test $# -gt 0; then
	shift
    fi
done

test_failure()
{
    local testlineno=$BASH_LINENO
    local cb_commands=$1
    local match=$2
    local out=

    out="`(${runintmpdir:+cd ${tmpdir}} && ${abe_path}/abe.sh --space 4960 ${cb_commands} 2>&1 | tee ${testlogs}/${testlineno}.log | grep "${match}" | sed -e 's:\(^ERROR\).*\('"${match}"'\).*:\1 \2:')`"
    cbtest ${testlineno} "${out}" "ERROR ${match}" "ERROR ${cb_commands}"
}

test_pass()
{
    local testlineno=$BASH_LINENO
    local cb_commands=$1
    local match=$2
    local out=

    # Continue to search for error so we don't get false positives.
    out="`(${runintmpdir:+cd ${tmpdir}} && ${abe_path}/abe.sh --space 4960 ${cb_commands} 2>&1 | tee ${testlogs}/${testlineno}.log | grep "${match}" | sed -e 's:\(^ERROR\).*\('"${match}"'\).*:\1 \2:')`"
    cbtest ${testlineno} "${out}" "${match}" "VALID ${cb_commands}"
}

test_config_default()
{
  local feature="$1"
  local feature_match="$2"
  local skip_match="$3"
  local perform_match="$4"

  # If we're running in an existing build directory we don't know WHAT the
  # user has set as the default so we set it to 'yes' explicity, and preserve
  # the original.
  indir=${PWD}
  if test x"${runintmpdir}" != x""; then
    indir=${tmpdir}
  fi
  cp ${indir}/host.conf ${indir}/host.conf.orig
  trap "cp ${indir}/host.conf.orig ${indir}/host.conf" EXIT

  sed -i -e "s/^${feature}=.*/${feature}=yes/" "${indir}/host.conf"

  # The default.
  cb_commands="--dump"
  match="${feature_match} *yes"
  test_pass "${cb_commands}" "${match}"

  cb_commands="--dump --disable ${feature}"
  match="${feature_match} *no"
  test_pass "${cb_commands}" "${match}"

  # Change the configured default to 'no'
  sed -i -e "s/${feature}=.*/${feature}=no/" "${indir}/host.conf"

  # Verify that it's now 'no'
  cb_commands="--dump"
  match="${feature_match} *no"
  test_pass "${cb_commands}" "${match}"

  # Verify that 'enable ${feature}' now works.
  cb_commands="--dump --enable ${feature}"
  match="${feature_match} *yes"
  test_pass "${cb_commands}" "${match}"

  mv ${indir}/host.conf.orig ${indir}/host.conf
  trap - EXIT

  # Let's make sure the stage is actually skipped.
  # --force makes sure we run through to the stage even
  # if the builddir builds stamps are new.
  cb_commands="--dryrun --force --target arm-linux-gnueabihf --disable ${feature} --build all"
  test_pass "${cb_commands}" "${skip_match}"

  # Let's make sure the stage is actually NOT skipped.
  # --force makes sure we run through to the stage even
  # if the builddir builds stamps are new.
  cb_commands="--dryrun --force --target arm-linux-gnueabihf --enable ${feature} --build all"
  test_pass "${cb_commands}" "${perform_match}"
}

cb_commands="--dry-run"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--dryrun"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--dry"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="-dry"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--dr"
match="Directive not supported"
test_failure "${cb_commands}" "${match}"

cb_commands="-dr"
match="Directive not supported"
test_failure "${cb_commands}" "${match}"

cb_commands="--drnasdfa"
match="Directive not supported"
test_failure "${cb_commands}" "${match}"

# Test for expected failure for removed deprecated feature --dostep.
cb_commands="--dostep"
match="Directive not supported"
test_failure "${cb_commands}" "${match}"

# Test for expected failure for --libc=<foo>
# https://bugs.linaro.org/show_bug.cgi?id=1372
cb_commands="--libc"
match="Directive not supported"
test_failure "${cb_commands}" "${match}"

# Test for expected failure for --libc=<foo>
# https://bugs.linaro.org/show_bug.cgi?id=1372
cb_commands="--libc="
match="Directive not supported"
test_failure "${cb_commands}" "${match}"

# Test for expected failure for unknown toolchain component
# https://bugs.linaro.org/show_bug.cgi?id=1372
cb_commands="libc="
match="Component specified not supported"
test_failure "${cb_commands}" "${match}"

# Test for non-directive dangling command
# https://bugs.linaro.org/show_bug.cgi?id=1372
cb_commands="libc"
match="Command not recognized"
test_failure "${cb_commands}" "${match}"

cb_commands="--target=foo"
match="A space is expected"
test_failure "${cb_commands}" "${match}"

cb_commands="--target"
match="target requires a directive"
test_failure "${cb_commands}" "${match}"

cb_commands="--timeout"
match="timeout requires a directive"
test_failure "${cb_commands}" "${match}"

cb_commands="--timeout=foo"
match="A space is expected"
test_failure "${cb_commands}" "${match}"

cb_commands="--timeout 25"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--target foo"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--build=all"
match="A space is expected"
test_failure "${cb_commands}" "${match}"

cb_commands="--dryrun --build --foobar"
match="found the next"
test_failure "${cb_commands}" "${match}"

cb_commands="--dryrun --build"
match="requires a directive"
test_failure "${cb_commands}" "${match}"

cb_commands="--checkout"
match="requires a directive"
test_failure "${cb_commands}" "${match}"

cb_commands="--checkout=all"
match="A space is expected"
test_failure "${cb_commands}" "${match}"

cb_commands="--checkout --all"
match="found the next"
test_failure "${cb_commands}" "${match}"

cb_commands="--checkout --foo"
match="found the next"
test_failure "${cb_commands}" "${match}"

cb_commands="--dryrun --checkout all"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--dryrun --checkout gcc.git"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--dryrun --target arm-linux-gnueabihf --checkout glibc.git"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--dryrun --target arm-linux-gnueabihf --checkout=glibc.git"
match="A space is expected"
test_failure "${cb_commands}" "${match}"

cb_commands="--dryrun --target arm-linux-gnueabihf --checkout all"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--set=libc=glibc"
match="A space is expected"
test_failure "${cb_commands}" "${match}"

cb_commands="--set"
match="requires a directive"
test_failure "${cb_commands}" "${match}"

cb_commands="--release=foobar"
match="A space is expected"
test_failure "${cb_commands}" "${match}"

cb_commands="--release"
match="requires a directive"
test_failure "${cb_commands}" "${match}"

target="aarch64-none-elf"
libc="foo"
cb_commands="--target ${target} --set libc=${libc}"
match="set_package"
test_failure "${cb_commands}" "${match}"

target="aarch64-none-elf"
libc="glibc"
cb_commands="--target ${target} --set libc=${libc}"
match="crosscheck_clibrary_target"
test_failure "${cb_commands}" "${match}"

target="aarch64-none-elf"
libc="glibc"
cb_commands="--target ${target} --set libc=${libc}"
match="crosscheck_clibrary_target"
test_failure "${cb_commands}" "${match}"

target="aarch64-none-elf"
# A baremetal target should pick the right clibrary (newlib)
cb_commands="--target ${target}"
match=''
test_pass "${cb_commands}" "${match}"

target="aarch64-none-elf"
# A baremetal target should pick the right clibrary (newlib)
cb_commands="--target ${target} --dump"
match='newlib'
test_pass "${cb_commands}" "${match}"

target="armeb-linux-gnueabihf"
# A baremetal target should pick the right clibrary (newlib)
cb_commands="--target ${target} --dump"
match='glibc'
test_pass "${cb_commands}" "${match}"

target="armeb-linux-gnueabihf"
# A baremetal target should pick the right clibrary (newlib)
cb_commands="--target ${target} --dump"
match='glibc'
test_pass "${cb_commands}" "${match}"

target="armeb-linux-gnueabi"
cb_commands="--target ${target} --dump"
match='glibc'
test_pass "${cb_commands}" "${match}"

target="armeb-linux-gnueabi"
cb_commands="--target ${target} --dump"
match='glibc'
test_pass "${cb_commands}" "${match}"

target="armeb-linux-gnueabi"
# A baremetal target should pick the right clibrary (newlib)
cb_commands="--target ${target} --dump"
match='glibc'
test_pass "${cb_commands}" "${match}"

target="armeb-none-eabi"
# A baremetal target should pick the right clibrary (newlib)
cb_commands="--target ${target} --dump"
match='newlib'
test_pass "${cb_commands}" "${match}"

target="arm-none-eabi"
# A baremetal target should pick the right clibrary (newlib)
cb_commands="--target ${target} --dump"
match='newlib'
test_pass "${cb_commands}" "${match}"

target="aarch64-none-elf"
libc="newlib"
cb_commands="--target ${target} --set libc=${libc}"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--snapshots"
match='requires a directive'
test_failure "${cb_commands}" "${match}"

cb_commands="--stage"
match='requires a directive'
test_failure "${cb_commands}" "${match}"

cb_commands="--stage a"
match='stage requires a 2 or 1 directive'
test_failure "${cb_commands}" "${match}"

cb_commands="--stage 3"
match='stage requires a 2 or 1 directive'
test_failure "${cb_commands}" "${match}"

cb_commands="--stage 3"
match='stage requires a 2 or 1 directive'
test_failure "${cb_commands}" "${match}"


cb_commands="--snapshots --sooboo"
match='found the next'
test_failure "${cb_commands}" "${match}"

cb_commands="--snapshots=foo/bar --build all"
match="A space is expected"
test_failure "${cb_commands}" "${match}"

cb_commands="--dryrun --snapshots ${local_snapshots} --build all"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--dryrun --build gcc.git"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--dryrun --build asdflkajsdflkajsfdlasfdlaksfdlkaj.git"
match="Malformed input. No url found"
test_failure "${cb_commands}" "${match}"

# This tests that --build can go before --target and --target is still processed correctly.
cb_commands="--dryrun --build all --target arm-linux-gnueabihf --dump"
match='arm-linux-gnueabihf'
test_pass "${cb_commands}" "${match}"

# This tests that --checkout can go before --target and --target is still processed correctly.
cb_commands="--dryrun --checkout all --target arm-linux-gnueabihf --dump"
match='arm-linux-gnueabihf'
test_pass "${cb_commands}" "${match}"

test_config_default make_docs 'Make Documentation' 'Skipping make docs'    'Making docs in'
test_config_default install   'Install'            'Skipping make install' 'Making install in'

# The default.
cb_commands="--dump"
match='Bootstrap          no'
test_pass "${cb_commands}" "${match}"

cb_commands="--enable bootstrap --dump"
match='Bootstrap          yes'
test_pass "${cb_commands}" "${match}"

cb_commands="--dump"
match='Install            yes'
test_pass "${cb_commands}" "${match}"

cb_commands="--disable install --dump"
match='Install            no'
test_pass "${cb_commands}" "${match}"

cb_commands="--dump"
match='Source Update      yes'
test_pass "${cb_commands}" "${match}"

cb_commands="--disable update --dump"
match='Source Update      no'
test_pass "${cb_commands}" "${match}"

# Test dump ordering.  --target processing is immediate, so --dump
# should work before or after --target.
cb_commands="--target arm-linux-gnueabihf --dump"
match='Target is\:         arm-linux-gnueabihf'
test_pass "${cb_commands}" "${match}"

cb_commands="--dump --target arm-linux-gnueabihf"
match='Target is\:         arm-linux-gnueabihf'
test_pass "${cb_commands}" "${match}"

# This tests that --checkout and --build can be run together.
cb_commands="--dryrun --target arm-linux-gnueabihf --checkout all --build all"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="--set"
match='requires a directive'
test_failure "${cb_commands}" "${match}"

cb_commands="--set --foobar"
match='found the next'
test_failure "${cb_commands}" "${match}"

cb_commands="--set=libc=glibc"
match="A space is expected"
test_failure "${cb_commands}" "${match}"

cb_commands="--set gcc=meh"
match="'gcc' is not a supported package"
test_failure "${cb_commands}" "${match}"

cb_commands="--set libc=glibc"
match=''
test_pass "${cb_commands}" "${match}"

cb_commands="glibc=glibc.git"
match=''
test_pass "${cb_commands}" "${match}"

target="aarch64-none-elf"
cb_commands="--target ${target} newlib=newlib.git"
match=''
test_pass "${cb_commands}" "${match}"

target="aarch64-none-elf"
cb_commands="--target ${target} --set libc=glibc"
match="crosscheck_clibrary_target"
test_failure "${cb_commands}" "${match}"

target="aarch64-none-elf"
cb_commands="--set libc=glibc --target ${target}"
match="crosscheck_clibrary_target"
test_failure "${cb_commands}" "${match}"

target="aarch64-none-elf"
cb_commands="--set libc=newlibv --target ${target}"
match=''
test_failure "${cb_commands}" "${match}"

target="aarch64-none-elf"
cb_commands="--target ${target} --set libc=newlib"
match=''
test_pass "${cb_commands}" "${match}"

# The same as previous but with other commands mixed in.
target="aarch64-none-elf"
cb_commands="--set libc=glibc --dry-run --build all --target ${target}"
match="crosscheck_clibrary_target"
test_failure "${cb_commands}" "${match}"

# The same as previous but with other commands mixed in.
target="arm-linux-gnueabihf"
cb_commands="--set libc=glibc --dry-run --build all --target ${target}"
match=''
test_pass "${cb_commands}" "${match}"

# This one's a bit different because it doesn't work by putting the phrase to
# be grepped in 'match'... yet.
cb_commands="--dryrun --build gcc.git --stage 2"
testlineno="`expr $LINENO + 1`"
out="`(${runintmpdir:+cd ${tmpdir}} && ${abe_path}/abe.sh --space 4960 ${cb_commands} 2>&1 | tee ${testlogs}/${testlineno}.log | grep -c " build.*gcc.*stage2")`"
if test ${out} -gt 0; then
    pass ${testlineno} "VALID: --dryrun --build gcc.git --stage 2"
else
    fail ${testlineno} "VALID: --dryrun --build gcc.git --stage 2"
fi

cb_commands="--dry-run --target arm-linux-gnueabihf --set arch=armv8-a"
match='Overriding default --with-arch to armv8-a'
test_pass "${cb_commands}" "${match}"

cb_commands="--dry-run --target arm-linux-gnueabihf --set cpu=cortex-a57"
match='Overriding default --with-cpu to cortex-a57'
test_pass "${cb_commands}" "${match}"

cb_commands="--dry-run --target arm-linux-gnueabihf --set tune=cortex-a53"
match='Overriding default --with-tune to cortex-a53'
test_pass "${cb_commands}" "${match}"

cb_commands="--dry-run --target arm-linux-gnueabihf --check=foo"
match='is invalid after'
test_failure "${cb_commands}" "${match}"

cb_commands="--dry-run --target arm-linux-gnueabihf --dump --check"
match='check              all'
test_pass "${cb_commands}" "${match}"

cb_commands="--dry-run --target arm-linux-gnueabihf --dump --check --dump"
match='check              all'
test_pass "${cb_commands}" "${match}"

# Yes this won't work because we match on 'exact' package name only.
cb_commands="--dry-run --target arm-linux-gnueabihf --dump --check gdb--dump"
match='dump is an invalid package'
test_failure "${cb_commands}" "${match}"

cb_commands="--dry-run --target arm-linux-gnueabihf --check --dump"
match='check              all'
test_pass "${cb_commands}" "${match}"

cb_commands="--dry-run --target arm-linux-gnueabihf --check gdb --dump"
match='check              gdb'
test_pass "${cb_commands}" "${match}"

cb_commands="--dry-run --target arm-linux-gnueabihf --check all --dump"
match='check              all'
test_pass "${cb_commands}" "${match}"

# Verify that --check without a directive doesn't strip the next switch from
# the command line.
cb_commands="--dry-run --check --target arm-linux-gnueabihf --dump"
match='         arm-linux-gnueabihf'
test_pass "${cb_commands}" "${match}"

# test various combinations of --check and --excludecheck

# This should explicitly add all tests to runtests but NOT include 'all' in the text
cb_commands="--check all --dump"
match='checking           glibc gcc gdb binutils'
test_pass "${cb_commands}" "${match}"

# Simply exclude 'gdb' from the list of all runtests.
cb_commands="--check all --excludecheck gdb --dump"
match='checking           glibc gcc binutils'
test_pass "${cb_commands}" "${match}"

# This should be the same as --check all --excludecheck gdb
cb_commands="--check  --excludecheck gdb --dump"
match='checking           glibc gcc binutils'
test_pass "${cb_commands}" "${match}"

# 'binutils' is on the end of the list which might have some whitespace issues.
cb_commands="--check all --excludecheck binutils --dump"
match='checking           glibc gcc gdb'
test_pass "${cb_commands}" "${match}"

# 'glibc' is at the beginning of the list which might have some whitespace issues.
cb_commands="--check all --excludecheck glibc --dump"
match='checking           gcc gdb binutils'
test_pass "${cb_commands}" "${match}"

# Make sure both are accounted for.
cb_commands="--check all --excludecheck glibc --excludecheck binutils --dump"
match='checking           gcc gdb'
test_pass "${cb_commands}" "${match}"

# Check a single test
cb_commands="--check gdb --dump"
match='checking           gdb'
test_pass "${cb_commands}" "${match}"

# Check binutils
cb_commands="--check binutils --dump"
match='checking           binutils'
test_pass "${cb_commands}" "${match}"

# Check glibc
cb_commands="--check glibc --dump"
match='checking           glibc'
test_pass "${cb_commands}" "${match}"

# Check gcc
cb_commands="--check gcc --dump"
match='checking           gcc'
test_pass "${cb_commands}" "${match}"

# Check that --dump is processed after --check.
cb_commands="--dump --check gcc"
match='checking           gcc'
test_pass "${cb_commands}" "${match}"

# What happens when you add several tests?
cb_commands="--check gdb --check gcc --dump"
match='checking           gdb gcc'
test_pass "${cb_commands}" "${match}"

# This should result in 'gdb gcc' in runtests because the order depends on when they were added with --check.
cb_commands="--check gdb --check gcc --dump"
match='checking           gdb gcc'
test_pass "${cb_commands}" "${match}"

# what if you mix 'all' and individual tests?  It should be all tests in all_unit_tests and no redundant tests.
cb_commands="--check all --check gdb --check glibc --dump"
match='checking           glibc gcc gdb binutils'
test_pass "${cb_commands}" "${match}"

# Make sure we get the same result with --check (without a directive) since this is the same as 'all'.
# It should be all tests in all_unit_tests and no redundant tests.
cb_commands="--check --check gdb --check glibc --dump"
match='checking           glibc gcc gdb binutils'
test_pass "${cb_commands}" "${match}"

# Make sure we can exclude binutils when 'all' is mixed with individual tests.
cb_commands="--check all --check gdb --check glibc --excludecheck binutils --dump"
match='checking           glibc gcc gdb'
test_pass "${cb_commands}" "${match}"

# Make sure we can exclude several packages when 'all' is mixed with individual tests.
cb_commands="--check all --check gdb --check glibc --excludecheck binutils --excludecheck gdb --dump"
match='checking           glibc gcc'
test_pass "${cb_commands}" "${match}"

# Order of where --check all shows up shouldn't affect outcome.
# Make sure we can exclude several packages when 'all' is mixed with individual tests.
cb_commands="--check gdb --check glibc --excludecheck binutils --excludecheck gdb --check all --dump"
match='checking           glibc gcc'
test_pass "${cb_commands}" "${match}"

# Order of where --check shows up shouldn't affect outcome.
# Make sure we can exclude several packages when 'all' is mixed with individual tests.
cb_commands="--check gdb --check glibc --excludecheck binutils --excludecheck gdb --check --dump"
match='checking           glibc gcc'
test_pass "${cb_commands}" "${match}"

# Make sure we can exclude several packages when 'all' is implicitly mixed with individual tests.
cb_commands="--check --check gdb --check glibc --excludecheck binutils --excludecheck gdb --dump"
match='checking           glibc gcc'
test_pass "${cb_commands}" "${match}"

# Order of --check and --excludecheck doesn't matter.  We always 'exclude' after we process 'check'.
# If we add --check gdb after we've already excluded it, it'll remain excluded.
cb_commands="--check --check gdb --check glibc --excludecheck binutils --excludecheck gdb --check gdb --dump"
match='checking           glibc gcc'
test_pass "${cb_commands}" "${match}"

# Removing everything that was added should result in no unit tests being run.
cb_commands="--check gdb --check glibc --excludecheck gdb --excludecheck glibc --dump"
match='checking           {none}'
test_pass "${cb_commands}" "${match}"

# Redundant check tests should have all instances overridden by excludecheck.
cb_commands="--check gdb --check gdb --check glibc --excludecheck gdb --excludecheck glibc --dump"
match='checking           {none}'
test_pass "${cb_commands}" "${match}"

# Redundant excludecheck tests shouldn't do anything unexpected.
cb_commands="--check gdb --check glibc --excludecheck glibc --excludecheck gdb --excludecheck glibc --dump"
match='checking           {none}'
test_pass "${cb_commands}" "${match}"

# Redundant excludecheck tests shouldn't accidentally remove an included test.
cb_commands="--check gdb --check glibc --excludecheck glibc --excludecheck glibc --dump"
match='checking           gdb'
test_pass "${cb_commands}" "${match}"

# Redundant check tests should only result in one instance of the test
cb_commands="--check gdb --check gdb --check glibc --dump"
match='checking           gdb glibc'
test_pass "${cb_commands}" "${match}"

# There should be nothing in runtests because nothing was specified with --check
cb_commands="--excludecheck glibc --dump"
match='checking           {none}'
test_pass "${cb_commands}" "${match}"

# This should error out because 'excludecheck' requires a directive
cb_commands="--check gdb --check gdb --check glibc --excludecheck --dump"
match='excludecheck requires a directive'
test_pass "${cb_commands}" "${match}"

# excluding a test that isn't being checked should work fine.
cb_commands="--check gdb --check gdb --check glibc --excludecheck gcc --dump"
match='checking           gdb glibc'
test_pass "${cb_commands}" "${match}"

# excluding this combination shouldn't leave extraneous spaces in runtests.
cb_commands="--check --excludecheck gcc --excludecheck gdb --dump"
match='checking           glibc binutils'
test_pass "${cb_commands}" "${match}"


# excluding all tests should work
cb_commands="--check all --excludecheck all --dump"
match='checking           {none}'
test_pass "${cb_commands}" "${match}"

# excluding all tests should work regardless of what other tests are included or excluded.
cb_commands="--check all --excludecheck all --check gdb --excludecheck gcc --dump"
match='checking           {none}'
test_pass "${cb_commands}" "${match}"

# excluding all tests should work even if no other tests have been included.
cb_commands="--excludecheck all --dump"
match='checking           {none}'
test_pass "${cb_commands}" "${match}"

# excluding all tests should work even if only one test has been included.
cb_commands="--check glibc --excludecheck all --dump"
match='checking           {none}'
test_pass "${cb_commands}" "${match}"

# checking a partial package name shoulderror
cb_commands="--check gd --dump"
match='gd is an invalid package name'
test_failure "${cb_commands}" "${match}"

# checking an invalid package should error.
cb_commands="--check foo --dump"
match='foo is an invalid package name'
test_failure "${cb_commands}" "${match}"

# excluding a partial package name should error
cb_commands="--check --excludecheck gd --dump"
match='gd is an invalid package name'
test_failure "${cb_commands}" "${match}"

# excluding an invalid package name should error
cb_commands="--check --excludecheck foo --dump"
match='foo is an invalid package name'
test_failure "${cb_commands}" "${match}"

# Only perform this test if we're running in the tmpdir because we
# don't want to damage the builds/ dir for a valid run.
if test x"${runintmpdir}" = xyes; then
    rm -rf ${tmpdir}/builds

    # Test that builds/ is restored if it is removed.
    cb_commands="--dry-run --target arm-linux-gnueabihf --dump --build all"
    match=''
    test_pass "${cb_commands}" "${match}"

    if test ! -d "${tmpdir}/builds"; then
	fail ${testlineno} "VALID: test that builds/ is restored if it is removed."
    else
	pass ${testlineno} "VALID: tests that builds/ is restored if it is removed."
    fi
fi

# If the tests pass successfully clean up /tmp/<tmpdir> but only if the
# directory name is conformant.  We don't want to accidentally remove /tmp.
if test x"${tmpdir}" = x"/tmp"; then
    echo ""
    echo "\n${local_snapshots} doesn't conform to /tmp/<tmpdir>/snapshots. Not safe to remove."
elif test -d "${tmpdir}/snapshots" -a ${failures} -lt 1; then
    echo ""
    echo "${testabe} finished with no unexpected failures. Removing ${tmpdir}"
    rm -rf ${tmpdir}
fi

# ----------------------------------------------------------------------------------
# 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