You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
5.7KB

  1. #! /bin/sh
  2. export LC_ALL=C
  3. base=$(dirname $0)
  4. . "${base}/md5.sh"
  5. base64=tests/base64
  6. test="${1#fate-}"
  7. samples=$2
  8. target_exec=$3
  9. target_path=$4
  10. command=$5
  11. cmp=${6:-diff}
  12. ref=${7:-"${base}/ref/fate/${test}"}
  13. fuzz=${8:-1}
  14. threads=${9:-1}
  15. thread_type=${10:-frame+slice}
  16. cpuflags=${11:-all}
  17. cmp_shift=${12:-0}
  18. cmp_target=${13:-0}
  19. size_tolerance=${14:-0}
  20. cmp_unit=${15:-2}
  21. gen=${16:-no}
  22. outdir="tests/data/fate"
  23. outfile="${outdir}/${test}"
  24. errfile="${outdir}/${test}.err"
  25. cmpfile="${outdir}/${test}.diff"
  26. repfile="${outdir}/${test}.rep"
  27. target_path(){
  28. test ${1} = ${1#/} && p=${target_path}/
  29. echo ${p}${1}
  30. }
  31. # $1=value1, $2=value2, $3=threshold
  32. # prints 0 if absolute difference between value1 and value2 is <= threshold
  33. compare(){
  34. echo "scale=2; v = $1 - $2; if (v < 0) v = -v; if (v > $3) r = 1; r" | bc
  35. }
  36. do_tiny_psnr(){
  37. psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
  38. val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
  39. size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
  40. size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
  41. val_cmp=$(compare $val $cmp_target $fuzz)
  42. size_cmp=$(compare $size1 $size2 $size_tolerance)
  43. if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
  44. echo "$psnr"
  45. return 1
  46. fi
  47. }
  48. oneoff(){
  49. do_tiny_psnr "$1" "$2" MAXDIFF
  50. }
  51. stddev(){
  52. do_tiny_psnr "$1" "$2" stddev
  53. }
  54. oneline(){
  55. printf '%s\n' "$1" | diff -u -b - "$2"
  56. }
  57. run(){
  58. test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  59. $target_exec $target_path/"$@"
  60. }
  61. probefmt(){
  62. run avprobe -show_format_entry format_name -v 0 "$@"
  63. }
  64. avconv(){
  65. dec_opts="-threads $threads -thread_type $thread_type"
  66. avconv_args="-nostats -cpuflags $cpuflags"
  67. for arg in $@; do
  68. [ x${arg} = x-i ] && avconv_args="${avconv_args} ${dec_opts}"
  69. avconv_args="${avconv_args} ${arg}"
  70. done
  71. run avconv ${avconv_args}
  72. }
  73. framecrc(){
  74. avconv "$@" -f framecrc -
  75. }
  76. framemd5(){
  77. avconv "$@" -f framemd5 -
  78. }
  79. crc(){
  80. avconv "$@" -f crc -
  81. }
  82. md5(){
  83. avconv "$@" md5:
  84. }
  85. pcm(){
  86. avconv "$@" -vn -f s16le -
  87. }
  88. enc_dec_pcm(){
  89. out_fmt=$1
  90. dec_fmt=$2
  91. pcm_fmt=$3
  92. src_file=$(target_path $4)
  93. shift 4
  94. encfile="${outdir}/${test}.${out_fmt}"
  95. cleanfiles=$encfile
  96. encfile=$(target_path ${encfile})
  97. avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  98. avconv -f $out_fmt -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
  99. }
  100. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact"
  101. DEC_OPTS="-threads $threads -idct simple $FLAGS"
  102. ENC_OPTS="-threads 1 -idct simple -dct fastint"
  103. enc_dec(){
  104. src_fmt=$1
  105. srcfile=$2
  106. enc_fmt=$3
  107. enc_opt=$4
  108. dec_fmt=$5
  109. dec_opt=$6
  110. encfile="${outdir}/${test}.${enc_fmt}"
  111. decfile="${outdir}/${test}.out.${dec_fmt}"
  112. cleanfiles="$cleanfiles $decfile"
  113. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  114. tsrcfile=$(target_path $srcfile)
  115. tencfile=$(target_path $encfile)
  116. tdecfile=$(target_path $decfile)
  117. avconv -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  118. -f $enc_fmt -y $tencfile || return
  119. do_md5sum $encfile
  120. echo $(wc -c $encfile)
  121. avconv $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
  122. -f $dec_fmt -y $tdecfile || return
  123. do_md5sum $decfile
  124. tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
  125. }
  126. lavftest(){
  127. t="${test#lavf-}"
  128. ref=${base}/ref/lavf/$t
  129. ${base}/lavf-regression.sh $t lavf tests/vsynth1 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
  130. }
  131. video_filter(){
  132. filters=$1
  133. shift
  134. label=${test#filter-}
  135. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  136. printf '%-20s' $label
  137. avconv $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
  138. $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5:
  139. }
  140. pixdesc(){
  141. pix_fmts="$(avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^IO/ { print $2 }' | sort)"
  142. for pix_fmt in $pix_fmts; do
  143. test=$pix_fmt
  144. video_filter "format=$pix_fmt,pixdesctest" -pix_fmt $pix_fmt
  145. done
  146. }
  147. pixfmts(){
  148. filter=${test#filter-pixfmts-}
  149. filter_args=$1
  150. showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
  151. exclude_fmts=${outfile}${filter}_exclude_fmts
  152. out_fmts=${outfile}${filter}_out_fmts
  153. # exclude pixel formats which are not supported as input
  154. avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^\..\./ { print $2 }' | sort >$exclude_fmts
  155. $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts
  156. pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
  157. for pix_fmt in $pix_fmts; do
  158. test=$pix_fmt
  159. video_filter "format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
  160. done
  161. rm $exclude_fmts $out_fmts
  162. }
  163. mkdir -p "$outdir"
  164. exec 3>&2
  165. eval $command >"$outfile" 2>$errfile
  166. err=$?
  167. if [ $err -gt 128 ]; then
  168. sig=$(kill -l $err 2>/dev/null)
  169. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  170. fi
  171. if test -e "$ref" || test $cmp = "oneline" ; then
  172. case $cmp in
  173. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  174. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  175. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  176. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  177. null) cat "$outfile" >$cmpfile ;;
  178. esac
  179. cmperr=$?
  180. test $err = 0 && err=$cmperr
  181. test $err = 0 || cat $cmpfile
  182. else
  183. echo "reference file '$ref' not found"
  184. err=1
  185. fi
  186. echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
  187. if test $err != 0 && test $gen != "no" ; then
  188. echo "GEN $ref"
  189. cp -f "$outfile" "$ref"
  190. err=$?
  191. fi
  192. test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
  193. exit $err