tests/fate-run.sh
2fad0977
 #! /bin/sh
 
078ae66b
 export LC_ALL=C
 
2fad0977
 base=$(dirname $0)
 . "${base}/md5.sh"
 
b82be636
 base64=tests/base64
 
2fad0977
 test="${1#fate-}"
122a9af7
 samples=$2
2fad0977
 target_exec=$3
122a9af7
 target_path=$4
2fad0977
 command=$5
3ade7d32
 cmp=${6:-diff}
 ref=${7:-"${base}/ref/fate/${test}"}
0720d263
 fuzz=${8:-1}
7851eb68
 threads=${9:-1}
bc5acfa7
 thread_type=${10:-frame+slice}
018f39ef
 cpuflags=${11:-all}
5ecadc66
 cmp_shift=${12:-0}
bb684296
 cmp_target=${13:-0}
cffd7580
 size_tolerance=${14:-0}
47b5996b
 cmp_unit=${15:-2}
b01b60a2
 gen=${16:-no}
26e87a22
 
2fad0977
 outdir="tests/data/fate"
 outfile="${outdir}/${test}"
bcb0a154
 errfile="${outdir}/${test}.err"
b82be636
 cmpfile="${outdir}/${test}.diff"
 repfile="${outdir}/${test}.rep"
2fad0977
 
9cc338b1
 target_path(){
     test ${1} = ${1#/} && p=${target_path}/
     echo ${p}${1}
 }
 
bb684296
 # $1=value1, $2=value2, $3=threshold
 # prints 0 if absolute difference between value1 and value2 is <= threshold
 compare(){
a56fba50
     echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
bb684296
 }
 
e153cfa8
 do_tiny_psnr(){
47b5996b
     psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
e153cfa8
     val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
83b203dc
     size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
     size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
bb684296
     val_cmp=$(compare $val $cmp_target $fuzz)
cffd7580
     size_cmp=$(compare $size1 $size2 $size_tolerance)
     if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
aab3ea5f
         echo "$psnr"
         return 1
     fi
 }
 
e153cfa8
 oneoff(){
bb684296
     do_tiny_psnr "$1" "$2" MAXDIFF
e153cfa8
 }
 
 stddev(){
bb684296
     do_tiny_psnr "$1" "$2" stddev
e153cfa8
 }
 
40fa14f7
 oneline(){
0ff0af73
     printf '%s\n' "$1" | diff -u -b - "$2"
40fa14f7
 }
 
dff1fc51
 run(){
c4795e80
     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
dff1fc51
     $target_exec $target_path/"$@"
 }
 
4bfa67bd
 probefmt(){
4a753fc5
     run ffprobe -show_entries format=format_name -print_format default=nw=1:nk=1 -v 0 "$@"
4bfa67bd
 }
 
fcd08262
 ffmpeg(){
8d18bc55
     dec_opts="-threads $threads -thread_type $thread_type"
f8911b98
     ffmpeg_args="-nostats -cpuflags $cpuflags"
8d18bc55
     for arg in $@; do
835fd779
         [ x${arg} = x-i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
f8911b98
         ffmpeg_args="${ffmpeg_args} ${arg}"
8d18bc55
     done
f8911b98
     run ffmpeg ${ffmpeg_args}
2b18c451
 }
 
 framecrc(){
fcd08262
     ffmpeg "$@" -f framecrc -
2b18c451
 }
 
 framemd5(){
fcd08262
     ffmpeg "$@" -f framemd5 -
2b18c451
 }
 
 crc(){
fcd08262
     ffmpeg "$@" -f crc -
2b18c451
 }
 
 md5(){
fcd08262
     ffmpeg "$@" md5:
2b18c451
 }
 
 pcm(){
fcd08262
     ffmpeg "$@" -vn -f s16le -
2b18c451
 }
 
90e5b58a
 enc_dec_pcm(){
     out_fmt=$1
9cc338b1
     dec_fmt=$2
     pcm_fmt=$3
     src_file=$(target_path $4)
     shift 4
90e5b58a
     encfile="${outdir}/${test}.${out_fmt}"
     cleanfiles=$encfile
9cc338b1
     encfile=$(target_path ${encfile})
fcd08262
     ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
fd8da83d
     ffmpeg -flags +bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
90e5b58a
 }
 
7263cd55
 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)
b0387edd
     ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
7263cd55
         -f $enc_fmt -y $tencfile || return
     do_md5sum $encfile
     echo $(wc -c $encfile)
eb2f499e
     ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
7263cd55
         -f $dec_fmt -y $tdecfile || return
     do_md5sum $decfile
     tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
 }
 
