• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# Copyright (c) 2021-2024 Petr Vorel <pvorel@suse.cz>
3
4# TODO "unknown failure, exit code": test_assert test08 tst_cgroup01 tst_cgroup02 tst_res_flags variant
5# TODO TFAIL: test_macros0[1-6] test23 test26
6# TODO TBROK: test_exec_child test_kconfig01 test_kconfig02 tst_needs_cmds04 tst_needs_cmds05 test_runtime02 test01 test02 test03 test04 test06 test11 test13 test22 test25 tst_safe_fileops
7# TODO TWARN: test_guarded_buf test14 tst_capability01 tst_print_result
8LTP_C_API_TESTS="${LTP_C_API_TESTS:-
9test_children_cleanup.sh
10test_kconfig.sh
11test_kconfig03
12test_parse_filesize
13test_runtime01
14test_timer
15test_zero_hugepage.sh
16test0[579]
17test1[59]
18test2[04]
19tst_bool_expr
20tst_capability02
21tst_device
22tst_expiration_timer
23tst_fuzzy_sync0[1-3]
24tst_needs_cmds0[1-36-8]
25tst_res_hexd
26tst_safe_sscanf
27tst_strstatus}"
28
29# TODO "unknown failure, exit code": shell/tst_res_flags.sh shell/timeout03.sh
30# TODO TBROK: shell/test_timeout.sh (sometimes) shell/timeout04.sh
31LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-
32shell/timeout0[1-2].sh
33shell/tst_all_filesystems.sh
34shell/tst_all_filesystems_skip.sh
35shell/tst_device_size.sh
36shell/tst_errexit.sh
37shell/tst_format_device.sh
38shell/tst_check_driver.sh
39shell/tst_check_kconfig0[1-5].sh
40shell/tst_mount_device.sh
41shell/tst_mount_device_tmpfs.sh
42shell/tst_skip_filesystems.sh
43shell/net/*.sh}"
44
45cd $(dirname $0)
46PATH="$PWD/../../testcases/lib/:$PATH"
47
48. tst_ansi_color.sh
49
50usage()
51{
52	cat << EOF
53Usage: $0 [-b DIR ] [-c|-s]
54-b DIR  build directory (required for out-of-tree build)
55-c      run C API tests only
56-s      run shell API tests only
57-h      print this help
58EOF
59}
60
61tst_flag2mask()
62{
63	case "$1" in
64	TPASS) return 0;;
65	TFAIL) return 1;;
66	TBROK) return 2;;
67	TWARN) return 4;;
68	TINFO) return 16;;
69	TCONF) return 32;;
70	esac
71}
72
73runtest_res()
74{
75	if [ $# -eq 0 ]; then
76		echo >&2
77		return
78	fi
79
80	local res="$1"
81	shift
82
83	printf "runtest " >&2
84	tst_print_colored $res "$res: " >&2
85	echo "$@" >&2
86
87}
88
89runtest_brk()
90{
91	local res="$1"
92	shift
93
94	tst_flag2mask "$res"
95	local mask=$?
96
97	runtest_res
98	runtest_res $res $@
99
100	exit $mask
101}
102
103run_tests()
104{
105	local target="$1"
106	local srcdir="$2"
107	local dir i res ret=0 tbrok tconf tfail tpass twarn vars
108
109	eval vars="\$LTP_${target}_API_TESTS"
110
111	runtest_res TINFO "=== Run $target tests ==="
112
113	for i in $vars; do
114		runtest_res TINFO "* $i"
115		if [ -f "$i" ]; then
116			dir="."
117		elif [ "$srcdir" -a -f "$srcdir/$i" ]; then
118			dir="$srcdir"
119		else
120			runtest_brk TBROK "Error: $i file not found (PWD: $PWD)"
121		fi
122
123		$dir/$i 1>&2
124		res=$?
125
126		[ $res -ne 0 -a $res -ne 32 ] && ret=1
127
128		case $res in
129			0) tpass="$tpass $i";;
130			1) tfail="$tfail $i";;
131			2) tbrok="$tbrok $i";;
132			4) twarn="$twarn $i";;
133			32) tconf="$tconf $i";;
134			127) runtest_brk TBROK "Error: file not found (wrong PATH? out-of-tree build without -b?), exit code: $res";;
135			*) runtest_brk TBROK "Error: unknown failure, exit code: $res";;
136		esac
137		runtest_res
138	done
139
140	runtest_res TINFO "=== $target TEST RESULTS ==="
141	runtest_res TINFO "$(echo $tpass | wc -w)x TPASS:$tpass"
142	runtest_res TINFO "$(echo $tfail | wc -w)x TFAIL:$tfail"
143	runtest_res TINFO "$(echo $tbrok | wc -w)x TBROK:$tbrok"
144	runtest_res TINFO "$(echo $twarn | wc -w)x TWARN:$twarn"
145	runtest_res TINFO "$(echo $tconf | wc -w)x TCONF:$tconf"
146	runtest_res
147
148	return $ret
149}
150
151run_c_tests()
152{
153	local ret srcdir="$PWD"
154
155	if [ "$builddir" ]; then
156		cd $builddir/lib/newlib_tests
157	fi
158
159	run_tests "C" "$srcdir"
160	ret=$?
161
162	if [ "$builddir" ]; then
163		cd "$srcdir"
164	fi
165
166	return $ret
167}
168
169run_shell_tests()
170{
171	run_tests "SHELL"
172}
173
174
175print_result()
176{
177	local target="$1"
178	local res="$2"
179
180
181	if [ -z "$res" ]; then
182		runtest_res TCONF "$target tests skipped"
183	elif [ $res -eq 0 ]; then
184		runtest_res TPASS "All $target tests TCONF/TPASS"
185	else
186		runtest_res TFAIL "Some $target test(s) TBROK/TFAIL/TWARN"
187	fi
188}
189
190builddir=
191c_fail=
192run=
193shell_fail=
194
195while getopts b:chs opt; do
196	case $opt in
197		'h') usage; exit 0;;
198		'b') builddir=$OPTARG; PATH="$builddir/testcases/lib:$PATH";;
199		'c') run="c";;
200		's') run="s";;
201		*) usage; runtest_brk TBROK "Error: invalid option";;
202	esac
203done
204
205runtest_res TINFO "PATH='$PATH'"
206
207if [ -z "$run" -o "$run" = "c" ]; then
208	run_c_tests
209	c_fail=$?
210fi
211
212if [ -z "$run" -o "$run" = "s" ]; then
213	export KCONFIG_PATH=config02
214	runtest_res TINFO "KCONFIG_PATH='$KCONFIG_PATH'"
215	run_shell_tests
216	shell_fail=$?
217fi
218
219runtest_res TINFO "=== FINAL TEST RESULTS ==="
220
221print_result "C" "$c_fail"
222print_result "shell" "$shell_fail"
223
224exit $((c_fail|shell_fail))
225