fate-run.sh 5.74 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}
25
gen=${16:-no}
Måns Rullgård's avatar
Måns Rullgård committed
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"
Måns Rullgård's avatar
Måns Rullgård committed
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
    echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
42 43
}

Måns Rullgård's avatar
Måns Rullgård committed
44
do_tiny_psnr(){
45
    psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
Måns Rullgård's avatar
Måns Rullgård committed
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
}

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

stddev(){
62
    do_tiny_psnr "$1" "$2" stddev
Måns Rullgård's avatar
Måns Rullgård committed
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
probefmt(){
    run avprobe -show_format_entry format_name -v 0 "$@"
}

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

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

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

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

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

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

108 109
enc_dec_pcm(){
    out_fmt=$1
110 111 112 113
    dec_fmt=$2
    pcm_fmt=$3
    src_file=$(target_path $4)
    shift 4
114 115
    encfile="${outdir}/${test}.${out_fmt}"
    cleanfiles=$encfile
116 117 118
    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} -
119 120
}

121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
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)
143
    avconv $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
144 145 146 147 148
        -f $dec_fmt -y $tdecfile || return
    do_md5sum $decfile
    tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
}

149
lavftest(){
150 151 152
    t="${test#lavf-}"
    ref=${base}/ref/lavf/$t
    ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
153 154
}

155 156 157 158 159 160 161 162 163 164
video_filter(){
    filters=$1
    shift
    label=${test#filter-}
    raw_src="${target_path}/tests/vsynth1/%02d.pgm"
    printf '%-20s' $label
    avconv $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
        $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5:
}

165 166 167 168 169 170 171 172
pixdesc(){
    pix_fmts="$(avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^IO/ { print $2 }' | sort)"
    for pix_fmt in $pix_fmts; do
        test=$pix_fmt
        video_filter "format=$pix_fmt,pixdesctest" -pix_fmt $pix_fmt
    done
}

173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
pixfmts(){
    filter=${test#filter-pixfmts-}
    filter_args=$1

    showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
    exclude_fmts=${outfile}${filter}_exclude_fmts
    out_fmts=${outfile}${filter}_out_fmts

    # exclude pixel formats which are not supported as input
    avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^\..\./ { print $2 }' | sort >$exclude_fmts
    $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts

    pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
    for pix_fmt in $pix_fmts; do
        test=$pix_fmt
        video_filter "format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
    done

    rm $exclude_fmts $out_fmts
}

Måns Rullgård's avatar
Måns Rullgård committed
194 195
mkdir -p "$outdir"

196
exec 3>&2
197
eval $command >"$outfile" 2>$errfile
198
err=$?
199

200 201
if [ $err -gt 128 ]; then
    sig=$(kill -l $err 2>/dev/null)
202
    test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
203 204
fi

205
if test -e "$ref" || test $cmp = "oneline" ; then
Måns Rullgård's avatar
Måns Rullgård committed
206
    case $cmp in
207
        diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
208 209
        oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
        stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
210
        oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
211
        null)   cat               "$outfile"            >$cmpfile ;;
Måns Rullgård's avatar
Måns Rullgård committed
212 213 214 215 216
    esac
    cmperr=$?
    test $err = 0 && err=$cmperr
    test $err = 0 || cat $cmpfile
else
217
    echo "reference file '$ref' not found"
Måns Rullgård's avatar
Måns Rullgård committed
218
    err=1
219 220
fi

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

223 224 225 226 227 228
if test $err != 0 && test $gen != "no" ; then
    echo "GEN     $ref"
    cp -f "$outfile" "$ref"
    err=$?
fi

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