]> git.sesse.net Git - ffmpeg/blob - tests/fate-run.sh
tests: Convert lavf container tests to non-legacy test scripts
[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 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)
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         return 1
56     fi
57 }
58
59 oneoff(){
60     do_tiny_psnr "$1" "$2" MAXDIFF
61 }
62
63 stddev(){
64     do_tiny_psnr "$1" "$2" stddev
65 }
66
67 oneline(){
68     printf '%s\n' "$1" | diff -u -b - "$2"
69 }
70
71 run(){
72     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
73     $target_exec $target_path/"$@"
74 }
75
76 probefmt(){
77     run avprobe -show_format_entry format_name -v 0 "$@"
78 }
79
80 probestream(){
81     run avprobe -show_stream_entry "$1" -v 0 "$2"
82 }
83
84 avconv(){
85     dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
86     avconv_args="-nostats -cpuflags $cpuflags"
87     for arg in $@; do
88         [ x${arg} = x-i ] && avconv_args="${avconv_args} ${dec_opts}"
89         avconv_args="${avconv_args} ${arg}"
90     done
91     run avconv ${avconv_args}
92 }
93
94 framecrc(){
95     avconv "$@" -f framecrc -
96 }
97
98 framemd5(){
99     avconv "$@" -f framemd5 -
100 }
101
102 crc(){
103     avconv "$@" -f crc -
104 }
105
106 md5(){
107     avconv "$@" md5:
108 }
109
110 pcm(){
111     avconv "$@" -vn -f s16le -
112 }
113
114 enc_dec_pcm(){
115     out_fmt=$1
116     dec_fmt=$2
117     pcm_fmt=$3
118     src_file=$(target_path $4)
119     shift 4
120     encfile="${outdir}/${test}.${out_fmt}"
121     cleanfiles=$encfile
122     encfile=$(target_path ${encfile})
123     avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
124     avconv -f $out_fmt -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
125 }
126
127 FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
128 DEC_OPTS="-threads $threads -idct simple $FLAGS"
129 ENC_OPTS="-threads 1        -idct simple -dct fastint"
130
131 enc_dec(){
132     src_fmt=$1
133     srcfile=$2
134     enc_fmt=$3
135     enc_opt=$4
136     dec_fmt=$5
137     dec_opt=$6
138     encfile="${outdir}/${test}.${enc_fmt}"
139     decfile="${outdir}/${test}.out.${dec_fmt}"
140     cleanfiles="$cleanfiles $decfile"
141     test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
142     tsrcfile=$(target_path $srcfile)
143     tencfile=$(target_path $encfile)
144     tdecfile=$(target_path $decfile)
145     avconv -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
146         -f $enc_fmt -y $tencfile || return
147     do_md5sum $encfile
148     echo $(wc -c $encfile)
149     avconv $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
150         -f $dec_fmt -y $tdecfile || return
151     do_md5sum $decfile
152     tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
153 }
154
155 # FIXME: There is a certain duplication between the avconv-related helper
156 # functions above and below that should be refactored.
157 avconv2="$target_exec ${target_path}/avconv"
158 raw_src="${target_path}/tests/vsynth1/%02d.pgm"
159 pcm_src="${target_path}/tests/data/asynth1.sw"
160 crcfile="tests/data/$test.lavf.crc"
161 target_crcfile="${target_path}/$crcfile"
162
163 echov(){
164     echo "$@" >&3
165 }
166
167 AVCONV_OPTS="-nostats -y -cpuflags $cpuflags -threads $threads"
168 DEC_OPTS="-flags +bitexact -idct simple -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
169 ENC_OPTS="$DEC_OPTS -threads 1 -dct fastint"
170
171 run_avconv(){
172     $echov $avconv2 $AVCONV_OPTS $*
173     $avconv2 $AVCONV_OPTS $*
174 }
175
176 do_avconv(){
177     f="$1"
178     shift
179     set -- $* ${target_path}/$f
180     run_avconv $*
181     do_md5sum $f
182     echo $(wc -c $f)
183 }
184
185 do_avconv_crc(){
186     f="$1"
187     shift
188     run_avconv $* -f crc "$target_crcfile"
189     echo "$f $(cat $crcfile)"
190 }
191
192 lavf_audio(){
193     t="${test#lavf-}"
194     outdir="tests/data/lavf"
195     file=${outdir}/lavf.$t
196     do_avconv $file $DEC_OPTS $1 -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $2
197     do_avconv_crc $file $DEC_OPTS $3 -i $target_path/$file
198 }
199
200 lavf_container(){
201     t="${test#lavf-}"
202     outdir="tests/data/lavf"
203     file=${outdir}/lavf.$t
204     do_avconv $file $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le $1 -i $pcm_src $ENC_OPTS -b:a 64k -t 1 -qscale:v 10 $2
205     test $3 = "disable_crc" ||
206         do_avconv_crc $file $DEC_OPTS -i $target_path/$file $3
207 }
208
209 lavf_image(){
210     t="${test#lavf-}"
211     outdir="tests/data/images/$t"
212     mkdir -p "$outdir"
213     file=${outdir}/%02d.$t
214     run_avconv $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $1 $ENC_OPTS $2 -frames 12 -y -qscale 10 $target_path/$file
215     do_md5sum ${outdir}/02.$t
216     do_avconv_crc $file $DEC_OPTS $2 -i $target_path/$file
217     echo $(wc -c ${outdir}/02.$t)
218 }
219
220 lavf_image2pipe(){
221     t="${test#lavf-}"
222     t="${t%pipe}"
223     outdir="tests/data/lavf"
224     file=${outdir}/${t}pipe.$t
225     do_avconv $file $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src -f image2pipe $ENC_OPTS -t 1 -qscale 10
226     do_avconv_crc $file $DEC_OPTS -f image2pipe -i $target_path/$file
227 }
228
229 lavftest(){
230     t="${test#lavf-}"
231     ref=${base}/ref/lavf/$t
232     ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
233 }
234
235 pixfmt_conversion(){
236     conversion="${test#pixfmt-}"
237     outdir="tests/data/pixfmt"
238     raw_dst="$outdir/$conversion.out.yuv"
239     file=${outdir}/${conversion}.yuv
240     run_avconv $DEC_OPTS -r 1 -f image2 -c:v pgmyuv -i $raw_src \
241                $ENC_OPTS -f rawvideo -t 1 -s 352x288 -pix_fmt $conversion $target_path/$raw_dst
242     do_avconv $file $DEC_OPTS -f rawvideo -s 352x288 -pix_fmt $conversion -i $target_path/$raw_dst \
243               $ENC_OPTS -f rawvideo -s 352x288 -pix_fmt yuv444p
244 }
245
246 video_filter(){
247     filters=$1
248     shift
249     label=${test#filter-}
250     printf '%-20s' $label
251     avconv $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src \
252         $FLAGS $ENC_OPTS -vf "$filters" -c:v rawvideo -frames:v 5 $* -f nut md5:
253 }
254
255 pixfmts(){
256     filter=${test#filter-pixfmts-}
257     filter_args=$1
258
259     showfiltfmts="$target_exec $target_path/libavfilter/tests/filtfmts"
260     exclude_fmts=${outfile}${filter}_exclude_fmts
261     out_fmts=${outfile}${filter}_out_fmts
262
263     # exclude pixel formats which are not supported as input
264     avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^\..\./ { print $2 }' | sort >$exclude_fmts
265     $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts
266
267     pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
268
269     outertest=$test
270     for pix_fmt in $pix_fmts; do
271         test=$pix_fmt
272         video_filter "format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v 1
273     done
274
275     rm $exclude_fmts $out_fmts
276     test=$outertest
277 }
278
279 null(){
280     :
281 }
282
283 exec 3>&2
284 eval $command >"$outfile" 2>$errfile
285 err=$?
286
287 if [ $err -gt 128 ]; then
288     sig=$(kill -l $err 2>/dev/null)
289     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
290 fi
291
292 if test -e "$ref" || test $cmp = "oneline" || test $cmp = "null" ; then
293     case $cmp in
294         diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
295         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
296         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
297         oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
298         null)   cat               "$outfile"            >$cmpfile ;;
299     esac
300     cmperr=$?
301     test $err = 0 && err=$cmperr
302     if [ "$report_type" = "ignore" ]; then
303         test $err = 0 || echo "IGNORE\t${test}" && err=0 && unset sig
304     else
305         test $err = 0 || cat $cmpfile
306     fi
307 else
308     echo "reference file '$ref' not found"
309     err=1
310 fi
311
312 if [ $err -eq 0 ] && test $report_type = "standard" ; then
313     unset cmpo erro
314 else
315     cmpo="$($base64 <$cmpfile)"
316     erro="$($base64 <$errfile)"
317 fi
318 echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
319
320 if test $err != 0 && test $gen != "no" ; then
321     echo "GEN     $ref"
322     cp -f "$outfile" "$ref"
323     err=$?
324 fi
325
326 test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
327 exit $err