2 ## Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 ## This source code is subject to the terms of the BSD 2 Clause License and
5 ## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 ## was not distributed with this source code in the LICENSE file, you can
7 ## obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 ## Media Patent License 1.0 was not distributed with this source code in the
9 ## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
11 ## This file contains shell code shared by test scripts for libaom tools.
13 # Use $AOM_TEST_TOOLS_COMMON_SH as a pseudo include guard.
14 if [ -z "${AOM_TEST_TOOLS_COMMON_SH}" ]; then
15 AOM_TEST_TOOLS_COMMON_SH
=included
18 devnull
='> /dev/null 2>&1'
26 if [ "${AOM_TEST_VERBOSE_OUTPUT}" = "yes" ]; then
31 # Sets $AOM_TOOL_TEST to the name specified by positional parameter one.
36 # Clears the AOM_TOOL_TEST variable after confirming that $AOM_TOOL_TEST matches
37 # positional parameter one.
39 if [ "$1" != "${AOM_TOOL_TEST}" ]; then
40 echo "FAIL completed test mismatch!."
41 echo " completed test: ${1}"
42 echo " active test: ${AOM_TOOL_TEST}."
45 AOM_TOOL_TEST
='<unset>'
48 # Echoes the target configuration being tested.
49 test_configuration_target
() {
50 aom_config_mk
="${LIBAOM_CONFIG_PATH}/config.mk"
51 # TODO(tomfinegan): Remove the parts requiring config.mk when the configure
52 # script is removed from the repository.
53 if [ ! -f "${aom_config_mk}" ]; then
54 aom_config_c
="${LIBAOM_CONFIG_PATH}/aom_config.c"
55 # Clean up the cfg pointer line from aom_config.c for easier re-use by
56 # someone examining a failure in the example tests.
57 # 1. Run grep on aom_config.c for cfg and limit the results to 1.
58 # 2. Split the line using ' = ' as separator.
59 # 3. Abuse sed to consume the leading " and trailing "; from the assignment
61 cmake_config
=$
(awk -F ' = ' '/cfg/ { print $NF; exit }' "${aom_config_c}" \
62 |
sed -e s
/\"// -e s
/\"\
;//)
63 echo cmake generated via
command: cmake path
/to
/aom
${cmake_config}
66 # Find the TOOLCHAIN line, split it using ':=' as the field separator, and
67 # print the last field to get the value. Then pipe the value to tr to consume
68 # any leading/trailing spaces while allowing tr to echo the output to stdout.
69 awk -F ':=' '/TOOLCHAIN/ { print $NF }' "${aom_config_mk}" |
tr -d ' '
72 # Trap function used for failure reports and tool output directory removal.
73 # When the contents of $AOM_TOOL_TEST do not match the string '<unset>', reports
74 # failure of test stored in $AOM_TOOL_TEST.
76 if [ -n "${AOM_TOOL_TEST}" ] && [ "${AOM_TOOL_TEST}" != '<unset>' ]; then
77 echo "FAIL: $AOM_TOOL_TEST"
79 if [ -n "${AOM_TEST_OUTPUT_DIR}" ] && [ -d "${AOM_TEST_OUTPUT_DIR}" ]; then
80 rm -rf "${AOM_TEST_OUTPUT_DIR}"
84 # Echoes the git hash portion of the VERSION_STRING variable defined in
85 # $LIBAOM_CONFIG_PATH/config.mk to stdout, or the version number string when
86 # no git hash is contained in VERSION_STRING.
88 aom_config_mk
="${LIBAOM_CONFIG_PATH}/config.mk"
89 if [ ! -f "${aom_config_mk}" ]; then
90 aom_config_c
="${LIBAOM_CONFIG_PATH}/aom_config.c"
91 # Clean up the aom_git_hash pointer line from aom_config.c.
92 # 1. Run grep on aom_config.c for aom_git_hash and limit results to 1.
93 # 2. Split the line using ' = "' as separator.
94 # 3. Abuse sed to consume the trailing "; from the assignment to the
95 # aom_git_hash pointer.
96 awk -F ' = "' '/aom_git_hash/ { print $NF; exit }' "${aom_config_c}" \
101 # Find VERSION_STRING line, split it with "-g" and print the last field to
102 # output the git hash to stdout.
103 aom_version
=$
(awk -F -g '/VERSION_STRING/ {print $NF}' "${aom_config_mk}")
104 # Handle two situations here:
105 # 1. The default case: $aom_version is a git hash, so echo it unchanged.
106 # 2. When being run a non-dev tree, the -g portion is not present in the
107 # version string: It's only the version number.
108 # In this case $aom_version is something like 'VERSION_STRING=v1.3.0', so
109 # we echo only what is after the '='.
110 echo "${aom_version##*=}"
113 # Echoes the short form of the current git hash.
115 if git
--version > /dev
/null
2>&1; then
116 (cd "$(dirname "${0}")"
119 # Return the config hash if git is unavailable: Fail silently, git hashes
120 # are used only for warnings.
125 # Echoes warnings to stdout when git hash in aom_config.h does not match the
128 hash_at_configure_time
=$
(config_hash
)
129 hash_now
=$
(current_hash
)
131 if [ "${hash_at_configure_time}" != "${hash_now}" ]; then
132 echo "Warning: git hash has changed since last configure."
133 vlog
" config hash: ${hash_at_configure_time} hash now: ${hash_now}"
137 # $1 is the name of an environment variable containing a directory name to
140 local dir
=$
(eval echo "\${$1}")
141 if [ ! -d "${dir}" ]; then
142 elog
"'${dir}': No such directory"
143 elog
"The $1 environment variable must be set to a valid directory."
148 # This script requires that the LIBAOM_BIN_PATH, LIBAOM_CONFIG_PATH, and
149 # LIBAOM_TEST_DATA_PATH variables are in the environment: Confirm that
150 # the variables are set and that they all evaluate to directory paths.
151 verify_aom_test_environment
() {
152 test_env_var_dir
"LIBAOM_BIN_PATH" \
153 && test_env_var_dir
"LIBAOM_CONFIG_PATH" \
154 && test_env_var_dir
"LIBAOM_TEST_DATA_PATH"
157 # Greps aom_config.h in LIBAOM_CONFIG_PATH for positional parameter one, which
158 # should be a LIBAOM preprocessor flag. Echoes yes to stdout when the feature
160 aom_config_option_enabled
() {
161 aom_config_option
="${1}"
162 aom_config_file
="${LIBAOM_CONFIG_PATH}/aom_config.h"
163 config_line
=$
(grep "${aom_config_option}" "${aom_config_file}")
164 if echo "${config_line}" |
egrep -q '1$'; then
169 # Echoes yes when output of test_configuration_target() contains win32 or win64.
170 is_windows_target
() {
171 if test_configuration_target \
172 |
grep -q -e win32
-e win64
> /dev
/null
2>&1; then
177 # Echoes path to $1 when it's executable and exists in ${LIBAOM_BIN_PATH}, or an
178 # empty string. Caller is responsible for testing the string once the function
181 local readonly tool_name
="$1"
182 local tool_path
="${LIBAOM_BIN_PATH}/${tool_name}${AOM_TEST_EXE_SUFFIX}"
183 if [ ! -x "${tool_path}" ]; then
184 # Try one directory up: when running via examples.sh the tool could be in
185 # the parent directory of $LIBAOM_BIN_PATH.
186 tool_path
="${LIBAOM_BIN_PATH}/../${tool_name}${AOM_TEST_EXE_SUFFIX}"
189 if [ ! -x "${tool_path}" ]; then
195 # Echoes yes to stdout when the file named by positional parameter one exists
196 # in LIBAOM_BIN_PATH, and is executable.
197 aom_tool_available
() {
199 local tool
="${LIBAOM_BIN_PATH}/${tool_name}${AOM_TEST_EXE_SUFFIX}"
200 [ -x "${tool}" ] && echo yes
203 # Echoes yes to stdout when aom_config_option_enabled() reports yes for
204 # CONFIG_AV1_DECODER.
205 av1_decode_available
() {
206 [ "$(aom_config_option_enabled CONFIG_AV1_DECODER)" = "yes" ] && echo yes
209 # Echoes yes to stdout when aom_config_option_enabled() reports yes for
210 # CONFIG_AV1_ENCODER.
211 av1_encode_available
() {
212 [ "$(aom_config_option_enabled CONFIG_AV1_ENCODER)" = "yes" ] && echo yes
215 # Echoes yes to stdout when aom_config_option_enabled() reports yes for
217 webm_io_available
() {
218 [ "$(aom_config_option_enabled CONFIG_WEBM_IO)" = "yes" ] && echo yes
221 # Filters strings from $1 using the filter specified by $2. Filter behavior
222 # depends on the presence of $3. When $3 is present, strings that match the
223 # filter are excluded. When $3 is omitted, strings matching the filter are
225 # The filtered result is echoed to stdout.
231 if [ -n "${exclude}" ]; then
232 # When positional parameter three exists the caller wants to remove strings.
233 # Tell grep to invert matches using the -v argument.
239 if [ -n "${filter}" ]; then
240 for s
in ${strings}; do
241 if echo "${s}" | egrep -q ${exclude} "${filter}" > /dev
/null
2>&1; then
242 filtered_strings
="${filtered_strings} ${s}"
246 filtered_strings
="${strings}"
248 echo "${filtered_strings}"
251 # Runs user test functions passed via positional parameters one and two.
252 # Functions in positional parameter one are treated as environment verification
253 # functions and are run unconditionally. Functions in positional parameter two
254 # are run according to the rules specified in aom_test_usage().
256 local env_tests
="verify_aom_test_environment $1"
257 local tests_to_filter
="$2"
258 local test_name
="${AOM_TEST_NAME}"
260 if [ -z "${test_name}" ]; then
261 test_name
="$(basename "${0%.*}")"
264 if [ "${AOM_TEST_RUN_DISABLED_TESTS}" != "yes" ]; then
265 # Filter out DISABLED tests.
266 tests_to_filter
=$
(filter_strings
"${tests_to_filter}" ^DISABLED exclude
)
269 if [ -n "${AOM_TEST_FILTER}" ]; then
270 # Remove tests not matching the user's filter.
271 tests_to_filter
=$
(filter_strings
"${tests_to_filter}" ${AOM_TEST_FILTER})
274 # User requested test listing: Dump test names and return.
275 if [ "${AOM_TEST_LIST_TESTS}" = "yes" ]; then
276 for test_name
in $tests_to_filter; do
282 # Don't bother with the environment tests if everything else was disabled.
283 [ -z "${tests_to_filter}" ] && return
285 # Combine environment and actual tests.
286 local tests_to_run
="${env_tests} ${tests_to_filter}"
291 for test in ${tests_to_run}; do
299 local tested_config
="$(test_configuration_target) @ $(current_hash)"
300 echo "${test_name}: Done, all tests pass for ${tested_config}."
305 Usage: ${0##*/} [arguments]
306 --bin-path <path to libaom binaries directory>
307 --config-path <path to libaom config directory>
308 --filter <filter>: User test filter. Only tests matching filter are run.
309 --run-disabled-tests: Run disabled tests.
310 --help: Display this message and exit.
311 --test-data-path <path to libaom test data directory>
312 --show-program-output: Shows output from all programs being tested.
313 --prefix: Allows for a user specified prefix to be inserted before all test
314 programs. Grants the ability, for example, to run test programs
316 --list-tests: List all test names and exit without actually running tests.
317 --verbose: Verbose output.
319 When the --bin-path option is not specified the script attempts to use
320 \$LIBAOM_BIN_PATH and then the current directory.
322 When the --config-path option is not specified the script attempts to use
323 \$LIBAOM_CONFIG_PATH and then the current directory.
325 When the -test-data-path option is not specified the script attempts to use
326 \$LIBAOM_TEST_DATA_PATH and then the current directory.
330 # Returns non-zero (failure) when required environment variables are empty
332 aom_test_check_environment
() {
333 if [ -z "${LIBAOM_BIN_PATH}" ] || \
334 [ -z "${LIBAOM_CONFIG_PATH}" ] || \
335 [ -z "${LIBAOM_TEST_DATA_PATH}" ]; then
340 # Echo aomenc command line parameters allowing use of a raw yuv file as
343 echo ""${YUV_RAW_INPUT}"
344 --width="${YUV_RAW_INPUT_WIDTH}"
345 --height="${YUV_RAW_INPUT_HEIGHT}""
348 # Do a small encode for testing decoders.
349 encode_yuv_raw_input_av1
() {
350 if [ "$(av1_encode_available)" = "yes" ]; then
351 local readonly output
="$1"
352 local readonly encoder
="$(aom_tool_path aomenc)"
354 eval "${encoder}" $
(yuv_raw_input
) \
358 --output="${output}" \
361 if [ ! -e "${output}" ]; then
362 elog
"Output file does not exist."
368 # Parse the command line.
369 while [ -n "$1" ]; do
376 LIBAOM_CONFIG_PATH
="$2"
383 --run-disabled-tests)
384 AOM_TEST_RUN_DISABLED_TESTS
=yes
391 LIBAOM_TEST_DATA_PATH
="$2"
399 AOM_TEST_VERBOSE_OUTPUT
=yes
401 --show-program-output)
405 AOM_TEST_LIST_TESTS
=yes
415 # Handle running the tests from a build directory without arguments when running
416 # the tests on *nix/macosx.
417 LIBAOM_BIN_PATH
="${LIBAOM_BIN_PATH:-.}"
418 LIBAOM_CONFIG_PATH
="${LIBAOM_CONFIG_PATH:-.}"
419 LIBAOM_TEST_DATA_PATH
="${LIBAOM_TEST_DATA_PATH:-.}"
421 # Create a temporary directory for output files, and a trap to clean it up.
422 if [ -n "${TMPDIR}" ]; then
423 AOM_TEST_TEMP_ROOT
="${TMPDIR}"
424 elif [ -n "${TEMPDIR}" ]; then
425 AOM_TEST_TEMP_ROOT
="${TEMPDIR}"
427 AOM_TEST_TEMP_ROOT
=/tmp
430 AOM_TEST_OUTPUT_DIR
="${AOM_TEST_TEMP_ROOT}/aom_test_$$"
432 if ! mkdir
-p "${AOM_TEST_OUTPUT_DIR}" || \
433 [ ! -d "${AOM_TEST_OUTPUT_DIR}" ]; then
434 echo "${0##*/}: Cannot create output directory, giving up."
435 echo "${0##*/}: AOM_TEST_OUTPUT_DIR=${AOM_TEST_OUTPUT_DIR}"
439 if [ "$(is_windows_target)" = "yes" ]; then
440 AOM_TEST_EXE_SUFFIX
=".exe"
443 # Variables shared by tests.
444 VP8_IVF_FILE
="${LIBAOM_TEST_DATA_PATH}/vp80-00-comprehensive-001.ivf"
449 AV1_LT_50_FRAMES_WEBM_FILE
=""
451 YUV_RAW_INPUT
="${LIBAOM_TEST_DATA_PATH}/hantro_collage_w352h288.yuv"
452 YUV_RAW_INPUT_WIDTH
=352
453 YUV_RAW_INPUT_HEIGHT
=288
455 Y4M_NOSQ_PAR_INPUT
="${LIBAOM_TEST_DATA_PATH}/park_joy_90p_8_420_a10-1.y4m"
456 Y4M_720P_INPUT
="${LIBAOM_TEST_DATA_PATH}/niklas_1280_720_30.y4m"
458 # Setup a trap function to clean up after tests complete.
461 vlog
"$(basename "${0%.*}") test configuration:
462 LIBAOM_BIN_PATH=${LIBAOM_BIN_PATH}
463 LIBAOM_CONFIG_PATH=${LIBAOM_CONFIG_PATH}
464 LIBAOM_TEST_DATA_PATH=${LIBAOM_TEST_DATA_PATH}
465 AOM_IVF_FILE=${AOM_IVF_FILE}
466 AV1_IVF_FILE=${AV1_IVF_FILE}
467 AV1_WEBM_FILE=${AV1_WEBM_FILE}
468 AOM_TEST_EXE_SUFFIX=${AOM_TEST_EXE_SUFFIX}
469 AOM_TEST_FILTER=${AOM_TEST_FILTER}
470 AOM_TEST_LIST_TESTS=${AOM_TEST_LIST_TESTS}
471 AOM_TEST_OUTPUT_DIR=${AOM_TEST_OUTPUT_DIR}
472 AOM_TEST_PREFIX=${AOM_TEST_PREFIX}
473 AOM_TEST_RUN_DISABLED_TESTS=${AOM_TEST_RUN_DISABLED_TESTS}
474 AOM_TEST_SHOW_PROGRAM_OUTPUT=${AOM_TEST_SHOW_PROGRAM_OUTPUT}
475 AOM_TEST_TEMP_ROOT=${AOM_TEST_TEMP_ROOT}
476 AOM_TEST_VERBOSE_OUTPUT=${AOM_TEST_VERBOSE_OUTPUT}
477 YUV_RAW_INPUT=${YUV_RAW_INPUT}
478 YUV_RAW_INPUT_WIDTH=${YUV_RAW_INPUT_WIDTH}
479 YUV_RAW_INPUT_HEIGHT=${YUV_RAW_INPUT_HEIGHT}
480 Y4M_NOSQ_PAR_INPUT=${Y4M_NOSQ_PAR_INPUT}"
482 fi # End $AOM_TEST_TOOLS_COMMON_SH pseudo include guard.