]> git.sesse.net Git - ffmpeg/blob - tests/fate-run.sh
Merge commit '108f2f381acb93827fb4add0517eeae859afa3bf'
[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)
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 -show_entries format=format_name -print_format default=nw=1:nk=1 -v 0 "$@"
88 }
89
90 probeframes(){
91     run ffprobe -show_frames -v 0 "$@"
92 }
93
94 ffmpeg(){
95     dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
96     ffmpeg_args="-nostats -cpuflags $cpuflags"
97     for arg in $@; do
98         [ x${arg} = x-i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
99         ffmpeg_args="${ffmpeg_args} ${arg}"
100     done
101     run ffmpeg ${ffmpeg_args}
102 }
103
104 framecrc(){
105     ffmpeg "$@" -flags +bitexact -f framecrc -
106 }
107
108 framemd5(){
109     ffmpeg "$@" -flags +bitexact -f framemd5 -
110 }
111
112 crc(){
113     ffmpeg "$@" -f crc -
114 }
115
116 md5(){
117     ffmpeg "$@" md5:
118 }
119
120 pcm(){
121     ffmpeg "$@" -vn -f s16le -
122 }
123
124 fmtstdout(){
125     fmt=$1
126     shift 1
127     ffmpeg -flags +bitexact "$@" -f $fmt -
128 }
129
130 enc_dec_pcm(){
131     out_fmt=$1
132     dec_fmt=$2
133     pcm_fmt=$3
134     src_file=$(target_path $4)
135     shift 4
136     encfile="${outdir}/${test}.${out_fmt}"
137     cleanfiles=$encfile
138     encfile=$(target_path ${encfile})
139     ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
140     ffmpeg -flags +bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
141 }
142
143 FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
144 DEC_OPTS="-threads $threads -idct simple $FLAGS"
145 ENC_OPTS="-threads 1        -idct simple -dct fastint"
146
147 enc_dec(){
148     src_fmt=$1
149     srcfile=$2
150     enc_fmt=$3
151     enc_opt=$4
152     dec_fmt=$5
153     dec_opt=$6
154     encfile="${outdir}/${test}.${enc_fmt}"
155     decfile="${outdir}/${test}.out.${dec_fmt}"
156     cleanfiles="$cleanfiles $decfile"
157     test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
158     tsrcfile=$(target_path $srcfile)
159     tencfile=$(target_path $encfile)
160     tdecfile=$(target_path $decfile)
161     ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
162         -f $enc_fmt -y $tencfile || return
163     do_md5sum $encfile
164     echo $(wc -c $encfile)
165     ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
166         -f $dec_fmt -y $tdecfile || return
167     do_md5sum $decfile
168     tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
169 }
170
171 lavffatetest(){
172     t="${test#lavf-fate-}"
173     ref=${base}/ref/lavf-fate/$t
174     ${base}/lavf-regression.sh $t lavf-fate tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
175 }
176
177 lavftest(){
178     t="${test#lavf-}"
179     ref=${base}/ref/lavf/$t
180     ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
181 }
182
183 video_filter(){
184     filters=$1
185     shift
186     label=${test#filter-}
187     raw_src="${target_path}/tests/vsynth1/%02d.pgm"
188     printf '%-20s' $label
189     ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
190         $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5:
191 }
192
193 pixfmts(){
194     filter=${test#filter-pixfmts-}
195     filter=${filter%_*}
196     filter_args=$1
197     prefilter_chain=$2
198
199     showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
200     scale_exclude_fmts=${outfile}_scale_exclude_fmts
201     scale_in_fmts=${outfile}_scale_in_fmts
202     scale_out_fmts=${outfile}_scale_out_fmts
203     in_fmts=${outfile}_in_fmts
204
205     # exclude pixel formats which are not supported as input
206     $showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
207     $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
208     comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts
209
210     $showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
211     pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
212
213     outertest=$test
214     for pix_fmt in $pix_fmts; do
215         test=$pix_fmt
216         video_filter "${prefilter_chain}format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
217     done
218
219     rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
220     test=$outertest
221 }
222
223 mkdir -p "$outdir"
224
225 # Disable globbing: command arguments may contain globbing characters and
226 # must be kept verbatim
227 set -f
228
229 exec 3>&2
230 eval $command >"$outfile" 2>$errfile
231 err=$?
232
233 if [ $err -gt 128 ]; then
234     sig=$(kill -l $err 2>/dev/null)
235     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
236 fi
237
238 if test -e "$ref" || test $cmp = "oneline" ; then
239     case $cmp in
240         diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
241         rawdiff)diff -u    "$ref" "$outfile"            >$cmpfile ;;
242         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
243         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
244         oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
245         null)   cat               "$outfile"            >$cmpfile ;;
246     esac
247     cmperr=$?
248     test $err = 0 && err=$cmperr
249     test $err = 0 || cat $cmpfile
250 else
251     echo "reference file '$ref' not found"
252     err=1
253 fi
254
255 echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
256
257 if test $err != 0 && test $gen != "no" ; then
258     echo "GEN     $ref"
259     cp -f "$outfile" "$ref"
260     err=$?
261 fi
262
263 if test $err = 0; then
264     rm -f $outfile $errfile $cmpfile $cleanfiles
265 elif test $gen = "no"; then
266     echo "Test $test failed. Look at $errfile for details."
267     test "${V:-0}" -gt 0 && cat $errfile
268 else
269     echo "Updating reference failed, possibly no output file was generated."
270 fi
271 exit $err