summaryrefslogtreecommitdiff
path: root/embedded-test.sh
blob: 241de9e32161b4c826a24ed20e79f390bd7ad138 (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
#!/bin/sh
# Copyright © 2014
#	Waldemar Brodkorb <wbx@openadk.org>
#
# Provided that these terms and disclaimer and all copyright notices
# are retained or reproduced in an accompanying document, permission
# is granted to deal in this work without restriction, including un‐
# limited rights to use, publicly perform, distribute, sell, modify,
# merge, give away, or sublicence.
#
# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
# the utmost extent permitted by applicable law, neither express nor
# implied; without malicious intent or gross negligence. In no event
# may a licensor, author or contributor be held liable for indirect,
# direct, other damage, loss, or other issues arising in any way out
# of dealing in the work, even if advised of the possibility of such
# damage or existence of a defect, except proven that it results out
# of said person’s immediate fault when using the work as intended.
#
# Alternatively, this work may be distributed under the Terms of the
# General Public License, any version as published by the Free Soft‐
# ware Foundation.

# architecture specific notes:
#  mips64n32/mips64eln32 produces segfaults on boot for uClibc/uClibc-ng
#  sheb network card get no ip

adk_arch_list_uclibcng="arm armhf bfin m68k m68k-nommu mips mipsel mips64 mips64eln32 mips64n32 mips64n64 mips64el mips64el mips64eln64 ppc-nofpu sh sheb sparc x86 x86_64 xtensa"
adk_arch_list_uclibc="arm armhf bfin m68k m68k-nommu mips mipsel mips64 mips64eln32 mips64n32 mips64n64 mips64el mips64el mips64eln64 ppc-nofpu sh sheb sparc x86 x86_64"
adk_arch_list_musl="arm armhf mips mipsel ppc-nofpu sh sheb x86 x86_64"
adk_arch_list_glibc="aarch64 arm armhf m68k mips mipsel mips64 mips64eln32 mips64n32 mips64n64 mips64el mips64eln32 mips64eln64 ppc-nofpu ppc64 sh sheb sparc sparc64 x86 x86_64"

br_arch_list_uclibcng="arcle arcbe bfin arm mips mipsel mips64 mips64el ppc sh sparc x86 x86_64 xtensa"
br_arch_list_uclibc="arcle arcbe bfin arm mips mipsel mips64 mips64el ppc sh sparc x86 x86_64 xtensa"
br_arch_list_musl="arm mips mipsel ppc sh x86 x86_64"
br_arch_list_glibc="aarch64 arm mips mipsel mips64 mips64el ppc sh sparc x86 x86_64"

topdir=$(pwd)

tools='make git wget xz cpio tar awk sed'
f=0
for tool in $tools; do
	if ! which $tool >/dev/null; then
		echo "Checking if $tool is installed... failed"
		f=1
	fi
done
if [ $f -eq 1 ];then exit 1; fi

help() {
	cat >&2 <<EOF
Syntax: $0 -v <vendor> -l <libc> -s <source> -a <arch> -t <tests>

Explanation:
	-v: vendor for buildsystem (openadk|buildroot)
	-l: c library to use (uclibc-ng|musl|glibc|uclibc)
	-g: use latest git version
	-a: architecture to check
	-u: update vendor source via git pull
	-s: use directory with source for C library
	-d: enable debug
	-c: clean build directory before build
	-n: set NTP server for test run
	-t: run tests (boot|libc|ltp|native)
	-p: add extra packages
	-h: help text
EOF

}

clean=0
shell=0
update=0
debug=0
git=0

ntp=time.fu-berlin.de

while getopts "hgumdcn:a:v:s:l:t:p:" ch; do
        case $ch in
                m)
                        shell=1
                        ;;
                g)
                        git=1
                        ;;
                c)
                        clean=1
                        ;;
                d)
                        debug=1
                        ;;
                u)
                        update=1
                        ;;
                s)
                        source=$OPTARG
                        ;;
                l)
                        libc=$OPTARG
                        ;;
                n)
                        ntp=$OPTARG
                        ;;
                a)
                        archlist=$OPTARG
                        ;;
                p)
                        pkgs=$OPTARG
                        ;;
                t)
                        tests=$OPTARG
                        ;;
                v)
                        vendor=$OPTARG
                        ;;
		h)
			help
			exit 1
			;;
        esac
