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

43
do_tiny_psnr(){
44
    psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
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
}

56
oneoff(){
57
    do_tiny_psnr "$1" "$2" MAXDIFF
58 59 60
}

stddev(){
61
    do_tiny_psnr "$1" "$2" stddev
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
probefmt(){
74
    run ffprobe -show_entries format=format_name -print_format default=nw=1:nk=1 -v 0 "$@"
75 76
}

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

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

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

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

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

pcm(){
104
    ffmpeg "$@" -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
    encfile=$(target_path ${encfile})
116
    ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
117
    ffmpeg -flags +bitexact -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
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)
138
    ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
139 140 141
        -f $enc_fmt -y $tencfile || return
    do_md5sum $encfile
    echo $(wc -c $encfile)
142
    ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
143 144 145 146 147
        -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" "$samples"
152 153
}

154 155 156 157
lavffatetest(){
    regtest lavf lavf-fate tests/vsynth1
}

158 159 160 161 162
lavftest(){
    regtest lavf lavf tests/vsynth1
}

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

Måns Rullgård's avatar
Måns Rullgård committed
182 183
mkdir -p "$outdir"

184
exec 3>&2
185
eval $command >"$outfile" 2>$errfile
186
err=$?
187

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

193
if test -e "$ref" || test $cmp = "oneline" ; then
194
    case $cmp in
195
        diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
196 197
        oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
        stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
198
        oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
199
        null)   cat               "$outfile"            >$cmpfile ;;
200 201 202 203 204
    esac
    cmperr=$?
    test $err = 0 && err=$cmperr
    test $err = 0 || cat $cmpfile
else
205
    echo "reference file '$ref' not found"
206
    err=1
207 208
fi

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

211 212 213 214 215
if test $err = 0; then
    rm -f $outfile $errfile $cmpfile $cleanfiles
else
    echo "Test $test failed. Look at $errfile for details."
fi
216
exit $err