fate-run.sh 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. hwaccel=${17:-none}
  23. outdir="tests/data/fate"
  24. outfile="${outdir}/${test}"
  25. errfile="${outdir}/${test}.err"
  26. cmpfile="${outdir}/${test}.diff"
  27. repfile="${outdir}/${test}.rep"
  28. target_path(){
  29. test ${1} = ${1#/} && p=${target_path}/
  30. echo ${p}${1}
  31. }
  32. # $1=value1, $2=value2, $3=threshold
  33. # prints 0 if absolute difference between value1 and value2 is <= threshold
  34. compare(){
  35. awk "BEGIN { v = $1 - $2; printf ((v < 0 ? -v : v) > $3) }"
  36. }
  37. do_tiny_psnr(){
  38. psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0) || return 1
  39. val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
  40. size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
  41. size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
  42. val_cmp=$(compare $val $cmp_target $fuzz)
  43. size_cmp=$(compare $size1 $size2 $size_tolerance)
  44. if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
  45. echo "$psnr"
  46. if [ "$val_cmp" != 0 ]; then
  47. echo "$3: |$val - $cmp_target| >= $fuzz"
  48. fi
  49. if [ "$size_cmp" != 0 ]; then
  50. echo "size: |$size1 - $size2| >= $size_tolerance"
  51. fi
  52. return 1
  53. fi
  54. }
  55. oneoff(){
  56. do_tiny_psnr "$1" "$2" MAXDIFF
  57. }
  58. stddev(){
  59. do_tiny_psnr "$1" "$2" stddev
  60. }
  61. oneline(){
  62. printf '%s\n' "$1" | diff -u -b - "$2"
  63. }
  64. run(){
  65. test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  66. $target_exec $target_path/"$@"
  67. }
  68. runecho(){
  69. test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  70. $target_exec $target_path/"$@" >&3
  71. }
  72. probefmt(){
  73. run ffprobe${PROGSUF} -show_entries format=format_name -print_format default=nw=1:nk=1 -v 0 "$@"
  74. }
  75. runlocal(){
  76. test "${V:-0}" -gt 0 && echo ${base}/"$@" ${base} >&3
  77. ${base}/"$@" ${base}
  78. }
  79. probeframes(){
  80. run ffprobe${PROGSUF} -show_frames -v 0 "$@"
  81. }
  82. ffmpeg(){
  83. dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
  84. ffmpeg_args="-nostdin -nostats -cpuflags $cpuflags"
  85. for arg in $@; do
  86. [ x${arg} = x-i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
  87. ffmpeg_args="${ffmpeg_args} ${arg}"
  88. done
  89. run ffmpeg${PROGSUF} ${ffmpeg_args}
  90. }
  91. framecrc(){
  92. ffmpeg "$@" -flags +bitexact -fflags +bitexact -f framecrc -
  93. }
  94. framemd5(){
  95. ffmpeg "$@" -flags +bitexact -fflags +bitexact -f framemd5 -
  96. }
  97. crc(){
  98. ffmpeg "$@" -f crc -
  99. }
  100. md5(){
  101. ffmpeg "$@" md5:
  102. }
  103. pcm(){
  104. ffmpeg "$@" -vn -f s16le -
  105. }
  106. fmtstdout(){
  107. fmt=$1
  108. shift 1
  109. ffmpeg -flags +bitexact -fflags +bitexact "$@" -f $fmt -
  110. }
  111. enc_dec_pcm(){
  112. out_fmt=$1
  113. dec_fmt=$2
  114. pcm_fmt=$3
  115. src_file=$(target_path $4)
  116. shift 4
  117. encfile="${outdir}/${test}.${out_fmt}"
  118. cleanfiles=$encfile
  119. encfile=$(target_path ${encfile})
  120. ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  121. ffmpeg -flags +bitexact -fflags +bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -fflags +bitexact -f ${dec_fmt} -
  122. }
  123. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
  124. DEC_OPTS="-threads $threads -idct simple $FLAGS"
  125. ENC_OPTS="-threads 1 -idct simple -dct fastint"
  126. enc_dec(){
  127. src_fmt=$1
  128. srcfile=$2
  129. enc_fmt=$3
  130. enc_opt=$4
  131. dec_fmt=$5
  132. dec_opt=$6
  133. encfile="${outdir}/${test}.${enc_fmt}"
  134. decfile="${outdir}/${test}.out.${dec_fmt}"
  135. cleanfiles="$cleanfiles $decfile"
  136. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  137. tsrcfile=$(target_path $srcfile)
  138. tencfile=$(target_path $encfile)
  139. tdecfile=$(target_path $decfile)
  140. ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  141. -f $enc_fmt -y $tencfile || return
  142. do_md5sum $encfile
  143. echo $(wc -c $encfile)
  144. ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
  145. -f $dec_fmt -y $tdecfile || return
  146. do_md5sum $decfile
  147. tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
  148. }
  149. lavffatetest(){
  150. t="${test#lavf-fate-}"
  151. ref=${base}/ref/lavf-fate/$t
  152. ${base}/lavf-regression.sh $t lavf-fate tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
  153. }
  154. lavftest(){
  155. t="${test#lavf-}"
  156. ref=${base}/ref/lavf/$t
  157. ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
  158. }
  159. video_filter(){
  160. filters=$1
  161. shift
  162. label=${test#filter-}
  163. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  164. printf '%-20s' $label
  165. ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
  166. $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo -frames:v 5 $* -f nut md5:
  167. }
  168. pixfmts(){
  169. filter=${test#filter-pixfmts-}
  170. filter=${filter%_*}
  171. filter_args=$1
  172. prefilter_chain=$2
  173. nframes=${3:-1}
  174. showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
  175. scale_exclude_fmts=${outfile}_scale_exclude_fmts
  176. scale_in_fmts=${outfile}_scale_in_fmts
  177. scale_out_fmts=${outfile}_scale_out_fmts
  178. in_fmts=${outfile}_in_fmts
  179. # exclude pixel formats which are not supported as input
  180. $showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
  181. $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
  182. comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts
  183. $showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
  184. pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
  185. outertest=$test
  186. for pix_fmt in $pix_fmts; do
  187. test=$pix_fmt
  188. video_filter "${prefilter_chain}format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v $nframes
  189. done
  190. rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
  191. test=$outertest
  192. }
  193. gapless(){
  194. sample=$(target_path $1)
  195. extra_args=$2
  196. decfile1="${outdir}/${test}.out-1"
  197. decfile2="${outdir}/${test}.out-2"
  198. decfile3="${outdir}/${test}.out-3"
  199. cleanfiles="$cleanfiles $decfile1 $decfile2 $decfile3"
  200. # test packet data
  201. ffmpeg $extra_args -i "$sample" -flags +bitexact -fflags +bitexact -c:a copy -f framecrc -y $decfile1
  202. do_md5sum $decfile1
  203. # test decoded (and cut) data
  204. ffmpeg $extra_args -i "$sample" -flags +bitexact -fflags +bitexact -f wav md5:
  205. # the same as above again, with seeking to the start
  206. ffmpeg $extra_args -ss 0 -seek_timestamp 1 -i "$sample" -flags +bitexact -fflags +bitexact -c:a copy -f framecrc -y $decfile2
  207. do_md5sum $decfile2
  208. ffmpeg $extra_args -ss 0 -seek_timestamp 1 -i "$sample" -flags +bitexact -fflags +bitexact -f wav md5:
  209. # test packet data, with seeking to a specific position
  210. ffmpeg $extra_args -ss 5 -seek_timestamp 1 -i "$sample" -flags +bitexact -fflags +bitexact -c:a copy -f framecrc -y $decfile3
  211. do_md5sum $decfile3
  212. }
  213. concat(){
  214. template=$1
  215. sample=$2
  216. mode=$3
  217. extra_args=$4
  218. concatfile="${outdir}/${test}.ffconcat"
  219. packetfile="${outdir}/${test}.ffprobe"
  220. cleanfiles="$concatfile $packetfile"
  221. awk "{gsub(/%SRCFILE%/, \"$sample\"); print}" $template > $concatfile
  222. if [ "$mode" = "md5" ]; then
  223. run ffprobe${PROGSUF} -bitexact -show_streams -show_packets -v 0 -fflags keepside -safe 0 $extra_args $concatfile | tr -d '\r' > $packetfile
  224. do_md5sum $packetfile
  225. else
  226. run ffprobe${PROGSUF} -bitexact -show_streams -show_packets -v 0 -of compact=p=0:nk=1 -fflags keepside -safe 0 $extra_args $concatfile
  227. fi
  228. }
  229. mkdir -p "$outdir"
  230. # Disable globbing: command arguments may contain globbing characters and
  231. # must be kept verbatim
  232. set -f
  233. exec 3>&2
  234. eval $command >"$outfile" 2>$errfile
  235. err=$?
  236. if [ $err -gt 128 ]; then
  237. sig=$(kill -l $err 2>/dev/null)
  238. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  239. fi
  240. if test -e "$ref" || test $cmp = "oneline" ; then
  241. case $cmp in
  242. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  243. rawdiff)diff -u "$ref" "$outfile" >$cmpfile ;;
  244. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  245. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  246. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  247. null) cat "$outfile" >$cmpfile ;;
  248. esac
  249. cmperr=$?
  250. test $err = 0 && err=$cmperr
  251. test $err = 0 || cat $cmpfile
  252. else
  253. echo "reference file '$ref' not found"
  254. err=1
  255. fi
  256. if [ $err -eq 0 ]; then
  257. unset cmpo erro
  258. else
  259. cmpo="$($base64 <$cmpfile)"
  260. erro="$($base64 <$errfile)"
  261. fi
  262. echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
  263. if test $err != 0 && test $gen != "no" ; then
  264. echo "GEN $ref"
  265. cp -f "$outfile" "$ref"
  266. err=$?
  267. fi
  268. if test $err = 0; then
  269. rm -f $outfile $errfile $cmpfile $cleanfiles
  270. elif test $gen = "no"; then
  271. echo "Test $test failed. Look at $errfile for details."
  272. test "${V:-0}" -gt 0 && cat $errfile
  273. else
  274. echo "Updating reference failed, possibly no output file was generated."
  275. fi
  276. exit $err