done
shift $((OPTIND - 1))

if [ -z $vendor ];then
	echo "You need to provide a vendor/buildsystem"
	echo "Either openadk or buildroot is supported."
	exit 1
fi

if [ -z $libc ];then
	echo "You need to provide a C library"
	echo "Either uclibc-ng, musl, glibc or uclibc is supported."
	exit 1
fi

case $libc in
	uclibc-ng)
		version=1.0.0rc1
		gitversion=1.0.0
		libver=uClibc-ng-${gitversion}
		libdir=uClibc-ng
		;;
	uclibc)
		version=0.9.33.2
		gitversion=0.9.34-git
		libver=uClibc-${gitversion}
		libdir=uClibc
		;;
	glibc)
		version=2.19
		gitversion=2.19.90
		libver=glibc-${gitversion}
		libdir=glibc
		;;
	musl)
		version=1.1.4
		gitversion=git
		libver=musl-${gitversion}
		libdir=musl
		;;
	*)
		echo "c library not supported"
		exit 1
esac

if [ -z "$archlist" ];then
	if [ $vendor = "openadk" ];then
		case $libc in
			uclibc-ng)
				archlist=$adk_arch_list_uclibcng
				;;
			uclibc)
				archlist=$adk_arch_list_uclibc
				;;
			glibc)
				archlist=$adk_arch_list_glibc
				;;
			musl)
				archlist=$adk_arch_list_musl
				;;
			*)
				exit 1
				;;
		esac
	fi
	if [ $vendor = "buildroot" ];then
		case $libc in
			uclibc-ng)
				archlist=$br_arch_list_uclibcng
				;;
			uclibc)
				archlist=$br_arch_list_uclibc
				;;
			glibc)
				archlist=$br_arch_list_glibc
				;;
			musl)
				archlist=$br_arch_list_musl
				;;
			*)
				exit 1
				;;
		esac
	fi
fi

case $vendor in
	openadk)
		echo "Using OpenADK to check $libc on $archlist"
		vendor_git=http://git.openadk.org/openadk.git
		;;
	buildroot)
		echo "Using buildroot to check $libc on $archlist"
		vendor_git=http://git.buildroot.net/git/buildroot.git
		;;
	*)
		echo "Vendor $vendor not supported."
		exit 1
		;;
esac

if [ ! -d $vendor ];then
	git clone $vendor_git
	if [ $? -ne 0 ];then
		echo "Cloning from $vendor_git failed."
		exit 1
	fi
	if [ "$vendor" = "buildroot" ];then
		wget http://downloads.uclibc-ng.org/buildroot-uClibc-ng.patch
		(cd buildroot && patch -p1 <../buildroot-uClibc-ng.patch)
	fi
else
	if [ $update -eq 1 ];then
		(cd $vendor && git pull)
		if [ $? -ne 0 ];then
			echo "Updating from $vendor_git failed."
			exit 1
		fi
	fi
fi

if [ ! -z $source ];then
	if [ ! -d $source ];then
		echo "Not a directory."
		exit 1
	fi
	git=1
	usrc=$(mktemp -d /tmp/XXXX)
	echo "Creating source tarball $vendor/dl/${libver}.tar.xz"
	cp -a $source $usrc/$libver
	mkdir -p $topdir/$vendor/dl 2>/dev/null
	rm $topdir/$vendor/dl/${libver}.tar.xz 2>/dev/null
	(cd $usrc && tar cJf $topdir/$vendor/dl/${libver}.tar.xz ${libver} )
fi

