You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
6.6KB

  1. #! /bin/sh
  2. export LC_ALL=C
  3. base=$(dirname $0)
  4. . "${base}/md5.sh"
  5. base64=tests/base64
  6. test="${1#fate-}"
  7. samples=$2
  8. target_exec=$3
  9. target_path=$4
  10. command=$5
  11. cmp=${6:-diff}
  12. ref=${7:-"${base}/ref/fate/${test}"}
  13. fuzz=${8:-1}
  14. threads=${9:-1}
  15. thread_type=${10:-frame+slice}
  16. cpuflags=${11:-all}
  17. cmp_shift=${12:-0}
  18. cmp_target=${13:-0}
  19. size_tolerance=${14:-0}
  20. cmp_unit=${15:-2}
  21. gen=${16:-no}
  22. outdir="tests/data/fate"
  23. outfile="${outdir}/${test}"
  24. errfile="${outdir}/${test}.err"
  25. cmpfile="${outdir}/${test}.diff"
  26. repfile="${outdir}/${test}.rep"
  27. target_path(){
  28. test ${1} = ${1#/} && p=${target_path}/
  29. echo ${p}${1}
  30. }
  31. # $1=value1, $2=value2, $3=threshold
  32. # prints 0 if absolute difference between value1 and value2 is <= threshold
  33. compare(){
  34. echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
  35. }
  36. do_tiny_psnr(){
  37. psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
  38. val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
  39. size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
  40. size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
  41. val_cmp=$(compare $val $cmp_target $fuzz)
  42. size_cmp=$(compare $size1 $size2 $size_tolerance)
  43. if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
  44. echo "$psnr"
  45. return 1
  46. fi
  47. }
  48. oneoff(){
  49. do_tiny_psnr "$1" "$2" MAXDIFF
  50. }
  51. stddev(){
  52. do_tiny_psnr "$1" "$2" stddev
  53. }
  54. oneline(){
  55. printf '%s\n' "$1" | diff -u -b - "$2"
  56. }
  57. run(){
  58. test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  59. $target_exec $target_path/"$@"
  60. }
  61. probefmt(){
  62. run ffprobe -show_entries format=format_name -print_format default=nw=1:nk=1 -v 0 "$@"
  63. }
  64. ffmpeg(){
  65. dec_opts="-threads $threads -thread_type $thread_type"
  66. ffmpeg_args="-nostats -cpuflags $cpuflags"
  67. for arg in $@; do
  68. [ x${arg} = x-i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
  69. ffmpeg_args="${ffmpeg_args} ${arg}"
  70. done
  71. run ffmpeg ${ffmpeg_args}
  72. }
  73. framecrc(){
  74. ffmpeg "$@" -f framecrc -
  75. }
  76. framemd5(){
  77. ffmpeg "$@" -f framemd5 -
  78. }
  79. crc(){
  80. ffmpeg "$@" -f crc -
  81. }
  82. md5(){
  83. ffmpeg "$@" md5:
  84. }
  85. pcm(){
  86. ffmpeg "$@" -vn -f s16le -
  87. }
  88. enc_dec_pcm(){
  89. out_fmt=$1
  90. dec_fmt=$2
  91. pcm_fmt=$3
  92. src_file=$(target_path $4)
  93. shift 4
  94. encfile="${outdir}/${test}.${out_fmt}"
  95. cleanfiles=$encfile
  96. encfile=$(target_path ${encfile})
  97. ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  98. ffmpeg -flags +bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
  99. }
  100. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact"
  101. DEC_OPTS="-threads $threads -idct simple $FLAGS"
  102. ENC_OPTS="-threads 1 -idct simple -dct fastint"
  103. enc_dec(){
  104. src_fmt=$1
  105. srcfile=$2
  106. enc_fmt=$3
  107. enc_opt=$4
  108. dec_fmt=$5
  109. dec_opt=$6
  110. encfile="${outdir}/${test}.${enc_fmt}"
  111. decfile="${outdir}/${test}.out.${dec_fmt}"
  112. cleanfiles="$cleanfiles $decfile"
  113. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  114. tsrcfile=$(target_path $srcfile)
  115. tencfile=$(target_path $encfile)
  116. tdecfile=$(target_path $decfile)
  117. ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  118. -f $enc_fmt -y $tencfile || return
  119. do_md5sum $encfile
  120. echo $(wc -c $encfile)
  121. ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
  122. -f $dec_fmt -y $tdecfile || return
  123. do_md5sum $decfile
  124. tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
  125. }
  126. lavffatetest(){
  127. t="${test#lavf-fate-}"
  128. ref=${base}/ref/lavf-fate/$t
  129. ${base}/lavf-regression.sh $t lavf-fate tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$samples"
  130. }
  131. lavftest(){
  132. t="${test#lavf-}"
  133. ref=${base}/ref/lavf/$t
  134. ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$samples"
  135. }
  136. video_filter(){
  137. filters=$1
  138. shift
  139. label=${test#filter-}
  140. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  141. printf '%-20s' $label
  142. ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
  143. $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5:
  144. }
  145. pixdesc(){
  146. pix_fmts="$(ffmpeg -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^IO/ { print $2 }' | sort)"
  147. for pix_fmt in $pix_fmts; do
  148. test=$pix_fmt
  149. video_filter "format=$pix_fmt,pixdesctest" -pix_fmt $pix_fmt
  150. done
  151. }
  152. pixfmts(){
  153. filter=${test#filter-pixfmts-}
  154. filter=${filter%_*}
  155. filter_args=$1
  156. prefilter_chain=$2
  157. showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
  158. scale_exclude_fmts=${outfile}_scale_exclude_fmts
  159. scale_in_fmts=${outfile}_scale_in_fmts
  160. scale_out_fmts=${outfile}_scale_out_fmts
  161. in_fmts=${outfile}_in_fmts
  162. # exclude pixel formats which are not supported as input
  163. $showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
  164. $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
  165. comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts
  166. $showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
  167. pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
  168. for pix_fmt in $pix_fmts; do
  169. test=$pix_fmt
  170. video_filter "${prefilter_chain}format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
  171. done
  172. rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
  173. }
  174. mkdir -p "$outdir"
  175. # Disable globbing: command arguments may contain globbing characters and
  176. # must be kept verbatim
  177. set -f
  178. exec 3>&2
  179. eval $command >"$outfile" 2>$errfile
  180. err=$?
  181. if [ $err -gt 128 ]; then
  182. sig=$(kill -l $err 2>/dev/null)
  183. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  184. fi
  185. if test -e "$ref" || test $cmp = "oneline" ; then
  186. case $cmp in
  187. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  188. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  189. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  190. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  191. null) cat "$outfile" >$cmpfile ;;
  192. esac
  193. cmperr=$?
  194. test $err = 0 && err=$cmperr
  195. test $err = 0 || cat $cmpfile
  196. else
  197. echo "reference file '$ref' not found"
  198. err=1
  199. fi
  200. echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
  201. if test $err != 0 && test $gen != "no" ; then
  202. echo "GEN $ref"
  203. cp -f "$outfile" "$ref"
  204. err=$?
  205. fi
  206. if test $err = 0; then
  207. rm -f $outfile $errfile $cmpfile $cleanfiles
  208. elif test $gen = "no"; then
  209. echo "Test $test failed. Look at $errfile for details."
  210. else
  211. echo "Updating reference failed, possibly no output file was generated."
  212. fi
  213. exit $err