fate: use diff -b in oneline comparison
[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
9cc338b1
JR
31target_path(){
32 test ${1} = ${1#/} && p=${target_path}/
33 echo ${p}${1}
34}
35
bb684296
JR
36# $1=value1, $2=value2, $3=threshold
37# prints 0 if absolute difference between value1 and value2 is <= threshold
38compare(){
a56fba50 39 echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
bb684296
JR
40}
41
e153cfa8 42do_tiny_psnr(){
5ecadc66 43 psnr=$(tests/tiny_psnr "$1" "$2" 2 $cmp_shift 0)
e153cfa8 44 val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
83b203dc
MR
45 size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
46 size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
bb684296 47 val_cmp=$(compare $val $cmp_target $fuzz)
cffd7580
JR
48 size_cmp=$(compare $size1 $size2 $size_tolerance)
49 if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
aab3ea5f
MR
50 echo "$psnr"
51 return 1
52 fi
53}
54
e153cfa8 55oneoff(){
bb684296 56 do_tiny_psnr "$1" "$2" MAXDIFF
e153cfa8
MR
57}
58
59stddev(){
bb684296 60 do_tiny_psnr "$1" "$2" stddev
e153cfa8
MR
61}
62
40fa14f7 63oneline(){
0ff0af73 64 printf '%s\n' "$1" | diff -u -b - "$2"
40fa14f7
MR
65}
66
dff1fc51 67run(){
c4795e80 68 test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
dff1fc51
MR
69 $target_exec $target_path/"$@"
70}
71
4bfa67bd
RB
72probefmt(){
73 run avprobe -show_format_entry format_name -v 0 "$@"
74}
75
6291d7e4 76avconv(){
018f39ef 77 run avconv -nostats -threads $threads -thread_type $thread_type -cpuflags $cpuflags "$@"
2b18c451
MR
78}
79
80framecrc(){
6291d7e4 81 avconv "$@" -f framecrc -
2b18c451
MR
82}
83
84framemd5(){
6291d7e4 85 avconv "$@" -f framemd5 -
2b18c451
MR
86}
87
88crc(){
6291d7e4 89 avconv "$@" -f crc -
2b18c451
MR
90}
91
92md5(){
6291d7e4 93 avconv "$@" md5:
2b18c451
MR
94}
95
96pcm(){
6291d7e4 97 avconv "$@" -vn -f s16le -
2b18c451
MR
98}
99
90e5b58a
JR
100enc_dec_pcm(){
101 out_fmt=$1
9cc338b1
JR
102 dec_fmt=$2
103 pcm_fmt=$3
104 src_file=$(target_path $4)
105 shift 4
90e5b58a
JR
106 encfile="${outdir}/${test}.${out_fmt}"
107 cleanfiles=$encfile
9cc338b1
JR
108 encfile=$(target_path ${encfile})
109 avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
110 avconv -f $out_fmt -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
90e5b58a
JR
111}
112
9a3f31ef
MR
113regtest(){
114 t="${test#$2-}"
115 ref=${base}/ref/$2/$t
018f39ef 116 ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
9a3f31ef
MR
117}
118
119codectest(){
120 regtest codec $1 tests/$1
121}
122
123lavftest(){
124 regtest lavf lavf tests/vsynth1
125}
126
127lavfitest(){
8fae6e7c 128 cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
9a3f31ef
MR
129 regtest lavfi lavfi tests/vsynth1
130}
131
132seektest(){
133 t="${test#seek-}"
134 ref=${base}/ref/seek/$t
135 case $t in
136 image_*) file="tests/data/images/${t#image_}/%02d.${t#image_}" ;;
137 *) file=$(echo $t | tr _ '?')
138 for d in acodec vsynth2 lavf; do
139 test -f tests/data/$d/$file && break
140 done
141 file=$(echo tests/data/$d/$file)
142 ;;
143 esac
dec4b470 144 run libavformat/seek-test $target_path/$file
9a3f31ef 145}
150ef830 146
2fad0977
MR
147mkdir -p "$outdir"
148
c4795e80 149exec 3>&2
bcb0a154 150$command > "$outfile" 2>$errfile
ffe72624 151err=$?
3ade7d32 152
4e705a68
MR
153if [ $err -gt 128 ]; then
154 sig=$(kill -l $err 2>/dev/null)
5b60c293 155 test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
4e705a68
MR
156fi
157
40fa14f7 158if test -e "$ref" || test $cmp = "oneline" ; then
b82be636
MR
159 case $cmp in
160 diff) diff -u -w "$ref" "$outfile" >$cmpfile ;;
0720d263
JR
161 oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
162 stddev) stddev "$ref" "$outfile" >$cmpfile ;;
40fa14f7 163 oneline)oneline "$ref" "$outfile" >$cmpfile ;;
84757de0 164 null) cat "$outfile" >$cmpfile ;;
b82be636
MR
165 esac
166 cmperr=$?
167 test $err = 0 && err=$cmperr
168 test $err = 0 || cat $cmpfile
169else
9a3f31ef 170 echo "reference file '$ref' not found"
b82be636 171 err=1
9a3f31ef
MR
172fi
173
4e705a68 174echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
7d610af6 175
b82be636
MR
176test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
177exit $err