fate-run.sh 11 KB

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