a45e9a95b3fe6c53e294ded4012084df9a14e322
[libav.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 val=$(cat "$2")
65 test x"$val" = x"$1" || { r=$?; printf -- '-%s\n+%s\n' "$ref" "$val"; }
66 return ${r:-0}
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 run avconv -nostats -threads $threads -thread_type $thread_type -cpuflags $cpuflags "$@"
80 }
81
82 framecrc(){
83 avconv "$@" -f framecrc -
84 }
85
86 framemd5(){
87 avconv "$@" -f framemd5 -
88 }
89
90 crc(){
91 avconv "$@" -f crc -
92 }
93
94 md5(){
95 avconv "$@" md5:
96 }
97
98 pcm(){
99 avconv "$@" -vn -f s16le -
100 }
101
102 enc_dec_pcm(){
103 out_fmt=$1
104 dec_fmt=$2
105 pcm_fmt=$3
106 src_file=$(target_path $4)
107 shift 4
108 encfile="${outdir}/${test}.${out_fmt}"
109 cleanfiles=$encfile
110 encfile=$(target_path ${encfile})
111 avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
112 avconv -f $out_fmt -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
113 }
114
115 regtest(){
116 t="${test#$2-}"
117 ref=${base}/ref/$2/$t
118 ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
119 }
120
121 codectest(){
122 regtest codec $1 tests/$1
123 }
124
125 lavftest(){
126 regtest lavf lavf tests/vsynth1
127 }
128
129 lavfitest(){
130 cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
131 regtest lavfi lavfi tests/vsynth1
132 }
133
134 seektest(){
135 t="${test#seek-}"
136 ref=${base}/ref/seek/$t
137 case $t in
138 image_*) file="tests/data/images/${t#image_}/%02d.${t#image_}" ;;
139 *) file=$(echo $t | tr _ '?')
140 for d in acodec vsynth2 lavf; do
141 test -f tests/data/$d/$file && break
142 done
143 file=$(echo tests/data/$d/$file)
144 ;;
145 esac
146 run libavformat/seek-test $target_path/$file
147 }
148
149 mkdir -p "$outdir"
150
151 exec 3>&2
152 $command > "$outfile" 2>$errfile
153 err=$?
154
155 if [ $err -gt 128 ]; then
156 sig=$(kill -l $err 2>/dev/null)
157 test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
158 fi
159
160 if test -e "$ref" || test $cmp = "oneline" ; then
161 case $cmp in
162 diff) diff -u -w "$ref" "$outfile" >$cmpfile ;;
163 oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
164 stddev) stddev "$ref" "$outfile" >$cmpfile ;;
165 oneline)oneline "$ref" "$outfile" >$cmpfile ;;
166 null) cat "$outfile" >$cmpfile ;;
167 esac
168 cmperr=$?
169 test $err = 0 && err=$cmperr
170 test $err = 0 || cat $cmpfile
171 else
172 echo "reference file '$ref' not found"
173 err=1
174 fi
175
176 echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
177
178 test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
179 exit $err