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