Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. #! /bin/sh
  2.  
  3. export LC_ALL=C
  4.  
  5. base=$(dirname $0)
  6. . "${base}/md5.sh"
  7.  
  8. base64=tests/base64
  9.  
  10. test="${1#fate-}"
  11. samples=$2
  12. target_exec=$3
  13. target_path=$4
  14. command=$5
  15. cmp=${6:-diff}
  16. 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.  
  27. outdir="tests/data/fate"
  28. outfile="${outdir}/${test}"
  29. errfile="${outdir}/${test}.err"
  30. cmpfile="${outdir}/${test}.diff"
  31. repfile="${outdir}/${test}.rep"
  32.  
  33. target_path(){
  34.    test ${1} = ${1#/} && p=${target_path}/
  35.    echo ${p}${1}
  36. }
  37.  
  38. # $1=value1, $2=value2, $3=threshold
  39. # prints 0 if absolute difference between value1 and value2 is <= threshold
  40. compare(){
  41.    echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
  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.     size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
  48.     size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
  49.     val_cmp=$(compare $val $cmp_target $fuzz)
  50.     size_cmp=$(compare $size1 $size2 $size_tolerance)
  51.     if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
  52.         echo "$psnr"
  53.         return 1
  54.     fi
  55. }
  56.  
  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.     $target_exec $target_path/"$@"
  72. }
  73.  
  74. probefmt(){
  75.     run ffprobe -show_entries format=format_name -print_format default=nw=1:nk=1 -v 0 "$@"
  76. }
  77.  
  78. probeframes(){
  79.     run ffprobe -show_frames -v 0 "$@"
  80. }
  81.  
  82. ffmpeg(){
  83.     dec_opts="-threads $threads -thread_type $thread_type"
  84.     ffmpeg_args="-nostats -cpuflags $cpuflags"
  85.     for arg in $@; do
  86.         [ x${arg} = x-i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
  87.         ffmpeg_args="${ffmpeg_args} ${arg}"
  88.     done
  89.     run ffmpeg ${ffmpeg_args}
  90. }
  91.  
  92. framecrc(){
  93.     ffmpeg "$@" -flags +bitexact -f framecrc -
  94. }
  95.  
  96. framemd5(){
  97.     ffmpeg "$@" -flags +bitexact -f framemd5 -
  98. }
  99.  
  100. crc(){
  101.     ffmpeg "$@" -f crc -
  102. }
  103.  
  104. md5(){
  105.     ffmpeg "$@" md5:
  106. }
  107.  
  108. pcm(){
  109.     ffmpeg "$@" -vn -f s16le -
  110. }
  111.  
  112. enc_dec_pcm(){
  113.     out_fmt=$1
  114.     dec_fmt=$2
  115.     pcm_fmt=$3
  116.     src_file=$(target_path $4)
  117.     shift 4
  118.     encfile="${outdir}/${test}.${out_fmt}"
  119.     cleanfiles=$encfile
  120.     encfile=$(target_path ${encfile})
  121.     ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  122.     ffmpeg -flags +bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
  123. }
  124.  
  125. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact"
  126. DEC_OPTS="-threads $threads -idct simple $FLAGS"
  127. ENC_OPTS="-threads 1        -idct simple -dct fastint"
  128.  
  129. enc_dec(){
  130.     src_fmt=$1
  131.     srcfile=$2
  132.     enc_fmt=$3
  133.     enc_opt=$4
  134.     dec_fmt=$5
  135.     dec_opt=$6
  136.     encfile="${outdir}/${test}.${enc_fmt}"
  137.     decfile="${outdir}/${test}.out.${dec_fmt}"
  138.     cleanfiles="$cleanfiles $decfile"
  139.     test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  140.     tsrcfile=$(target_path $srcfile)
  141.     tencfile=$(target_path $encfile)
  142.     tdecfile=$(target_path $decfile)
  143.     ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  144.         -f $enc_fmt -y $tencfile || return
  145.     do_md5sum $encfile
  146.     echo $(wc -c $encfile)
  147.     ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
  148.         -f $dec_fmt -y $tdecfile || return
  149.     do_md5sum $decfile
  150.     tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
  151. }
  152.  
  153. lavffatetest(){
  154.     t="${test#lavf-fate-}"
  155.     ref=${base}/ref/lavf-fate/$t
  156.     ${base}/lavf-regression.sh $t lavf-fate tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$samples"
  157. }
  158.  
  159. lavftest(){
  160.     t="${test#lavf-}"
  161.     ref=${base}/ref/lavf/$t
  162.     ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$samples"
  163. }
  164.  
  165. video_filter(){
  166.     filters=$1
  167.     shift
  168.     label=${test#filter-}
  169.     raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  170.     printf '%-20s' $label
  171.     ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
  172.         $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5:
  173. }
  174.  
  175. pixdesc(){
  176.     pix_fmts="$(ffmpeg -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^IO/ { print $2 }' | sort)"
  177.     for pix_fmt in $pix_fmts; do
  178.         test=$pix_fmt
  179.         video_filter "format=$pix_fmt,pixdesctest" -pix_fmt $pix_fmt
  180.     done
  181. }
  182.  
  183. pixfmts(){
  184.     filter=${test#filter-pixfmts-}
  185.     filter=${filter%_*}
  186.     filter_args=$1
  187.     prefilter_chain=$2
  188.  
  189.     showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
  190.     scale_exclude_fmts=${outfile}_scale_exclude_fmts
  191.     scale_in_fmts=${outfile}_scale_in_fmts
  192.     scale_out_fmts=${outfile}_scale_out_fmts
  193.     in_fmts=${outfile}_in_fmts
  194.  
  195.     # exclude pixel formats which are not supported as input
  196.     $showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
  197.     $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
  198.     comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts
  199.  
  200.     $showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
  201.     pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
  202.  
  203.     for pix_fmt in $pix_fmts; do
  204.         test=$pix_fmt
  205.         video_filter "${prefilter_chain}format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
  206.     done
  207.  
  208.     rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
  209. }
  210.  
  211. mkdir -p "$outdir"
  212.  
  213. # Disable globbing: command arguments may contain globbing characters and
  214. # must be kept verbatim
  215. set -f
  216.  
  217. exec 3>&2
  218. eval $command >"$outfile" 2>$errfile
  219. err=$?
  220.  
  221. if [ $err -gt 128 ]; then
  222.     sig=$(kill -l $err 2>/dev/null)
  223.     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  224. fi
  225.  
  226. if test -e "$ref" || test $cmp = "oneline" ; then
  227.     case $cmp in
  228.         diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
  229.         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
  230.         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
  231.         oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
  232.         null)   cat               "$outfile"            >$cmpfile ;;
  233.     esac
  234.     cmperr=$?
  235.     test $err = 0 && err=$cmperr
  236.     test $err = 0 || cat $cmpfile
  237. else
  238.     echo "reference file '$ref' not found"
  239.     err=1
  240. fi
  241.  
  242. echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
  243.  
  244. if test $err != 0 && test $gen != "no" ; then
  245.     echo "GEN     $ref"
  246.     cp -f "$outfile" "$ref"
  247.     err=$?
  248. fi
  249.  
  250. if test $err = 0; then
  251.     rm -f $outfile $errfile $cmpfile $cleanfiles
  252. elif test $gen = "no"; then
  253.     echo "Test $test failed. Look at $errfile for details."
  254. else
  255.     echo "Updating reference failed, possibly no output file was generated."
  256. fi
  257. exit $err
  258.