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