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