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