f7a7abaa76f0c6c30bde13783b419ba40ddab41b
[ffmpeg.git] / tests / fate-run.sh
1 #! /bin/sh
2
3 export LC_ALL=C
4
5 base=$(dirname $0)
6 . "${base}/md5.sh"
7
8 base64=tests/base64
9
10 test="${1#fate-}"
11 samples=$2
12 target_exec=$3
13 target_path=$4
14 command=$5
15 cmp=${6:-diff}
16 ref=${7:-"${base}/ref/fate/${test}"}
17 fuzz=${8:-1}
18 threads=${9:-1}
19 thread_type=${10:-frame+slice}
20 cpuflags=${11:-all}
21 cmp_shift=${12:-0}
22 cmp_target=${13:-0}
23 size_tolerance=${14:-0}
24
25 outdir="tests/data/fate"
26 outfile="${outdir}/${test}"
27 errfile="${outdir}/${test}.err"
28 cmpfile="${outdir}/${test}.diff"
29 repfile="${outdir}/${test}.rep"
30
31 target_path(){
32     test ${1} = ${1#/} && p=${target_path}/
33     echo ${p}${1}
34 }
35
36 # $1=value1, $2=value2, $3=threshold
37 # prints 0 if absolute difference between value1 and value2 is <= threshold
38 compare(){
39     echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
40 }
41
42 do_tiny_psnr(){
43     psnr=$(tests/tiny_psnr "$1" "$2" 2 $cmp_shift 0)
44     val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
45     size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
46     size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
47     val_cmp=$(compare $val $cmp_target $fuzz)
48     size_cmp=$(compare $size1 $size2 $size_tolerance)
49     if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
50         echo "$psnr"
51         return 1
52     fi
53 }
54
55 oneoff(){
56     do_tiny_psnr "$1" "$2" MAXDIFF
57 }
58
59 stddev(){
60     do_tiny_psnr "$1" "$2" stddev
61 }
62
63 run(){
64     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
65     $target_exec $target_path/"$@"
66 }
67
68 avconv(){
69     run avconv -nostats -threads $threads -thread_type $thread_type -cpuflags $cpuflags "$@"
70 }
71
72 framecrc(){
73     avconv "$@" -f framecrc -
74 }
75
76 framemd5(){
77     avconv "$@" -f framemd5 -
78 }
79
80 crc(){
81     avconv "$@" -f crc -
82 }
83
84 md5(){
85     avconv "$@" md5:
86 }
87
88 pcm(){
89     avconv "$@" -vn -f s16le -
90 }
91
92 enc_dec_pcm(){
93     out_fmt=$1
94     dec_fmt=$2
95     pcm_fmt=$3
96     src_file=$(target_path $4)
97     shift 4
98     encfile="${outdir}/${test}.${out_fmt}"
99     cleanfiles=$encfile
100     encfile=$(target_path ${encfile})
101     avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
102     avconv -f $out_fmt -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
103 }
104
105 regtest(){
106     t="${test#$2-}"
107     ref=${base}/ref/$2/$t
108     ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
109 }
110
111 codectest(){
112     regtest codec $1 tests/$1
113 }
114
115 lavftest(){
116     regtest lavf lavf tests/vsynth1
117 }
118
119 lavfitest(){
120     cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
121     regtest lavfi lavfi tests/vsynth1
122 }
123
124 seektest(){
125     t="${test#seek-}"
126     ref=${base}/ref/seek/$t
127     case $t in
128         image_*) file="tests/data/images/${t#image_}/%02d.${t#image_}" ;;
129         *)       file=$(echo $t | tr _ '?')
130                  for d in acodec vsynth2 lavf; do
131                      test -f tests/data/$d/$file && break
132                  done
133                  file=$(echo tests/data/$d/$file)
134                  ;;
135     esac
136     run libavformat/seek-test $target_path/$file
137 }
138
139 mkdir -p "$outdir"
140
141 exec 3>&2
142 $command > "$outfile" 2>$errfile
143 err=$?
144
145 if [ $err -gt 128 ]; then
146     sig=$(kill -l $err 2>/dev/null)
147     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
148 fi
149
150 if test -e "$ref"; then
151     case $cmp in
152         diff)   diff -u -w "$ref" "$outfile"            >$cmpfile ;;
153         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
154         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
155         null)   cat               "$outfile"            >$cmpfile ;;
156     esac
157     cmperr=$?
158     test $err = 0 && err=$cmperr
159     test $err = 0 || cat $cmpfile
160 else
161     echo "reference file '$ref' not found"
162     err=1
163 fi
164
165 echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
166
167 test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
168 exit $err