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.

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