1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
#!/usr/bin/env bash
# Tests library functions and types.
#
# Version: 20240413
EXIT_SUCCESS=0;
EXIT_FAILURE=1;
EXIT_IGNORE=77;
LIBRARY_TESTS="attribute attribute_list_entry bitmap_values buffer_data_handle cluster_block cluster_block_data cluster_block_stream cluster_block_vector compressed_block compressed_block_data_handle compressed_block_vector compressed_data_handle compression compression_unit_data_handle compression_unit_descriptor data_run data_stream directory_entries_tree directory_entry error extent file_entry file_name_attribute file_name_values file_system fixup_values index index_entry index_entry_header index_entry_vector index_node index_node_header index_root_header index_value io_handle logged_utility_stream_values mft mft_attribute mft_attribute_list mft_attribute_list_entry mft_entry mft_entry_header name notify object_identifier_values path_hint profiler reparse_point_attribute reparse_point_values sds_index_value security_descriptor_index security_descriptor_index_value security_descriptor_values standard_information_values txf_data_values usn_change_journal volume_header volume_information_attribute volume_information_values volume_name_attribute volume_name_values";
LIBRARY_TESTS_WITH_INPUT="mft_metadata_file support volume";
OPTION_SETS=("offset");
INPUT_GLOB="*";
run_test()
{
local TEST_NAME=$1;
local TEST_DESCRIPTION="Testing: ${TEST_NAME}";
local TEST_EXECUTABLE="./fsntfs_test_${TEST_NAME}";
if ! test -x "${TEST_EXECUTABLE}";
then
TEST_EXECUTABLE="${TEST_EXECUTABLE}.exe";
fi
# TODO: add support for TEST_PROFILE and OPTION_SETS?
run_test_with_arguments "${TEST_DESCRIPTION}" "${TEST_EXECUTABLE}";
local RESULT=$?;
return ${RESULT};
}
run_test_with_input()
{
local TEST_NAME=$1;
local TEST_DESCRIPTION="Testing: ${TEST_NAME}";
local TEST_EXECUTABLE="./fsntfs_test_${TEST_NAME}";
if ! test -x "${TEST_EXECUTABLE}";
then
TEST_EXECUTABLE="${TEST_EXECUTABLE}.exe";
fi
if ! test -d "input";
then
echo "Test input directory not found.";
return ${EXIT_IGNORE};
fi
local RESULT=`ls input/* | tr ' ' '\n' | wc -l`;
if test ${RESULT} -eq ${EXIT_SUCCESS};
then
echo "No files or directories found in the test input directory";
return ${EXIT_IGNORE};
fi
local TEST_PROFILE_DIRECTORY=$(get_test_profile_directory "input" "libfsntfs");
local IGNORE_LIST=$(read_ignore_list "${TEST_PROFILE_DIRECTORY}");
RESULT=${EXIT_SUCCESS};
for TEST_SET_INPUT_DIRECTORY in input/*;
do
if ! test -d "${TEST_SET_INPUT_DIRECTORY}";
then
continue;
fi
if check_for_directory_in_ignore_list "${TEST_SET_INPUT_DIRECTORY}" "${IGNORE_LIST}";
then
continue;
fi
local TEST_SET_DIRECTORY=$(get_test_set_directory "${TEST_PROFILE_DIRECTORY}" "${TEST_SET_INPUT_DIRECTORY}");
if test -f "${TEST_SET_DIRECTORY}/files";
then
IFS="" read -a INPUT_FILES <<< $(cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?");
else
IFS="" read -a INPUT_FILES <<< $(ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB});
fi
for INPUT_FILE in "${INPUT_FILES[@]}";
do
OPTION_INPUT_FILE="${INPUT_FILE}";
if test "${OSTYPE}" = "msys";
then
# A test executable built with MinGW expects a Windows path.
INPUT_FILE=`echo ${INPUT_FILE} | sed 's?/?\\\\?g'`;
fi
local TESTED_WITH_OPTIONS=0;
for OPTION_SET in ${OPTION_SETS[@]};
do
local TEST_DATA_OPTION_FILE=$(get_test_data_option_file "${TEST_SET_DIRECTORY}" "${OPTION_INPUT_FILE}" "${OPTION_SET}");
if test -f ${TEST_DATA_OPTION_FILE};
then
TESTED_WITH_OPTIONS=1;
IFS=" " read -a OPTIONS <<< $(read_test_data_option_file "${TEST_SET_DIRECTORY}" "${INPUT_FILE}" "${OPTION_SET}");
run_test_on_input_file "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SET}" "${TEST_EXECUTABLE}" "${INPUT_FILE}" "${OPTIONS[@]}";
RESULT=$?;
if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
fi
done
if test ${TESTED_WITH_OPTIONS} -eq 0;
then
run_test_on_input_file "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "" "${TEST_EXECUTABLE}" "${INPUT_FILE}";
RESULT=$?;
fi
if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done
if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done
return ${RESULT};
}
if test -n "${SKIP_LIBRARY_TESTS}";
then
exit ${EXIT_IGNORE};
fi
TEST_DIRECTORY=`dirname $0`;
TEST_RUNNER="${TEST_DIRECTORY}/test_runner.sh";
if ! test -f "${TEST_RUNNER}";
then
echo "Missing test runner: ${TEST_RUNNER}";
exit ${EXIT_FAILURE};
fi
source ${TEST_RUNNER};
RESULT=${EXIT_IGNORE};
for TEST_NAME in ${LIBRARY_TESTS};
do
run_test "${TEST_NAME}";
RESULT=$?;
if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done
if test ${RESULT} -ne ${EXIT_SUCCESS} && test ${RESULT} -ne ${EXIT_IGNORE};
then
exit ${RESULT};
fi
for TEST_NAME in ${LIBRARY_TESTS_WITH_INPUT};
do
if test -d "input";
then
run_test_with_input "${TEST_NAME}";
RESULT=$?;
else
run_test "${TEST_NAME}";
RESULT=$?;
fi
if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done
exit ${RESULT};
|