fate-run.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. probechapters(){
  83. run ffprobe${PROGSUF} -show_chapters -v 0 "$@"
  84. }
  85. probegaplessinfo(){
  86. filename="$1"
  87. shift
  88. run ffprobe${PROGSUF} -bitexact -select_streams a -show_entries format=start_time,duration:stream=index,start_pts,duration_ts -v 0 "$filename" "$@"
  89. pktfile1="${outdir}/${test}.pkts"
  90. framefile1="${outdir}/${test}.frames"
  91. cleanfiles="$cleanfiles $pktfile1 $framefile1"
  92. run ffprobe${PROGSUF} -bitexact -select_streams a -of compact -count_packets -show_entries packet=pts,dts,duration:stream=nb_read_packets -v 0 "$filename" "$@" > "$pktfile1"
  93. head -n 8 "$pktfile1"
  94. tail -n 9 "$pktfile1"
  95. run ffprobe${PROGSUF} -bitexact -select_streams a -of compact -count_frames -show_entries frame=pkt_pts,pkt_dts,best_effort_timestamp,pkt_duration,nb_samples:stream=nb_read_frames -v 0 "$filename" "$@" > "$framefile1"
  96. head -n 8 "$framefile1"
  97. tail -n 9 "$framefile1"
  98. }
  99. ffmpeg(){
  100. dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
  101. ffmpeg_args="-nostdin -nostats -cpuflags $cpuflags"
  102. for arg in $@; do
  103. [ x${arg} = x-i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
  104. ffmpeg_args="${ffmpeg_args} ${arg}"
  105. done
  106. run ffmpeg${PROGSUF} ${ffmpeg_args}
  107. }
  108. framecrc(){
  109. ffmpeg "$@" -flags +bitexact -fflags +bitexact -f framecrc -
  110. }
  111. ffmetadata(){
  112. ffmpeg "$@" -flags +bitexact -fflags +bitexact -f ffmetadata -
  113. }
  114. framemd5(){
  115. ffmpeg "$@" -flags +bitexact -fflags +bitexact -f framemd5 -
  116. }
  117. crc(){
  118. ffmpeg "$@" -f crc -
  119. }
  120. md5(){
  121. ffmpeg "$@" md5:
  122. }
  123. pcm(){
  124. ffmpeg "$@" -vn -f s16le -
  125. }
  126. fmtstdout(){
  127. fmt=$1
  128. shift 1
  129. ffmpeg -flags +bitexact -fflags +bitexact "$@" -f $fmt -
  130. }
  131. enc_dec_pcm(){
  132. out_fmt=$1
  133. dec_fmt=$2
  134. pcm_fmt=$3
  135. src_file=$(target_path $4)
  136. shift 4
  137. encfile="${outdir}/${test}.${out_fmt}"
  138. cleanfiles=$encfile
  139. encfile=$(target_path ${encfile})
  140. ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  141. ffmpeg -flags +bitexact -fflags +bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -fflags +bitexact -f ${dec_fmt} -
  142. }
  143. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
  144. DEC_OPTS="-threads $threads -idct simple $FLAGS"
  145. ENC_OPTS="-threads 1 -idct simple -dct fastint"
  146. enc_dec(){
  147. src_fmt=$1
  148. srcfile=$2
  149. enc_fmt=$3
  150. enc_opt=$4
  151. dec_fmt=$5
  152. dec_opt=$6
  153. encfile="${outdir}/${test}.${enc_fmt}"
  154. decfile="${outdir}/${test}.out.${dec_fmt}"
  155. cleanfiles="$cleanfiles $decfile"
  156. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  157. tsrcfile=$(target_path $srcfile)
  158. tencfile=$(target_path $encfile)
  159. tdecfile=$(target_path $decfile)
  160. ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  161. -f $enc_fmt -y $tencfile || return
  162. do_md5sum $encfile
  163. echo $(wc -c $encfile)
  164. ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
  165. -f $dec_fmt -y $tdecfile || return
  166. do_md5sum $decfile
  167. tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
  168. }
  169. transcode(){
  170. src_fmt=$1
  171. srcfile=$2
  172. enc_fmt=$3
  173. enc_opt=$4
  174. final_decode=$5
  175. encfile="${outdir}/${test}.${enc_fmt}"
  176. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  177. tsrcfile=$(target_path $srcfile)
  178. tencfile=$(target_path $encfile)
  179. ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  180. -f $enc_fmt -y $tencfile || return
  181. do_md5sum $encfile
  182. echo $(wc -c $encfile)
  183. ffmpeg $DEC_OPTS -i $encfile $ENC_OPTS $FLAGS $final_decode \
  184. -f framecrc - || return
  185. }
  186. lavffatetest(){
  187. t="${test#lavf-fate-}"
  188. ref=${base}/ref/lavf-fate/$t
  189. ${base}/lavf-regression.sh $t lavf-fate tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
  190. }
  191. lavftest(){
  192. t="${test#lavf-}"
  193. ref=${base}/ref/lavf/$t
  194. ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
  195. }
  196. video_filter(){
  197. filters=$1
  198. shift
  199. label=${test#filter-}
  200. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  201. printf '%-20s' $label
  202. ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
  203. $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo -frames:v 5 $* -f nut md5:
  204. }
  205. pixfmts(){
  206. filter=${test#filter-pixfmts-}
  207. filter=${filter%_*}
  208. filter_args=$1
  209. prefilter_chain=$2
  210. nframes=${3:-1}
  211. showfiltfmts="$target_exec $target_path/libavfilter/tests/filtfmts"
  212. scale_exclude_fmts=${outfile}_scale_exclude_fmts
  213. scale_in_fmts=${outfile}_scale_in_fmts
  214. scale_out_fmts=${outfile}_scale_out_fmts
  215. in_fmts=${outfile}_in_fmts
  216. # exclude pixel formats which are not supported as input
  217. $showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
  218. $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
  219. comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts
  220. $showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
  221. pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
  222. outertest=$test
  223. for pix_fmt in $pix_fmts; do
  224. test=$pix_fmt
  225. video_filter "${prefilter_chain}format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v $nframes
  226. done
  227. rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
  228. test=$outertest
  229. }
  230. gapless(){
  231. sample=$(target_path $1)
  232. extra_args=$2
  233. decfile1="${outdir}/${test}.out-1"
  234. decfile2="${outdir}/${test}.out-2"
  235. decfile3="${outdir}/${test}.out-3"
  236. cleanfiles="$cleanfiles $decfile1 $decfile2 $decfile3"
  237. # test packet data
  238. ffmpeg $extra_args -i "$sample" -flags +bitexact -fflags +bitexact -c:a copy -f framecrc -y $decfile1
  239. do_md5sum $decfile1
  240. # test decoded (and cut) data
  241. ffmpeg $extra_args -i "$sample" -flags +bitexact -fflags +bitexact -f wav md5:
  242. # the same as above again, with seeking to the start
  243. ffmpeg $extra_args -ss 0 -seek_timestamp 1 -i "$sample" -flags +bitexact -fflags +bitexact -c:a copy -f framecrc -y $decfile2
  244. do_md5sum $decfile2
  245. ffmpeg $extra_args -ss 0 -seek_timestamp 1 -i "$sample" -flags +bitexact -fflags +bitexact -f wav md5:
  246. # test packet data, with seeking to a specific position
  247. ffmpeg $extra_args -ss 5 -seek_timestamp 1 -i "$sample" -flags +bitexact -fflags +bitexact -c:a copy -f framecrc -y $decfile3
  248. do_md5sum $decfile3
  249. }
  250. gaplessenc(){
  251. sample=$(target_path $1)
  252. format=$2
  253. codec=$3
  254. file1="${outdir}/${test}.out-1"
  255. cleanfiles="$cleanfiles $file1"
  256. # test data after reencoding
  257. ffmpeg -i "$sample" -flags +bitexact -fflags +bitexact -map 0:a -c:a $codec -f $format -y "$file1"
  258. probegaplessinfo "$file1"
  259. }
  260. audio_match(){
  261. sample=$(target_path $1)
  262. trefile=$(target_path $2)
  263. extra_args=$3
  264. decfile="${outdir}/${test}.wav"
  265. cleanfiles="$cleanfiles $decfile"
  266. ffmpeg -i "$sample" -flags +bitexact -fflags +bitexact $extra_args -y $decfile
  267. tests/audiomatch $decfile $trefile
  268. }
  269. concat(){
  270. template=$1
  271. sample=$2
  272. mode=$3
  273. extra_args=$4
  274. concatfile="${outdir}/${test}.ffconcat"
  275. packetfile="${outdir}/${test}.ffprobe"
  276. cleanfiles="$concatfile $packetfile"
  277. awk "{gsub(/%SRCFILE%/, \"$sample\"); print}" $template > $concatfile
  278. if [ "$mode" = "md5" ]; then
  279. run ffprobe${PROGSUF} -bitexact -show_streams -show_packets -v 0 -fflags keepside -safe 0 $extra_args $concatfile | tr -d '\r' > $packetfile
  280. do_md5sum $packetfile
  281. else
  282. run ffprobe${PROGSUF} -bitexact -show_streams -show_packets -v 0 -of compact=p=0:nk=1 -fflags keepside -safe 0 $extra_args $concatfile
  283. fi
  284. }
  285. mkdir -p "$outdir"
  286. # Disable globbing: command arguments may contain globbing characters and
  287. # must be kept verbatim
  288. set -f
  289. exec 3>&2
  290. eval $command >"$outfile" 2>$errfile
  291. err=$?
  292. if [ $err -gt 128 ]; then
  293. sig=$(kill -l $err 2>/dev/null)
  294. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  295. fi
  296. if test -e "$ref" || test $cmp = "oneline" || test $cmp = "grep" ; then
  297. case $cmp in
  298. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  299. rawdiff)diff -u "$ref" "$outfile" >$cmpfile ;;
  300. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  301. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  302. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  303. grep) grep "$ref" "$errfile" >$cmpfile ;;
  304. null) cat "$outfile" >$cmpfile ;;
  305. esac
  306. cmperr=$?
  307. test $err = 0 && err=$cmperr
  308. test $err = 0 || cat $cmpfile
  309. else
  310. echo "reference file '$ref' not found"
  311. err=1
  312. fi
  313. if [ $err -eq 0 ]; then
  314. unset cmpo erro
  315. else
  316. cmpo="$($base64 <$cmpfile)"
  317. erro="$($base64 <$errfile)"
  318. fi
  319. echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
  320. if test $err != 0 && test $gen != "no" ; then
  321. echo "GEN $ref"
  322. cp -f "$outfile" "$ref"
  323. err=$?
  324. fi
  325. if test $err = 0; then
  326. rm -f $outfile $errfile $cmpfile $cleanfiles
  327. elif test $gen = "no"; then
  328. echo "Test $test failed. Look at $errfile for details."
  329. test "${V:-0}" -gt 0 && cat $errfile
  330. else
  331. echo "Updating reference failed, possibly no output file was generated."
  332. fi
  333. exit $err