stress.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/bin/sh
  2. ##
  3. ## Copyright (c) 2016 The WebM project authors. All Rights Reserved.
  4. ##
  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.
  10. ##
  11. ## This file performs a stress test. It runs (STRESS_ONEPASS_MAX_JOBS,
  12. ## default=5) one, (STRESS_TWOPASS_MAX_JOBS, default=5) two pass &
  13. ## (STRESS_RT_MAX_JOBS, default=5) encodes and (STRESS_<codec>_DECODE_MAX_JOBS,
  14. ## default=30) decodes in parallel.
  15. . $(dirname $0)/tools_common.sh
  16. YUV="${LIBVPX_TEST_DATA_PATH}/niklas_1280_720_30.yuv"
  17. VP8="${LIBVPX_TEST_DATA_PATH}/tos_vp8.webm"
  18. VP9="${LIBVPX_TEST_DATA_PATH}/vp90-2-sintel_1920x818_tile_1x4_fpm_2279kbps.webm"
  19. DATA_URL="http://downloads.webmproject.org/test_data/libvpx/"
  20. SHA1_FILE="$(dirname $0)/test-data.sha1"
  21. # Set sha1sum to proper sha program (sha1sum, shasum, sha1). This code is
  22. # cribbed from libs.mk.
  23. [ -x "$(which sha1sum)" ] && sha1sum=sha1sum
  24. [ -x "$(which shasum)" ] && sha1sum=shasum
  25. [ -x "$(which sha1)" ] && sha1sum=sha1
  26. # Download a file from the url and check its sha1sum.
  27. download_and_check_file() {
  28. # Get the file from the file path.
  29. local root="${1#${LIBVPX_TEST_DATA_PATH}/}"
  30. # Download the file using curl. Trap to insure non partial file.
  31. (trap "rm -f $1" INT TERM \
  32. && eval "curl --retry 1 -L -o $1 ${DATA_URL}${root} ${devnull}")
  33. # Check the sha1 sum of the file.
  34. if [ -n "${sha1sum}" ]; then
  35. set -e
  36. grep ${root} ${SHA1_FILE} \
  37. | (cd ${LIBVPX_TEST_DATA_PATH}; ${sha1sum} -c);
  38. fi
  39. }
  40. # Environment check: Make sure input is available.
  41. stress_verify_environment() {
  42. if [ ! -e "${SHA1_FILE}" ] ; then
  43. echo "Missing ${SHA1_FILE}"
  44. return 1
  45. fi
  46. for file in "${YUV}" "${VP8}" "${VP9}"; do
  47. if [ ! -e "${file}" ] ; then
  48. download_and_check_file "${file}"
  49. fi
  50. done
  51. if [ ! -e "${YUV}" ] || [ ! -e "${VP8}" ] || [ ! -e "${VP9}" ] ; then
  52. elog "Libvpx test data must exist in LIBVPX_TEST_DATA_PATH."
  53. return 1
  54. fi
  55. if [ -z "$(vpx_tool_path vpxenc)" ]; then
  56. elog "vpxenc not found. It must exist in LIBVPX_BIN_PATH or its parent."
  57. return 1
  58. fi
  59. if [ -z "$(vpx_tool_path vpxdec)" ]; then
  60. elog "vpxdec not found. It must exist in LIBVPX_BIN_PATH or its parent."
  61. return 1
  62. fi
  63. }
  64. # This function runs tests on libvpx that run multiple encodes and decodes
  65. # in parallel in hopes of catching synchronization and/or threading issues.
  66. stress() {
  67. local decoder="$(vpx_tool_path vpxdec)"
  68. local encoder="$(vpx_tool_path vpxenc)"
  69. local codec="$1"
  70. local webm="$2"
  71. local decode_count="$3"
  72. local threads="$4"
  73. local enc_args="$5"
  74. local pids=""
  75. local rt_max_jobs=${STRESS_RT_MAX_JOBS:-5}
  76. local onepass_max_jobs=${STRESS_ONEPASS_MAX_JOBS:-5}
  77. local twopass_max_jobs=${STRESS_TWOPASS_MAX_JOBS:-5}
  78. # Enable job control, so we can run multiple processes.
  79. set -m
  80. # Start $onepass_max_jobs encode jobs in parallel.
  81. for i in $(seq ${onepass_max_jobs}); do
  82. bitrate=$(($i * 20 + 300))
  83. eval "${VPX_TEST_PREFIX}" "${encoder}" "--codec=${codec} -w 1280 -h 720" \
  84. "${YUV}" "-t ${threads} --limit=150 --test-decode=fatal --passes=1" \
  85. "--target-bitrate=${bitrate} -o ${VPX_TEST_OUTPUT_DIR}/${i}.1pass.webm" \
  86. "${enc_args}" ${devnull} &
  87. pids="${pids} $!"
  88. done
  89. # Start $twopass_max_jobs encode jobs in parallel.
  90. for i in $(seq ${twopass_max_jobs}); do
  91. bitrate=$(($i * 20 + 300))
  92. eval "${VPX_TEST_PREFIX}" "${encoder}" "--codec=${codec} -w 1280 -h 720" \
  93. "${YUV}" "-t ${threads} --limit=150 --test-decode=fatal --passes=2" \
  94. "--target-bitrate=${bitrate} -o ${VPX_TEST_OUTPUT_DIR}/${i}.2pass.webm" \
  95. "${enc_args}" ${devnull} &
  96. pids="${pids} $!"
  97. done
  98. # Start $rt_max_jobs rt encode jobs in parallel.
  99. for i in $(seq ${rt_max_jobs}); do
  100. bitrate=$(($i * 20 + 300))
  101. eval "${VPX_TEST_PREFIX}" "${encoder}" "--codec=${codec} -w 1280 -h 720" \
  102. "${YUV}" "-t ${threads} --limit=150 --test-decode=fatal " \
  103. "--target-bitrate=${bitrate} --lag-in-frames=0 --error-resilient=1" \
  104. "--kf-min-dist=3000 --kf-max-dist=3000 --cpu-used=-6 --static-thresh=1" \
  105. "--end-usage=cbr --min-q=2 --max-q=56 --undershoot-pct=100" \
  106. "--overshoot-pct=15 --buf-sz=1000 --buf-initial-sz=500" \
  107. "--buf-optimal-sz=600 --max-intra-rate=900 --resize-allowed=0" \
  108. "--drop-frame=0 --passes=1 --rt --noise-sensitivity=4" \
  109. "-o ${VPX_TEST_OUTPUT_DIR}/${i}.rt.webm" ${devnull} &
  110. pids="${pids} $!"
  111. done
  112. # Start $decode_count decode jobs in parallel.
  113. for i in $(seq "${decode_count}"); do
  114. eval "${decoder}" "-t ${threads}" "${webm}" "--noblit" ${devnull} &
  115. pids="${pids} $!"
  116. done
  117. # Wait for all parallel jobs to finish.
  118. fail=0
  119. for job in "${pids}"; do
  120. wait $job || fail=$(($fail + 1))
  121. done
  122. return $fail
  123. }
  124. vp8_stress_test() {
  125. local vp8_max_jobs=${STRESS_VP8_DECODE_MAX_JOBS:-40}
  126. if [ "$(vp8_decode_available)" = "yes" -a \
  127. "$(vp8_encode_available)" = "yes" ]; then
  128. stress vp8 "${VP8}" "${vp8_max_jobs}" 4
  129. fi
  130. }
  131. vp8_stress_test_token_parititions() {
  132. local vp8_max_jobs=${STRESS_VP8_DECODE_MAX_JOBS:-40}
  133. if [ "$(vp8_decode_available)" = "yes" -a \
  134. "$(vp8_encode_available)" = "yes" ]; then
  135. for threads in 2 4 8; do
  136. for token_partitions in 1 2 3; do
  137. stress vp8 "${VP8}" "${vp8_max_jobs}" ${threads} \
  138. "--token-parts=$token_partitions"
  139. done
  140. done
  141. fi
  142. }
  143. vp9_stress() {
  144. local vp9_max_jobs=${STRESS_VP9_DECODE_MAX_JOBS:-25}
  145. if [ "$(vp9_decode_available)" = "yes" -a \
  146. "$(vp9_encode_available)" = "yes" ]; then
  147. stress vp9 "${VP9}" "${vp9_max_jobs}" "$@"
  148. fi
  149. }
  150. vp9_stress_test() {
  151. for threads in 4 8 64; do
  152. vp9_stress "$threads" "--row-mt=0"
  153. done
  154. }
  155. vp9_stress_test_row_mt() {
  156. for threads in 4 8 64; do
  157. vp9_stress "$threads" "--row-mt=1"
  158. done
  159. }
  160. run_tests stress_verify_environment \
  161. "vp8_stress_test vp8_stress_test_token_parititions
  162. vp9_stress_test vp9_stress_test_row_mt"