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