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.

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