fate-run.sh 2.89 KB
Newer Older
Måns Rullgård's avatar
Måns Rullgård committed
1 2
#! /bin/sh

3 4
export LC_ALL=C

Måns Rullgård's avatar
Måns Rullgård committed
5 6 7
base=$(dirname $0)
. "${base}/md5.sh"

8 9
base64=tests/base64

Måns Rullgård's avatar
Måns Rullgård committed
10
test="${1#fate-}"
11
samples=$2
Måns Rullgård's avatar
Måns Rullgård committed
12
target_exec=$3
13
target_path=$4
Måns Rullgård's avatar
Måns Rullgård committed
14
command=$5
15 16 17
cmp=${6:-diff}
ref=${7:-"${base}/ref/fate/${test}"}
fuzz=$8
18
threads=${9:-1}
19
thread_type=${10:-3}
20
tool=${11}
21

Måns Rullgård's avatar
Måns Rullgård committed
22 23
outdir="tests/data/fate"
outfile="${outdir}/${test}"
24
errfile="${outdir}/${test}.err"
25 26
cmpfile="${outdir}/${test}.diff"
repfile="${outdir}/${test}.rep"
Måns Rullgård's avatar
Måns Rullgård committed
27

28
do_tiny_psnr(){
29
    psnr=$(tests/tiny_psnr "$1" "$2" 2 0 0)
30
    val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
31 32
    size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
    size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
33
    res=$(echo "if ($val $4 $5) 1" | bc)
34
    if [ "$res" != 1 ] || [ $size1 != $size2 ]; then
35 36 37 38 39
        echo "$psnr"
        return 1
    fi
}

40 41 42 43 44 45 46 47
oneoff(){
    do_tiny_psnr "$1" "$2" MAXDIFF '<=' ${fuzz:-1}
}

stddev(){
    do_tiny_psnr "$1" "$2" stddev  '<=' ${fuzz:-1}
}

48
run(){
49
    test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
50 51 52
    $target_exec $target_path/"$@"
}

53
avconv(){
54
    run $tool -v 0 -threads $threads -thread_type $thread_type "$@"
55 56 57
}

framecrc(){
58
    avconv "$@" -f framecrc -
59 60 61
}

framemd5(){
62
    avconv "$@" -f framemd5 -
63 64 65
}

crc(){
66
    avconv "$@" -f crc -
67 68 69
}

md5(){
70
    avconv "$@" md5:
71 72 73
}

pcm(){
74
    avconv "$@" -vn -f s16le -
75 76
}

77 78 79
regtest(){
    t="${test#$2-}"
    ref=${base}/ref/$2/$t
80
    ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$tool"
81 82 83 84 85 86 87 88 89 90 91
}

codectest(){
    regtest codec $1 tests/$1
}

lavftest(){
    regtest lavf lavf tests/vsynth1
}

lavfitest(){
92
    cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    regtest lavfi lavfi tests/vsynth1
}

seektest(){
    t="${test#seek-}"
    ref=${base}/ref/seek/$t
    case $t in
        image_*) file="tests/data/images/${t#image_}/%02d.${t#image_}" ;;
        *)       file=$(echo $t | tr _ '?')
                 for d in acodec vsynth2 lavf; do
                     test -f tests/data/$d/$file && break
                 done
                 file=$(echo tests/data/$d/$file)
                 ;;
    esac
108
    $target_exec $target_path/libavformat/seek-test $target_path/$file
109
}
110

Måns Rullgård's avatar
Måns Rullgård committed
111 112
mkdir -p "$outdir"

113
exec 3>&2
114
$command > "$outfile" 2>$errfile
115
err=$?
116

117 118
if [ $err -gt 128 ]; then
    sig=$(kill -l $err 2>/dev/null)
119
    test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
120 121
fi

122 123 124 125 126
if test -e "$ref"; then
    case $cmp in
        diff)   diff -u -w "$ref" "$outfile"            >$cmpfile ;;
        oneoff) oneoff     "$ref" "$outfile" "$fuzz"    >$cmpfile ;;
        stddev) stddev     "$ref" "$outfile" "$fuzz"    >$cmpfile ;;
127
        null)   cat               "$outfile"            >$cmpfile ;;
128 129 130 131 132
    esac
    cmperr=$?
    test $err = 0 && err=$cmperr
    test $err = 0 || cat $cmpfile
else
133
    echo "reference file '$ref' not found"
134
    err=1
135 136
fi

137
echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
138

139 140
test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
exit $err