aboutsummaryrefslogtreecommitdiff
path: root/test.sh
blob: 3df92ba6501f506e8cc5388a6c52beaf814309ce (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
#!/bin/sh

testcbuild2="`basename $0`"

# The directory where the script lives.
topdir="`dirname $0`"
cbuild2="`realpath $0`"
topdir="`dirname ${cbuild2}`"
export cbuild_path=${topdir}

# We need a host.conf file to squelch cbuild2 error messages.
created_host_conf=
if test ! -e "${PWD}/host.conf"; then
    echo "Creating temporary host.conf file as ${PWD}/host.conf"
    echo "cbuild_path=${cbuild_path}" > ${PWD}/host.conf
    # source the host.conf file to get the values exported.
    . ${PWD}/host.conf
    created_host_conf="yes"
fi

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

# Override $local_snapshots so that the local_snapshots directory
# of an existing build is not moved or damaged.  This affects all
# called instances of cbuild2.sh below.
export local_snapshots="`mktemp -d /tmp/cbuild2.$$.XXX`/snapshots"
export sources_conf=${topdir}testsuite/test_sources.conf
export remote_snapshots=http://cbuild.validation.linaro.org/snapshots
export wget_bin=/usr/bin/wget
export wget_quiet=yes

# Create the snapshots/ subdir before it is used.
# It's possible that /tmp is out of space and this will fail.
out="`mkdir -p ${local_snapshots}`"
if test "$?" -gt 0; then
    exit 1
fi

usage()
{
    echo "  ${testcbuild2} [--debug|-v]"
    echo "                 [--md5sums <path/to/alternative/snapshots/md5sums>]"
    echo ""
    echo "  ${testcbuild2} is the cbuild2 frontend command conformance test."
    echo ""
    echo " ${testcbuild2} 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

if test ! -e "${local_snapshots}/md5sums"; then
    out="`fetch md5sums 2>/dev/null`"
    if test $? -gt 0; then
	echo "Failed to fetch md5sums.  Use --snapshots for offline mode." 1>&2 
	exit 1;
    fi
    echo "Using ${local_snapshots}/md5sums for snapshots file."
fi

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

    out="`./cbuild2.sh ${cb_commands} 2>&1 | 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="`./cbuild2.sh ${cb_commands} 2>&1 | grep "${match}" | sed -e 's:\(^ERROR\).*\('"${match}"'\).*:\1 \2:'`"
    cbtest ${testlineno} "${out}" "${match}" "VALID ${cb_commands}"
}

cb_commands="--dry-run"
match="Complete build process took"
test_pass "${cb_commands}" "${match}"

cb_commands="--dryrun"
match="Complete build process took"
test_pass "${cb_commands}" "${match}"

cb_commands="--dry"
match="Complete build process took"
test_pass "${cb_commands}" "${match}"

cb_commands="-dry"
match="Complete build process took"
test_pass "${cb_commands}" "${match}"

cb_commands="--dr"
match="Command not recognized"
test_failure "${cb_commands}" "${match}"

cb_commands="-dr"
match="Command not recognized"
test_failure "${cb_commands}" "${match}"

cb_commands="--drnasdfa"
match="Command not recognized"
test_failure "${cb_commands}" "${match}"

# Test for expected failure for removed deprecated feature --dostep.
cb_commands="--dostep"
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="Complete build process took"
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-none-linux-gnueabihf --checkout glibc.git"
match=''
test_pass "${cb_commands}" "${match}"

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

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

libc="glibc"
target="aarch64-none-elf"
cb_commands="--target ${target} --set libc=${libc}"
match="crosscheck_clibrary_target"
test_failure "${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="eglibc"
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"
libc="newlib"
cb_commands="--target ${target} --set libc=${libc}"
match=''
test_pass "${cb_commands}" "${match}"

# Verify that setting glibc=glibc.git will fail for baremetal.
cb_commands="--dryrun --target aarch64-none-elf glibc=glibc.git"
match='crosscheck_clibrary_target'
test_failure "${cb_commands}" "${match}"

# Verify that glibc=glibc.git will fail when se before the target
# for baremetal.
cb_commands="--dryrun glibc=glibc.git --target aarch64-none-elf"
match='crosscheck_clibrary_target'
test_pass "${cb_commands}" "${match}"


cb_commands="--snapshots"
match='requires a 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="Couldn't find the source for"
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-none-linux-gnueabihf --dump"
match='arm-none-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-none-linux-gnueabihf --dump"
match='arm-none-linux-gnueabihf'
test_pass "${cb_commands}" "${match}"

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

# This tests that --checkout and --build can be run together.
cb_commands="--dryrun --target arm-none-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} glibc=glibc.git"
match="crosscheck_clibrary_target"
test_failure "${cb_commands}" "${match}"

target="aarch64-none-elf"
cb_commands="--target ${target} eglibc=eglibc.git"
match="crosscheck_clibrary_target"
test_failure "${cb_commands}" "${match}"

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

tmpdir=`dirname ${local_snapshots}`

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-none-linux-gnueabihf"
cb_commands="--set libc=glibc --dry-run --build all --target ${target}"
match=''
test_pass "${cb_commands}" "${match}"



# 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 "${testcbuild2} finished with no unexpected failures. Removing ${tmpdir}"
    rm -rf ${tmpdir}
fi

if test x"$created_host_conf" = x"yes"; then
    echo "Removing temporary ${PWD}/host.conf file."
    rm ${PWD}/host.conf
fi

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

exit 0