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.

211 lines
4.9KB

  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_format_entry format_name -print_format default=nw=1:nk=1 -v 0 "$@"
  62. }
  63. ffmpeg(){
  64. run ffmpeg -nostats -threads $threads -thread_type $thread_type -cpuflags $cpuflags "$@"
  65. }
  66. framecrc(){
  67. ffmpeg "$@" -f framecrc -
  68. }
  69. framemd5(){
  70. ffmpeg "$@" -f framemd5 -
  71. }
  72. crc(){
  73. ffmpeg "$@" -f crc -
  74. }
  75. md5(){
  76. ffmpeg "$@" md5:
  77. }
  78. pcm(){
  79. ffmpeg "$@" -vn -f s16le -
  80. }
  81. enc_dec_pcm(){
  82. out_fmt=$1
  83. dec_fmt=$2
  84. pcm_fmt=$3
  85. src_file=$(target_path $4)
  86. shift 4
  87. encfile="${outdir}/${test}.${out_fmt}"
  88. cleanfiles=$encfile
  89. encfile=$(target_path ${encfile})
  90. ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  91. ffmpeg -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
  92. }
  93. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact"
  94. DEC_OPTS="-threads $threads -idct simple $FLAGS"
  95. ENC_OPTS="-threads 1 -idct simple -dct fastint"
  96. enc_dec(){
  97. src_fmt=$1
  98. srcfile=$2
  99. enc_fmt=$3
  100. enc_opt=$4
  101. dec_fmt=$5
  102. dec_opt=$6
  103. encfile="${outdir}/${test}.${enc_fmt}"
  104. decfile="${outdir}/${test}.out.${dec_fmt}"
  105. cleanfiles="$cleanfiles $decfile"
  106. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  107. tsrcfile=$(target_path $srcfile)
  108. tencfile=$(target_path $encfile)
  109. tdecfile=$(target_path $decfile)
  110. ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  111. -f $enc_fmt -y $tencfile || return
  112. do_md5sum $encfile
  113. echo $(wc -c $encfile)
  114. ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
  115. -f $dec_fmt -y $tdecfile || return
  116. do_md5sum $decfile
  117. tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
  118. }
  119. regtest(){
  120. t="${test#$2-}"
  121. ref=${base}/ref/$2/$t
  122. ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$samples"
  123. }
  124. lavffatetest(){
  125. regtest lavf lavf-fate tests/vsynth1
  126. }
  127. lavftest(){
  128. regtest lavf lavf tests/vsynth1
  129. }
  130. lavfitest(){
  131. cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
  132. regtest lavfi lavfi tests/vsynth1
  133. }
  134. seektest(){
  135. t="${test#seek-}"
  136. ref=${base}/ref/seek/$t
  137. case $t in
  138. image_*) file="tests/data/images/${t#image_}/%02d.${t#image_}" ;;
  139. *) file=$(echo $t | tr _ '?')
  140. for d in fate/acodec- fate/vsynth2- lavf/; do
  141. test -f tests/data/$d$file && break
  142. done
  143. file=$(echo tests/data/$d$file)
  144. ;;
  145. esac
  146. run libavformat/seek-test $target_path/$file
  147. }
  148. mkdir -p "$outdir"
  149. exec 3>&2
  150. eval $command >"$outfile" 2>$errfile
  151. err=$?
  152. if [ $err -gt 128 ]; then
  153. sig=$(kill -l $err 2>/dev/null)
  154. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  155. fi
  156. if test -e "$ref" || test $cmp = "oneline" ; then
  157. case $cmp in
  158. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  159. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  160. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  161. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  162. null) cat "$outfile" >$cmpfile ;;
  163. esac
  164. cmperr=$?
  165. test $err = 0 && err=$cmperr
  166. test $err = 0 || cat $cmpfile
  167. else
  168. echo "reference file '$ref' not found"
  169. err=1
  170. fi
  171. echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
  172. if test $err = 0; then
  173. rm -f $outfile $errfile $cmpfile $cleanfiles
  174. else
  175. echo "Test $test failed. Look at $errfile for details."
  176. fi
  177. exit $err