runtest() {

	arch=$1
	qemu=qemu-system-${arch}
	qemu_args=
	qemu_append="ntp_server=$ntp"
	if [ $debug -eq 0 ];then
		qemu_append="$qemu_append quiet"
	fi
	if [ $shell -eq 1 ];then
		qemu_append="$qemu_append shell"
	fi
	suffix=
	psuffix=
	libdir=lib
	march=${arch}

	case ${arch} in
		aarch64)
			cpu_arch=aarch64
			qemu_machine=virt
			qemu_args="${qemu_args} -cpu cortex-a57 -netdev user,id=eth0 -device virtio-net-device,netdev=eth0"
			;;
		arm) 
			cpu_arch=arm
			qemu_machine=vexpress-a9
			qemu_args="${qemu_args} -cpu cortex-a9 -net user -net nic,model=lan9118"
			suffix=eabi
			psuffix=$suffix
			;;
		armhf) 
			cpu_arch=arm
			march=arm
			qemu=qemu-system-${cpu_arch}
			qemu_machine=vexpress-a9
			qemu_args="${qemu_args} -cpu cortex-a9 -net user -net nic,model=lan9118"
			suffix=eabihf
			psuffix=$suffix
			;;
		mips) 
			cpu_arch=mips
			qemu_machine=malta
			qemu_args="${qemu_args} -device e1000,netdev=adk0 -netdev user,id=adk0"
			;;
		mipsel) 
			cpu_arch=mipsel
			march=mips
			qemu_machine=malta
			qemu_args="${qemu_args} -device e1000,netdev=adk0 -netdev user,id=adk0"
			;;
		mips64) 
			cpu_arch=mips64
			qemu_machine=malta
			qemu_args="${qemu_args} -device e1000,netdev=adk0 -netdev user,id=adk0"
			suffix=abi32
			psuffix=o32
			;;
		mips64n32) 
			cpu_arch=mips64
			march=mips64
			qemu=qemu-system-${cpu_arch}
			qemu_machine=malta
			qemu_args="${qemu_args} -device e1000,netdev=adk0 -netdev user,id=adk0"
			suffix=abin32
			psuffix=n32
			;;
		mips64n64) 
			cpu_arch=mips64
			march=mips64
			qemu=qemu-system-${cpu_arch}
			qemu_machine=malta
			qemu_args="${qemu_args} -device e1000,netdev=adk0 -netdev user,id=adk0"
			suffix=abi64
			psuffix=n64
			;;
		mips64el) 
			cpu_arch=mips64el
			march=mips64
			qemu_machine=malta
			qemu_args="${qemu_args} -device e1000,netdev=adk0 -netdev user,id=adk0"
			suffix=abi32
			psuffix=o32
			;;
		mips64eln32) 
			cpu_arch=mips64el
			march=mips64
			qemu=qemu-system-${cpu_arch}
			qemu_machine=malta
			qemu_args="${qemu_args} -device e1000,netdev=adk0 -netdev user,id=adk0"
			suffix=abin32
			psuffix=n32
			;;
		mips64eln64) 
			cpu_arch=mips64el
			march=mips64
			qemu=qemu-system-${cpu_arch}
			qemu_machine=malta
			qemu_args="${qemu_args} -device e1000,netdev=adk0 -netdev user,id=adk0"
			suffix=abi64
			psuffix=n64
			;;
		ppc-nofpu)
			cpu_arch=ppc
			march=ppc
			qemu=qemu-system-${cpu_arch}
			qemu_args="${qemu_args} -device e1000,netdev=adk0 -netdev user,id=adk0"
			qemu_machine=bamboo
			;;
		ppc)
			cpu_arch=ppc
			march=ppc
			qemu=qemu-system-${cpu_arch}
			qemu_args="${qemu_args} -device e1000,netdev=adk0 -netdev user,id=adk0"
			qemu_machine=mac99
			;;
		powerpc64|ppc64) 
			cpu_arch=ppc64
			qemu=qemu-system-${cpu_arch}
			qemu_machine=pseries
			;;
		sh) 
			cpu_arch=sh4
			qemu=qemu-system-${cpu_arch}
			qemu_machine=r2d
			qemu_args="${qemu_args} -monitor null -serial null -serial stdio"
			;;
		sheb) 
			cpu_arch=sh4eb
			march=sh
			qemu=qemu-system-${cpu_arch}
			qemu_machine=r2d
			qemu_args="${qemu_args} -monitor null -serial null -serial stdio"
			;;
		sparc) 
			cpu_arch=sparc
			qemu_machine=SS-5
			;;
		sparc64) 
			cpu_arch=sparc64
			qemu_machine=sun4u
			qemu_args="${qemu_args} -net nic,model=virtio -net user"
			;;
		x86) 
			cpu_arch=i486
			qemu=qemu-system-i386
			qemu_machine=pc
			qemu_args="${qemu_args}"
			;;
		x86_64) 
			cpu_arch=x86_64
			qemu_machine=pc
			libdir=lib64
			;;
		x86_64_x32) 
			cpu_arch=x86_64
			qemu=qemu-system-${cpu_arch}
			qemu_machine=pc
			libdir=libx32
			suffix=x32
			;;
		xtensa) 
			cpu_arch=xtensa
			qemu=qemu-system-${cpu_arch}
			qemu_machine=lx60
			qemu_args="${qemu_args} -cpu dc232b"
			;;
		*) 
			echo "architecture ${arch} not supported"; exit 1;;
	esac

	if ! which $qemu >/dev/null; then
		echo "Checking if $qemu is installed... failed"
		exit 1
	fi
	qemuver=$(${qemu} -version|awk '{ print $4 }')
	if [ $(echo $qemuver |sed -e "s#\.##g" -e "s#,##") -lt 210 ];then
		echo "Your qemu version is too old. Please update to 2.1 or greater"
		exit 1
	fi

	case $libc in
		uclibc-ng)
			prefix=uclibc
			;;
		glibc)
			prefix=gnu
			;;
		*)
			prefix=$libc
			;;
	esac
	cross=${cpu_arch}-${vendor}-linux-${prefix}${suffix}
	if [ -z $psuffix ];then
		TCPATH=${topdir}/${vendor}/toolchain_qemu-${march}_${libc}_${cpu_arch}
	else
		TCPATH=${topdir}/${vendor}/toolchain_qemu-${march}_${libc}_${cpu_arch}_${psuffix}
	fi
	export PATH="${TCPATH}/usr/bin:$PATH"

	if ! which ${cross}-gcc >/dev/null; then
		echo "Checking if ${cross}-gcc is installed... failed"
		exit 1
	fi

	echo "Starting test for ${arch}"
	echo "Generating root filesystem for test run"
	root=$(mktemp -d /tmp/XXXX)
	if [ ! -f openadk/firmware/qemu-${march}_${libc}/qemu-${march}-${libc}-initramfsarchive.tar.gz ];then
		echo "No root filesystem available for architecture ${arch}"
		exit 1
	fi
	tar -xf openadk/firmware/qemu-${march}_${libc}/qemu-${march}-${libc}-initramfsarchive.tar.gz -C $root

	if [ $2 = "boot" ];then
