Subversion Repositories Kolibri OS

Rev

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. target_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. hwaccel=${17:-none}
  27.  
  28. outdir="tests/data/fate"
  29. outfile="${outdir}/${test}"
  30. errfile="${outdir}/${test}.err"
  31. cmpfile="${outdir}/${test}.diff"
  32. repfile="${outdir}/${test}.rep"
  33.  
  34. target_path(){
  35.    test ${1} = ${1#/} && p=${target_path}/
  36.    echo ${p}${1}
  37. }
  38.  
  39. # $1=value1, $2=value2, $3=threshold
  40. # prints 0 if absolute difference between value1 and value2 is <= threshold
  41. compare(){
  42.    awk "BEGIN { v = $1 - $2; printf ((v < 0 ? -v : v) > $3) }"
  43. }
  44.  
  45. do_tiny_psnr(){
  46.    psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0) || return 1
  47.    val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
  48.     size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
  49.     size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
  50.     val_cmp=$(compare $val $cmp_target $fuzz)
  51.     size_cmp=$(compare $size1 $size2 $size_tolerance)
  52.     if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
  53.         echo "$psnr"
  54.         if [ "$val_cmp" != 0 ]; then
  55.             echo "$3: |$val - $cmp_target| >= $fuzz"
  56.         fi
  57.         if [ "$size_cmp" != 0 ]; then
  58.             echo "size: |$size1 - $size2| >= $size_tolerance"
  59.         fi
  60.         return 1
  61.     fi
  62. }
  63.  
  64. oneoff(){
  65.     do_tiny_psnr "$1" "$2" MAXDIFF
  66. }
  67.  
  68. stddev(){
  69.     do_tiny_psnr "$1" "$2" stddev
  70. }
  71.  
  72. oneline(){
  73.     printf '%s\n' "$1" | diff -u -b - "$2"
  74. }
  75.  
  76. run(){
  77.     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  78.     $target_exec $target_path/"$@"
  79. }
  80.  
  81. runecho(){
  82.     test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  83.     $target_exec $target_path/"$@" >&3
  84. }
  85.  
  86. probefmt(){
  87.     run ffprobe -show_entries format=format_name -print_format default=nw=1:nk=1 -v 0 "$@"
  88. }
  89.  
  90. probeframes(){
  91.     run ffprobe -show_frames -v 0 "$@"
  92. }
  93.  
  94. ffmpeg(){
  95.     dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
  96.     ffmpeg_args="-nostdin -nostats -cpuflags $cpuflags"
  97.     for arg in $@; do
  98.         [ x${arg} = x-i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
  99.         ffmpeg_args="${ffmpeg_args} ${arg}"
  100.     done
  101.     run ffmpeg ${ffmpeg_args}
  102. }
  103.  
  104. framecrc(){
  105.     ffmpeg "$@" -flags +bitexact -fflags +bitexact -f framecrc -
  106. }
  107.  
  108. framemd5(){
  109.     ffmpeg "$@" -flags +bitexact -fflags +bitexact -f framemd5 -
  110. }
  111.  
  112. crc(){
  113.     ffmpeg "$@" -f crc -
  114. }
  115.  
  116. md5(){
  117.     ffmpeg "$@" md5:
  118. }
  119.  
  120. pcm(){
  121.     ffmpeg "$@" -vn -f s16le -
  122. }
  123.  
  124. fmtstdout(){
  125.     fmt=$1
  126.     shift 1
  127.     ffmpeg -flags +bitexact -fflags +bitexact "$@" -f $fmt -
  128. }
  129.  
  130. enc_dec_pcm(){
  131.     out_fmt=$1
  132.     dec_fmt=$2
  133.     pcm_fmt=$3
  134.     src_file=$(target_path $4)
  135.     shift 4
  136.     encfile="${outdir}/${test}.${out_fmt}"
  137.     cleanfiles=$encfile
  138.     encfile=$(target_path ${encfile})
  139.     ffmpeg -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  140.     ffmpeg -flags +bitexact -fflags +bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
  141. }
  142.  
  143. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
  144. DEC_OPTS="-threads $threads -idct simple $FLAGS"
  145. ENC_OPTS="-threads 1        -idct simple -dct fastint"
  146.  
  147. enc_dec(){
  148.     src_fmt=$1
  149.     srcfile=$2
  150.     enc_fmt=$3
  151.     enc_opt=$4
  152.     dec_fmt=$5
  153.     dec_opt=$6
  154.     encfile="${outdir}/${test}.${enc_fmt}"
  155.     decfile="${outdir}/${test}.out.${dec_fmt}"
  156.     cleanfiles="$cleanfiles $decfile"
  157.     test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  158.     tsrcfile=$(target_path $srcfile)
  159.     tencfile=$(target_path $encfile)
  160.     tdecfile=$(target_path $decfile)
  161.     ffmpeg -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  162.         -f $enc_fmt -y $tencfile || return
  163.     do_md5sum $encfile
  164.     echo $(wc -c $encfile)
  165.     ffmpeg $8 $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
  166.         -f $dec_fmt -y $tdecfile || return
  167.     do_md5sum $decfile
  168.     tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
  169. }
  170.  
  171. lavffatetest(){
  172.     t="${test#lavf-fate-}"
  173.     ref=${base}/ref/lavf-fate/$t
  174.     ${base}/lavf-regression.sh $t lavf-fate tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
  175. }
  176.  
  177. lavftest(){
  178.     t="${test#lavf-}"
  179.     ref=${base}/ref/lavf/$t
  180.     ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags" "$target_samples"
  181. }
  182.  
  183. video_filter(){
  184.     filters=$1
  185.     shift
  186.     label=${test#filter-}
  187.     raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  188.     printf '%-20s' $label
  189.     ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
  190.         $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo -frames:v 5 $* -f nut md5:
  191. }
  192.  
  193. pixfmts(){
  194.     filter=${test#filter-pixfmts-}
  195.     filter=${filter%_*}
  196.     filter_args=$1
  197.     prefilter_chain=$2
  198.     nframes=${3:-1}
  199.  
  200.     showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
  201.     scale_exclude_fmts=${outfile}_scale_exclude_fmts
  202.     scale_in_fmts=${outfile}_scale_in_fmts
  203.     scale_out_fmts=${outfile}_scale_out_fmts
  204.     in_fmts=${outfile}_in_fmts
  205.  
  206.     # exclude pixel formats which are not supported as input
  207.     $showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
  208.     $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
  209.     comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts
  210.  
  211.     $showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
  212.     pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
  213.  
  214.     outertest=$test
  215.     for pix_fmt in $pix_fmts; do
  216.         test=$pix_fmt
  217.         video_filter "${prefilter_chain}format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v $nframes
  218.     done
  219.  
  220.     rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
  221.     test=$outertest
  222. }
  223.  
  224. gapless(){
  225.     sample=$(target_path $1)
  226.     extra_args=$2
  227.  
  228.     decfile1="${outdir}/${test}.out-1"
  229.     decfile2="${outdir}/${test}.out-2"
  230.     decfile3="${outdir}/${test}.out-3"
  231.     cleanfiles="$cleanfiles $decfile1 $decfile2 $decfile3"
  232.  
  233.     # test packet data
  234.     ffmpeg $extra_args -i "$sample" -flags +bitexact -fflags +bitexact -c:a copy -f framecrc -y $decfile1
  235.     do_md5sum $decfile1
  236.     # test decoded (and cut) data
  237.     ffmpeg $extra_args -i "$sample" -flags +bitexact -fflags +bitexact -f wav md5:
  238.     # the same as above again, with seeking to the start
  239.     ffmpeg $extra_args -ss 0 -seek_timestamp 1 -i "$sample" -flags +bitexact -fflags +bitexact -c:a copy -f framecrc -y $decfile2
  240.     do_md5sum $decfile2
  241.     ffmpeg $extra_args -ss 0 -seek_timestamp 1 -i "$sample" -flags +bitexact -fflags +bitexact -f wav md5:
  242.     # test packet data, with seeking to a specific position
  243.     ffmpeg $extra_args -ss 5 -seek_timestamp 1 -i "$sample" -flags +bitexact -fflags +bitexact -c:a copy -f framecrc -y $decfile3
  244.     do_md5sum $decfile3
  245. }
  246.  
  247. mkdir -p "$outdir"
  248.  
  249. # Disable globbing: command arguments may contain globbing characters and
  250. # must be kept verbatim
  251. set -f
  252.  
  253. exec 3>&2
  254. eval $command >"$outfile" 2>$errfile
  255. err=$?
  256.  
  257. if [ $err -gt 128 ]; then
  258.     sig=$(kill -l $err 2>/dev/null)
  259.     test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  260. fi
  261.  
  262. if test -e "$ref" || test $cmp = "oneline" ; then
  263.     case $cmp in
  264.         diff)   diff -u -b "$ref" "$outfile"            >$cmpfile ;;
  265.         rawdiff)diff -u    "$ref" "$outfile"            >$cmpfile ;;
  266.         oneoff) oneoff     "$ref" "$outfile"            >$cmpfile ;;
  267.         stddev) stddev     "$ref" "$outfile"            >$cmpfile ;;
  268.         oneline)oneline    "$ref" "$outfile"            >$cmpfile ;;
  269.         null)   cat               "$outfile"            >$cmpfile ;;
  270.     esac
  271.     cmperr=$?
  272.     test $err = 0 && err=$cmperr
  273.     test $err = 0 || cat $cmpfile
  274. else
  275.     echo "reference file '$ref' not found"
  276.     err=1
  277. fi
  278.  
  279. if [ $err -eq 0 ]; then
  280.     unset cmpo erro
  281. else
  282.     cmpo="$($base64 <$cmpfile)"
  283.     erro="$($base64 <$errfile)"
  284. fi
  285. echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
  286.  
  287. if test $err != 0 && test $gen != "no" ; then
  288.     echo "GEN     $ref"
  289.     cp -f "$outfile" "$ref"
  290.     err=$?
  291. fi
  292.  
  293. if test $err = 0; then
  294.     rm -f $outfile $errfile $cmpfile $cleanfiles
  295. elif test $gen = "no"; then
  296.     echo "Test $test failed. Look at $errfile for details."
  297.     test "${V:-0}" -gt 0 && cat $errfile
  298. else
  299.     echo "Updating reference failed, possibly no output file was generated."
  300. fi
  301. exit $err
  302.