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.

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