fate-run.sh 6.7 KB

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