You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

399 lines
11KB

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