fate-run.sh 6.81 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
target_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
gen=${16:-no}
26

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

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

38 39 40
# $1=value1, $2=value2, $3=threshold
# prints 0 if absolute difference between value1 and value2 is <= threshold
compare(){
41
    awk "BEGIN { v = $1 - $2; printf ((v < 0 ? -v : v) > $3) }"
42 43
}

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

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

stddev(){
62
    do_tiny_psnr "$1" "$2" stddev
63 64
}

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

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

74 75 76 77 78
runecho(){
    test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
    $target_exec $target_path/"$@" >&3
}

79
probefmt(){
80
    run ffprobe -show_entries format=format_name -print_format default=nw=1:nk=1 -v 0 "$@"
Thilo Borgmann's avatar
Thilo Borgmann committed
81 82 83 84
}

probeframes(){
    run ffprobe -show_frames -v 0 "$@"
85 86
}

87
ffmpeg(){
88
    dec_opts="-threads $threads -thread_type $thread_type"
89
    ffmpeg_args="-nostats -cpuflags $cpuflags"
90
    for arg in $@; do
91
        [ x${arg} = x-i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
92
        ffmpeg_args="${ffmpeg_args} ${arg}"
93
    done
94
    run ffmpeg ${ffmpeg_args}
95 96 97
}

framecrc(){
98
    ffmpeg "$@" -flags +bitexact -f framecrc -
99 100 101
}

framemd5(){
102
    ffmpeg "$@" -flags +bitexact -f framemd5 -
103 104 105
}

crc(){
106
    ffmpeg "$@" -f crc -
107 108 109
}

md5(){
110
    ffmpeg "$@" md5:
111 112 113
}

pcm(){
114
    ffmpeg "$@" -vn -f s16le -
115 116
}

117 118 119
fmtstdout(){
    fmt=$1
    shift 1
120
    ffmpeg -flags +bitexact "$@" -f $fmt -
121 122
}

123 124
enc_dec_pcm(){
    out_fmt=$1
125 126 127 128
    dec_fmt=$2
    pcm_fmt=$3
    src_file=$(target_path $4)
    shift 4
129 130
    encfile="${outdir}/${test}.${out_fmt}"
    cleanfiles=$encfile
131
    encfile=$(target_path ${encfile})
132
    ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
133
    ffmpeg -flags +bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
134 135
}

136
FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
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)
154
    ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
155 156 157
        -f $enc_fmt -y $tencfile || return
    do_md5sum $encfile
    echo $(wc -c $encfile)
158
    ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
159 160 161 162 163
        -f $dec_fmt -y $tdecfile || return
    do_md5sum $decfile
    tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
}

164
lavffatetest(){
165 166
    t="${test#lavf-fate-}"
    ref=${base}/ref/lavf-fate/$t
167
    ${base}/lavf-regression.sh $t lavf-fate tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
168 169
}

170
lavftest(){
171 172
    t="${test#lavf-}"
    ref=${base}/ref/lavf/$t
173
    ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
174 175
}

176 177 178 179 180 181
video_filter(){
    filters=$1
    shift
    label=${test#filter-}
    raw_src="${target_path}/tests/vsynth1/%02d.pgm"
    printf '%-20s' $label
182
    ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
183 184 185
        $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5:
}

186 187
pixfmts(){
    filter=${test#filter-pixfmts-}
188
    filter=${filter%_*}
189
    filter_args=$1
190
    prefilter_chain=$2
191 192

    showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
193 194 195 196
    scale_exclude_fmts=${outfile}_scale_exclude_fmts
    scale_in_fmts=${outfile}_scale_in_fmts
    scale_out_fmts=${outfile}_scale_out_fmts
    in_fmts=${outfile}_in_fmts
197 198

    # exclude pixel formats which are not supported as input
199 200 201 202 203 204
    $showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
    $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
    comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts

    $showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
    pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
205

206
    outertest=$test
207 208
    for pix_fmt in $pix_fmts; do
        test=$pix_fmt
209
        video_filter "${prefilter_chain}format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
210 211
    done

212
    rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
213
    test=$outertest
214 215
}

Måns Rullgård's avatar
Måns Rullgård committed
216 217
mkdir -p "$outdir"

218 219 220 221
# Disable globbing: command arguments may contain globbing characters and
# must be kept verbatim
set -f

222
exec 3>&2
223
eval $command >"$outfile" 2>$errfile
224
err=$?
225

226 227
if [ $err -gt 128 ]; then
    sig=$(kill -l $err 2>/dev/null)
228
    test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
229 230
fi

231
if test -e "$ref" || test $cmp = "oneline" ; then
232
    case $cmp in
233
        diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
234
        rawdiff)diff -u    "$ref" "$outfile"            >$cmpfile ;;
235 236
        oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
        stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
237
        oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
238
        null)   cat               "$outfile"            >$cmpfile ;;
239 240 241 242 243
    esac
    cmperr=$?
    test $err = 0 && err=$cmperr
    test $err = 0 || cat $cmpfile
else
244
    echo "reference file '$ref' not found"
245
    err=1
246 247
fi

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

250 251 252 253 254 255
if test $err != 0 && test $gen != "no" ; then
    echo "GEN     $ref"
    cp -f "$outfile" "$ref"
    err=$?
fi

256 257
if test $err = 0; then
    rm -f $outfile $errfile $cmpfile $cleanfiles
258
elif test $gen = "no"; then
259
    echo "Test $test failed. Look at $errfile for details."
260
    test "${V:-0}" -gt 0 && cat $errfile
261 262
else
    echo "Updating reference failed, possibly no output file was generated."
263
fi
264
exit $err