]> git.sesse.net Git - ffmpeg/blob - tests/fate-run.sh
bfin: hpeldsp: Split no_rnd pixel operations off into a separate file
[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 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
27 outdir="tests/data/fate"
28 outfile="${outdir}/${test}"
29 errfile="${outdir}/${test}.err"
30 cmpfile="${outdir}/${test}.diff"
31 repfile="${outdir}/${test}.rep"
32
33 target_path(){
34     test ${1} = ${1#/} && p=${target_path}/
35     echo ${p}${1}
36 }
37
38 # $1=value1, $2=value2, $3=threshold
39 # prints 0 if absolute difference between value1 and value2 is <= threshold
40 compare(){
41     echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
42 }
43
44 do_tiny_psnr(){
45     psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
46     val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
47     size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
48     size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
49     val_cmp=$(compare $val $cmp_target $fuzz)
50     size_cmp=$(compare $size1 $size2 $size_tolerance)
51     if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
52         echo "$psnr"
53         return 1
54     fi
55 }
56
57 oneoff(){
58     do_tiny_psnr "$1" "$2" MAXDIFF
59 }
60
61 stddev(){
62     do_tiny_psnr "$1" "$2" stddev
63 }
64
65 oneline(){
66     printf '%s\n' "$1" | diff -u -b - "$2"
67 }
68
69 run(){
70     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
71     $target_exec $target_path/"$@"
72 }
73
74 probefmt(){
75     run avprobe -show_format_entry format_name -v 0 "$@"
76 }
77
78 avconv(){
79     dec_opts="-threads $threads -thread_type $thread_type"
80     avconv_args="-nostats -cpuflags $cpuflags"
81     for arg in $@; do
82         [ x${arg} = x-i ] && avconv_args="${avconv_args} ${dec_opts}"
83         avconv_args="${avconv_args} ${arg}"
84     done
85     run avconv ${avconv_args}
86 }
87
88 framecrc(){
89     avconv "$@" -f framecrc -
90 }
91
92 framemd5(){
93     avconv "$@" -f framemd5 -
94 }
95
96 crc(){
97     avconv "$@" -f crc -
98 }
99
100 md5(){
101     avconv "$@" md5:
102 }
103
104 pcm(){
105     avconv "$@" -vn -f s16le -
106 }
107
108 enc_dec_pcm(){
109     out_fmt=$1
110     dec_fmt=$2
111     pcm_fmt=$3
112     src_file=$(target_path $4)
113     shift 4
114     encfile="${outdir}/${test}.${out_fmt}"
115     cleanfiles=$encfile
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} -
119 }
120
121 FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact"
122 DEC_OPTS="-threads $threads -idct simple $FLAGS"
123 ENC_OPTS="-threads 1        -idct simple -dct fastint"
124
125 enc_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)
143     avconv $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
144         -f $dec_fmt -y $tdecfile || return
145     do_md5sum $decfile
146     tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
147 }
148
149 lavftest(){
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"
153 }
154
155 video_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
165 pixdesc(){
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
173 pixfmts(){
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
194 mkdir -p "$outdir"
195
196 exec 3>&2
197 eval $command >"$outfile" 2>$errfile
198 err=$?
199
200 if [ $err -gt 128 ]; then
201     sig=$(kill -l $err 2>/dev/null)
202     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
203 fi
204
205 if test -e "$ref" || test $cmp = "oneline" ; then
206     case $cmp in
207         diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
208         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
209         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
210         oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
211         null)   cat               "$outfile"            >$cmpfile ;;
212     esac
213     cmperr=$?
214     test $err = 0 && err=$cmperr
215     test $err = 0 || cat $cmpfile
216 else
217     echo "reference file '$ref' not found"
218     err=1
219 fi
220
221 echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
222
223 if test $err != 0 && test $gen != "no" ; then
224     echo "GEN     $ref"
225     cp -f "$outfile" "$ref"
226     err=$?
227 fi
228
229 test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
230 exit $err