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.

202 lines
4.7KB

  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. outdir="tests/data/fate"
  22. outfile="${outdir}/${test}"
  23. errfile="${outdir}/${test}.err"
  24. cmpfile="${outdir}/${test}.diff"
  25. repfile="${outdir}/${test}.rep"
  26. target_path(){
  27. test ${1} = ${1#/} && p=${target_path}/
  28. echo ${p}${1}
  29. }
  30. # $1=value1, $2=value2, $3=threshold
  31. # prints 0 if absolute difference between value1 and value2 is <= threshold
  32. compare(){
  33. echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
  34. }
  35. do_tiny_psnr(){
  36. psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
  37. val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
  38. size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
  39. size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
  40. val_cmp=$(compare $val $cmp_target $fuzz)
  41. size_cmp=$(compare $size1 $size2 $size_tolerance)
  42. if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
  43. echo "$psnr"
  44. return 1
  45. fi
  46. }
  47. oneoff(){
  48. do_tiny_psnr "$1" "$2" MAXDIFF
  49. }
  50. stddev(){
  51. do_tiny_psnr "$1" "$2" stddev
  52. }
  53. oneline(){
  54. printf '%s\n' "$1" | diff -u -b - "$2"
  55. }
  56. run(){
  57. test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  58. $target_exec $target_path/"$@"
  59. }
  60. probefmt(){
  61. run ffprobe -show_entries format=format_name -print_format default=nw=1:nk=1 -v 0 "$@"
  62. }
  63. ffmpeg(){
  64. dec_opts="-threads $threads -thread_type $thread_type"
  65. ffmpeg_args="-nostats -cpuflags $cpuflags"
  66. for arg in $@; do
  67. [ ${arg} = -i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
  68. ffmpeg_args="${ffmpeg_args} ${arg}"
  69. done
  70. run ffmpeg ${ffmpeg_args}
  71. }
  72. framecrc(){
  73. ffmpeg "$@" -f framecrc -
  74. }
  75. framemd5(){
  76. ffmpeg "$@" -f framemd5 -
  77. }
  78. crc(){
  79. ffmpeg "$@" -f crc -
  80. }
  81. md5(){
  82. ffmpeg "$@" md5:
  83. }
  84. pcm(){
  85. ffmpeg "$@" -vn -f s16le -
  86. }
  87. enc_dec_pcm(){
  88. out_fmt=$1
  89. dec_fmt=$2
  90. pcm_fmt=$3
  91. src_file=$(target_path $4)
  92. shift 4
  93. encfile="${outdir}/${test}.${out_fmt}"
  94. cleanfiles=$encfile
  95. encfile=$(target_path ${encfile})
  96. ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  97. ffmpeg -flags +bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
  98. }
  99. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact"
  100. DEC_OPTS="-threads $threads -idct simple $FLAGS"
  101. ENC_OPTS="-threads 1 -idct simple -dct fastint"
  102. enc_dec(){
  103. src_fmt=$1
  104. srcfile=$2
  105. enc_fmt=$3
  106. enc_opt=$4
  107. dec_fmt=$5
  108. dec_opt=$6
  109. encfile="${outdir}/${test}.${enc_fmt}"
  110. decfile="${outdir}/${test}.out.${dec_fmt}"
  111. cleanfiles="$cleanfiles $decfile"
  112. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  113. tsrcfile=$(target_path $srcfile)
  114. tencfile=$(target_path $encfile)
  115. tdecfile=$(target_path $decfile)
  116. ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  117. -f $enc_fmt -y $tencfile || return
  118. do_md5sum $encfile
  119. echo $(wc -c $encfile)
  120. ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
  121. -f $dec_fmt -y $tdecfile || return
  122. do_md5sum $decfile
  123. tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
  124. }
  125. regtest(){
  126. t="${test#$2-}"
  127. ref=${base}/ref/$2/$t
  128. ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$samples"
  129. }
  130. lavffatetest(){
  131. regtest lavf lavf-fate tests/vsynth1
  132. }
  133. lavftest(){
  134. regtest lavf lavf tests/vsynth1
  135. }
  136. lavfitest(){
  137. cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
  138. regtest lavfi lavfi tests/vsynth1
  139. }
  140. mkdir -p "$outdir"
  141. exec 3>&2
  142. eval $command >"$outfile" 2>$errfile
  143. err=$?
  144. if [ $err -gt 128 ]; then
  145. sig=$(kill -l $err 2>/dev/null)
  146. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  147. fi
  148. if test -e "$ref" || test $cmp = "oneline" ; then
  149. case $cmp in
  150. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  151. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  152. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  153. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  154. null) cat "$outfile" >$cmpfile ;;
  155. esac
  156. cmperr=$?
  157. test $err = 0 && err=$cmperr
  158. test $err = 0 || cat $cmpfile
  159. else
  160. echo "reference file '$ref' not found"
  161. err=1
  162. fi
  163. echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
  164. if test $err = 0; then
  165. rm -f $outfile $errfile $cmpfile $cleanfiles
  166. else
  167. echo "Test $test failed. Look at $errfile for details."
  168. fi
  169. exit $err