3 ## Copyright (c) 2014 The WebM project authors. All Rights Reserved.
5 ## Use of this source code is governed by a BSD-style license
6 ## that can be found in the LICENSE file in the root of the source
7 ## tree. An additional intellectual property rights grant can be found
8 ## in the file PATENTS. All contributing project authors may
9 ## be found in the AUTHORS file in the root of the source tree.
11 ## This file contains shell code shared by test scripts for libvpx tools.
13 # Use $VPX_TEST_TOOLS_COMMON_SH as a pseudo include guard.
14 if [ -z "${VPX_TEST_TOOLS_COMMON_SH}" ]; then
15 VPX_TEST_TOOLS_COMMON_SH=included
18 devnull='> /dev/null 2>&1'
26 if [ "${VPX_TEST_VERBOSE_OUTPUT}" = "yes" ]; then
31 # Sets $VPX_TOOL_TEST to the name specified by positional parameter one.
36 # Clears the VPX_TOOL_TEST variable after confirming that $VPX_TOOL_TEST matches
37 # positional parameter one.
39 if [ "$1" != "${VPX_TOOL_TEST}" ]; then
40 echo "FAIL completed test mismatch!."
41 echo " completed test: ${1}"
42 echo " active test: ${VPX_TOOL_TEST}."
45 VPX_TOOL_TEST='<unset>'
48 # Echoes the target configuration being tested.
49 test_configuration_target() {
50 vpx_config_mk="${LIBVPX_CONFIG_PATH}/config.mk"
51 # Find the TOOLCHAIN line, split it using ':=' as the field separator, and
52 # print the last field to get the value. Then pipe the value to tr to consume
53 # any leading/trailing spaces while allowing tr to echo the output to stdout.
54 awk -F ':=' '/TOOLCHAIN/ { print $NF }' "${vpx_config_mk}" | tr -d ' '
57 # Trap function used for failure reports and tool output directory removal.
58 # When the contents of $VPX_TOOL_TEST do not match the string '<unset>', reports
59 # failure of test stored in $VPX_TOOL_TEST.
61 if [ -n "${VPX_TOOL_TEST}" ] && [ "${VPX_TOOL_TEST}" != '<unset>' ]; then
62 echo "FAIL: $VPX_TOOL_TEST"
64 if [ -n "${VPX_TEST_OUTPUT_DIR}" ] && [ -d "${VPX_TEST_OUTPUT_DIR}" ]; then
65 rm -rf "${VPX_TEST_OUTPUT_DIR}"
69 # Echoes the git hash portion of the VERSION_STRING variable defined in
70 # $LIBVPX_CONFIG_PATH/config.mk to stdout, or the version number string when
71 # no git hash is contained in VERSION_STRING.
73 vpx_config_mk="${LIBVPX_CONFIG_PATH}/config.mk"
74 # Find VERSION_STRING line, split it with "-g" and print the last field to
75 # output the git hash to stdout.
76 vpx_version=$(awk -F -g '/VERSION_STRING/ {print $NF}' "${vpx_config_mk}")
77 # Handle two situations here:
78 # 1. The default case: $vpx_version is a git hash, so echo it unchanged.
79 # 2. When being run a non-dev tree, the -g portion is not present in the
80 # version string: It's only the version number.
81 # In this case $vpx_version is something like 'VERSION_STRING=v1.3.0', so
82 # we echo only what is after the '='.
83 echo "${vpx_version##*=}"
86 # Echoes the short form of the current git hash.
88 if git --version > /dev/null 2>&1; then
89 (cd "$(dirname "${0}")"
90 git rev-parse --short HEAD)
92 # Return the config hash if git is unavailable: Fail silently, git hashes
93 # are used only for warnings.
98 # Echoes warnings to stdout when git hash in vpx_config.h does not match the
101 hash_at_configure_time=$(config_hash)
102 hash_now=$(current_hash)
104 if [ "${hash_at_configure_time}" != "${hash_now}" ]; then
105 echo "Warning: git hash has changed since last configure."
109 # This script requires that the LIBVPX_BIN_PATH, LIBVPX_CONFIG_PATH, and
110 # LIBVPX_TEST_DATA_PATH variables are in the environment: Confirm that
111 # the variables are set and that they all evaluate to directory paths.
112 verify_vpx_test_environment() {
113 if [ ! -d "${LIBVPX_BIN_PATH}" ]; then
114 echo "The LIBVPX_BIN_PATH environment variable must be set."
117 if [ ! -d "${LIBVPX_CONFIG_PATH}" ]; then
118 echo "The LIBVPX_CONFIG_PATH environment variable must be set."
121 if [ ! -d "${LIBVPX_TEST_DATA_PATH}" ]; then
122 echo "The LIBVPX_TEST_DATA_PATH environment variable must be set."
127 # Greps vpx_config.h in LIBVPX_CONFIG_PATH for positional parameter one, which
128 # should be a LIBVPX preprocessor flag. Echoes yes to stdout when the feature
130 vpx_config_option_enabled() {
131 vpx_config_option="${1}"
132 vpx_config_file="${LIBVPX_CONFIG_PATH}/vpx_config.h"
133 config_line=$(grep "${vpx_config_option}" "${vpx_config_file}")
134 if echo "${config_line}" | egrep -q '1$'; then
139 # Echoes yes when output of test_configuration_target() contains win32 or win64.
140 is_windows_target() {
141 if test_configuration_target \
142 | grep -q -e win32 -e win64 > /dev/null 2>&1; then
147 # Echoes path to $1 when it's executable and exists in ${LIBVPX_BIN_PATH}, or an
148 # empty string. Caller is responsible for testing the string once the function
151 local readonly tool_name="$1"
152 local tool_path="${LIBVPX_BIN_PATH}/${tool_name}${VPX_TEST_EXE_SUFFIX}"
153 if [ ! -x "${tool_path}" ]; then
154 # Try one directory up: when running via examples.sh the tool could be in
155 # the parent directory of $LIBVPX_BIN_PATH.
156 tool_path="${LIBVPX_BIN_PATH}/../${tool_name}${VPX_TEST_EXE_SUFFIX}"
159 if [ ! -x "${tool_path}" ]; then
165 # Echoes yes to stdout when the file named by positional parameter one exists
166 # in LIBVPX_BIN_PATH, and is executable.
167 vpx_tool_available() {
169 local tool="${LIBVPX_BIN_PATH}/${tool_name}${VPX_TEST_EXE_SUFFIX}"
170 [ -x "${tool}" ] && echo yes
173 # Echoes yes to stdout when vpx_config_option_enabled() reports yes for
174 # CONFIG_VP8_DECODER.
175 vp8_decode_available() {
176 [ "$(vpx_config_option_enabled CONFIG_VP8_DECODER)" = "yes" ] && echo yes
179 # Echoes yes to stdout when vpx_config_option_enabled() reports yes for
180 # CONFIG_VP8_ENCODER.
181 vp8_encode_available() {
182 [ "$(vpx_config_option_enabled CONFIG_VP8_ENCODER)" = "yes" ] && echo yes
185 # Echoes yes to stdout when vpx_config_option_enabled() reports yes for
186 # CONFIG_VP9_DECODER.
187 vp9_decode_available() {
188 [ "$(vpx_config_option_enabled CONFIG_VP9_DECODER)" = "yes" ] && echo yes
191 # Echoes yes to stdout when vpx_config_option_enabled() reports yes for
192 # CONFIG_VP9_ENCODER.
193 vp9_encode_available() {
194 [ "$(vpx_config_option_enabled CONFIG_VP9_ENCODER)" = "yes" ] && echo yes
197 # Echoes yes to stdout when vpx_config_option_enabled() reports yes for
199 webm_io_available() {
200 [ "$(vpx_config_option_enabled CONFIG_WEBM_IO)" = "yes" ] && echo yes
203 # Filters strings from positional parameter one using the filter specified by
204 # positional parameter two. Filter behavior depends on the presence of a third
205 # positional parameter. When parameter three is present, strings that match the
206 # filter are excluded. When omitted, strings matching the filter are included.
207 # The filtered string is echoed to stdout.
213 if [ -n "${exclude}" ]; then
214 # When positional parameter three exists the caller wants to remove strings.
215 # Tell grep to invert matches using the -v argument.
221 if [ -n "${filter}" ]; then
222 for s in ${strings}; do
223 if echo "${s}" | egrep -q ${exclude} "${filter}" > /dev/null 2>&1; then
224 filtered_strings="${filtered_strings} ${s}"
228 filtered_strings="${strings}"
230 echo "${filtered_strings}"
233 # Runs user test functions passed via positional parameters one and two.
234 # Functions in positional parameter one are treated as environment verification
235 # functions and are run unconditionally. Functions in positional parameter two
236 # are run according to the rules specified in vpx_test_usage().
238 local env_tests="verify_vpx_test_environment $1"
239 local tests_to_filter="$2"
240 local test_name="${VPX_TEST_NAME}"
242 if [ -z "${test_name}" ]; then
243 test_name="$(basename "${0%.*}")"
246 if [ "${VPX_TEST_RUN_DISABLED_TESTS}" != "yes" ]; then
247 # Filter out DISABLED tests.
248 tests_to_filter=$(filter_strings "${tests_to_filter}" ^DISABLED exclude)
251 if [ -n "${VPX_TEST_FILTER}" ]; then
252 # Remove tests not matching the user's filter.
253 tests_to_filter=$(filter_strings "${tests_to_filter}" ${VPX_TEST_FILTER})
256 local tests_to_run="${env_tests} ${tests_to_filter}"
261 for test in ${tests_to_run}; do
269 local tested_config="$(test_configuration_target) @ $(current_hash)"
270 echo "${test_name}: Done, all tests pass for ${tested_config}."
275 Usage: ${0##*/} [arguments]
276 --bin-path <path to libvpx binaries directory>
277 --config-path <path to libvpx config directory>
278 --filter <filter>: User test filter. Only tests matching filter are run.
279 --run-disabled-tests: Run disabled tests.
280 --help: Display this message and exit.
281 --test-data-path <path to libvpx test data directory>
282 --show-program-output: Shows output from all programs being tested.
283 --prefix: Allows for a user specified prefix to be inserted before all test
284 programs. Grants the ability, for example, to run test programs
286 --verbose: Verbose output.
288 When the --bin-path option is not specified the script attempts to use
289 \$LIBVPX_BIN_PATH and then the current directory.
291 When the --config-path option is not specified the script attempts to use
292 \$LIBVPX_CONFIG_PATH and then the current directory.
294 When the -test-data-path option is not specified the script attempts to use
295 \$LIBVPX_TEST_DATA_PATH and then the current directory.
299 # Returns non-zero (failure) when required environment variables are empty
301 vpx_test_check_environment() {
302 if [ -z "${LIBVPX_BIN_PATH}" ] || \
303 [ -z "${LIBVPX_CONFIG_PATH}" ] || \
304 [ -z "${LIBVPX_TEST_DATA_PATH}" ]; then
309 # Parse the command line.
310 while [ -n "$1" ]; do
317 LIBVPX_CONFIG_PATH="$2"
324 --run-disabled-tests)
325 VPX_TEST_RUN_DISABLED_TESTS=yes
332 LIBVPX_TEST_DATA_PATH="$2"
340 VPX_TEST_VERBOSE_OUTPUT=yes
342 --show-program-output)
353 # Handle running the tests from a build directory without arguments when running
354 # the tests on *nix/macosx.
355 LIBVPX_BIN_PATH="${LIBVPX_BIN_PATH:-.}"
356 LIBVPX_CONFIG_PATH="${LIBVPX_CONFIG_PATH:-.}"
357 LIBVPX_TEST_DATA_PATH="${LIBVPX_TEST_DATA_PATH:-.}"
359 # Create a temporary directory for output files, and a trap to clean it up.
360 if [ -n "${TMPDIR}" ]; then
361 VPX_TEST_TEMP_ROOT="${TMPDIR}"
362 elif [ -n "${TEMPDIR}" ]; then
363 VPX_TEST_TEMP_ROOT="${TEMPDIR}"
365 VPX_TEST_TEMP_ROOT=/tmp
368 VPX_TEST_RAND=$(awk 'BEGIN { srand(); printf "%d\n",(rand() * 32768)}')
369 VPX_TEST_OUTPUT_DIR="${VPX_TEST_TEMP_ROOT}/vpx_test_${VPX_TEST_RAND}"
371 if ! mkdir -p "${VPX_TEST_OUTPUT_DIR}" || \
372 [ ! -d "${VPX_TEST_OUTPUT_DIR}" ]; then
373 echo "${0##*/}: Cannot create output directory, giving up."
374 echo "${0##*/}: VPX_TEST_OUTPUT_DIR=${VPX_TEST_OUTPUT_DIR}"
378 if [ "$(is_windows_target)" = "yes" ]; then
379 VPX_TEST_EXE_SUFFIX=".exe"
382 # Variables shared by tests.
383 VP8_IVF_FILE="${LIBVPX_TEST_DATA_PATH}/vp80-00-comprehensive-001.ivf"
384 VP9_IVF_FILE="${LIBVPX_TEST_DATA_PATH}/vp90-2-09-subpixel-00.ivf"
386 VP9_WEBM_FILE="${LIBVPX_TEST_DATA_PATH}/vp90-2-00-quantizer-00.webm"
388 YUV_RAW_INPUT="${LIBVPX_TEST_DATA_PATH}/hantro_collage_w352h288.yuv"
389 YUV_RAW_INPUT_WIDTH=352
390 YUV_RAW_INPUT_HEIGHT=288
392 # Setup a trap function to clean up after tests complete.
395 vlog "$(basename "${0%.*}") test configuration:
396 LIBVPX_BIN_PATH=${LIBVPX_BIN_PATH}
397 LIBVPX_CONFIG_PATH=${LIBVPX_CONFIG_PATH}
398 LIBVPX_TEST_DATA_PATH=${LIBVPX_TEST_DATA_PATH}
399 VP8_IVF_FILE=${VP8_IVF_FILE}
400 VP9_IVF_FILE=${VP9_IVF_FILE}
401 VP9_WEBM_FILE=${VP9_WEBM_FILE}
402 VPX_TEST_EXE_SUFFIX=${VPX_TEST_EXE_SUFFIX}
403 VPX_TEST_FILTER=${VPX_TEST_FILTER}
404 VPX_TEST_OUTPUT_DIR=${VPX_TEST_OUTPUT_DIR}
405 VPX_TEST_PREFIX=${VPX_TEST_PREFIX}
406 VPX_TEST_RAND=${VPX_TEST_RAND}
407 VPX_TEST_RUN_DISABLED_TESTS=${VPX_TEST_RUN_DISABLED_TESTS}
408 VPX_TEST_SHOW_PROGRAM_OUTPUT=${VPX_TEST_SHOW_PROGRAM_OUTPUT}
409 VPX_TEST_TEMP_ROOT=${VPX_TEST_TEMP_ROOT}
410 VPX_TEST_VERBOSE_OUTPUT=${VPX_TEST_VERBOSE_OUTPUT}
411 YUV_RAW_INPUT=${YUV_RAW_INPUT}
412 YUV_RAW_INPUT_WIDTH=${YUV_RAW_INPUT_WIDTH}
413 YUV_RAW_INPUT_HEIGHT=${YUV_RAW_INPUT_HEIGHT}"
415 fi # End $VPX_TEST_TOOLS_COMMON_SH pseudo include guard.