ffprobe: remove ad-hoc behavior when nb_fmt_entries_to_show is 1
[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 oneline(){
64     printf '%s\n' "$1" | diff -u -b - "$2"
65 }
66
67 run(){
68     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
69     $target_exec $target_path/"$@"
70 }
71
72 probefmt(){
73     run ffprobe -show_format_entry format_name -print_format default=nw=1:nk=1 -v 0 "$@"
74 }
75
76 avconv(){
77     run ffmpeg -nostats -threads $threads -thread_type $thread_type -cpuflags $cpuflags "$@"
78 }
79
80 framecrc(){
81     avconv "$@" -f framecrc -
82 }
83
84 framemd5(){
85     avconv "$@" -f framemd5 -
86 }
87
88 crc(){
89     avconv "$@" -f crc -
90 }
91
92 md5(){
93     avconv "$@" md5:
94 }
95
96 pcm(){
97     avconv "$@" -vn -f s16le -
98 }
99
100 enc_dec_pcm(){
101     out_fmt=$1
102     dec_fmt=$2
103     pcm_fmt=$3
104     src_file=$(target_path $4)
105     shift 4
106     encfile="${outdir}/${test}.${out_fmt}"
107     cleanfiles=$encfile
108     encfile=$(target_path ${encfile})
109     avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
110     avconv -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
111 }
112
113 regtest(){
114     t="${test#$2-}"
115     ref=${base}/ref/$2/$t
116     ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$samples"
117 }
118
119 codectest(){
120     regtest codec $1 tests/$1
121 }
122
123 lavffatetest(){
124     regtest lavf lavf-fate tests/vsynth1
125 }
126
127 lavftest(){
128     regtest lavf lavf tests/vsynth1
129 }
130
131 lavfitest(){
132     cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
133     regtest lavfi lavfi tests/vsynth1
134 }
135
136 seektest(){
137     t="${test#seek-}"
138     ref=${base}/ref/seek/$t
139     case $t in
140         image_*) file="tests/data/images/${t#image_}/%02d.${t#image_}" ;;
141         *)       file=$(echo $t | tr _ '?')
142                  for d in acodec vsynth2 lavf; do
143                      test -f tests/data/$d/$file && break
144                  done
145                  file=$(echo tests/data/$d/$file)
146                  ;;
147     esac
148     run libavformat/seek-test $target_path/$file
149 }
150
151 mkdir -p "$outdir"
152
153 exec 3>&2
154 $command > "$outfile" 2>$errfile
155 err=$?
156
157 if [ $err -gt 128 ]; then
158     sig=$(kill -l $err 2>/dev/null)
159     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
160 fi
161
162 if test -e "$ref" || test $cmp = "oneline" ; then
163     case $cmp in
164         diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
165         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
166         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
167         oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
168         null)   cat               "$outfile"            >$cmpfile ;;
169     esac
170     cmperr=$?
171     test $err = 0 && err=$cmperr
172     test $err = 0 || cat $cmpfile
173 else
174     echo "reference file '$ref' not found"
175     err=1
176 fi
177
178 echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
179
180 if test $err = 0; then
181     rm -f $outfile $errfile $cmpfile $cleanfiles
182 else
183     echo "Test $test failed. Look at $errfile for details."
184 fi
185 exit $err