tests: Convert lavf pixfmt conversion tests to non-legacy test scripts
[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}
96a06dba 26hwaccel=${17:-none}
35d1f726 27report_type=${18:-standard}
26e87a22 28
2fad0977
MR
29outdir="tests/data/fate"
30outfile="${outdir}/${test}"
bcb0a154 31errfile="${outdir}/${test}.err"
b82be636
MR
32cmpfile="${outdir}/${test}.diff"
33repfile="${outdir}/${test}.rep"
2fad0977 34
9cc338b1
JR
35target_path(){
36 test ${1} = ${1#/} && p=${target_path}/
37 echo ${p}${1}
38}
39
bb684296
JR
40# $1=value1, $2=value2, $3=threshold
41# prints 0 if absolute difference between value1 and value2 is <= threshold
42compare(){
a982c5d7 43 awk "BEGIN { v = $1 - $2; printf ((v < 0 ? -v : v) > $3) }"
bb684296
JR
44}
45
e153cfa8 46do_tiny_psnr(){
47b5996b 47 psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
e153cfa8 48 val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
83b203dc
MR
49 size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
50 size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
bb684296 51 val_cmp=$(compare $val $cmp_target $fuzz)
cffd7580
JR
52 size_cmp=$(compare $size1 $size2 $size_tolerance)
53 if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
aab3ea5f
MR
54 echo "$psnr"
55 return 1
56 fi
57}
58
e153cfa8 59oneoff(){
bb684296 60 do_tiny_psnr "$1" "$2" MAXDIFF
e153cfa8
MR
61}
62
63stddev(){
bb684296 64 do_tiny_psnr "$1" "$2" stddev
e153cfa8
MR
65}
66
40fa14f7 67oneline(){
0ff0af73 68 printf '%s\n' "$1" | diff -u -b - "$2"
40fa14f7
MR
69}
70
dff1fc51 71run(){
c4795e80 72 test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
dff1fc51
MR
73 $target_exec $target_path/"$@"
74}
75
4bfa67bd
RB
76probefmt(){
77 run avprobe -show_format_entry format_name -v 0 "$@"
78}
79
b90c8a3d
VG
80probestream(){
81 run avprobe -show_stream_entry "$1" -v 0 "$2"
82}
83
6291d7e4 84avconv(){
96a06dba 85 dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
8d18bc55
AK
86 avconv_args="-nostats -cpuflags $cpuflags"
87 for arg in $@; do
da025d11 88 [ x${arg} = x-i ] && avconv_args="${avconv_args} ${dec_opts}"
8d18bc55
AK
89 avconv_args="${avconv_args} ${arg}"
90 done
91 run avconv ${avconv_args}
2b18c451
MR
92}
93
94framecrc(){
6291d7e4 95 avconv "$@" -f framecrc -
2b18c451
MR
96}
97
98framemd5(){
6291d7e4 99 avconv "$@" -f framemd5 -
2b18c451
MR
100}
101
102crc(){
6291d7e4 103 avconv "$@" -f crc -
2b18c451
MR
104}
105
106md5(){
6291d7e4 107 avconv "$@" md5:
2b18c451
MR
108}
109
110pcm(){
6291d7e4 111 avconv "$@" -vn -f s16le -
2b18c451
MR
112}
113
90e5b58a
JR
114enc_dec_pcm(){
115 out_fmt=$1
9cc338b1
JR
116 dec_fmt=$2
117 pcm_fmt=$3
118 src_file=$(target_path $4)
119 shift 4
90e5b58a
JR
120 encfile="${outdir}/${test}.${out_fmt}"
121 cleanfiles=$encfile
9cc338b1
JR
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} -
90e5b58a
JR
125}
126
0c1959b0 127FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
7263cd55
MR
128DEC_OPTS="-threads $threads -idct simple $FLAGS"
129ENC_OPTS="-threads 1 -idct simple -dct fastint"
130
131enc_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)
9146e872 149 avconv $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
7263cd55
MR
150 -f $dec_fmt -y $tdecfile || return
151 do_md5sum $decfile
152 tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
153}
154
a70eac7a
DB
155# FIXME: There is a certain duplication between the avconv-related helper
156# functions above and below that should be refactored.
157avconv2="$target_exec ${target_path}/avconv"
158raw_src="${target_path}/tests/vsynth1/%02d.pgm"
eb8a8115 159pcm_src="${target_path}/tests/data/asynth1.sw"
a70eac7a
DB
160crcfile="tests/data/$test.lavf.crc"
161target_crcfile="${target_path}/$crcfile"
162
163echov(){
164 echo "$@" >&3
165}
166
167AVCONV_OPTS="-nostats -y -cpuflags $cpuflags -threads $threads"
168DEC_OPTS="-flags +bitexact -idct simple -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
169ENC_OPTS="$DEC_OPTS -threads 1 -dct fastint"
170
171run_avconv(){
172 $echov $avconv2 $AVCONV_OPTS $*
173 $avconv2 $AVCONV_OPTS $*
174}
175
176do_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
185do_avconv_crc(){
186 f="$1"
187 shift
188 run_avconv $* -f crc "$target_crcfile"
189 echo "$f $(cat $crcfile)"
190}
191
eb8a8115
DB
192lavf_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
a957e937
DB
200lavf_image(){
201 t="${test#lavf-}"
202 outdir="tests/data/images/$t"
203 mkdir -p "$outdir"
204 file=${outdir}/%02d.$t
205 run_avconv $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $1 $ENC_OPTS $2 -frames 12 -y -qscale 10 $target_path/$file
206 do_md5sum ${outdir}/02.$t
207 do_avconv_crc $file $DEC_OPTS $2 -i $target_path/$file
208 echo $(wc -c ${outdir}/02.$t)
209}
210
a70eac7a
DB
211lavf_image2pipe(){
212 t="${test#lavf-}"
213 t="${t%pipe}"
214 outdir="tests/data/lavf"
215 file=${outdir}/${t}pipe.$t
216 do_avconv $file $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src -f image2pipe $ENC_OPTS -t 1 -qscale 10
217 do_avconv_crc $file $DEC_OPTS -f image2pipe -i $target_path/$file
218}
219
9a3f31ef 220lavftest(){
bd392785
DB
221 t="${test#lavf-}"
222 ref=${base}/ref/lavf/$t
223 ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
9a3f31ef
MR
224}
225
896fe15d
DB
226pixfmt_conversion(){
227 conversion="${test#pixfmt-}"
228 outdir="tests/data/pixfmt"
229 raw_dst="$outdir/$conversion.out.yuv"
230 file=${outdir}/${conversion}.yuv
231 run_avconv $DEC_OPTS -r 1 -f image2 -c:v pgmyuv -i $raw_src \
232 $ENC_OPTS -f rawvideo -t 1 -s 352x288 -pix_fmt $conversion $target_path/$raw_dst
233 do_avconv $file $DEC_OPTS -f rawvideo -s 352x288 -pix_fmt $conversion -i $target_path/$raw_dst \
234 $ENC_OPTS -f rawvideo -s 352x288 -pix_fmt yuv444p
235}
236
03b052c0
DB
237video_filter(){
238 filters=$1
239 shift
240 label=${test#filter-}
03b052c0 241 printf '%-20s' $label
4141a5a2
DB
242 avconv $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src \
243 $FLAGS $ENC_OPTS -vf "$filters" -c:v rawvideo -frames:v 5 $* -f nut md5:
03b052c0
DB
244}
245
b963f021
DB
246pixfmts(){
247 filter=${test#filter-pixfmts-}
248 filter_args=$1
249
a6a750c7 250 showfiltfmts="$target_exec $target_path/libavfilter/tests/filtfmts"
b963f021
DB
251 exclude_fmts=${outfile}${filter}_exclude_fmts
252 out_fmts=${outfile}${filter}_out_fmts
253
254 # exclude pixel formats which are not supported as input
255 avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^\..\./ { print $2 }' | sort >$exclude_fmts
256 $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts
257
258 pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
358b7ec3
TG
259
260 outertest=$test
b963f021
DB
261 for pix_fmt in $pix_fmts; do
262 test=$pix_fmt
2fb02ecf 263 video_filter "format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v 1
b963f021
DB
264 done
265
266 rm $exclude_fmts $out_fmts
358b7ec3 267 test=$outertest
b963f021
DB
268}
269
db869f4e
DB
270null(){
271 :
272}
273
c4795e80 274exec 3>&2
7263cd55 275eval $command >"$outfile" 2>$errfile
ffe72624 276err=$?
3ade7d32 277
4e705a68
MR
278if [ $err -gt 128 ]; then
279 sig=$(kill -l $err 2>/dev/null)
5b60c293 280 test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
4e705a68
MR
281fi
282
698ac8f9 283if test -e "$ref" || test $cmp = "oneline" || test $cmp = "null" ; then
b82be636 284 case $cmp in
11e33402 285 diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
0720d263
JR
286 oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
287 stddev) stddev "$ref" "$outfile" >$cmpfile ;;
40fa14f7 288 oneline)oneline "$ref" "$outfile" >$cmpfile ;;
84757de0 289 null) cat "$outfile" >$cmpfile ;;
b82be636
MR
290 esac
291 cmperr=$?
292 test $err = 0 && err=$cmperr
35d1f726 293 if [ "$report_type" = "ignore" ]; then
eef860dd 294 test $err = 0 || echo "IGNORE\t${test}" && err=0 && unset sig
35d1f726
JG
295 else
296 test $err = 0 || cat $cmpfile
297 fi
b82be636 298else
9a3f31ef 299 echo "reference file '$ref' not found"
b82be636 300 err=1
9a3f31ef
MR
301fi
302
35d1f726 303if [ $err -eq 0 ] && test $report_type = "standard" ; then
3b1e35d4
TG
304 unset cmpo erro
305else
306 cmpo="$($base64 <$cmpfile)"
307 erro="$($base64 <$errfile)"
308fi
309echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
7d610af6 310
b01b60a2
LB
311if test $err != 0 && test $gen != "no" ; then
312 echo "GEN $ref"
313 cp -f "$outfile" "$ref"
314 err=$?
315fi
316
b82be636
MR
317test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
318exit $err