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