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