1#!/bin/bash
2# Info tool testing script
3#
4# Version: 20200705
5
6EXIT_SUCCESS=0;
7EXIT_FAILURE=1;
8EXIT_IGNORE=77;
9
10PROFILES=("fsapfsinfo" "fsapfsinfo_fs");
11OPTIONS_PER_PROFILE=("" "-H");
12OPTION_SETS="offset password";
13
14INPUT_GLOB="*";
15
16if test -n "${SKIP_TOOLS_TESTS}" || test -n "${SKIP_TOOLS_END_TO_END_TESTS}";
17then
18	exit ${EXIT_IGNORE};
19fi
20
21TEST_EXECUTABLE="../fsapfstools/fsapfsinfo";
22
23if ! test -x "${TEST_EXECUTABLE}";
24then
25	TEST_EXECUTABLE="../fsapfstools/fsapfsinfo.exe";
26fi
27
28if ! test -x "${TEST_EXECUTABLE}";
29then
30	echo "Missing test executable: ${TEST_EXECUTABLE}";
31
32	exit ${EXIT_FAILURE};
33fi
34
35TEST_RUNNER="tests/test_runner.sh";
36
37if ! test -f "${TEST_RUNNER}";
38then
39	TEST_RUNNER="./test_runner.sh";
40fi
41
42if ! test -f "${TEST_RUNNER}";
43then
44	echo "Missing test runner: ${TEST_RUNNER}";
45
46	exit ${EXIT_FAILURE};
47fi
48
49source ${TEST_RUNNER};
50
51if ! test -d "input";
52then
53	echo "Test input directory not found.";
54
55	exit ${EXIT_IGNORE};
56fi
57RESULT=`ls input/* | tr ' ' '\n' | wc -l`;
58
59if test ${RESULT} -eq ${EXIT_SUCCESS};
60then
61	echo "No files or directories found in the test input directory";
62
63	exit ${EXIT_IGNORE};
64fi
65
66for PROFILE_INDEX in ${!PROFILES[*]};
67do
68	TEST_PROFILE=${PROFILES[${PROFILE_INDEX}]};
69
70	TEST_PROFILE_DIRECTORY=$(get_test_profile_directory "input" "${TEST_PROFILE}");
71
72	IGNORE_LIST=$(read_ignore_list "${TEST_PROFILE_DIRECTORY}");
73
74	IFS=" " read -a OPTIONS <<< ${OPTIONS_PER_PROFILE[${PROFILE_INDEX}]};
75
76	RESULT=${EXIT_SUCCESS};
77
78	for TEST_SET_INPUT_DIRECTORY in input/*;
79	do
80		if ! test -d "${TEST_SET_INPUT_DIRECTORY}";
81		then
82			continue;
83		fi
84		TEST_SET=`basename ${TEST_SET_INPUT_DIRECTORY}`;
85
86		if check_for_test_set_in_ignore_list "${TEST_SET}" "${IGNORE_LIST}";
87		then
88			continue;
89		fi
90		TEST_SET_DIRECTORY=$(get_test_set_directory "${TEST_PROFILE_DIRECTORY}" "${TEST_SET_INPUT_DIRECTORY}");
91
92		run_test_on_test_set_with_options "${TEST_SET_DIRECTORY}" "fsapfsinfo" "with_stdout_reference" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${OPTIONS[@]}";
93		RESULT=$?;
94
95		# Ignore failures due to corrupted data.
96		if test "${TEST_SET}" = "corrupted";
97		then
98			RESULT=${EXIT_SUCCESS};
99		fi
100		if test ${RESULT} -ne ${EXIT_SUCCESS};
101		then
102			break;
103		fi
104	done
105done
106
107exit ${RESULT};
108
109