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.

423 lines
12KB

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