cat > ${root}/run.sh << EOF
#!/bin/sh
uname -a
rdate -n \$ntp_server
file /bin/busybox
for i in \$(ls /lib/*.so|grep -v libgcc);do
	size \$i
done
exit
EOF
	fi
	if [ $2 = "ltp" ];then
cat > ${root}/run.sh << EOF
#!/bin/sh
uname -a
rdate -n \$ntp_server
/opt/ltp/runltp
exit
EOF
	fi
	if [ $2 = "libc" ];then

		case $libc in
			uclibc-ng|uclibc)
cat > ${root}/run.sh << EOF
#!/bin/sh
uname -a
rdate -n \$ntp_server
cd /opt/$libc/test
CROSS_COMPILE=": ||" make UCLIBC_ONLY=y -k run
exit
EOF
			;;
			musl|glibc)
cat > ${root}/run.sh << EOF
#!/bin/sh
uname -a
rdate -n \$ntp_server
cd /opt/libc-test
make run
exit
EOF
			;;
		esac

	fi
	chmod u+x ${root}/run.sh

	kernel=openadk/firmware/qemu-${march}_${libc}/qemu-${march}-initramfsarchive-kernel

	echo "Creating initramfs filesystem"
	(cd $root; find . | cpio -o -C512 -Hnewc |xz --check=crc32 --stdout > ${topdir}/initramfs.${arch})
	rm -rf $root

	echo "Now running the tests in qemu for architecture ${arch}"
	echo "${qemu} -M ${qemu_machine} ${qemu_args} -append ${qemu_append} -kernel ${kernel} -qmp tcp:127.0.0.1:4444,server,nowait -no-reboot -nographic -initrd initramfs.${arch}"
	${qemu} -M ${qemu_machine} ${qemu_args} -append "${qemu_append}" -kernel ${kernel} -qmp tcp:127.0.0.1:4444,server,nowait -no-reboot -nographic -initrd initramfs.${arch} | tee REPORT.${arch}.${libc}.$2
	if [ $? -eq 0 ];then
		echo "Test for ${arch} finished. See REPORT.${arch}.${libc}.$2"
		echo 
	else
		echo "Test $2 failed for ${arch} with ${libc}."
		echo 
	fi
}

create_buildroot_defconfig_arcle() {
	cat > configs/arcle_defconfig << EOD
BR2_arcle=y

BR2_TOOLCHAIN_BUILDROOT_UCLIBC_NG=y
BR2_KERNEL_HEADERS_3_15=y
BR2_DEFAULT_KERNEL_HEADERS="3.15.6"
BR2_BINUTILS_VERSION_2_24=y
BR2_GCC_VERSION_4_8_X=y
BR2_TOOLCHAIN_HAS_THREADS=y
EOD
}

create_buildroot_defconfig_arcbe() {
	cat > configs/arcbe_defconfig << EOD
BR2_arcle=y

BR2_TOOLCHAIN_BUILDROOT_UCLIBC_NG=y
BR2_KERNEL_HEADERS_3_15=y
BR2_DEFAULT_KERNEL_HEADERS="3.15.6"
BR2_BINUTILS_VERSION_2_24=y
BR2_GCC_VERSION_4_8_X=y
BR2_TOOLCHAIN_HAS_THREADS=y
EOD
}

create_buildroot_defconfig_bfin() {
	cat > configs/bfin_defconfig << EOD
BR2_bfin=y
BR2_BINFMT_FDPIC=y
BR2_bf609=y

BR2_TOOLCHAIN_BUILDROOT_UCLIBC_NG=y
BR2_KERNEL_HEADERS_3_15=y
BR2_DEFAULT_KERNEL_HEADERS="3.15.6"
BR2_BINUTILS_VERSION_2_22=y
BR2_GCC_VERSION_4_5_X=y
BR2_TOOLCHAIN_HAS_THREADS=y
EOD
}

build_buildroot() {
	cd buildroot
	case $1 in
		arcle)
			create_buildroot_defconfig_arcle
			make arcle_defconfig
			make clean all
			;;
		arcbe)
			create_buildroot_defconfig_arcbe
			make arcbe_defconfig
			make clean all
			;;
		arm)
			make qemu_arm_vexpress_defconfig
			make clean all
			;;
		bfin)
			create_buildroot_defconfig_bfin
			make bfin_defconfig
			make clean all
			;;
		mips)
			make qemu_mips_malta_defconfig
			make clean all
			;;
		mipsel)
			make qemu_mipsel_malta_defconfig
			make clean all
			;;
		mips64)
			make qemu_mips64_malta_defconfig
			make clean all
			;;
		mips64el)
			make qemu_mips64el_malta_defconfig
			make clean all
			;;
		ppc)
			make qemu_ppc_mpc8544ds_defconfig
			make clean all
			;;
		sh)
			make qemu_sh4_r2d_defconfig
			make clean all
			;;
		sparc)
			make qemu_sparc_ss10_defconfig
			make clean all
			;;
		x86)
			make qemu_x86_defconfig
			make clean all
			;;
		x86_64)
			make qemu_x86_64_defconfig
			make clean all
			;;
		xtensa)
			make qemu_xtensa_lx60_defconfig
			make clean all
			;;
		*)
			echo "architecture not supported in buildroot"
			exit 1
			;;
	esac
	if [ $? -ne 0 ];then
		echo "build failed"
		exit 1
	fi
	cd ..
}

compile_openadk() {
	rm .config*
	make $1 defconfig
	for pkg in $pkgs; do p=$(echo $pkg|tr '[:lower:]' '[:upper:]');printf "ADK_COMPILE_$p=y\nADK_PACKAGE_$p=y" >> .config;done
	make $1 all
}

build_openadk() {
	cd openadk
	make prereq
	# always trigger regeneration of kernel config
	rm build_*_${libc}_${arch}*/linux/.config 2>/dev/null
	make package=$libc clean >/dev/null 2>&1
	# start with a clean dir
	if [ $clean -eq 1 ];then
		make cleandir
	fi
	DEFAULT="ADK_TARGET_LIBC=$libc ADK_TARGET_FS=initramfsarchive ADK_TARGET_COLLECTION=test"
	if [ $debug -eq 1 ];then
		DEFAULT="$DEFAULT VERBOSE=1"
	fi
	if [ $git -eq 1 ];then
		DEFAULT="$DEFAULT ADK_LIBC_GIT=y"
	fi
	if [ ! -z $source ];then
		DEFAULT="$DEFAULT ADK_NO_CHECKSUM=y"
	fi
	if [ $2 = "boot" ];then
		DEFAULT="$DEFAULT ADK_TEST_BASE=y"
	fi
	if [ $2 = "ltp" ];then
		DEFAULT="$DEFAULT ADK_TEST_LTP=y"
	fi
	if [ $2 = "libc" ];then
		case $libc in
			uclibc-ng)
				DEFAULT="$DEFAULT ADK_TEST_UCLIBC_NG_TESTSUITE=y"
				;;
			uclibc)
				DEFAULT="$DEFAULT ADK_TEST_UCLIBC_TESTSUITE=y"
				;;
			glibc)
				DEFAULT="$DEFAULT ADK_TEST_GLIBC_TESTSUITE=y"
				;;
			musl)
				DEFAULT="$DEFAULT ADK_TEST_MUSL_TESTSUITE=y"
				;;
			*)
				echo "test suite not available"
				exit 1
				;;
		esac
	fi
	if [ $2 = "native" ];then
		case $libc in
			uclibc-ng)
				DEFAULT="$DEFAULT ADK_TEST_UCLIBC_NG_NATIVE=y"
				;;
			uclibc)
				DEFAULT="$DEFAULT ADK_TEST_UCLIBC_NATIVE=y"
				;;
			musl)
				DEFAULT="$DEFAULT ADK_TEST_MUSL_NATIVE=y"
				;;
			glibc)
				DEFAULT="$DEFAULT ADK_TEST_GLIBC_NATIVE=y"
				;;
			*)
				echo "native build not available"
				exit 1
				;;
		esac
	fi
	case $1 in
		aarch64)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=aarch64 ADK_TARGET_SYSTEM=qemu-aarch64"
			compile_openadk "$DEFAULT"
			;;
		arm)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=arm ADK_TARGET_SYSTEM=qemu-arm ADK_TARGET_ABI=eabi ADK_TARGET_ENDIAN=little"
			compile_openadk "$DEFAULT"
			;;
		armhf)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=arm ADK_TARGET_SYSTEM=qemu-arm ADK_TARGET_ABI=eabihf ADK_TARGET_ENDIAN=little" 
			compile_openadk $DEFAULT
			;;
		bfin)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=bfin ADK_TARGET_SYSTEM=toolchain-bfin"
			compile_openadk "$DEFAULT"
			;;
		m68k)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=m68k ADK_TARGET_SYSTEM=aranym-m68k"
			compile_openadk $DEFAULT
			;;
		m68k-nommu)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=m68k ADK_TARGET_SYSTEM=qemu-m68k"
			compile_openadk $DEFAULT
			;;
		mips)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=mips ADK_TARGET_SYSTEM=qemu-mips ADK_TARGET_ENDIAN=big"
			compile_openadk $DEFAULT
			;;
		mipsel)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=mips ADK_TARGET_SYSTEM=qemu-mips ADK_TARGET_ENDIAN=little"
			compile_openadk $DEFAULT
			;;
		mips64)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=mips64 ADK_TARGET_SYSTEM=qemu-mips64 ADK_TARGET_ENDIAN=big ADK_TARGET_ABI=o32"
			compile_openadk $DEFAULT
			;;
		mips64n32)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=mips64 ADK_TARGET_SYSTEM=qemu-mips64 ADK_TARGET_ENDIAN=big ADK_TARGET_ABI=n32"
			compile_openadk $DEFAULT
			;;
		mips64n64)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=mips64 ADK_TARGET_SYSTEM=qemu-mips64 ADK_TARGET_ENDIAN=big ADK_TARGET_ABI=n64"
			compile_openadk $DEFAULT
			;;
		mips64el)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=mips64 ADK_TARGET_SYSTEM=qemu-mips64 ADK_TARGET_ENDIAN=little ADK_TARGET_ABI=o32"
			compile_openadk $DEFAULT
			;;
		mips64eln32)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=mips64 ADK_TARGET_SYSTEM=qemu-mips64 ADK_TARGET_ENDIAN=little ADK_TARGET_ABI=n32"
			compile_openadk $DEFAULT
			;;
		mips64eln64)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=mips64 ADK_TARGET_SYSTEM=qemu-mips64 ADK_TARGET_ENDIAN=little ADK_TARGET_ABI=n64"
			compile_openadk $DEFAULT
			;;
		ppc-nofpu)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=ppc ADK_TARGET_SYSTEM=qemu-ppc"
			compile_openadk $DEFAULT
			;;
		sh)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=sh ADK_TARGET_SYSTEM=qemu-sh ADK_TARGET_ENDIAN=little"
			compile_openadk $DEFAULT
			;;
		sheb)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=sh ADK_TARGET_SYSTEM=qemu-sh ADK_TARGET_ENDIAN=big"
			compile_openadk $DEFAULT
			;;
		*)
			DEFAULT="$DEFAULT ADK_TARGET_ARCH=$1 ADK_TARGET_SYSTEM=qemu-$1"
			compile_openadk $DEFAULT
			;;
	esac
	if [ $? -ne 0 ];then
		echo "build failed"
		exit 1
	fi
	cd ..
}	

echo "Compiling base system and toolchain"

if [ "$vendor" = "buildroot" ];then
	for arch in ${archlist}; do
		build_buildroot $arch notest
	done
fi

if [ "$vendor" = "openadk" ];then
	for arch in ${archlist}; do
		build_openadk $arch notest
		if [ ! -z "$tests" ];then
			for test in ${tests}; do
				if [ $test = "boot" -o $test = "libc" -o $test = "ltp" -o $test = "native" ];then
					case $arch in
						bfin|m68k|m68k-nommu|ppc|sheb|mips64eln32|mips64n32)
						echo "runtime tests disabled for $arch."
						;;
					*)
						build_openadk $arch $test
						runtest $arch $test
						;;
					esac
				else
					echo "Test $test is not valid. Allowed tests: boot libc ltp native"
				fi
			done
		fi
	done
fi

echo "All tests finished."
exit 0