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