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_c
="${LIBAOM_CONFIG_PATH}/config/aom_config.c"
51 # Clean up the cfg pointer line from aom_config.c for easier re-use by
52 # someone examining a failure in the example tests.
53 # 1. Run grep on aom_config.c for cfg and limit the results to 1.
54 # 2. Split the line using ' = ' as separator.
55 # 3. Abuse sed to consume the leading " and trailing "; from the assignment
57 cmake_config
=$
(awk -F ' = ' '/cfg/ { print $NF; exit }' "${aom_config_c}" \
58 |
sed -e s
/\"// -e s
/\"\
;//)
59 echo cmake generated via
command: cmake path
/to
/aom
${cmake_config}
62 # Trap function used for failure reports and tool output directory removal.
63 # When the contents of $AOM_TOOL_TEST do not match the string '<unset>', reports
64 # failure of test stored in $AOM_TOOL_TEST.
66 if [ -n "${AOM_TOOL_TEST}" ] && [ "${AOM_TOOL_TEST}" != '<unset>' ]; then
67 echo "FAIL: $AOM_TOOL_TEST"
69 if [ "${AOM_TEST_PRESERVE_OUTPUT}" = "yes" ]; then
72 if [ -n "${AOM_TEST_OUTPUT_DIR}" ] && [ -d "${AOM_TEST_OUTPUT_DIR}" ]; then
73 rm -rf "${AOM_TEST_OUTPUT_DIR}"
77 # Echoes the version string assigned to the VERSION_STRING_NOSP variable defined
78 # in $LIBAOM_CONFIG_PATH/config/aom_version.h to stdout.
80 aom_version_h
="${LIBAOM_CONFIG_PATH}/config/aom_version.h"
82 # Find VERSION_STRING_NOSP line, split it with '"' and print the next to last
83 # field to output the version string to stdout.
84 aom_version
=$
(awk -F \" '/VERSION_STRING_NOSP/ {print $(NF-1)}' \
86 echo "v${aom_version}"
89 # Echoes current git version as reported by running 'git describe', or the
90 # version used by the cmake build when git is unavailable.
92 if git
--version > /dev
/null
2>&1; then
93 (cd "$(dirname "${0}")"
100 # Echoes warnings to stdout when source version and CMake build generated
101 # version are out of sync.
102 check_version_strings
() {
103 cmake_version
=$
(cmake_version
)
104 source_version
=$
(source_version
)
106 if [ "${cmake_version}" != "${source_version}" ]; then
107 echo "Warning: version has changed since last cmake run."
108 vlog
" cmake version: ${cmake_version} version now: ${source_version}"
112 # $1 is the name of an environment variable containing a directory name to
115 local dir
=$
(eval echo "\${$1}")
116 if [ ! -d "${dir}" ]; then
117 elog
"'${dir}': No such directory"
118 elog
"The $1 environment variable must be set to a valid directory."
123 # This script requires that the LIBAOM_BIN_PATH, LIBAOM_CONFIG_PATH, and
124 # LIBAOM_TEST_DATA_PATH variables are in the environment: Confirm that
125 # the variables are set and that they all evaluate to directory paths.
126 verify_aom_test_environment
() {
127 test_env_var_dir
"LIBAOM_BIN_PATH" \
128 && test_env_var_dir
"LIBAOM_CONFIG_PATH" \
129 && test_env_var_dir
"LIBAOM_TEST_DATA_PATH"
132 # Greps aom_config.h in LIBAOM_CONFIG_PATH for positional parameter one, which
133 # should be a LIBAOM preprocessor flag. Echoes yes to stdout when the feature
135 aom_config_option_enabled
() {
136 aom_config_option
="${1}"
137 aom_config_file
="${LIBAOM_CONFIG_PATH}/config/aom_config.h"
138 config_line
=$
(grep "${aom_config_option}" "${aom_config_file}")
139 if echo "${config_line}" |
egrep -q '1$'; then
144 # Echoes yes when output of test_configuration_target() contains win32 or win64.
145 is_windows_target
() {
146 if test_configuration_target \
147 |
grep -q -e win32
-e win64
> /dev
/null
2>&1; then
152 # Echoes path to $1 when it's executable and exists in one of the directories
153 # included in $tool_paths, or an empty string. Caller is responsible for testing
154 # the string once the function returns.
157 local root_path
="${LIBAOM_BIN_PATH}"
158 local suffix
="${AOM_TEST_EXE_SUFFIX}"
160 ${root_path}/${tool_name}${suffix} \
161 ${root_path}/../${tool_name}${suffix} \
162 ${root_path}/tools/${tool_name}${suffix} \
163 ${root_path}/../tools/${tool_name}${suffix}"
167 for tool_path
in ${tool_paths}; do
168 if [ -x "${tool_path}" ] && [ -f "${tool_path}" ]; then
177 # Echoes yes to stdout when the file named by positional parameter one exists
178 # in LIBAOM_BIN_PATH, and is executable.
179 aom_tool_available
() {
181 local tool
="${LIBAOM_BIN_PATH}/${tool_name}${AOM_TEST_EXE_SUFFIX}"
182 [ -x "${tool}" ] && echo yes
185 # Echoes yes to stdout when aom_config_option_enabled() reports yes for
186 # CONFIG_AV1_DECODER.
187 av1_decode_available
() {
188 [ "$(aom_config_option_enabled CONFIG_AV1_DECODER)" = "yes" ] && echo yes
191 # Echoes yes to stdout when aom_config_option_enabled() reports yes for
192 # CONFIG_AV1_ENCODER.
193 av1_encode_available
() {
194 [ "$(aom_config_option_enabled CONFIG_AV1_ENCODER)" = "yes" ] && echo yes
197 # Echoes "fast" encode params for use with aomenc.
198 aomenc_encode_test_fast_params
() {
200 --limit=${AV1_ENCODE_TEST_FRAME_LIMIT}
205 # Echoes realtime encode params for use with aomenc.
206 aomenc_encode_test_rt_params
() {
207 echo "--limit=${AV1_ENCODE_TEST_FRAME_LIMIT}
211 --enable-order-hint=0
221 --enable-warped-motion=0
222 --enable-ref-frame-mvs=0
224 --enable-order-hint=0
225 --coeff-cost-upd-freq=3
226 --mode-cost-upd-freq=3
227 --mv-cost-upd-freq=3"
230 # Echoes yes to stdout when aom_config_option_enabled() reports yes for
231 # CONFIG_AV1_HIGHBITDEPTH.
232 highbitdepth_available
() {
233 [ "$(aom_config_option_enabled CONFIG_AV1_HIGHBITDEPTH)" = "yes" ] && echo yes
236 # Echoes yes to stdout when aom_config_option_enabled() reports yes for
238 webm_io_available
() {
239 [ "$(aom_config_option_enabled CONFIG_WEBM_IO)" = "yes" ] && echo yes
242 # Echoes yes to stdout when aom_config_option_enabled() reports yes for
243 # CONFIG_REALTIME_ONLY.
244 realtime_only_build
() {
245 [ "$(aom_config_option_enabled CONFIG_REALTIME_ONLY)" = "yes" ] && echo yes
248 # Filters strings from $1 using the filter specified by $2. Filter behavior
249 # depends on the presence of $3. When $3 is present, strings that match the
250 # filter are excluded. When $3 is omitted, strings matching the filter are
252 # The filtered result is echoed to stdout.
258 if [ -n "${exclude}" ]; then
259 # When positional parameter three exists the caller wants to remove strings.
260 # Tell grep to invert matches using the -v argument.
266 if [ -n "${filter}" ]; then
267 for s
in ${strings}; do
268 if echo "${s}" | egrep -q ${exclude} "${filter}" > /dev
/null
2>&1; then
269 filtered_strings
="${filtered_strings} ${s}"
273 filtered_strings
="${strings}"
275 echo "${filtered_strings}"
278 # Runs user test functions passed via positional parameters one and two.
279 # Functions in positional parameter one are treated as environment verification
280 # functions and are run unconditionally. Functions in positional parameter two
281 # are run according to the rules specified in aom_test_usage().
283 local env_tests
="verify_aom_test_environment $1"
284 local tests_to_filter
="$2"
285 local test_name
="${AOM_TEST_NAME}"
287 if [ -z "${test_name}" ]; then
288 test_name
="$(basename "${0%.*}")"
291 if [ "${AOM_TEST_RUN_DISABLED_TESTS}" != "yes" ]; then
292 # Filter out DISABLED tests.
293 tests_to_filter
=$
(filter_strings
"${tests_to_filter}" ^DISABLED exclude
)
296 if [ -n "${AOM_TEST_FILTER}" ]; then
297 # Remove tests not matching the user's filter.
298 tests_to_filter
=$
(filter_strings
"${tests_to_filter}" ${AOM_TEST_FILTER})
301 # User requested test listing: Dump test names and return.
302 if [ "${AOM_TEST_LIST_TESTS}" = "yes" ]; then
303 for test_name
in $tests_to_filter; do
309 # Don't bother with the environment tests if everything else was disabled.
310 [ -z "${tests_to_filter}" ] && return
312 # Combine environment and actual tests.
313 local tests_to_run
="${env_tests} ${tests_to_filter}"
315 # av1_c_vs_simd_encode is a standalone test, and it doesn't need to check the
317 if [ "${test_name}" != "av1_c_vs_simd_encode" ]; then
318 check_version_strings
322 for test in ${tests_to_run}; do
330 local tested_config
="$(test_configuration_target) @ $(source_version)"
331 echo "${test_name}: Done, all tests pass for ${tested_config}."
336 Usage: ${0##*/} [arguments]
337 --bin-path <path to libaom binaries directory>
338 --config-path <path to libaom config directory>
339 --filter <filter>: User test filter. Only tests matching filter are run.
340 --run-disabled-tests: Run disabled tests.
341 --help: Display this message and exit.
342 --test-data-path <path to libaom test data directory>
343 --show-program-output: Shows output from all programs being tested.
344 --prefix: Allows for a user specified prefix to be inserted before all test
345 programs. Grants the ability, for example, to run test programs
347 --list-tests: List all test names and exit without actually running tests.
348 --verbose: Verbose output.
350 When the --bin-path option is not specified the script attempts to use
351 \$LIBAOM_BIN_PATH and then the current directory.
353 When the --config-path option is not specified the script attempts to use
354 \$LIBAOM_CONFIG_PATH and then the current directory.
356 When the -test-data-path option is not specified the script attempts to use
357 \$LIBAOM_TEST_DATA_PATH and then the current directory.
361 # Returns non-zero (failure) when required environment variables are empty
363 aom_test_check_environment
() {
364 if [ -z "${LIBAOM_BIN_PATH}" ] || \
365 [ -z "${LIBAOM_CONFIG_PATH}" ] || \
366 [ -z "${LIBAOM_TEST_DATA_PATH}" ]; then
371 # Echo aomenc command line parameters allowing use of a raw yuv file as
374 echo ""${YUV_RAW_INPUT}"
375 --width="${YUV_RAW_INPUT_WIDTH}"
376 --height="${YUV_RAW_INPUT_HEIGHT}""
379 # Do a small encode for testing decoders.
380 encode_yuv_raw_input_av1
() {
381 if [ "$(av1_encode_available)" = "yes" ]; then
383 local encoder
="$(aom_tool_path aomenc)"
385 eval "${encoder}" $
(yuv_raw_input
) \
386 $
(aomenc_encode_test_fast_params
) \
387 --output="${output}" \
391 if [ ! -e "${output}" ]; then
392 elog
"Output file does not exist."
398 # Parse the command line.
399 while [ -n "$1" ]; do
406 LIBAOM_CONFIG_PATH
="$2"
413 --run-disabled-tests)
414 AOM_TEST_RUN_DISABLED_TESTS
=yes
421 LIBAOM_TEST_DATA_PATH
="$2"
429 AOM_TEST_VERBOSE_OUTPUT
=yes
431 --show-program-output)
435 AOM_TEST_LIST_TESTS
=yes
445 # Handle running the tests from a build directory without arguments when running
446 # the tests on *nix/macosx.
447 LIBAOM_BIN_PATH
="${LIBAOM_BIN_PATH:-.}"
448 LIBAOM_CONFIG_PATH
="${LIBAOM_CONFIG_PATH:-.}"
449 LIBAOM_TEST_DATA_PATH
="${LIBAOM_TEST_DATA_PATH:-.}"
451 # Create a temporary directory for output files, and a trap to clean it up.
452 if [ -n "${TMPDIR}" ]; then
453 AOM_TEST_TEMP_ROOT
="${TMPDIR}"
454 elif [ -n "${TEMPDIR}" ]; then
455 AOM_TEST_TEMP_ROOT
="${TEMPDIR}"
457 AOM_TEST_TEMP_ROOT
=/tmp
460 AOM_TEST_OUTPUT_DIR
="${AOM_TEST_OUTPUT_DIR:-${AOM_TEST_TEMP_ROOT}/aom_test_$$}"
462 if ! mkdir
-p "${AOM_TEST_OUTPUT_DIR}" || \
463 [ ! -d "${AOM_TEST_OUTPUT_DIR}" ]; then
464 echo "${0##*/}: Cannot create output directory, giving up."
465 echo "${0##*/}: AOM_TEST_OUTPUT_DIR=${AOM_TEST_OUTPUT_DIR}"
469 AOM_TEST_PRESERVE_OUTPUT
=${AOM_TEST_PRESERVE_OUTPUT:-no}
471 # This checking requires config/aom_config.c that is available in Jenkins
473 if [ "$(is_windows_target)" = "yes" ]; then
474 AOM_TEST_EXE_SUFFIX
=".exe"
477 # Variables shared by tests.
478 AV1_ENCODE_CPU_USED
=${AV1_ENCODE_CPU_USED:-1}
479 AV1_ENCODE_TEST_FRAME_LIMIT
=${AV1_ENCODE_TEST_FRAME_LIMIT:-5}
480 AV1_IVF_FILE
="${AV1_IVF_FILE:-${AOM_TEST_OUTPUT_DIR}/av1.ivf}"
481 AV1_OBU_ANNEXB_FILE
="${AV1_OBU_ANNEXB_FILE:-${AOM_TEST_OUTPUT_DIR}/av1.annexb.obu}"
482 AV1_OBU_SEC5_FILE
="${AV1_OBU_SEC5_FILE:-${AOM_TEST_OUTPUT_DIR}/av1.section5.obu}"
483 AV1_WEBM_FILE
="${AV1_WEBM_FILE:-${AOM_TEST_OUTPUT_DIR}/av1.webm}"
485 YUV_RAW_INPUT
="${LIBAOM_TEST_DATA_PATH}/hantro_collage_w352h288.yuv"
486 YUV_RAW_INPUT_WIDTH
=352
487 YUV_RAW_INPUT_HEIGHT
=288
489 Y4M_NOSQ_PAR_INPUT
="${LIBAOM_TEST_DATA_PATH}/park_joy_90p_8_420_a10-1.y4m"
490 Y4M_720P_INPUT
="${LIBAOM_TEST_DATA_PATH}/niklas_1280_720_30.y4m"
492 # Setup a trap function to clean up after tests complete.
495 vlog
"$(basename "${0%.*}") test configuration:
496 LIBAOM_BIN_PATH=${LIBAOM_BIN_PATH}
497 LIBAOM_CONFIG_PATH=${LIBAOM_CONFIG_PATH}
498 LIBAOM_TEST_DATA_PATH=${LIBAOM_TEST_DATA_PATH}
499 AOM_TEST_EXE_SUFFIX=${AOM_TEST_EXE_SUFFIX}
500 AOM_TEST_FILTER=${AOM_TEST_FILTER}
501 AOM_TEST_LIST_TESTS=${AOM_TEST_LIST_TESTS}
502 AOM_TEST_OUTPUT_DIR=${AOM_TEST_OUTPUT_DIR}
503 AOM_TEST_PREFIX=${AOM_TEST_PREFIX}
504 AOM_TEST_PRESERVE_OUTPUT=${AOM_TEST_PRESERVE_OUTPUT}
505 AOM_TEST_RUN_DISABLED_TESTS=${AOM_TEST_RUN_DISABLED_TESTS}
506 AOM_TEST_SHOW_PROGRAM_OUTPUT=${AOM_TEST_SHOW_PROGRAM_OUTPUT}
507 AOM_TEST_TEMP_ROOT=${AOM_TEST_TEMP_ROOT}
508 AOM_TEST_VERBOSE_OUTPUT=${AOM_TEST_VERBOSE_OUTPUT}
509 AV1_ENCODE_CPU_USED=${AV1_ENCODE_CPU_USED}
510 AV1_ENCODE_TEST_FRAME_LIMIT=${AV1_ENCODE_TEST_FRAME_LIMIT}
511 AV1_IVF_FILE=${AV1_IVF_FILE}
512 AV1_OBU_ANNEXB_FILE=${AV1_OBU_ANNEXB_FILE}
513 AV1_OBU_SEC5_FILE=${AV1_OBU_SEC5_FILE}
514 AV1_WEBM_FILE=${AV1_WEBM_FILE}
515 YUV_RAW_INPUT=${YUV_RAW_INPUT}
516 YUV_RAW_INPUT_WIDTH=${YUV_RAW_INPUT_WIDTH}
517 YUV_RAW_INPUT_HEIGHT=${YUV_RAW_INPUT_HEIGHT}
518 Y4M_NOSQ_PAR_INPUT=${Y4M_NOSQ_PAR_INPUT}"
520 fi # End $AOM_TEST_TOOLS_COMMON_SH pseudo include guard.