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