mov: enable parsing for VC-1.
[ffmpeg.git] / 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
25 outdir="tests/data/fate"
26 outfile="${outdir}/${test}"
27 errfile="${outdir}/${test}.err"
28 cmpfile="${outdir}/${test}.diff"
29 repfile="${outdir}/${test}.rep"
30
31 target_path(){
32     test ${1} = ${1#/} && p=${target_path}/
33     echo ${p}${1}
34 }
35
36 # $1=value1, $2=value2, $3=threshold
37 # prints 0 if absolute difference between value1 and value2 is <= threshold
38 compare(){
39     echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
40 }
41
42 do_tiny_psnr(){
43     psnr=$(tests/tiny_psnr "$1" "$2" 2 $cmp_shift 0)
44     val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
45     size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
46     size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
47     val_cmp=$(compare $val $cmp_target $fuzz)
48     size_cmp=$(compare $size1 $size2 $size_tolerance)
49     if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
50         echo "$psnr"
51         return 1
52     fi
53 }
54
55 oneoff(){
56     do_tiny_psnr "$1" "$2" MAXDIFF
57 }
58
59 stddev(){
60     do_tiny_psnr "$1" "$2" stddev
61 }
62
63 oneline(){
64     printf '%s\n' "$1" | diff -u -b - "$2"
65 }
66
67 run(){
68     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
69     $target_exec $target_path/"$@"
70 }
71
72 probefmt(){
73     run avprobe -show_format_entry format_name -v 0 "$@"
74 }
75
76 avconv(){
77     run avconv -nostats -threads $threads -thread_type $thread_type -cpuflags $cpuflags "$@"
78 }
79
80 framecrc(){
81     avconv "$@" -f framecrc -
82 }
83
84 framemd5(){
85     avconv "$@" -f framemd5 -
86 }
87
88 crc(){
89     avconv "$@" -f crc -
90 }
91
92 md5(){
93     avconv "$@" md5:
94 }
95
96 pcm(){
97     avconv "$@" -vn -f s16le -
98 }
99
100 enc_dec_pcm(){
101     out_fmt=$1
102     dec_fmt=$2
103     pcm_fmt=$3
104     src_file=$(target_path $4)
105     shift 4
106     encfile="${outdir}/${test}.${out_fmt}"
107     cleanfiles=$encfile
108     encfile=$(target_path ${encfile})
109     avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
110     avconv -f $out_fmt -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
111 }
112
113 regtest(){
114     t="${test#$2-}"
115     ref=${base}/ref/$2/$t
116     ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
117 }
118
119 codectest(){
120     regtest codec $1 tests/$1
121 }
122
123 lavftest(){
124     regtest lavf lavf tests/vsynth1
125 }
126
127 lavfitest(){
128     cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
129     regtest lavfi lavfi tests/vsynth1
130 }
131
132 seektest(){
133     t="${test#seek-}"
134     ref=${base}/ref/seek/$t
135     case $t in
136         image_*) file="tests/data/images/${t#image_}/%02d.${t#image_}" ;;
137         *)       file=$(echo $t | tr _ '?')
138                  for d in acodec vsynth2 lavf; do
139                      test -f tests/data/$d/$file && break
140                  done
141                  file=$(echo tests/data/$d/$file)
142                  ;;
143     esac
144     run libavformat/seek-test $target_path/$file
145 }
146
147 mkdir -p "$outdir"
148
149 exec 3>&2
150 $command > "$outfile" 2>$errfile
151 err=$?
152
153 if [ $err -gt 128 ]; then
154     sig=$(kill -l $err 2>/dev/null)
155     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
156 fi
157
158 if test -e "$ref" || test $cmp = "oneline" ; then
159     case $cmp in
160         diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
161         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
162         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
163         oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
164         null)   cat               "$outfile"            >$cmpfile ;;
165     esac
166     cmperr=$?
167     test $err = 0 && err=$cmperr
168     test $err = 0 || cat $cmpfile
169 else
170     echo "reference file '$ref' not found"
171     err=1
172 fi
173
174 echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
175
176 test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
177 exit $err