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