1#!/bin/bash
2# Info tool testing script
3#
4# Version: 20200223
5
6EXIT_SUCCESS=0;
7EXIT_FAILURE=1;
8EXIT_IGNORE=77;
9
10PROFILES=("fsntfsinfo_bodyfile_fs" "fsntfsinfo_bodyfile_mft");
11OPTIONS_PER_PROFILE=("-Bbodyfile -H" "-Bbodyfile -Eall");
12OPTION_SETS="offset";
13
14INPUT_GLOB="*";
15
16test_callback()
17{
18	local TMPDIR=$1;
19	local TEST_SET_DIRECTORY=$2;
20	local TEST_OUTPUT=$3;
21	local TEST_EXECUTABLE=$4;
22	local TEST_INPUT=$5;
23	shift 5;
24	local ARGUMENTS=("$@");
25
26	TEST_EXECUTABLE=$( readlink_f "${TEST_EXECUTABLE}" );
27	INPUT_FILE_FULL_PATH=$( readlink_f "${INPUT_FILE}" );
28
29	(cd ${TMPDIR} && run_test_with_input_and_arguments "${TEST_EXECUTABLE}" "${INPUT_FILE_FULL_PATH}" ${ARGUMENTS[@]} >/dev/null);
30	local RESULT=$?;
31
32	if test ${RESULT} -eq ${EXIT_SUCCESS};
33	then
34		local TEST_RESULTS="${TMPDIR}/bodyfile";
35		local STORED_TEST_RESULTS="${TEST_SET_DIRECTORY}/${TEST_OUTPUT}-bodyfile.gz";
36
37		if test -f "${STORED_TEST_RESULTS}";
38		then
39			# Using zcat here since zdiff has issues on Mac OS X.
40			# Note that zcat on Mac OS X requires the input from stdin.
41			zcat < "${STORED_TEST_RESULTS}" | diff "${TEST_RESULTS}" -;
42			RESULT=$?;
43		else
44			gzip ${TEST_RESULTS};
45
46			mv "${TEST_RESULTS}.gz" "${TEST_SET_DIRECTORY}/${TEST_OUTPUT}-bodyfile.gz";
47		fi
48	fi
49	return ${RESULT};
50}
51
52if ! test -z ${SKIP_TOOLS_TESTS};
53then
54	exit ${EXIT_IGNORE};
55fi
56
57TEST_EXECUTABLE="../fsntfstools/fsntfsinfo";
58
59if ! test -x "${TEST_EXECUTABLE}";
60then
61	TEST_EXECUTABLE="../fsntfstools/fsntfsinfo.exe";
62fi
63
64if ! test -x "${TEST_EXECUTABLE}";
65then
66	echo "Missing test executable: ${TEST_EXECUTABLE}";
67
68	exit ${EXIT_FAILURE};
69fi
70
71TEST_RUNNER="tests/test_runner.sh";
72
73if ! test -f "${TEST_RUNNER}";
74then
75	TEST_RUNNER="./test_runner.sh";
76fi
77
78if ! test -f "${TEST_RUNNER}";
79then
80	echo "Missing test runner: ${TEST_RUNNER}";
81
82	exit ${EXIT_FAILURE};
83fi
84
85source ${TEST_RUNNER};
86
87if ! test -d "input";
88then
89	echo "Test input directory not found.";
90
91	exit ${EXIT_IGNORE};
92fi
93RESULT=`ls input/* | tr ' ' '\n' | wc -l`;
94
95if test ${RESULT} -eq ${EXIT_SUCCESS};
96then
97	echo "No files or directories found in the test input directory";
98
99	exit ${EXIT_IGNORE};
100fi
101
102for PROFILE_INDEX in ${!PROFILES[*]};
103do
104	TEST_PROFILE=${PROFILES[${PROFILE_INDEX}]};
105
106	TEST_PROFILE_DIRECTORY=$(get_test_profile_directory "input" "${TEST_PROFILE}");
107
108	IGNORE_LIST=$(read_ignore_list "${TEST_PROFILE_DIRECTORY}");
109
110	IFS=" " read -a OPTIONS <<< ${OPTIONS_PER_PROFILE[${PROFILE_INDEX}]};
111
112	RESULT=${EXIT_SUCCESS};
113
114	for TEST_SET_INPUT_DIRECTORY in input/*;
115	do
116		if ! test -d "${TEST_SET_INPUT_DIRECTORY}";
117		then
118			continue;
119		fi
120		TEST_SET=`basename ${TEST_SET_INPUT_DIRECTORY}`;
121
122		if check_for_test_set_in_ignore_list "${TEST_SET}" "${IGNORE_LIST}";
123		then
124			continue;
125		fi
126		TEST_SET_DIRECTORY=$(get_test_set_directory "${TEST_PROFILE_DIRECTORY}" "${TEST_SET_INPUT_DIRECTORY}");
127
128		run_test_on_test_set_with_options "${TEST_SET_DIRECTORY}" "fsntfsinfo" "with_callback" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${OPTIONS[@]}";
129		RESULT=$?;
130
131		# Ignore failures due to corrupted data.
132		if test "${TEST_SET}" = "corrupted";
133		then
134			RESULT=${EXIT_SUCCESS};
135		fi
136		if test ${RESULT} -ne ${EXIT_SUCCESS};
137		then
138			break;
139		fi
140	done
141done
142
143exit ${RESULT};
144
145