366145d22f20fb64fd02020ce8bc18421a4ed7f9
[libav.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
18 threads=${9:-1}
19 thread_type=${10:-3}
20
21 outdir="tests/data/fate"
22 outfile="${outdir}/${test}"
23 errfile="${outdir}/${test}.err"
24 cmpfile="${outdir}/${test}.diff"
25 repfile="${outdir}/${test}.rep"
26
27 do_tiny_psnr(){
28 psnr=$(tests/tiny_psnr "$1" "$2" 2 0 0)
29 val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
30 size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
31 size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
32 res=$(echo "if ($val $4 $5) 1" | bc)
33 if [ "$res" != 1 ] || [ $size1 != $size2 ]; then
34 echo "$psnr"
35 return 1
36 fi
37 }
38
39 oneoff(){
40 do_tiny_psnr "$1" "$2" MAXDIFF '<=' ${fuzz:-1}
41 }
42
43 stddev(){
44 do_tiny_psnr "$1" "$2" stddev '<=' ${fuzz:-1}
45 }
46
47 run(){
48 test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
49 $target_exec $target_path/"$@"
50 }
51
52 ffmpeg(){
53 run ffmpeg -v 0 -threads $threads -thread_type $thread_type "$@"
54 }
55
56 framecrc(){
57 ffmpeg "$@" -f framecrc -
58 }
59
60 framemd5(){
61 ffmpeg "$@" -f framemd5 -
62 }
63
64 crc(){
65 ffmpeg "$@" -f crc -
66 }
67
68 md5(){
69 ffmpeg "$@" md5:
70 }
71
72 pcm(){
73 ffmpeg "$@" -vn -f s16le -
74 }
75
76 regtest(){
77 t="${test#$2-}"
78 ref=${base}/ref/$2/$t
79 cleanfiles="$cleanfiles $outfile $errfile"
80 outfile=tests/data/regression/$2/$t
81 errfile=tests/data/$t.$2.err
82 ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type"
83 }
84
85 codectest(){
86 regtest codec $1 tests/$1
87 }
88
89 lavftest(){
90 regtest lavf lavf tests/vsynth1
91 }
92
93 lavfitest(){
94 cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
95 regtest lavfi lavfi tests/vsynth1
96 }
97
98 seektest(){
99 t="${test#seek-}"
100 ref=${base}/ref/seek/$t
101 case $t in
102 image_*) file="tests/data/images/${t#image_}/%02d.${t#image_}" ;;
103 *) file=$(echo $t | tr _ '?')
104 for d in acodec vsynth2 lavf; do
105 test -f tests/data/$d/$file && break
106 done
107 file=$(echo tests/data/$d/$file)
108 ;;
109 esac
110 $target_exec $target_path/tests/seek_test $target_path/$file
111 }
112
113 mkdir -p "$outdir"
114
115 exec 3>&2
116 $command > "$outfile" 2>$errfile
117 err=$?
118
119 if [ $err -gt 128 ]; then
120 sig=$(kill -l $err 2>/dev/null)
121 test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
122 fi
123
124 if test -e "$ref"; then
125 case $cmp in
126 diff) diff -u -w "$ref" "$outfile" >$cmpfile ;;
127 oneoff) oneoff "$ref" "$outfile" "$fuzz" >$cmpfile ;;
128 stddev) stddev "$ref" "$outfile" "$fuzz" >$cmpfile ;;
129 esac
130 cmperr=$?
131 test $err = 0 && err=$cmperr
132 test $err = 0 || cat $cmpfile
133 else
134 echo "reference file '$ref' not found"
135 err=1
136 fi
137
138 echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
139
140 test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
141 exit $err