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.

367 lines
10KB

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