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.

246 lines
6.0KB

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