]> git.sesse.net Git - ffmpeg/blob - tests/fate-run.sh
qsvdec: Only warn about unconsumed data if it happens more than once
[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
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)
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         return 1
55     fi
56 }
57
58 oneoff(){
59     do_tiny_psnr "$1" "$2" MAXDIFF
60 }
61
62 stddev(){
63     do_tiny_psnr "$1" "$2" stddev
64 }
65
66 oneline(){
67     printf '%s\n' "$1" | diff -u -b - "$2"
68 }
69
70 run(){
71     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
72     $target_exec $target_path/"$@"
73 }
74
75 probefmt(){
76     run avprobe -show_format_entry format_name -v 0 "$@"
77 }
78
79 probestream(){
80     run avprobe -show_stream_entry "$1" -v 0 "$2"
81 }
82
83 avconv(){
84     dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
85     avconv_args="-nostats -cpuflags $cpuflags"
86     for arg in $@; do
87         [ x${arg} = x-i ] && avconv_args="${avconv_args} ${dec_opts}"
88         avconv_args="${avconv_args} ${arg}"
89     done
90     run avconv ${avconv_args}
91 }
92
93 framecrc(){
94     avconv "$@" -f framecrc -
95 }
96
97 framemd5(){
98     avconv "$@" -f framemd5 -
99 }
100
101 crc(){
102     avconv "$@" -f crc -
103 }
104
105 md5(){
106     avconv "$@" md5:
107 }
108
109 pcm(){
110     avconv "$@" -vn -f s16le -
111 }
112
113 enc_dec_pcm(){
114     out_fmt=$1
115     dec_fmt=$2
116     pcm_fmt=$3
117     src_file=$(target_path $4)
118     shift 4
119     encfile="${outdir}/${test}.${out_fmt}"
120     cleanfiles=$encfile
121     encfile=$(target_path ${encfile})
122     avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
123     avconv -f $out_fmt -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
124 }
125
126 FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
127 DEC_OPTS="-threads $threads -idct simple $FLAGS"
128 ENC_OPTS="-threads 1        -idct simple -dct fastint"
129
130 enc_dec(){
131     src_fmt=$1
132     srcfile=$2
133     enc_fmt=$3
134     enc_opt=$4
135     dec_fmt=$5
136     dec_opt=$6
137     encfile="${outdir}/${test}.${enc_fmt}"
138     decfile="${outdir}/${test}.out.${dec_fmt}"
139     cleanfiles="$cleanfiles $decfile"
140     test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
141     tsrcfile=$(target_path $srcfile)
142     tencfile=$(target_path $encfile)
143     tdecfile=$(target_path $decfile)
144     avconv -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
145         -f $enc_fmt -y $tencfile || return
146     do_md5sum $encfile
147     echo $(wc -c $encfile)
148     avconv $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
149         -f $dec_fmt -y $tdecfile || return
150     do_md5sum $decfile
151     tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
152 }
153
154 lavftest(){
155     t="${test#lavf-}"
156     ref=${base}/ref/lavf/$t
157     ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
158 }
159
160 video_filter(){
161     filters=$1
162     shift
163     label=${test#filter-}
164     raw_src="${target_path}/tests/vsynth1/%02d.pgm"
165     printf '%-20s' $label
166     avconv $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
167         $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo -frames:v 5 $* -f nut md5:
168 }
169
170 pixfmts(){
171     filter=${test#filter-pixfmts-}
172     filter_args=$1
173
174     showfiltfmts="$target_exec $target_path/libavfilter/tests/filtfmts"
175     exclude_fmts=${outfile}${filter}_exclude_fmts
176     out_fmts=${outfile}${filter}_out_fmts
177
178     # exclude pixel formats which are not supported as input
179     avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^\..\./ { print $2 }' | sort >$exclude_fmts
180     $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts
181
182     pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
183
184     outertest=$test
185     for pix_fmt in $pix_fmts; do
186         test=$pix_fmt
187         video_filter "format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v 1
188     done
189
190     rm $exclude_fmts $out_fmts
191     test=$outertest
192 }
193
194 mkdir -p "$outdir"
195
196 exec 3>&2
197 eval $command >"$outfile" 2>$errfile
198 err=$?
199
200 if [ $err -gt 128 ]; then
201     sig=$(kill -l $err 2>/dev/null)
202     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
203 fi
204
205 if test -e "$ref" || test $cmp = "oneline" ; then
206     case $cmp in
207         diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
208         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
209         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
210         oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
211         null)   cat               "$outfile"            >$cmpfile ;;
212     esac
213     cmperr=$?
214     test $err = 0 && err=$cmperr
215     test $err = 0 || cat $cmpfile
216 else
217     echo "reference file '$ref' not found"
218     err=1
219 fi
220
221 if [ $err -eq 0 ]; then
222     unset cmpo erro
223 else
224     cmpo="$($base64 <$cmpfile)"
225     erro="$($base64 <$errfile)"
226 fi
227 echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
228
229 if test $err != 0 && test $gen != "no" ; then
230     echo "GEN     $ref"
231     cp -f "$outfile" "$ref"
232     err=$?
233 fi
234
235 test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
236 exit $err