• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# Copyright (c) 2024 Petr Vorel <pvorel@suse.cz>
3
4TESTS_PASS="
5shell_loader.sh
6shell_loader_all_filesystems.sh
7shell_loader_c_child.sh
8shell_loader_filesystems.sh
9shell_loader_kconfigs.sh
10shell_loader_supported_archs.sh
11shell_loader_tcnt.sh
12shell_test01
13shell_test02
14shell_test03
15shell_test04
16shell_test05"
17
18TESTS_FAIL="shell_loader_tags.sh"
19
20TESTS_TBROK="
21shell_loader_invalid_block.sh
22shell_loader_invalid_metadata.sh
23shell_loader_no_metadata.sh
24shell_loader_wrong_metadata.sh"
25
26TESTS_TCONF="shell_test06"
27
28FAIL=
29
30srcdir="$(realpath $(dirname $0))"
31builddir="$srcdir"
32
33usage()
34{
35	cat << EOF
36Usage: $0 [-b DIR ] [-s TESTS]
37-b DIR   build directory (required for out-of-tree build)
38-h       print this help
39EOF
40}
41
42while getopts b:h opt; do
43	case $opt in
44		'h') usage; exit 0;;
45		'b')
46			builddir="$OPTARG/testcases/lib/"
47			if [ ! -d "$builddir" ]; then
48				echo "directory '$builddir' does not exist!" >&2
49				exit 1
50			fi
51			;;
52		*) usage; runtest_brk TBROK "Error: invalid option";;
53	esac
54done
55
56# srcdir is for *.sh, builddir for *.c
57export PATH="$PATH:$srcdir:$builddir:$srcdir/tests/:$builddir/tests/"
58
59
60tst_mask2flag()
61{
62	case "$1" in
63	0) echo TPASS;;
64	1) echo TFAIL;;
65	2) echo TBROK;;
66	4) echo TWARN;;
67	16) echo TINFO;;
68	32) echo TCONF;;
69	esac
70}
71
72run_tests()
73{
74	local exp="$1"
75	local test rc
76	shift
77
78	for test in "$@"; do
79		printf "\n*** Running '$test' (exp: $(tst_mask2flag $exp)) ***\n"
80		$test
81		rc=$?
82		if [ "$rc" = 127 ]; then
83			echo "Test '$test' not found, maybe out-of-tree build and unset builddir?" >&2
84			exit 1
85		elif [ "$rc" != "$exp" ]; then
86			FAIL="$FAIL\n* $test ($(tst_mask2flag $rc), exp: $(tst_mask2flag $exp))"
87		fi
88	done
89}
90
91run_tests 0 $TESTS_PASS
92run_tests 32 $TESTS_TCONF
93
94echo
95echo "*** Testing LTP test -h option ***"
96echo
97run_tests 0 "shell_loader.sh -h"
98
99echo
100echo "*** Testing LTP test -i option ***"
101echo
102run_tests 0 "shell_loader.sh -i 2"
103
104echo
105echo "***** RESULTS *****"
106
107if [ "$FAIL" ]; then
108	printf "Failed tests:$FAIL\n"
109	exit 1
110fi
111
112echo "All tests passed"
113