fate-run.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. report_type=${18:-standard}
  24. keep=${19:-0}
  25. outdir="tests/data/fate"
  26. outfile="${outdir}/${test}"
  27. errfile="${outdir}/${test}.err"
  28. cmpfile="${outdir}/${test}.diff"
  29. repfile="${outdir}/${test}.rep"
  30. target_path(){
  31. test ${1} = ${1#/} && p=${target_path}/
  32. echo ${p}${1}
  33. }
  34. # $1=value1, $2=value2, $3=threshold
  35. # prints 0 if absolute difference between value1 and value2 is <= threshold
  36. compare(){
  37. awk "BEGIN { v = $1 - $2; printf ((v < 0 ? -v : v) > $3) }"
  38. }
  39. do_tiny_psnr(){
  40. psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0) || return 1
  41. val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
  42. size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
  43. size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
  44. val_cmp=$(compare $val $cmp_target $fuzz)
  45. size_cmp=$(compare $size1 $size2 $size_tolerance)
  46. if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
  47. echo "$psnr"
  48. if [ "$val_cmp" != 0 ]; then
  49. echo "$3: |$val - $cmp_target| >= $fuzz"
  50. fi
  51. if [ "$size_cmp" != 0 ]; then
  52. echo "size: |$size1 - $size2| >= $size_tolerance"
  53. fi
  54. return 1
  55. fi
  56. }
  57. oneoff(){
  58. do_tiny_psnr "$1" "$2" MAXDIFF
  59. }
  60. stddev(){
  61. do_tiny_psnr "$1" "$2" stddev
  62. }
  63. oneline(){
  64. printf '%s\n' "$1" | diff -u -b - "$2"
  65. }
  66. run(){
  67. test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  68. $target_exec $target_path/"$@"
  69. }
  70. runecho(){
  71. test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  72. $target_exec $target_path/"$@" >&3
  73. }
  74. probefmt(){
  75. run ffprobe${PROGSUF} -show_entries format=format_name -print_format default=nw=1:nk=1 -v 0 "$@"
  76. }
  77. probetags(){
  78. run ffprobe${PROGSUF} -show_entries format_tags -v 0 "$@"
  79. }
  80. runlocal(){
  81. test "${V:-0}" -gt 0 && echo ${base}/"$@" ${base} >&3
  82. ${base}/"$@" ${base}
  83. }
  84. probeframes(){
  85. run ffprobe${PROGSUF} -show_frames -v 0 "$@"
  86. }
  87. probechapters(){
  88. run ffprobe${PROGSUF} -show_chapters -v 0 "$@"
  89. }
  90. probegaplessinfo(){
  91. filename="$1"
  92. shift
  93. run ffprobe${PROGSUF} -bitexact -select_streams a -show_entries format=start_time,duration:stream=index,start_pts,duration_ts -v 0 "$filename" "$@"
  94. pktfile1="${outdir}/${test}.pkts"
  95. framefile1="${outdir}/${test}.frames"
  96. cleanfiles="$cleanfiles $pktfile1 $framefile1"
  97. run ffprobe${PROGSUF} -bitexact -select_streams a -of compact -count_packets -show_entries packet=pts,dts,duration,flags:stream=nb_read_packets -v 0 "$filename" "$@" > "$pktfile1"
  98. head -n 8 "$pktfile1"
  99. tail -n 9 "$pktfile1"
  100. 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"
  101. head -n 8 "$framefile1"
  102. tail -n 9 "$framefile1"
  103. }
  104. ffmpeg(){
  105. dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
  106. ffmpeg_args="-nostdin -nostats -cpuflags $cpuflags"
  107. for arg in $@; do
  108. [ x${arg} = x-i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
  109. ffmpeg_args="${ffmpeg_args} ${arg}"
  110. done
  111. run ffmpeg${PROGSUF} ${ffmpeg_args}
  112. }
  113. framecrc(){
  114. ffmpeg "$@" -bitexact -f framecrc -
  115. }
  116. ffmetadata(){
  117. ffmpeg "$@" -bitexact -f ffmetadata -
  118. }
  119. framemd5(){
  120. ffmpeg "$@" -bitexact -f framemd5 -
  121. }
  122. crc(){
  123. ffmpeg "$@" -f crc -
  124. }
  125. md5pipe(){
  126. ffmpeg "$@" md5:
  127. }
  128. md5(){
  129. encfile="${outdir}/${test}.out"
  130. cleanfiles="$cleanfiles $encfile"
  131. ffmpeg "$@" $encfile
  132. do_md5sum $encfile | awk '{print $1}'
  133. }
  134. pcm(){
  135. ffmpeg "$@" -vn -f s16le -
  136. }
  137. fmtstdout(){
  138. fmt=$1
  139. shift 1
  140. ffmpeg -bitexact "$@" -f $fmt -
  141. }
  142. enc_dec_pcm(){
  143. out_fmt=$1
  144. dec_fmt=$2
  145. pcm_fmt=$3
  146. src_file=$(target_path $4)
  147. shift 4
  148. encfile="${outdir}/${test}.${out_fmt}"
  149. cleanfiles=$encfile
  150. encfile=$(target_path ${encfile})
  151. ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  152. ffmpeg -bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -fflags +bitexact -f ${dec_fmt} -
  153. }
  154. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
  155. DEC_OPTS="-threads $threads -idct simple $FLAGS"
  156. ENC_OPTS="-threads 1 -idct simple -dct fastint"
  157. enc_dec(){
  158. src_fmt=$1
  159. srcfile=$2
  160. enc_fmt=$3
  161. enc_opt=$4
  162. dec_fmt=$5
  163. dec_opt=$6
  164. encfile="${outdir}/${test}.${enc_fmt}"
  165. decfile="${outdir}/${test}.out.${dec_fmt}"
  166. cleanfiles="$cleanfiles $decfile"
  167. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  168. tsrcfile=$(target_path $srcfile)
  169. tencfile=$(target_path $encfile)
  170. tdecfile=$(target_path $decfile)
  171. ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  172. -f $enc_fmt -y $tencfile || return
  173. do_md5sum $encfile
  174. echo $(wc -c $encfile)
  175. ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
  176. -f $dec_fmt -y $tdecfile || return
  177. do_md5sum $decfile
  178. tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
  179. }
  180. transcode(){
  181. src_fmt=$1
  182. srcfile=$2
  183. enc_fmt=$3
  184. enc_opt=$4
  185. final_decode=$5
  186. encfile="${outdir}/${test}.${enc_fmt}"
  187. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  188. tsrcfile=$(target_path $srcfile)
  189. tencfile=$(target_path $encfile)
  190. ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  191. -f $enc_fmt -y $tencfile || return
  192. do_md5sum $encfile
  193. echo $(wc -c $encfile)
  194. ffmpeg $DEC_OPTS -i $encfile $ENC_OPTS $FLAGS $final_decode \
  195. -f framecrc - || return
  196. }
  197. stream_remux(){
  198. src_fmt=$1
  199. srcfile=$2
  200. enc_fmt=$3
  201. stream_maps=$4
  202. final_decode=$5
  203. encfile="${outdir}/${test}.${enc_fmt}"
  204. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  205. tsrcfile=$(target_path $srcfile)
  206. tencfile=$(target_path $encfile)
  207. ffmpeg -f $src_fmt -i $tsrcfile $stream_maps -codec copy $FLAGS \
  208. -f $enc_fmt -y $tencfile || return
  209. ffmpeg $DEC_OPTS -i $encfile $ENC_OPTS $FLAGS $final_decode \
  210. -f framecrc - || return
  211. }
  212. lavffatetest(){
  213. t="${test#lavf-fate-}"
  214. ref=${base}/ref/lavf-fate/$t
  215. ${base}/lavf-regression.sh $t lavf-fate tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
  216. }
  217. lavftest(){
  218. t="${test#lavf-}"
  219. ref=${base}/ref/lavf/$t
  220. ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
  221. }
  222. refcmp_metadata(){
  223. refcmp=$1
  224. pixfmt=$2
  225. fuzz=${3:-0.001}
  226. ffmpeg $FLAGS $ENC_OPTS \
  227. -lavfi "testsrc2=size=300x200:rate=1:duration=5,format=${pixfmt},split[ref][tmp];[tmp]avgblur=4[enc];[enc][ref]${refcmp},metadata=print:file=-" \
  228. -f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f ${base}/refcmp-metadata.awk -
  229. }
  230. video_filter(){
  231. filters=$1
  232. shift
  233. label=${test#filter-}
  234. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  235. printf '%-20s' $label
  236. ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
  237. $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo -frames:v 5 $* -f nut md5:
  238. }
  239. pixfmts(){
  240. filter=${test#filter-pixfmts-}
  241. filter=${filter%_*}
  242. filter_args=$1
  243. prefilter_chain=$2
  244. nframes=${3:-1}
  245. showfiltfmts="$target_exec $target_path/libavfilter/tests/filtfmts"
  246. scale_exclude_fmts=${outfile}_scale_exclude_fmts
  247. scale_in_fmts=${outfile}_scale_in_fmts
  248. scale_out_fmts=${outfile}_scale_out_fmts
  249. in_fmts=${outfile}_in_fmts
  250. # exclude pixel formats which are not supported as input
  251. $showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
  252. $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
  253. comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts
  254. $showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
  255. pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
  256. outertest=$test
  257. for pix_fmt in $pix_fmts; do
  258. test=$pix_fmt
  259. video_filter "${prefilter_chain}format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v $nframes
  260. done
  261. rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
  262. test=$outertest
  263. }
  264. gapless(){
  265. sample=$(target_path $1)
  266. extra_args=$2
  267. decfile1="${outdir}/${test}.out-1"
  268. decfile2="${outdir}/${test}.out-2"
  269. decfile3="${outdir}/${test}.out-3"
  270. cleanfiles="$cleanfiles $decfile1 $decfile2 $decfile3"
  271. # test packet data
  272. ffmpeg $extra_args -i "$sample" -bitexact -c:a copy -f framecrc -y $decfile1
  273. do_md5sum $decfile1
  274. # test decoded (and cut) data
  275. ffmpeg $extra_args -i "$sample" -bitexact -f wav md5:
  276. # the same as above again, with seeking to the start
  277. ffmpeg $extra_args -ss 0 -seek_timestamp 1 -i "$sample" -bitexact -c:a copy -f framecrc -y $decfile2
  278. do_md5sum $decfile2
  279. ffmpeg $extra_args -ss 0 -seek_timestamp 1 -i "$sample" -bitexact -f wav md5:
  280. # test packet data, with seeking to a specific position
  281. ffmpeg $extra_args -ss 5 -seek_timestamp 1 -i "$sample" -bitexact -c:a copy -f framecrc -y $decfile3
  282. do_md5sum $decfile3
  283. }
  284. gaplessenc(){
  285. sample=$(target_path $1)
  286. format=$2
  287. codec=$3
  288. file1="${outdir}/${test}.out-1"
  289. cleanfiles="$cleanfiles $file1"
  290. # test data after reencoding
  291. ffmpeg -i "$sample" -bitexact -map 0:a -c:a $codec -f $format -y "$file1"
  292. probegaplessinfo "$file1"
  293. }
  294. audio_match(){
  295. sample=$(target_path $1)
  296. trefile=$(target_path $2)
  297. extra_args=$3
  298. decfile="${outdir}/${test}.wav"
  299. cleanfiles="$cleanfiles $decfile"
  300. ffmpeg -i "$sample" -bitexact $extra_args -y $decfile
  301. tests/audiomatch $decfile $trefile
  302. }
  303. concat(){
  304. template=$1
  305. sample=$2
  306. mode=$3
  307. extra_args=$4
  308. concatfile="${outdir}/${test}.ffconcat"
  309. packetfile="${outdir}/${test}.ffprobe"
  310. cleanfiles="$concatfile $packetfile"
  311. awk "{gsub(/%SRCFILE%/, \"$sample\"); print}" $template > $concatfile
  312. if [ "$mode" = "md5" ]; then
  313. run ffprobe${PROGSUF} -bitexact -show_streams -show_packets -v 0 -fflags keepside -safe 0 $extra_args $concatfile | tr -d '\r' > $packetfile
  314. do_md5sum $packetfile
  315. else
  316. run ffprobe${PROGSUF} -bitexact -show_streams -show_packets -v 0 -of compact=p=0:nk=1 -fflags keepside -safe 0 $extra_args $concatfile
  317. fi
  318. }
  319. null(){
  320. :
  321. }
  322. mkdir -p "$outdir"
  323. # Disable globbing: command arguments may contain globbing characters and
  324. # must be kept verbatim
  325. set -f
  326. exec 3>&2
  327. eval $command >"$outfile" 2>$errfile
  328. err=$?
  329. if [ $err -gt 128 ]; then
  330. sig=$(kill -l $err 2>/dev/null)
  331. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  332. fi
  333. if test -e "$ref" || test $cmp = "oneline" || test $cmp = "null" || test $cmp = "grep" ; then
  334. case $cmp in
  335. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  336. rawdiff)diff -u "$ref" "$outfile" >$cmpfile ;;
  337. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  338. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  339. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  340. grep) grep "$ref" "$errfile" >$cmpfile ;;
  341. null) cat "$outfile" >$cmpfile ;;
  342. esac
  343. cmperr=$?
  344. test $err = 0 && err=$cmperr
  345. if [ "$report_type" = "ignore" ]; then
  346. test $err = 0 || echo "IGNORE\t${test}" && err=0 && unset sig
  347. else
  348. test $err = 0 || cat $cmpfile
  349. fi
  350. else
  351. echo "reference file '$ref' not found"
  352. err=1
  353. fi
  354. if [ $err -eq 0 ] && test $report_type = "standard" ; then
  355. unset cmpo erro
  356. else
  357. cmpo="$($base64 <$cmpfile)"
  358. erro="$($base64 <$errfile)"
  359. fi
  360. echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
  361. if test $err != 0 && test $gen != "no" ; then
  362. echo "GEN $ref"
  363. cp -f "$outfile" "$ref"
  364. err=$?
  365. fi
  366. if test $err = 0; then
  367. if test $keep = 0; then
  368. rm -f $outfile $errfile $cmpfile $cleanfiles
  369. fi
  370. elif test $gen = "no"; then
  371. echo "Test $test failed. Look at $errfile for details."
  372. test "${V:-0}" -gt 0 && cat $errfile
  373. else
  374. echo "Updating reference failed, possibly no output file was generated."
  375. fi
  376. exit $err