xref: /aosp_15_r20/external/ltp/lib/newlib_tests/runtest.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh
2*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) 2021 Petr Vorel <[email protected]>
3*49cdfc7eSAndroid Build Coastguard Worker
4*49cdfc7eSAndroid Build Coastguard WorkerLTP_C_API_TESTS="${LTP_C_API_TESTS:-test05 test07 test09 test15 test_runtime01
5*49cdfc7eSAndroid Build Coastguard Workertst_needs_cmds01 tst_needs_cmds02 tst_needs_cmds03 tst_needs_cmds06
6*49cdfc7eSAndroid Build Coastguard Workertst_needs_cmds07 tst_bool_expr test_exec test_timer tst_res_hexd tst_strstatus
7*49cdfc7eSAndroid Build Coastguard Workertst_fuzzy_sync03 test_zero_hugepage.sh test_kconfig.sh test_kconfig03
8*49cdfc7eSAndroid Build Coastguard Workertest_children_cleanup.sh}"
9*49cdfc7eSAndroid Build Coastguard Worker
10*49cdfc7eSAndroid Build Coastguard WorkerLTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
11*49cdfc7eSAndroid Build Coastguard Workershell/tst_check_kconfig0[1-5].sh shell/tst_errexit.sh shell/net/*.sh}"
12*49cdfc7eSAndroid Build Coastguard Worker
13*49cdfc7eSAndroid Build Coastguard Workercd $(dirname $0)
14*49cdfc7eSAndroid Build Coastguard WorkerPATH="$PWD/../../testcases/lib/:$PATH"
15*49cdfc7eSAndroid Build Coastguard Worker
16*49cdfc7eSAndroid Build Coastguard Worker. tst_ansi_color.sh
17*49cdfc7eSAndroid Build Coastguard Worker
18*49cdfc7eSAndroid Build Coastguard Workerusage()
19*49cdfc7eSAndroid Build Coastguard Worker{
20*49cdfc7eSAndroid Build Coastguard Worker	cat << EOF
21*49cdfc7eSAndroid Build Coastguard WorkerUsage: $0 [-b DIR ] [-c|-s]
22*49cdfc7eSAndroid Build Coastguard Worker-b DIR  build directory (required for out-of-tree build)
23*49cdfc7eSAndroid Build Coastguard Worker-c      run C API tests only
24*49cdfc7eSAndroid Build Coastguard Worker-s      run shell API tests only
25*49cdfc7eSAndroid Build Coastguard Worker-h      print this help
26*49cdfc7eSAndroid Build Coastguard WorkerEOF
27*49cdfc7eSAndroid Build Coastguard Worker}
28*49cdfc7eSAndroid Build Coastguard Worker
29*49cdfc7eSAndroid Build Coastguard Workertst_flag2mask()
30*49cdfc7eSAndroid Build Coastguard Worker{
31*49cdfc7eSAndroid Build Coastguard Worker	case "$1" in
32*49cdfc7eSAndroid Build Coastguard Worker	TPASS) return 0;;
33*49cdfc7eSAndroid Build Coastguard Worker	TFAIL) return 1;;
34*49cdfc7eSAndroid Build Coastguard Worker	TBROK) return 2;;
35*49cdfc7eSAndroid Build Coastguard Worker	TWARN) return 4;;
36*49cdfc7eSAndroid Build Coastguard Worker	TINFO) return 16;;
37*49cdfc7eSAndroid Build Coastguard Worker	TCONF) return 32;;
38*49cdfc7eSAndroid Build Coastguard Worker	esac
39*49cdfc7eSAndroid Build Coastguard Worker}
40*49cdfc7eSAndroid Build Coastguard Worker
41*49cdfc7eSAndroid Build Coastguard Workerruntest_res()
42*49cdfc7eSAndroid Build Coastguard Worker{
43*49cdfc7eSAndroid Build Coastguard Worker	if [ $# -eq 0 ]; then
44*49cdfc7eSAndroid Build Coastguard Worker		echo >&2
45*49cdfc7eSAndroid Build Coastguard Worker		return
46*49cdfc7eSAndroid Build Coastguard Worker	fi
47*49cdfc7eSAndroid Build Coastguard Worker
48*49cdfc7eSAndroid Build Coastguard Worker	local res="$1"
49*49cdfc7eSAndroid Build Coastguard Worker	shift
50*49cdfc7eSAndroid Build Coastguard Worker
51*49cdfc7eSAndroid Build Coastguard Worker	printf "runtest " >&2
52*49cdfc7eSAndroid Build Coastguard Worker	tst_print_colored $res "$res: " >&2
53*49cdfc7eSAndroid Build Coastguard Worker	echo "$@" >&2
54*49cdfc7eSAndroid Build Coastguard Worker
55*49cdfc7eSAndroid Build Coastguard Worker}
56*49cdfc7eSAndroid Build Coastguard Worker
57*49cdfc7eSAndroid Build Coastguard Workerruntest_brk()
58*49cdfc7eSAndroid Build Coastguard Worker{
59*49cdfc7eSAndroid Build Coastguard Worker	local res="$1"
60*49cdfc7eSAndroid Build Coastguard Worker	shift
61*49cdfc7eSAndroid Build Coastguard Worker
62*49cdfc7eSAndroid Build Coastguard Worker	tst_flag2mask "$res"
63*49cdfc7eSAndroid Build Coastguard Worker	local mask=$?
64*49cdfc7eSAndroid Build Coastguard Worker
65*49cdfc7eSAndroid Build Coastguard Worker	runtest_res
66*49cdfc7eSAndroid Build Coastguard Worker	runtest_res $res $@
67*49cdfc7eSAndroid Build Coastguard Worker
68*49cdfc7eSAndroid Build Coastguard Worker	exit $mask
69*49cdfc7eSAndroid Build Coastguard Worker}
70*49cdfc7eSAndroid Build Coastguard Worker
71*49cdfc7eSAndroid Build Coastguard Workerrun_tests()
72*49cdfc7eSAndroid Build Coastguard Worker{
73*49cdfc7eSAndroid Build Coastguard Worker	local target="$1"
74*49cdfc7eSAndroid Build Coastguard Worker	local srcdir="$2"
75*49cdfc7eSAndroid Build Coastguard Worker	local dir i res ret=0 tbrok tconf tfail tpass twarn vars
76*49cdfc7eSAndroid Build Coastguard Worker
77*49cdfc7eSAndroid Build Coastguard Worker	eval vars="\$LTP_${target}_API_TESTS"
78*49cdfc7eSAndroid Build Coastguard Worker
79*49cdfc7eSAndroid Build Coastguard Worker	runtest_res TINFO "=== Run $target tests ==="
80*49cdfc7eSAndroid Build Coastguard Worker
81*49cdfc7eSAndroid Build Coastguard Worker	for i in $vars; do
82*49cdfc7eSAndroid Build Coastguard Worker		runtest_res TINFO "* $i"
83*49cdfc7eSAndroid Build Coastguard Worker		if [ -f "$i" ]; then
84*49cdfc7eSAndroid Build Coastguard Worker			dir="."
85*49cdfc7eSAndroid Build Coastguard Worker		elif [ "$srcdir" -a -f "$srcdir/$i" ]; then
86*49cdfc7eSAndroid Build Coastguard Worker			dir="$srcdir"
87*49cdfc7eSAndroid Build Coastguard Worker		else
88*49cdfc7eSAndroid Build Coastguard Worker			runtest_brk TBROK "Error: $i file not found (PWD: $PWD)"
89*49cdfc7eSAndroid Build Coastguard Worker		fi
90*49cdfc7eSAndroid Build Coastguard Worker
91*49cdfc7eSAndroid Build Coastguard Worker		$dir/$i 1>&2
92*49cdfc7eSAndroid Build Coastguard Worker		res=$?
93*49cdfc7eSAndroid Build Coastguard Worker
94*49cdfc7eSAndroid Build Coastguard Worker		[ $res -ne 0 -a $res -ne 32 ] && ret=1
95*49cdfc7eSAndroid Build Coastguard Worker
96*49cdfc7eSAndroid Build Coastguard Worker		case $res in
97*49cdfc7eSAndroid Build Coastguard Worker			0) tpass="$tpass $i";;
98*49cdfc7eSAndroid Build Coastguard Worker			1) tfail="$tfail $i";;
99*49cdfc7eSAndroid Build Coastguard Worker			2) tbrok="$tbrok $i";;
100*49cdfc7eSAndroid Build Coastguard Worker			4) twarn="$twarn $i";;
101*49cdfc7eSAndroid Build Coastguard Worker			32) tconf="$tconf $i";;
102*49cdfc7eSAndroid Build Coastguard Worker			127) runtest_brk TBROK "Error: file not found (wrong PATH? out-of-tree build without -b?), exit code: $res";;
103*49cdfc7eSAndroid Build Coastguard Worker			*) runtest_brk TBROK "Error: unknown failure, exit code: $res";;
104*49cdfc7eSAndroid Build Coastguard Worker		esac
105*49cdfc7eSAndroid Build Coastguard Worker		runtest_res
106*49cdfc7eSAndroid Build Coastguard Worker	done
107*49cdfc7eSAndroid Build Coastguard Worker
108*49cdfc7eSAndroid Build Coastguard Worker	runtest_res TINFO "=== $target TEST RESULTS ==="
109*49cdfc7eSAndroid Build Coastguard Worker	runtest_res TINFO "$(echo $tpass | wc -w)x TPASS:$tpass"
110*49cdfc7eSAndroid Build Coastguard Worker	runtest_res TINFO "$(echo $tfail | wc -w)x TFAIL:$tfail"
111*49cdfc7eSAndroid Build Coastguard Worker	runtest_res TINFO "$(echo $tbrok | wc -w)x TBROK:$tbrok"
112*49cdfc7eSAndroid Build Coastguard Worker	runtest_res TINFO "$(echo $twarn | wc -w)x TWARN:$twarn"
113*49cdfc7eSAndroid Build Coastguard Worker	runtest_res TINFO "$(echo $tconf | wc -w)x TCONF:$tconf"
114*49cdfc7eSAndroid Build Coastguard Worker	runtest_res
115*49cdfc7eSAndroid Build Coastguard Worker
116*49cdfc7eSAndroid Build Coastguard Worker	return $ret
117*49cdfc7eSAndroid Build Coastguard Worker}
118*49cdfc7eSAndroid Build Coastguard Worker
119*49cdfc7eSAndroid Build Coastguard Workerrun_c_tests()
120*49cdfc7eSAndroid Build Coastguard Worker{
121*49cdfc7eSAndroid Build Coastguard Worker	local ret srcdir="$PWD"
122*49cdfc7eSAndroid Build Coastguard Worker
123*49cdfc7eSAndroid Build Coastguard Worker	if [ "$builddir" ]; then
124*49cdfc7eSAndroid Build Coastguard Worker		cd $builddir/lib/newlib_tests
125*49cdfc7eSAndroid Build Coastguard Worker	fi
126*49cdfc7eSAndroid Build Coastguard Worker
127*49cdfc7eSAndroid Build Coastguard Worker	run_tests "C" "$srcdir"
128*49cdfc7eSAndroid Build Coastguard Worker	ret=$?
129*49cdfc7eSAndroid Build Coastguard Worker
130*49cdfc7eSAndroid Build Coastguard Worker	if [ "$builddir" ]; then
131*49cdfc7eSAndroid Build Coastguard Worker		cd "$srcdir"
132*49cdfc7eSAndroid Build Coastguard Worker	fi
133*49cdfc7eSAndroid Build Coastguard Worker
134*49cdfc7eSAndroid Build Coastguard Worker	return $ret
135*49cdfc7eSAndroid Build Coastguard Worker}
136*49cdfc7eSAndroid Build Coastguard Worker
137*49cdfc7eSAndroid Build Coastguard Workerrun_shell_tests()
138*49cdfc7eSAndroid Build Coastguard Worker{
139*49cdfc7eSAndroid Build Coastguard Worker	run_tests "SHELL"
140*49cdfc7eSAndroid Build Coastguard Worker}
141*49cdfc7eSAndroid Build Coastguard Worker
142*49cdfc7eSAndroid Build Coastguard Worker
143*49cdfc7eSAndroid Build Coastguard Workerprint_result()
144*49cdfc7eSAndroid Build Coastguard Worker{
145*49cdfc7eSAndroid Build Coastguard Worker	local target="$1"
146*49cdfc7eSAndroid Build Coastguard Worker	local res="$2"
147*49cdfc7eSAndroid Build Coastguard Worker
148*49cdfc7eSAndroid Build Coastguard Worker
149*49cdfc7eSAndroid Build Coastguard Worker	if [ -z "$res" ]; then
150*49cdfc7eSAndroid Build Coastguard Worker		runtest_res TCONF "$target tests skipped"
151*49cdfc7eSAndroid Build Coastguard Worker	elif [ $res -eq 0 ]; then
152*49cdfc7eSAndroid Build Coastguard Worker		runtest_res TPASS "All $target tests TCONF/TPASS"
153*49cdfc7eSAndroid Build Coastguard Worker	else
154*49cdfc7eSAndroid Build Coastguard Worker		runtest_res TFAIL "Some $target test(s) TBROK/TFAIL/TWARN"
155*49cdfc7eSAndroid Build Coastguard Worker	fi
156*49cdfc7eSAndroid Build Coastguard Worker}
157*49cdfc7eSAndroid Build Coastguard Worker
158*49cdfc7eSAndroid Build Coastguard Workerbuilddir=
159*49cdfc7eSAndroid Build Coastguard Workerc_fail=
160*49cdfc7eSAndroid Build Coastguard Workerrun=
161*49cdfc7eSAndroid Build Coastguard Workershell_fail=
162*49cdfc7eSAndroid Build Coastguard Worker
163*49cdfc7eSAndroid Build Coastguard Workerwhile getopts b:chs opt; do
164*49cdfc7eSAndroid Build Coastguard Worker	case $opt in
165*49cdfc7eSAndroid Build Coastguard Worker		'h') usage; exit 0;;
166*49cdfc7eSAndroid Build Coastguard Worker		'b') builddir=$OPTARG; PATH="$builddir/testcases/lib:$PATH";;
167*49cdfc7eSAndroid Build Coastguard Worker		'c') run="c";;
168*49cdfc7eSAndroid Build Coastguard Worker		's') run="s";;
169*49cdfc7eSAndroid Build Coastguard Worker		*) usage; runtest_brk TBROK "Error: invalid option";;
170*49cdfc7eSAndroid Build Coastguard Worker	esac
171*49cdfc7eSAndroid Build Coastguard Workerdone
172*49cdfc7eSAndroid Build Coastguard Worker
173*49cdfc7eSAndroid Build Coastguard Workerruntest_res TINFO "PATH='$PATH'"
174*49cdfc7eSAndroid Build Coastguard Worker
175*49cdfc7eSAndroid Build Coastguard Workerif [ -z "$run" -o "$run" = "c" ]; then
176*49cdfc7eSAndroid Build Coastguard Worker	run_c_tests
177*49cdfc7eSAndroid Build Coastguard Worker	c_fail=$?
178*49cdfc7eSAndroid Build Coastguard Workerfi
179*49cdfc7eSAndroid Build Coastguard Worker
180*49cdfc7eSAndroid Build Coastguard Workerif [ -z "$run" -o "$run" = "s" ]; then
181*49cdfc7eSAndroid Build Coastguard Worker	export KCONFIG_PATH=config02
182*49cdfc7eSAndroid Build Coastguard Worker	runtest_res TINFO "KCONFIG_PATH='$KCONFIG_PATH'"
183*49cdfc7eSAndroid Build Coastguard Worker	run_shell_tests
184*49cdfc7eSAndroid Build Coastguard Worker	shell_fail=$?
185*49cdfc7eSAndroid Build Coastguard Workerfi
186*49cdfc7eSAndroid Build Coastguard Worker
187*49cdfc7eSAndroid Build Coastguard Workerruntest_res TINFO "=== FINAL TEST RESULTS ==="
188*49cdfc7eSAndroid Build Coastguard Worker
189*49cdfc7eSAndroid Build Coastguard Workerprint_result "C" "$c_fail"
190*49cdfc7eSAndroid Build Coastguard Workerprint_result "shell" "$shell_fail"
191*49cdfc7eSAndroid Build Coastguard Worker
192*49cdfc7eSAndroid Build Coastguard Workerexit $((c_fail|shell_fail))
193