lavf: add AVFMT_FLAG_BITEXACT.
[libav.git] / tests / fate-run.sh
CommitLineData
2fad0977
MR
1#! /bin/sh
2
078ae66b
MR
3export LC_ALL=C
4
2fad0977
MR
5base=$(dirname $0)
6. "${base}/md5.sh"
7
b82be636
MR
8base64=tests/base64
9
2fad0977 10test="${1#fate-}"
122a9af7 11samples=$2
2fad0977 12target_exec=$3
122a9af7 13target_path=$4
2fad0977 14command=$5
3ade7d32 15cmp=${6:-diff}
3ade7d32 16ref=${7:-"${base}/ref/fate/${test}"}
0720d263 17fuzz=${8:-1}
7851eb68 18threads=${9:-1}
bc5acfa7 19thread_type=${10:-frame+slice}
018f39ef 20cpuflags=${11:-all}
5ecadc66 21cmp_shift=${12:-0}
bb684296 22cmp_target=${13:-0}
cffd7580 23size_tolerance=${14:-0}
47b5996b 24cmp_unit=${15:-2}
b01b60a2 25gen=${16:-no}
26e87a22 26
2fad0977
MR
27outdir="tests/data/fate"
28outfile="${outdir}/${test}"
bcb0a154 29errfile="${outdir}/${test}.err"
b82be636
MR
30cmpfile="${outdir}/${test}.diff"
31repfile="${outdir}/${test}.rep"
2fad0977 32
9cc338b1
JR
33target_path(){
34 test ${1} = ${1#/} && p=${target_path}/
35 echo ${p}${1}
36}
37
bb684296
JR
38# $1=value1, $2=value2, $3=threshold
39# prints 0 if absolute difference between value1 and value2 is <= threshold
40compare(){
a56fba50 41 echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
bb684296
JR
42}
43
e153cfa8 44do_tiny_psnr(){
47b5996b 45 psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
e153cfa8 46 val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
83b203dc
MR
47 size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
48 size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
bb684296 49 val_cmp=$(compare $val $cmp_target $fuzz)
cffd7580
JR
50 size_cmp=$(compare $size1 $size2 $size_tolerance)
51 if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
aab3ea5f
MR
52 echo "$psnr"
53 return 1
54 fi
55}
56
e153cfa8 57oneoff(){
bb684296 58 do_tiny_psnr "$1" "$2" MAXDIFF
e153cfa8
MR
59}
60
61stddev(){
bb684296 62 do_tiny_psnr "$1" "$2" stddev
e153cfa8
MR
63}
64
40fa14f7 65oneline(){
0ff0af73 66 printf '%s\n' "$1" | diff -u -b - "$2"
40fa14f7
MR
67}
68
dff1fc51 69run(){
c4795e80 70 test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
dff1fc51
MR
71 $target_exec $target_path/"$@"
72}
73
4bfa67bd
RB
74probefmt(){
75 run avprobe -show_format_entry format_name -v 0 "$@"
76}
77
6291d7e4 78avconv(){
8d18bc55
AK
79 dec_opts="-threads $threads -thread_type $thread_type"
80 avconv_args="-nostats -cpuflags $cpuflags"
81 for arg in $@; do
da025d11 82 [ x${arg} = x-i ] && avconv_args="${avconv_args} ${dec_opts}"
8d18bc55
AK
83 avconv_args="${avconv_args} ${arg}"
84 done
85 run avconv ${avconv_args}
2b18c451
MR
86}
87
88framecrc(){
6291d7e4 89 avconv "$@" -f framecrc -
2b18c451
MR
90}
91
92framemd5(){
6291d7e4 93 avconv "$@" -f framemd5 -
2b18c451
MR
94}
95
96crc(){
6291d7e4 97 avconv "$@" -f crc -
2b18c451
MR
98}
99
100md5(){
6291d7e4 101 avconv "$@" md5:
2b18c451
MR
102}
103
104pcm(){
6291d7e4 105 avconv "$@" -vn -f s16le -
2b18c451
MR
106}
107
90e5b58a
JR
108enc_dec_pcm(){
109 out_fmt=$1
9cc338b1
JR
110 dec_fmt=$2
111 pcm_fmt=$3
112 src_file=$(target_path $4)
113 shift 4
90e5b58a
JR
114 encfile="${outdir}/${test}.${out_fmt}"
115 cleanfiles=$encfile
9cc338b1
JR
116 encfile=$(target_path ${encfile})
117 avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
118 avconv -f $out_fmt -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
90e5b58a
JR
119}
120
0c1959b0 121FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
7263cd55
MR
122DEC_OPTS="-threads $threads -idct simple $FLAGS"
123ENC_OPTS="-threads 1 -idct simple -dct fastint"
124
125enc_dec(){
126 src_fmt=$1
127 srcfile=$2
128 enc_fmt=$3
129 enc_opt=$4
130 dec_fmt=$5
131 dec_opt=$6
132 encfile="${outdir}/${test}.${enc_fmt}"
133 decfile="${outdir}/${test}.out.${dec_fmt}"
134 cleanfiles="$cleanfiles $decfile"
135 test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
136 tsrcfile=$(target_path $srcfile)
137 tencfile=$(target_path $encfile)
138 tdecfile=$(target_path $decfile)
139 avconv -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
140 -f $enc_fmt -y $tencfile || return
141 do_md5sum $encfile
142 echo $(wc -c $encfile)
9146e872 143 avconv $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
7263cd55
MR
144 -f $dec_fmt -y $tdecfile || return
145 do_md5sum $decfile
146 tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
147}
148
9a3f31ef 149lavftest(){
bd392785
DB
150 t="${test#lavf-}"
151 ref=${base}/ref/lavf/$t
152 ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
9a3f31ef
MR
153}
154
03b052c0
DB
155video_filter(){
156 filters=$1
157 shift
158 label=${test#filter-}
159 raw_src="${target_path}/tests/vsynth1/%02d.pgm"
160 printf '%-20s' $label
161 avconv $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
162 $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5:
163}
164
28663511
DB
165pixdesc(){
166 pix_fmts="$(avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^IO/ { print $2 }' | sort)"
167 for pix_fmt in $pix_fmts; do
168 test=$pix_fmt
169 video_filter "format=$pix_fmt,pixdesctest" -pix_fmt $pix_fmt
170 done
171}
172
b963f021
DB
173pixfmts(){
174 filter=${test#filter-pixfmts-}
175 filter_args=$1
176
177 showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
178 exclude_fmts=${outfile}${filter}_exclude_fmts
179 out_fmts=${outfile}${filter}_out_fmts
180
181 # exclude pixel formats which are not supported as input
182 avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^\..\./ { print $2 }' | sort >$exclude_fmts
183 $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts
184
185 pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
186 for pix_fmt in $pix_fmts; do
187 test=$pix_fmt
188 video_filter "format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
189 done
190
191 rm $exclude_fmts $out_fmts
192}
193
2fad0977
MR
194mkdir -p "$outdir"
195
c4795e80 196exec 3>&2
7263cd55 197eval $command >"$outfile" 2>$errfile
ffe72624 198err=$?
3ade7d32 199
4e705a68
MR
200if [ $err -gt 128 ]; then
201 sig=$(kill -l $err 2>/dev/null)
5b60c293 202 test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
4e705a68
MR
203fi
204
40fa14f7 205if test -e "$ref" || test $cmp = "oneline" ; then
b82be636 206 case $cmp in
11e33402 207 diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
0720d263
JR
208 oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
209 stddev) stddev "$ref" "$outfile" >$cmpfile ;;
40fa14f7 210 oneline)oneline "$ref" "$outfile" >$cmpfile ;;
84757de0 211 null) cat "$outfile" >$cmpfile ;;
b82be636
MR
212 esac
213 cmperr=$?
214 test $err = 0 && err=$cmperr
215 test $err = 0 || cat $cmpfile
216else
9a3f31ef 217 echo "reference file '$ref' not found"
b82be636 218 err=1
9a3f31ef
MR
219fi
220
4e705a68 221echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
7d610af6 222
b01b60a2
LB
223if test $err != 0 && test $gen != "no" ; then
224 echo "GEN $ref"
225 cp -f "$outfile" "$ref"
226 err=$?
227fi
228
b82be636
MR
229test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
230exit $err