Merge remote-tracking branch 'libav/master'
[FFMpeg-mirror/mplayer-patches.git] / tests / fate-run.sh
blobd1633e8be4c367c793cb01dbf3e79250c1b9e8c2
1 #! /bin/sh
3 export LC_ALL=C
5 base=$(dirname $0)
6 . "${base}/md5.sh"
8 base64=tests/base64
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}
26 outdir="tests/data/fate"
27 outfile="${outdir}/${test}"
28 errfile="${outdir}/${test}.err"
29 cmpfile="${outdir}/${test}.diff"
30 repfile="${outdir}/${test}.rep"
32 target_path(){
33 test ${1} = ${1#/} && p=${target_path}/
34 echo ${p}${1}
37 # $1=value1, $2=value2, $3=threshold
38 # prints 0 if absolute difference between value1 and value2 is <= threshold
39 compare(){
40 echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
43 do_tiny_psnr(){
44 psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
45 val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
46 size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
47 size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
48 val_cmp=$(compare $val $cmp_target $fuzz)
49 size_cmp=$(compare $size1 $size2 $size_tolerance)
50 if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
51 echo "$psnr"
52 return 1
56 oneoff(){
57 do_tiny_psnr "$1" "$2" MAXDIFF
60 stddev(){
61 do_tiny_psnr "$1" "$2" stddev
64 oneline(){
65 printf '%s\n' "$1" | diff -u -b - "$2"
68 run(){
69 test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
70 $target_exec $target_path/"$@"
73 probefmt(){
74 run avprobe -show_format_entry format_name -v 0 "$@"
77 avconv(){
78 dec_opts="-threads $threads -thread_type $thread_type"
79 avconv_args="-nostats -cpuflags $cpuflags"
80 for arg in $@; do
81 [ x${arg} = x-i ] && avconv_args="${avconv_args} ${dec_opts}"
82 avconv_args="${avconv_args} ${arg}"
83 done
84 run avconv ${avconv_args}
87 framecrc(){
88 avconv "$@" -f framecrc -
91 framemd5(){
92 avconv "$@" -f framemd5 -
95 crc(){
96 avconv "$@" -f crc -
99 md5(){
100 avconv "$@" md5:
103 pcm(){
104 avconv "$@" -vn -f s16le -
107 enc_dec_pcm(){
108 out_fmt=$1
109 dec_fmt=$2
110 pcm_fmt=$3
111 src_file=$(target_path $4)
112 shift 4
113 encfile="${outdir}/${test}.${out_fmt}"
114 cleanfiles=$encfile
115 encfile=$(target_path ${encfile})
116 avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
117 avconv -f $out_fmt -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
120 FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact"
121 DEC_OPTS="-threads $threads -idct simple $FLAGS"
122 ENC_OPTS="-threads 1 -idct simple -dct fastint"
124 enc_dec(){
125 src_fmt=$1
126 srcfile=$2
127 enc_fmt=$3
128 enc_opt=$4
129 dec_fmt=$5
130 dec_opt=$6
131 encfile="${outdir}/${test}.${enc_fmt}"
132 decfile="${outdir}/${test}.out.${dec_fmt}"
133 cleanfiles="$cleanfiles $decfile"
134 test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
135 tsrcfile=$(target_path $srcfile)
136 tencfile=$(target_path $encfile)
137 tdecfile=$(target_path $decfile)
138 avconv -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
139 -f $enc_fmt -y $tencfile || return
140 do_md5sum $encfile
141 echo $(wc -c $encfile)
142 avconv $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
143 -f $dec_fmt -y $tdecfile || return
144 do_md5sum $decfile
145 tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
148 regtest(){
149 t="${test#$2-}"
150 ref=${base}/ref/$2/$t
151 ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
154 lavftest(){
155 regtest lavf lavf tests/vsynth1
158 lavfitest(){
159 cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
160 regtest lavfi lavfi tests/vsynth1
163 mkdir -p "$outdir"
165 exec 3>&2
166 eval $command >"$outfile" 2>$errfile
167 err=$?
169 if [ $err -gt 128 ]; then
170 sig=$(kill -l $err 2>/dev/null)
171 test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
174 if test -e "$ref" || test $cmp = "oneline" ; then
175 case $cmp in
176 diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
177 oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
178 stddev) stddev "$ref" "$outfile" >$cmpfile ;;
179 oneline)oneline "$ref" "$outfile" >$cmpfile ;;
180 null) cat "$outfile" >$cmpfile ;;
181 esac
182 cmperr=$?
183 test $err = 0 && err=$cmperr
184 test $err = 0 || cat $cmpfile
185 else
186 echo "reference file '$ref' not found"
187 err=1
190 echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
192 test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
193 exit $err