f23a7403
 lavffatetest(){
63208c03
     t="${test#lavf-fate-}"
     ref=${base}/ref/lavf-fate/$t
     ${base}/lavf-regression.sh $t lavf-fate tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$samples"
f23a7403
 }
 
9a3f31ef
 lavftest(){
bd392785
     t="${test#lavf-}"
     ref=${base}/ref/lavf/$t
63208c03
     ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$samples"
9a3f31ef
 }
 
03b052c0
 video_filter(){
     filters=$1
     shift
     label=${test#filter-}
     raw_src="${target_path}/tests/vsynth1/%02d.pgm"
     printf '%-20s' $label
506ebdac
     ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
03b052c0
         $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5:
 }
 
28663511
 pixdesc(){
191430a2
     pix_fmts="$(ffmpeg -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^IO/ { print $2 }' | sort)"
28663511
     for pix_fmt in $pix_fmts; do
         test=$pix_fmt
         video_filter "format=$pix_fmt,pixdesctest" -pix_fmt $pix_fmt
     done
 }
 
b963f021
 pixfmts(){
     filter=${test#filter-pixfmts-}
45734dea
     filter=${filter%_*}
b963f021
     filter_args=$1
93aede41
     prefilter_chain=$2
b963f021
 
     showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
24939d56
     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
b963f021
 
     # exclude pixel formats which are not supported as input
1e0a0aaf
     $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)
b963f021
 
     for pix_fmt in $pix_fmts; do
         test=$pix_fmt
93aede41
         video_filter "${prefilter_chain}format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
b963f021
     done
 
1e0a0aaf
     rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
b963f021
 }
 
2fad0977
 mkdir -p "$outdir"
 
be01d1a2
 # Disable globbing: command arguments may contain globbing characters and
 # must be kept verbatim
 set -f
 
c4795e80
 exec 3>&2
7263cd55
 eval $command >"$outfile" 2>$errfile
ffe72624
 err=$?
3ade7d32
 
4e705a68
 if [ $err -gt 128 ]; then
     sig=$(kill -l $err 2>/dev/null)
5b60c293
     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
4e705a68
 fi
 
40fa14f7
 if test -e "$ref" || test $cmp = "oneline" ; then
b82be636
     case $cmp in
11e33402
         diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
0720d263
         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
40fa14f7
         oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
84757de0
         null)   cat               "$outfile"            >$cmpfile ;;
b82be636
     esac
     cmperr=$?
     test $err = 0 && err=$cmperr
     test $err = 0 || cat $cmpfile
 else
9a3f31ef
     echo "reference file '$ref' not found"
b82be636
     err=1
9a3f31ef
 fi
 
4e705a68
 echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
7d610af6
 
b01b60a2
 if test $err != 0 && test $gen != "no" ; then
     echo "GEN     $ref"
     cp -f "$outfile" "$ref"
     err=$?
 fi
 
3d38a726
 if test $err = 0; then
     rm -f $outfile $errfile $cmpfile $cleanfiles
ee53777e
 elif test $gen = "no"; then
3d38a726
     echo "Test $test failed. Look at $errfile for details."
ee53777e
 else
     echo "Updating reference failed, possibly no output file was generated."
3d38a726
 fi
b82be636
 exit $err