1#!/bin/bash
2# Tests Python module functions and types.
3#
4# Version: 20200705
5
6EXIT_SUCCESS=0;
7EXIT_FAILURE=1;
8EXIT_IGNORE=77;
9
10TEST_FUNCTIONS="support";
11TEST_FUNCTIONS_WITH_INPUT="volume";
12OPTION_SETS="offset";
13
14TEST_TOOL_DIRECTORY=".";
15INPUT_GLOB="*";
16
17test_python_function()
18{
19	local TEST_FUNCTION=$1;
20
21	local TEST_DESCRIPTION="Testing Python-bindings functions: ${TEST_FUNCTION}";
22	local TEST_SCRIPT="${TEST_TOOL_DIRECTORY}/pyfsext_test_${TEST_FUNCTION}.py";
23
24	run_test_with_arguments "${TEST_DESCRIPTION}" "${TEST_SCRIPT}";
25	local RESULT=$?;
26
27	return ${RESULT};
28}
29
30test_python_function_with_input()
31{
32	local TEST_FUNCTION=$1;
33
34	local TEST_DESCRIPTION="Testing Python-bindings functions: ${TEST_FUNCTION}";
35	local TEST_SCRIPT="${TEST_TOOL_DIRECTORY}/pyfsext_test_${TEST_FUNCTION}.py";
36
37	if ! test -d "input";
38	then
39		echo "Test input directory not found.";
40
41		return ${EXIT_IGNORE};
42	fi
43	local RESULT=`ls input/* | tr ' ' '\n' | wc -l`;
44
45	if test ${RESULT} -eq ${EXIT_SUCCESS};
46	then
47		echo "No files or directories found in the test input directory";
48
49		return ${EXIT_IGNORE};
50	fi
51
52	local TEST_PROFILE_DIRECTORY=$(get_test_profile_directory "input" "pyfsext");
53
54	local IGNORE_LIST=$(read_ignore_list "${TEST_PROFILE_DIRECTORY}");
55
56	RESULT=${EXIT_SUCCESS};
57
58	for TEST_SET_INPUT_DIRECTORY in input/*;
59	do
60		if ! test -d "${TEST_SET_INPUT_DIRECTORY}";
61		then
62			continue;
63		fi
64		if check_for_directory_in_ignore_list "${TEST_SET_INPUT_DIRECTORY}" "${IGNORE_LIST}";
65		then
66			continue;
67		fi
68
69		local TEST_SET_DIRECTORY=$(get_test_set_directory "${TEST_PROFILE_DIRECTORY}" "${TEST_SET_INPUT_DIRECTORY}");
70
71		local OLDIFS=${IFS};
72
73		# IFS="\n"; is not supported by all platforms.
74		IFS="
75";
76
77		if test -f "${TEST_SET_DIRECTORY}/files";
78		then
79			for INPUT_FILE in `cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?"`;
80			do
81				run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_SCRIPT}" "${INPUT_FILE}";
82				RESULT=$?;
83
84				if test ${RESULT} -ne ${EXIT_SUCCESS};
85				then
86					break;
87				fi
88			done
89		else
90			for INPUT_FILE in `ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB}`;
91			do
92				run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_SCRIPT}" "${INPUT_FILE}";
93				RESULT=$?;
94
95				if test ${RESULT} -ne ${EXIT_SUCCESS};
96				then
97					break;
98				fi
99			done
100		fi
101		IFS=${OLDIFS};
102
103		if test ${RESULT} -ne ${EXIT_SUCCESS};
104		then
105			break;
106		fi
107	done
108
109	return ${RESULT};
110}
111
112if test -n "${SKIP_PYTHON_TESTS}";
113then
114	exit ${EXIT_IGNORE};
115fi
116
117TEST_RUNNER="tests/test_runner.sh";
118
119if ! test -f "${TEST_RUNNER}";
120then
121	TEST_RUNNER="./test_runner.sh";
122fi
123
124if ! test -f "${TEST_RUNNER}";
125then
126	echo "Missing test runner: ${TEST_RUNNER}";
127
128	exit ${EXIT_FAILURE};
129fi
130
131source ${TEST_RUNNER};
132
133RESULT=${EXIT_IGNORE};
134
135for TEST_FUNCTION in ${TEST_FUNCTIONS};
136do
137	test_python_function "${TEST_FUNCTION}";
138	RESULT=$?;
139
140	if test ${RESULT} -ne ${EXIT_SUCCESS};
141	then
142		break;
143	fi
144done
145
146if test ${RESULT} -ne ${EXIT_SUCCESS} && test ${RESULT} -ne ${EXIT_IGNORE};
147then
148	exit ${RESULT};
149fi
150
151for TEST_FUNCTION in ${TEST_FUNCTIONS_WITH_INPUT};
152do
153	if test -d "input";
154	then
155		test_python_function_with_input "${TEST_FUNCTION}";
156		RESULT=$?;
157	else
158		test_python_function "${TEST_FUNCTION}";
159		RESULT=$?;
160	fi
161
162	if test ${RESULT} -ne ${EXIT_SUCCESS};
163	then
164		break;
165	fi
166done
167
168exit ${RESULT};
169
170