fate: keep stderr from failing tests
[ffmpeg.git] / tests / fate-run.sh
1 #! /bin/sh
2
3 base=$(dirname $0)
4 . "${base}/md5.sh"
5
6 test="${1#fate-}"
7 samples=$2
8 target_exec=$3
9 target_path=$4
10 command=$5
11 cmp=${6:-diff}
12 ref=${7:-"${base}/ref/fate/${test}"}
13 fuzz=$8
14
15 outdir="tests/data/fate"
16 outfile="${outdir}/${test}"
17 errfile="${outdir}/${test}.err"
18
19 do_tiny_psnr(){
20     psnr=$(tests/tiny_psnr "$1" "$2" 2 0 0)
21     val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
22     size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
23     size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
24     res=$(echo "$val $4 $5" | bc)
25     if [ "$res" != 1 ] || [ $size1 != $size2 ]; then
26         echo "$psnr"
27         return 1
28     fi
29 }
30
31 oneoff(){
32     do_tiny_psnr "$1" "$2" MAXDIFF '<=' ${fuzz:-1}
33 }
34
35 stddev(){
36     do_tiny_psnr "$1" "$2" stddev  '<=' ${fuzz:-1}
37 }
38
39 ffmpeg(){
40     $target_exec $target_path/ffmpeg "$@"
41 }
42
43 framecrc(){
44     ffmpeg "$@" -f framecrc -
45 }
46
47 framemd5(){
48     ffmpeg "$@" -f framemd5 -
49 }
50
51 crc(){
52     ffmpeg "$@" -f crc -
53 }
54
55 md5(){
56     ffmpeg "$@" md5:
57 }
58
59 pcm(){
60     ffmpeg "$@" -vn -f s16le -
61 }
62
63 regtest(){
64     t="${test#$2-}"
65     ref=${base}/ref/$2/$t
66     outfile=tests/data/regression/$2/$t
67     errfile=tests/data/$t.$2.err
68     ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path"
69 }
70
71 codectest(){
72     regtest codec $1 tests/$1
73 }
74
75 lavftest(){
76     regtest lavf lavf tests/vsynth1
77 }
78
79 lavfitest(){
80     regtest lavfi lavfi tests/vsynth1
81 }
82
83 seektest(){
84     t="${test#seek-}"
85     ref=${base}/ref/seek/$t
86     case $t in
87         image_*) file="tests/data/images/${t#image_}/%02d.${t#image_}" ;;
88         *)       file=$(echo $t | tr _ '?')
89                  for d in acodec vsynth2 lavf; do
90                      test -f tests/data/$d/$file && break
91                  done
92                  file=$(echo tests/data/$d/$file)
93                  ;;
94     esac
95     $target_exec $target_path/tests/seek_test $target_path/$file
96 }
97
98 mkdir -p "$outdir"
99
100 $command > "$outfile" 2>$errfile
101 err=$?
102
103 if ! test -e "$ref"; then
104     echo "reference file '$ref' not found"
105     exit 1
106 fi
107
108 case $cmp in
109     diff)   diff -u -w "$ref" "$outfile"            ;;
110     oneoff) oneoff     "$ref" "$outfile" "$fuzz"    ;;
111     stddev) stddev     "$ref" "$outfile" "$fuzz"    ;;
112 esac
113
114 cmperr=$?
115 test $err = 0 && err=$cmperr
116 test $err = 0 && rm -f $outfile $errfile