FATE: allow a tolerance in the size comparison in do_tiny_psnr()
[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 # $1=value1, $2=value2, $3=threshold
32 # prints 0 if absolute difference between value1 and value2 is <= threshold
33 compare(){
34     v=$(echo "scale=2; if ($1 >= $2) { $1 - $2 } else { $2 - $1 }" | bc)
35     echo "if ($v <= $3) { 0 } else { 1 }" | bc
36 }
37
38 do_tiny_psnr(){
39     psnr=$(tests/tiny_psnr "$1" "$2" 2 $cmp_shift 0)
40     val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
41     size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
42     size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
43     val_cmp=$(compare $val $cmp_target $fuzz)
44     size_cmp=$(compare $size1 $size2 $size_tolerance)
45     if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
46         echo "$psnr"
47         return 1
48     fi
49 }
50
51 oneoff(){
52     do_tiny_psnr "$1" "$2" MAXDIFF
53 }
54
55 stddev(){
56     do_tiny_psnr "$1" "$2" stddev
57 }
58
59 run(){
60     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
61     $target_exec $target_path/"$@"
62 }
63
64 avconv(){
65     run avconv -nostats -threads $threads -thread_type $thread_type -cpuflags $cpuflags "$@"
66 }
67
68 framecrc(){
69     avconv "$@" -f framecrc -
70 }
71
72 framemd5(){
73     avconv "$@" -f framemd5 -
74 }
75
76 crc(){
77     avconv "$@" -f crc -
78 }
79
80 md5(){
81     avconv "$@" md5:
82 }
83
84 pcm(){
85     avconv "$@" -vn -f s16le -
86 }
87
88 regtest(){
89     t="${test#$2-}"
90     ref=${base}/ref/$2/$t
91     ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
92 }
93
94 codectest(){
95     regtest codec $1 tests/$1
96 }
97
98 lavftest(){
99     regtest lavf lavf tests/vsynth1
100 }
101
102 lavfitest(){
103     cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
104     regtest lavfi lavfi tests/vsynth1
105 }
106
107 seektest(){
108     t="${test#seek-}"
109     ref=${base}/ref/seek/$t
110     case $t in
111         image_*) file="tests/data/images/${t#image_}/%02d.${t#image_}" ;;
112         *)       file=$(echo $t | tr _ '?')
113                  for d in acodec vsynth2 lavf; do
114                      test -f tests/data/$d/$file && break
115                  done
116                  file=$(echo tests/data/$d/$file)
117                  ;;
118     esac
119     run libavformat/seek-test $target_path/$file
120 }
121
122 mkdir -p "$outdir"
123
124 exec 3>&2
125 $command > "$outfile" 2>$errfile
126 err=$?
127
128 if [ $err -gt 128 ]; then
129     sig=$(kill -l $err 2>/dev/null)
130     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
131 fi
132
133 if test -e "$ref"; then
134     case $cmp in
135         diff)   diff -u -w "$ref" "$outfile"            >$cmpfile ;;
136         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
137         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
138         null)   cat               "$outfile"            >$cmpfile ;;
139     esac
140     cmperr=$?
141     test $err = 0 && err=$cmperr
142     test $err = 0 || cat $cmpfile
143 else
144     echo "reference file '$ref' not found"
145     err=1
146 fi
147
148 echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
149
150 test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
151 exit $err