fate-run.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. fmtstdout(){
  96. fmt=$1
  97. shift 1
  98. ffmpeg -flags +bitexact "$@" -f $fmt -
  99. }
  100. enc_dec_pcm(){
  101. out_fmt=$1
  102. dec_fmt=$2
  103. pcm_fmt=$3
  104. src_file=$(target_path $4)
  105. shift 4
  106. encfile="${outdir}/${test}.${out_fmt}"
  107. cleanfiles=$encfile
  108. encfile=$(target_path ${encfile})
  109. ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  110. ffmpeg -flags +bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
  111. }
  112. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
  113. DEC_OPTS="-threads $threads -idct simple $FLAGS"
  114. ENC_OPTS="-threads 1 -idct simple -dct fastint"
  115. enc_dec(){
  116. src_fmt=$1
  117. srcfile=$2
  118. enc_fmt=$3
  119. enc_opt=$4
  120. dec_fmt=$5
  121. dec_opt=$6
  122. encfile="${outdir}/${test}.${enc_fmt}"
  123. decfile="${outdir}/${test}.out.${dec_fmt}"
  124. cleanfiles="$cleanfiles $decfile"
  125. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  126. tsrcfile=$(target_path $srcfile)
  127. tencfile=$(target_path $encfile)
  128. tdecfile=$(target_path $decfile)
  129. ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  130. -f $enc_fmt -y $tencfile || return
  131. do_md5sum $encfile
  132. echo $(wc -c $encfile)
  133. ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
  134. -f $dec_fmt -y $tdecfile || return
  135. do_md5sum $decfile
  136. tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
  137. }
  138. lavffatetest(){
  139. t="${test#lavf-fate-}"
  140. ref=${base}/ref/lavf-fate/$t
  141. ${base}/lavf-regression.sh $t lavf-fate tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
  142. }
  143. lavftest(){
  144. t="${test#lavf-}"
  145. ref=${base}/ref/lavf/$t
  146. ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
  147. }
  148. video_filter(){
  149. filters=$1
  150. shift
  151. label=${test#filter-}
  152. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  153. printf '%-20s' $label
  154. ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
  155. $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5:
  156. }
  157. pixfmts(){
  158. filter=${test#filter-pixfmts-}
  159. filter=${filter%_*}
  160. filter_args=$1
  161. prefilter_chain=$2
  162. showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
  163. scale_exclude_fmts=${outfile}_scale_exclude_fmts
  164. scale_in_fmts=${outfile}_scale_in_fmts
  165. scale_out_fmts=${outfile}_scale_out_fmts
  166. in_fmts=${outfile}_in_fmts
  167. # exclude pixel formats which are not supported as input
  168. $showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
  169. $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
  170. comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts
  171. $showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
  172. pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
  173. outertest=$test
  174. for pix_fmt in $pix_fmts; do
  175. test=$pix_fmt
  176. video_filter "${prefilter_chain}format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
  177. done
  178. rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
  179. test=$outertest
  180. }
  181. mkdir -p "$outdir"
  182. # Disable globbing: command arguments may contain globbing characters and
  183. # must be kept verbatim
  184. set -f
  185. exec 3>&2
  186. eval $command >"$outfile" 2>$errfile
  187. err=$?
  188. if [ $err -gt 128 ]; then
  189. sig=$(kill -l $err 2>/dev/null)
  190. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  191. fi
  192. if test -e "$ref" || test $cmp = "oneline" ; then
  193. case $cmp in
  194. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  195. rawdiff)diff -u "$ref" "$outfile" >$cmpfile ;;
  196. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  197. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  198. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  199. null) cat "$outfile" >$cmpfile ;;
  200. esac
  201. cmperr=$?
  202. test $err = 0 && err=$cmperr
  203. test $err = 0 || cat $cmpfile
  204. else
  205. echo "reference file '$ref' not found"
  206. err=1
  207. fi
  208. echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
  209. if test $err != 0 && test $gen != "no" ; then
  210. echo "GEN $ref"
  211. cp -f "$outfile" "$ref"
  212. err=$?
  213. fi
  214. if test $err = 0; then
  215. rm -f $outfile $errfile $cmpfile $cleanfiles
  216. elif test $gen = "no"; then
  217. echo "Test $test failed. Look at $errfile for details."
  218. test "${V:-0}" -gt 0 && cat $errfile
  219. else
  220. echo "Updating reference failed, possibly no output file was generated."
  221. fi
  222. exit $err