39db0e89e0ac6322f07953b586a088e042ffd2bf
[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 # $1=value1, $2=value2, $3=threshold
32 # prints 0 if absolute difference between value1 and value2 is <= threshold
33 compare(){
34     echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
35 }
36
37 do_tiny_psnr(){
38     psnr=$(tests/tiny_psnr "$1" "$2" 2 $cmp_shift 0)
39     val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
40     size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
41     size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
42     val_cmp=$(compare $val $cmp_target $fuzz)
43     size_cmp=$(compare $size1 $size2 $size_tolerance)
44     if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
45         echo "$psnr"
46         return 1
47     fi
48 }
49
50 oneoff(){
51     do_tiny_psnr "$1" "$2" MAXDIFF
52 }
53
54 stddev(){
55     do_tiny_psnr "$1" "$2" stddev
56 }
57
58 run(){
59     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
60     $target_exec $target_path/"$@"
61 }
62
63 avconv(){
64     run avconv -nostats -threads $threads -thread_type $thread_type -cpuflags $cpuflags "$@"
65 }
66
67 framecrc(){
68     avconv "$@" -f framecrc -
69 }
70
71 framemd5(){
72     avconv "$@" -f framemd5 -
73 }
74
75 crc(){
76     avconv "$@" -f crc -
77 }
78
79 md5(){
80     avconv "$@" md5:
81 }
82
83 pcm(){
84     avconv "$@" -vn -f s16le -
85 }
86
87 enc_dec_pcm(){
88     out_fmt=$1
89     pcm_fmt=$2
90     shift 2
91     encfile="${outdir}/${test}.${out_fmt}"
92     cleanfiles=$encfile
93     avconv -i $ref "$@" -f $out_fmt -y ${target_path}/${encfile} || return
94     avconv -f $out_fmt -i ${target_path}/${encfile} -c:a pcm_${pcm_fmt} -f wav -
95 }
96
97 regtest(){
98     t="${test#$2-}"
99     ref=${base}/ref/$2/$t
100     ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
101 }
102
103 codectest(){
104     regtest codec $1 tests/$1
105 }
106
107 lavftest(){
108     regtest lavf lavf tests/vsynth1
109 }
110
111 lavfitest(){
112     cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
113     regtest lavfi lavfi tests/vsynth1
114 }
115
116 seektest(){
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
128     run libavformat/seek-test $target_path/$file
129 }
130
131 mkdir -p "$outdir"
132
133 exec 3>&2
134 $command > "$outfile" 2>$errfile
135 err=$?
136
137 if [ $err -gt 128 ]; then
138     sig=$(kill -l $err 2>/dev/null)
139     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
140 fi
141
142 if test -e "$ref"; then
143     case $cmp in
144         diff)   diff -u -w "$ref" "$outfile"            >$cmpfile ;;
145         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
146         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
147         null)   cat               "$outfile"            >$cmpfile ;;
148     esac
149     cmperr=$?
150     test $err = 0 && err=$cmperr
151     test $err = 0 || cat $cmpfile
152 else
153     echo "reference file '$ref' not found"
154     err=1
155 fi
156
157 echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
158
159 test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
160 exit $err