fate-run.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. target_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. awk "BEGIN { v = $1 - $2; printf ((v < 0 ? -v : v) > $3) }"
  35. }
  36. do_tiny_psnr(){
  37. psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0) || return 1
  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. runecho(){
  62. test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  63. $target_exec $target_path/"$@" >&3
  64. }
  65. probefmt(){
  66. run ffprobe -show_entries format=format_name -print_format default=nw=1:nk=1 -v 0 "$@"
  67. }
  68. probeframes(){
  69. run ffprobe -show_frames -v 0 "$@"
  70. }
  71. ffmpeg(){
  72. dec_opts="-threads $threads -thread_type $thread_type"
  73. ffmpeg_args="-nostats -cpuflags $cpuflags"
  74. for arg in $@; do
  75. [ x${arg} = x-i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
  76. ffmpeg_args="${ffmpeg_args} ${arg}"
  77. done
  78. run ffmpeg ${ffmpeg_args}
  79. }
  80. framecrc(){
  81. ffmpeg "$@" -flags +bitexact -f framecrc -
  82. }
  83. framemd5(){
  84. ffmpeg "$@" -flags +bitexact -f framemd5 -
  85. }
  86. crc(){
  87. ffmpeg "$@" -f crc -
  88. }
  89. md5(){
  90. ffmpeg "$@" md5:
  91. }
  92. pcm(){
  93. ffmpeg "$@" -vn -f s16le -
  94. }
  95. enc_dec_pcm(){
  96. out_fmt=$1
  97. dec_fmt=$2
  98. pcm_fmt=$3
  99. src_file=$(target_path $4)
  100. shift 4
  101. encfile="${outdir}/${test}.${out_fmt}"
  102. cleanfiles=$encfile
  103. encfile=$(target_path ${encfile})
  104. ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  105. ffmpeg -flags +bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
  106. }
  107. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
  108. DEC_OPTS="-threads $threads -idct simple $FLAGS"
  109. ENC_OPTS="-threads 1 -idct simple -dct fastint"
  110. enc_dec(){
  111. src_fmt=$1
  112. srcfile=$2
  113. enc_fmt=$3
  114. enc_opt=$4
  115. dec_fmt=$5
  116. dec_opt=$6
  117. encfile="${outdir}/${test}.${enc_fmt}"
  118. decfile="${outdir}/${test}.out.${dec_fmt}"
  119. cleanfiles="$cleanfiles $decfile"
  120. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  121. tsrcfile=$(target_path $srcfile)
  122. tencfile=$(target_path $encfile)
  123. tdecfile=$(target_path $decfile)
  124. ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  125. -f $enc_fmt -y $tencfile || return
  126. do_md5sum $encfile
  127. echo $(wc -c $encfile)
  128. ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
  129. -f $dec_fmt -y $tdecfile || return
  130. do_md5sum $decfile
  131. tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
  132. }
  133. lavffatetest(){
  134. t="${test#lavf-fate-}"
  135. ref=${base}/ref/lavf-fate/$t
  136. ${base}/lavf-regression.sh $t lavf-fate tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
  137. }
  138. lavftest(){
  139. t="${test#lavf-}"
  140. ref=${base}/ref/lavf/$t
  141. ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
  142. }
  143. video_filter(){
  144. filters=$1
  145. shift
  146. label=${test#filter-}
  147. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  148. printf '%-20s' $label
  149. ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
  150. $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5:
  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. outertest=$test
  169. for pix_fmt in $pix_fmts; do
  170. test=$pix_fmt
  171. video_filter "${prefilter_chain}format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
  172. done
  173. rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
  174. test=$outertest
  175. }
  176. mkdir -p "$outdir"
  177. # Disable globbing: command arguments may contain globbing characters and
  178. # must be kept verbatim
  179. set -f
  180. exec 3>&2
  181. eval $command >"$outfile" 2>$errfile
  182. err=$?
  183. if [ $err -gt 128 ]; then
  184. sig=$(kill -l $err 2>/dev/null)
  185. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  186. fi
  187. if test -e "$ref" || test $cmp = "oneline" ; then
  188. case $cmp in
  189. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  190. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  191. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  192. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  193. null) cat "$outfile" >$cmpfile ;;
  194. esac
  195. cmperr=$?
  196. test $err = 0 && err=$cmperr
  197. test $err = 0 || cat $cmpfile
  198. else
  199. echo "reference file '$ref' not found"
  200. err=1
  201. fi
  202. echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
  203. if test $err != 0 && test $gen != "no" ; then
  204. echo "GEN $ref"
  205. cp -f "$outfile" "$ref"
  206. err=$?
  207. fi
  208. if test $err = 0; then
  209. rm -f $outfile $errfile $cmpfile $cleanfiles
  210. elif test $gen = "no"; then
  211. echo "Test $test failed. Look at $errfile for details."
  212. test "${V:-0}" -gt 0 && cat $errfile
  213. else
  214. echo "Updating reference failed, possibly no output file was generated."
  215. fi
  216. exit $err