FATE: allow a tolerance in the size comparison in do_tiny_psnr()
[libav.git] / tests / fate-run.sh
CommitLineData
2fad0977
MR
1#! /bin/sh
2
078ae66b
MR
3export LC_ALL=C
4
2fad0977
MR
5base=$(dirname $0)
6. "${base}/md5.sh"
7
b82be636
MR
8base64=tests/base64
9
2fad0977 10test="${1#fate-}"
122a9af7 11samples=$2
2fad0977 12target_exec=$3
122a9af7 13target_path=$4
2fad0977 14command=$5
3ade7d32 15cmp=${6:-diff}
3ade7d32 16ref=${7:-"${base}/ref/fate/${test}"}
0720d263 17fuzz=${8:-1}
7851eb68 18threads=${9:-1}
bc5acfa7 19thread_type=${10:-frame+slice}
018f39ef 20cpuflags=${11:-all}
5ecadc66 21cmp_shift=${12:-0}
bb684296 22cmp_target=${13:-0}
cffd7580 23size_tolerance=${14:-0}
26e87a22 24
2fad0977
MR
25outdir="tests/data/fate"
26outfile="${outdir}/${test}"
bcb0a154 27errfile="${outdir}/${test}.err"
b82be636
MR
28cmpfile="${outdir}/${test}.diff"
29repfile="${outdir}/${test}.rep"
2fad0977 30
bb684296
JR
31# $1=value1, $2=value2, $3=threshold
32# prints 0 if absolute difference between value1 and value2 is <= threshold
33compare(){
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
e153cfa8 38do_tiny_psnr(){
5ecadc66 39 psnr=$(tests/tiny_psnr "$1" "$2" 2 $cmp_shift 0)
e153cfa8 40 val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
83b203dc
MR
41 size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
42 size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
bb684296 43 val_cmp=$(compare $val $cmp_target $fuzz)
cffd7580
JR
44 size_cmp=$(compare $size1 $size2 $size_tolerance)
45 if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
aab3ea5f
MR
46 echo "$psnr"
47 return 1
48 fi
49}
50
e153cfa8 51oneoff(){
bb684296 52 do_tiny_psnr "$1" "$2" MAXDIFF
e153cfa8
MR
53}
54
55stddev(){
bb684296 56 do_tiny_psnr "$1" "$2" stddev
e153cfa8
MR
57}
58
dff1fc51 59run(){
c4795e80 60 test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
dff1fc51
MR
61 $target_exec $target_path/"$@"
62}
63
6291d7e4 64avconv(){
018f39ef 65 run avconv -nostats -threads $threads -thread_type $thread_type -cpuflags $cpuflags "$@"
2b18c451
MR
66}
67
68framecrc(){
6291d7e4 69 avconv "$@" -f framecrc -
2b18c451
MR
70}
71
72framemd5(){
6291d7e4 73 avconv "$@" -f framemd5 -
2b18c451
MR
74}
75
76crc(){
6291d7e4 77 avconv "$@" -f crc -
2b18c451
MR
78}
79
80md5(){
6291d7e4 81 avconv "$@" md5:
2b18c451
MR
82}
83
84pcm(){
6291d7e4 85 avconv "$@" -vn -f s16le -
2b18c451
MR
86}
87
9a3f31ef
MR
88regtest(){
89 t="${test#$2-}"
90 ref=${base}/ref/$2/$t
018f39ef 91 ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
9a3f31ef
MR
92}
93
94codectest(){
95 regtest codec $1 tests/$1
96}
97
98lavftest(){
99 regtest lavf lavf tests/vsynth1
100}
101
102lavfitest(){
8fae6e7c 103 cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
9a3f31ef
MR
104 regtest lavfi lavfi tests/vsynth1
105}
106
107seektest(){
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
dec4b470 119 run libavformat/seek-test $target_path/$file
9a3f31ef 120}
150ef830 121
2fad0977
MR
122mkdir -p "$outdir"
123
c4795e80 124exec 3>&2
bcb0a154 125$command > "$outfile" 2>$errfile
ffe72624 126err=$?
3ade7d32 127
4e705a68
MR
128if [ $err -gt 128 ]; then
129 sig=$(kill -l $err 2>/dev/null)
5b60c293 130 test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
4e705a68
MR
131fi
132
b82be636
MR
133if test -e "$ref"; then
134 case $cmp in
135 diff) diff -u -w "$ref" "$outfile" >$cmpfile ;;
0720d263
JR
136 oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
137 stddev) stddev "$ref" "$outfile" >$cmpfile ;;
84757de0 138 null) cat "$outfile" >$cmpfile ;;
b82be636
MR
139 esac
140 cmperr=$?
141 test $err = 0 && err=$cmperr
142 test $err = 0 || cat $cmpfile
143else
9a3f31ef 144 echo "reference file '$ref' not found"
b82be636 145 err=1
9a3f31ef
MR
146fi
147
4e705a68 148echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
7d610af6 149
b82be636
MR
150test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
151exit $err