5 # Copyright (c) 2003, 2004, 2005, 2006, 2007 Dan McMahill
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of version 2 of the GNU General Public License as
9 # published by the Free Software Foundation
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
19 # All rights reserved.
21 # This code was derived from code written by Dan McMahill as part of the
22 # latex-mk testsuite. The original code was covered by a BSD license
23 # but the copyright holder is releasing the version for gerbv under the GPL.
25 magic_test_skip
=${GERBV_MAGIC_TEST_SKIP:-no}
27 if test "x${magic_test_skip}" = "xyes" ; then
30 The environment variable GERBV_MAGIC_TEST_SKIP is set to yes.
31 This causes the testsuite to skip all tests and report no errors.
32 This is used for certain debugging *only*. The primary use is to
33 allow testing of the 'distcheck' target without including the effects
34 of the testsuite. The reason this is useful is that due to minor differences
35 in cairo versions and perhaps roundoff in different CPU's, the testsuite
36 may falsely report failures on some systems. These reported failures
37 prevent using 'distcheck' for verifying the rest of the build system.
49 ******* WARNING **** WARNING *******
50 This script is still in progress and
51 may not be functional at all. Please
52 stay tuned and hold off on any bug
53 reports until this message is gone
54 ******* WARNING **** WARNING *******
56 $0 -- Run gerbv regression tests
59 $0 [-g | --golden dir] [-r|--regen] [testname1 [testname2[ ...]]]
63 The $0 script is used both for running the gerbv regression testsuite
64 as well as maintaining it. The way the test suite works is a number
65 of different layouts are exported to portable network graphics (PNG)
66 files. The resulting PNG files are then compared on a pixel by pixel
67 basis to a set of reference PNG files.
69 Current versions of gerbv use cairo for rendering. Besides the
70 ability to render to the screen, cairo can render to PNG files. Since
71 the same rendering engine is used for screen and PNG rendering and the
72 parser is common, verification via PNG files is fairly accurate.
76 -g | --golden <dir> : Specifies that <dir> should be used for the
81 The GUI interface is not checked via the regression testsuite.
82 However, the RS274-X and drill file parsers along with the rendering
83 can be considered the core of the program.
90 echo "----------------------------------------------------------------------"
105 # set the 'golden' directory.
111 # regenerate the 'golden' output files. Use this with caution.
112 # In particular, all differences should be noted and understood.
118 echo "unknown option: $1"
131 # The gerbv executible
132 GERBV
=${GERBV:-../src/run_gerbv --}
133 GERBV_DEFAULT_FLAGS
=${GERBV_DEFAULT_FLAGS:---export=png --window=640x480}
138 # various ImageMagick tools
139 IM_ANIMATE
=${IM_ANIMATE:-animate}
140 IM_COMPARE
=${IM_COMPARE:-compare}
141 IM_COMPOSITE
=${IM_COMPOSITE:-composite}
142 IM_CONVERT
=${IM_CONVERT:-convert}
143 IM_DISPLAY
=${IM_DISPLAY:-display}
144 IM_MONTAGE
=${IM_MONTAGE:-montage}
147 INDIR
=${INDIR:-${srcdir}/inputs}
149 REFDIR
=${REFDIR:-${srcdir}/golden}
155 # the list of tests to run
156 TESTLIST
=${srcdir}/tests.list
158 if test "X$regen" = "Xyes" ; then
162 # create output directory
163 if test ! -d $OUTDIR ; then
165 if test $?
-ne 0 ; then
166 echo "Failed to create output directory ${OUTDIR}"
171 if test -z "$all_tests" ; then
172 if test ! -f ${TESTLIST} ; then
173 echo "ERROR: ($0) Test list $TESTLIST does not exist"
176 all_tests
=`${AWK} 'BEGIN{FS="|"} /^#/{next} {print $1}' ${TESTLIST} | sed 's; ;;g'`
179 if test -z "${all_tests}" ; then
180 echo "$0: No tests specified"
185 # fail/pass/total counts
194 top_srcdir ${top_srcdir}
199 GERBV_DEFAULT_FLAGS ${GERBV_DEFAULT_FLAGS}
207 IM_ANIMATE ${IM_ANIMATE}
208 IM_COMPARE ${IM_COMPARE}
209 IM_COMPOSITE ${IM_COMPOSITE}
210 IM_CONVERT ${IM_CONVERT}
211 IM_DISPLAY ${IM_DISPLAY}
212 IM_MONTAGE ${IM_MONTAGE}
216 for t
in $all_tests ; do
222 ######################################################################
224 # extract the details for the test
227 gerbv_flags
="${GERBV_DEFAULT_FLAGS}"
229 refpng
="${REFDIR}/${t}.png"
230 outpng
="${OUTDIR}/${t}.png"
231 errdir
="${ERRDIR}/${t}"
233 # test_name | layout file(s) | [optional arguments to gerbv] | [mismatch]
234 name
=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | $AWK 'BEGIN{FS="|"} {print $1}'`
235 files
=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | $AWK 'BEGIN{FS="|"} {print $2}'`
236 args
=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | $AWK 'BEGIN{FS="|"} {print $3}'`
237 mismatch
=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | $AWK 'BEGIN{FS="|"} {if($2 == "mismatch"){print "yes"}else{print "no"}}'`
239 if test "X${name}" = "X" ; then
240 echo "ERROR: Specified test ${t} does not appear to exist"
241 skip
=`expr $skip + 1`
245 if test "X${args}" != "X" ; then
246 gerbv_flags
="${args}"
249 ######################################################################
251 # check to see if the files we need exist
257 if test ! -f ${INDIR}/${f} ; then
258 echo "ERROR: File $f specified as part of the $t test does not exist"
261 path_files
="${path_files} ${INDIR}/${f}"
264 if test "$missing_files" = "yes" ; then
265 echo "${t} had missing input files. Skipping test"
266 skip
=`expr $skip + 1`
270 ######################################################################
272 # export the layout to PNG
275 echo "${GERBV} ${gerbv_flags} --output=${outpng} ${path_files}"
276 ${GERBV} ${gerbv_flags} --output=${outpng} ${path_files}
278 ######################################################################
280 # compare to the golden PNG file
283 if test "X$regen" != "Xyes" ; then
284 if test -f ${REFDIR}/${t}.png
; then
285 same
=`${IM_COMPARE} -metric MAE $refpng $outpng null: 2>&1 | \
286 ${AWK} '{if($1 == 0){print "yes"} else {print "no"}}'`
287 if test "$same" = yes ; then
289 pass
=`expr $pass + 1`
291 echo "FAILED: See ${errdir}"
293 ${IM_COMPARE} ${refpng} ${outpng} ${errdir}/compare.png
294 ${IM_COMPOSITE} ${refpng} ${outpng} -compose difference ${errdir}/composite.png
295 ${IM_CONVERT} ${refpng} ${outpng} -compose difference -composite -colorspace gray ${errdir}/gray.png
296 cat > ${errdir}/animate.sh
<< EOF
298 ${IM_CONVERT} -label "%f" ${refpng} ${outpng} miff:- | \
299 ${IM_MONTAGE} - -geometry +0+0 -tile 1x1 miff:- | \
300 ${IM_ANIMATE} -delay 0.5 -loop 0 -
302 chmod a
+x
${errdir}/animate.sh
303 fail
=`expr $fail + 1`
306 echo "No reference file ${REFDIR}/${t}.png. Skipping test"
307 skip
=`expr $skip + 1`
317 echo "Passed $pass, failed $fail, skipped $skip out of $tot tests."
320 if test $pass -ne $tot ; then