fate-run.sh 4.93 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"

Måns Rullgård's avatar
Måns Rullgård committed
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
cmp=${6:-diff}
ref=${7:-"${base}/ref/fate/${test}"}
17
fuzz=${8:-1}
18
threads=${9:-1}
19
thread_type=${10:-frame+slice}
20
cpuflags=${11:-all}
21
cmp_shift=${12:-0}
22
cmp_target=${13:-0}
23
size_tolerance=${14:-0}
24
cmp_unit=${15:-2}
Måns Rullgård's avatar
Måns Rullgård committed
25

Måns Rullgård's avatar
Måns Rullgård committed
26 27
outdir="tests/data/fate"
outfile="${outdir}/${test}"
28
errfile="${outdir}/${test}.err"
Måns Rullgård's avatar
Måns Rullgård committed
29 30
cmpfile="${outdir}/${test}.diff"
repfile="${outdir}/${test}.rep"
Måns Rullgård's avatar
Måns Rullgård committed
31

32 33 34 35 36
target_path(){
    test ${1} = ${1#/} && p=${target_path}/
    echo ${p}${1}
}

37 38 39
# $1=value1, $2=value2, $3=threshold
# prints 0 if absolute difference between value1 and value2 is <= threshold
compare(){
40
    echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
41 42
}

Måns Rullgård's avatar
Måns Rullgård committed
43
do_tiny_psnr(){
44
    psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
Måns Rullgård's avatar
Måns Rullgård committed
45
    val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
46 47
    size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
    size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
48
    val_cmp=$(compare $val $cmp_target $fuzz)
49 50
    size_cmp=$(compare $size1 $size2 $size_tolerance)
    if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
51 52 53 54 55
        echo "$psnr"
        return 1
    fi
}

Måns Rullgård's avatar
Måns Rullgård committed
56
oneoff(){
57
    do_tiny_psnr "$1" "$2" MAXDIFF
Måns Rullgård's avatar
Måns Rullgård committed
58 59 60
}

stddev(){
61
    do_tiny_psnr "$1" "$2" stddev
Måns Rullgård's avatar
Måns Rullgård committed
62 63
}

64
oneline(){
65
    printf '%s\n' "$1" | diff -u -b - "$2"
66 67
}

68
run(){
69
    test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
70 71 72
    $target_exec $target_path/"$@"
}

73 74 75 76
probefmt(){
    run avprobe -show_format_entry format_name -v 0 "$@"
}

77
avconv(){
78 79 80 81 82 83 84
    dec_opts="-threads $threads -thread_type $thread_type"
    avconv_args="-nostats -cpuflags $cpuflags"
    for arg in $@; do
        [ ${arg} = -i ] && avconv_args="${avconv_args} ${dec_opts}"
        avconv_args="${avconv_args} ${arg}"
    done
    run avconv ${avconv_args}
85 86 87
}

framecrc(){
88
    avconv "$@" -f framecrc -
89 90 91
}

framemd5(){
92
    avconv "$@" -f framemd5 -
93 94 95
}

crc(){
96
    avconv "$@" -f crc -
97 98 99
}

md5(){
100
    avconv "$@" md5:
101 102 103
}

pcm(){
104
    avconv "$@" -vn -f s16le -
105 106
}

107 108
enc_dec_pcm(){
    out_fmt=$1
109 110 111 112
    dec_fmt=$2
    pcm_fmt=$3
    src_file=$(target_path $4)
    shift 4
113 114
    encfile="${outdir}/${test}.${out_fmt}"
    cleanfiles=$encfile
115 116 117
    encfile=$(target_path ${encfile})
    avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
    avconv -f $out_fmt -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
118 119
}

120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact"
DEC_OPTS="-threads $threads -idct simple $FLAGS"
ENC_OPTS="-threads 1        -idct simple -dct fastint"

enc_dec(){
    src_fmt=$1
    srcfile=$2
    enc_fmt=$3
    enc_opt=$4
    dec_fmt=$5
    dec_opt=$6
    encfile="${outdir}/${test}.${enc_fmt}"
    decfile="${outdir}/${test}.out.${dec_fmt}"
    cleanfiles="$cleanfiles $decfile"
    test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
    tsrcfile=$(target_path $srcfile)
    tencfile=$(target_path $encfile)
    tdecfile=$(target_path $decfile)
    avconv -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
        -f $enc_fmt -y $tencfile || return
    do_md5sum $encfile
    echo $(wc -c $encfile)
    avconv $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
        -f $dec_fmt -y $tdecfile || return
    do_md5sum $decfile
    tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
}

148 149 150
regtest(){
    t="${test#$2-}"
    ref=${base}/ref/$2/$t
151
    ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
152 153 154 155 156 157 158
}

lavftest(){
    regtest lavf lavf tests/vsynth1
}

lavfitest(){
159
    cleanfiles="tests/data/lavfi/${test#lavfi-}.nut"
160 161 162 163 164 165 166 167 168
    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 _ '?')
169 170
                 for d in fate/acodec- fate/vsynth2- lavf/; do
                     test -f tests/data/$d$file && break
171
                 done
172
                 file=$(echo tests/data/$d$file)
173 174
                 ;;
    esac
175
    run libavformat/seek-test $target_path/$file
176
}
177

Måns Rullgård's avatar
Måns Rullgård committed
178 179
mkdir -p "$outdir"

180
exec 3>&2
181
eval $command >"$outfile" 2>$errfile
182
err=$?
183

184 185
if [ $err -gt 128 ]; then
    sig=$(kill -l $err 2>/dev/null)
186
    test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
187 188
fi

189
if test -e "$ref" || test $cmp = "oneline" ; then
Måns Rullgård's avatar
Måns Rullgård committed
190
    case $cmp in
191
        diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
192 193
        oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
        stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
194
        oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
195
        null)   cat               "$outfile"            >$cmpfile ;;
Måns Rullgård's avatar
Måns Rullgård committed
196 197 198 199 200
    esac
    cmperr=$?
    test $err = 0 && err=$cmperr
    test $err = 0 || cat $cmpfile
else
201
    echo "reference file '$ref' not found"
Måns Rullgård's avatar
Måns Rullgård committed
202
    err=1
203 204
fi

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

Måns Rullgård's avatar
Måns Rullgård committed
207 208
test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
exit $err