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.

235 lines
5.8KB

  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. regtest(){
  127. t="${test#$2-}"
  128. ref=${base}/ref/$2/$t
  129. ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$cpuflags"
  130. }
  131. lavftest(){
  132. regtest lavf lavf tests/vsynth1
  133. }
  134. video_filter(){
  135. filters=$1
  136. shift
  137. label=${test#filter-}
  138. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  139. printf '%-20s' $label
  140. avconv $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
  141. $FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5:
  142. }
  143. pixdesc(){
  144. pix_fmts="$(avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^IO/ { print $2 }' | sort)"
  145. for pix_fmt in $pix_fmts; do
  146. test=$pix_fmt
  147. video_filter "format=$pix_fmt,pixdesctest" -pix_fmt $pix_fmt
  148. done
  149. }
  150. pixfmts(){
  151. filter=${test#filter-pixfmts-}
  152. filter_args=$1
  153. showfiltfmts="$target_exec $target_path/libavfilter/filtfmts-test"
  154. exclude_fmts=${outfile}${filter}_exclude_fmts
  155. out_fmts=${outfile}${filter}_out_fmts
  156. # exclude pixel formats which are not supported as input
  157. avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^\..\./ { print $2 }' | sort >$exclude_fmts
  158. $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts
  159. pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
  160. for pix_fmt in $pix_fmts; do
  161. test=$pix_fmt
  162. video_filter "format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt
  163. done
  164. rm $exclude_fmts $out_fmts
  165. }
  166. mkdir -p "$outdir"
  167. exec 3>&2
  168. eval $command >"$outfile" 2>$errfile
  169. err=$?
  170. if [ $err -gt 128 ]; then
  171. sig=$(kill -l $err 2>/dev/null)
  172. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  173. fi
  174. if test -e "$ref" || test $cmp = "oneline" ; then
  175. case $cmp in
  176. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  177. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  178. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  179. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  180. null) cat "$outfile" >$cmpfile ;;
  181. esac
  182. cmperr=$?
  183. test $err = 0 && err=$cmperr
  184. test $err = 0 || cat $cmpfile
  185. else
  186. echo "reference file '$ref' not found"
  187. err=1
  188. fi
  189. echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile
  190. if test $err != 0 && test $gen != "no" ; then
  191. echo "GEN $ref"
  192. cp -f "$outfile" "$ref"
  193. err=$?
  194. fi
  195. test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
  196. exit $err