Make a copy of ffmpeg under a new name -- avconv.
[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
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 avconv(){
53     run avconv -v 0 -threads $threads -thread_type $thread_type "$@"
54 }
55
56 framecrc(){
57     avconv "$@" -f framecrc -
58 }
59
60 framemd5(){
61     avconv "$@" -f framemd5 -
62 }
63
64 crc(){
65     avconv "$@" -f crc -
66 }
67
68 md5(){
69     avconv "$@" md5:
70 }
71
72 pcm(){
73     avconv "$@" -vn -f s16le -
74 }
75
76 regtest(){
77     t="${test#$2-}"
78     ref=${base}/ref/$2/$t
79     ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type"
80 }
81
82 codectest(){
83     regtest codec $1 tests/$1
84 }
85
86 lavftest(){
87     regtest lavf lavf tests/vsynth1
88 }
89
90 lavfitest(){
91     cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
92     regtest lavfi lavfi tests/vsynth1
93 }
94
95 seektest(){
96     t="${test#seek-}"
97     ref=${base}/ref/seek/$t
98     case $t in
99         image_*) file="tests/data/images/${t#image_}/%02d.${t#image_}" ;;
100         *)       file=$(echo $t | tr _ '?')
101                  for d in acodec vsynth2 lavf; do
102                      test -f tests/data/$d/$file && break
103                  done
104                  file=$(echo tests/data/$d/$file)
105                  ;;
106     esac
107     $target_exec $target_path/libavformat/seek-test $target_path/$file
108 }
109
110 mkdir -p "$outdir"
111
112 exec 3>&2
113 $command > "$outfile" 2>$errfile
114 err=$?
115
116 if [ $err -gt 128 ]; then
117     sig=$(kill -l $err 2>/dev/null)
118     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
119 fi
120
121 if test -e "$ref"; then
122     case $cmp in
123         diff)   diff -u -w "$ref" "$outfile"            >$cmpfile ;;
124         oneoff) oneoff     "$ref" "$outfile" "$fuzz"    >$cmpfile ;;
125         stddev) stddev     "$ref" "$outfile" "$fuzz"    >$cmpfile ;;
126         null)   cat               "$outfile"            >$cmpfile ;;
127     esac
128     cmperr=$?
129     test $err = 0 && err=$cmperr
130     test $err = 0 || cat $cmpfile
131 else
132     echo "reference file '$ref' not found"
133     err=1
134 fi
135
136 echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
137
138 test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
139 exit $err