Desired changes in golden file output for spice-sdb
[geda-gaf/werner.git] / gnetlist / tests / common / run_backend_tests.sh
blob933ce50d745dbecb4f784f9cf2dc1220839182c7
1 #!/bin/sh
3 # This script runs the tests called out for in test.list
6 regen=no
8 usage() {
9 cat << EOF
11 $0 -- Testsuite program for various backends
13 Usage
15 $0 [-h | --help]
16 $0 [-r | --regen] <backend> [test1 [test2 [....]]]
18 Options
20 -h | --help Prints this help message and exits.
22 -r | --regen Regenerates the reference files. If you use
23 this option, YOU MUST HAND VERIFY THE RESULTS
24 BEFORE COMMITTING to the repository.
26 Description
28 $0 reads a file, tests.list, describing tests to run on <backend>.
29 If no specific test is specified on the $0 command line, then all
30 tests are run.
32 Examples
34 $0 spice-sdb
35 $0 --regen new_test spice-sdb
37 EOF
39 while test -n "$1"
41 case "$1"
44 -h|--help)
45 usage
46 exit 0
49 -r|--regen)
50 # regenerate the 'golden' output files. Use this with caution.
51 # In particular, all differences should be noted and understood.
52 regen=yes
53 shift
56 -*)
57 echo "unknown option: $1"
58 usage
59 exit 1
63 break
66 esac
67 done
69 if [ -f $1 ]; then
70 usage
71 exit 1
74 backend=$1
75 shift
77 echo "********USING BACKEND ${backend}*********"
79 # make sure we have the right paths when running this from inside the
80 # source tree and also from outside the source tree.
81 here=`pwd`
82 srcdir=${srcdir:-$here}
83 srcdir=`cd $srcdir && pwd`
85 GNETLIST=../../../src/gnetlist
87 rundir=${here}/run
89 GOLDEN_DIR=${srcdir}/outputs/${backend}
90 INPUT_DIR=${srcdir}/inputs
92 TESTLIST=${srcdir}/tests.list
93 ALWAYSCOPYLIST=${srcdir}/always-copy.list
95 if test ! -f $TESTLIST ; then
96 echo "ERROR: ($0) Test list $TESTLIST does not exist"
97 exit 1
100 # fail/pass/total counts
101 fail=0
102 pass=0
103 skip=0
104 tot=0
106 # here's where we look at the test.list file and extract the names of all
107 # the tests we want to run.
108 if test -z "$1" ; then
109 all_tests=`awk 'BEGIN{FS="|"} /^#/{next} /^[ \t]*$/{next} {print $1}' $TESTLIST | sed 's; ;;g'`
110 else
111 all_tests=$*
113 echo All tests = $all_tests
115 # here's where we look at always-copy.list file and extract the names of all
116 # the extra files we want to copy for every test
117 always_copy=`cat $ALWAYSCOPYLIST | sed '/^#/d'`
119 cat << EOF
121 Starting tests in $here
122 srcdir: $srcdir
123 INPUT_DIR: ${INPUT_DIR}
124 GOLDEN_DIR: ${GOLDEN_DIR}
125 GNETLIST: ${GNETLIST}
126 all_tests:
128 ${all_tests}
132 # Now run through all tests in test.list, prepare the $rundir,
133 # then run the tests.
134 for t in $all_tests ; do
136 # strip any leading garbage
137 t=`echo $t | sed 's;^\*;;g'`
139 # figure out what files we need to copy for this test and what
140 # arguments to feed gnetlist
141 schematics=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $2}'`
142 auxfiles=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $3}'`
143 args=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $4}'`
144 condition=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $5}' | sed 's; ;;g'`
146 refcode=${GOLDEN_DIR}/${t}.retcode
147 if test -f $refcode; then
148 code=`grep -v "^#" $refcode | sed 's; ;;g;'`
149 else
150 code=0
152 if test "X$code" = "X" ; then
153 code=0
156 echo "Schematics to copy = $schematics"
157 echo "Args to copy = $args"
158 echo "Always copying = $always_copy"
159 echo "Expected return code = \"$code\""
160 if test "X$condition" != "X" ; then
161 eval "ctest=\`echo \$$condition\`"
162 if test X$ctest = "Xyes" ; then
163 echo "Running test because $condition = yes"
164 else
165 echo "Skipping test because $condition = $ctest"
166 continue
170 tot=`expr $tot + 1`
172 # create temporary run directory and required subdirs
173 if test ! -d $rundir ; then
174 mkdir -p $rundir
175 mkdir -p $rundir/sym
176 mkdir -p $rundir/models
179 # Create the files needed
180 # Note that we need to include not only the .sch files,
181 # but also the contents of the sym and model directories.
182 if test ! -z "$schematics" ; then
183 echo "Copying over schematics to run dir"
184 for f in $schematics ; do
185 echo "cp ${INPUT_DIR}/${f} ${rundir}/${f}"
186 cp ${INPUT_DIR}/${f} ${rundir}/${f}
187 chmod 644 ${rundir}/${f}
188 done
190 if test ! -z "$auxfiles" ; then
191 echo "Copying over aux files to run dir"
192 for f in $auxfiles ; do
193 echo "cp ${INPUT_DIR}/${f} ${rundir}/${f}"
194 cp ${INPUT_DIR}/${f} ${rundir}/${f}
195 chmod 644 ${rundir}/${f}
196 done
198 if test ! -z "$always_copy" ; then
199 echo "Copying over always copied files to run dir"
200 for f in $always_copy ; do
201 echo "cp ${INPUT_DIR}/${f} ${rundir}/${f}"
202 cp ${INPUT_DIR}/${f} ${rundir}/${f}
203 chmod 644 ${rundir}/${f}
204 done
207 # run gnetlist -g $backend
208 echo "${GNETLIST} -g $backend $args $schematics"
209 cd ${rundir} && ${GNETLIST} -g $backend $args $schematics
210 rc=$?
212 # OK, now check results of run.
213 good=0
214 bad=0
215 soso=0
217 ref=${GOLDEN_DIR}/${t}-output.net
218 out=${rundir}/output.net
220 # Hack to help with vams backend
221 if [ -f ${rundir}/default_entity_arc.net ]; then
222 mv ${rundir}/default_entity_arc.net $out
225 if test "X$regen" = "Xyes" ; then
226 cp ${out} ${ref}
227 echo "$rc" > $refcode
228 echo "Regenerated ${ref}"
229 good=1
230 elif test $rc -ne $code ; then
231 echo "FAILED: gnetlist -g $backend returned $rc which did not match the expected $code"
232 bad=1
233 elif test -f ${ref} ; then
235 sed '/gnetlist -g/d' ${ref} > ${out}.tmp1
236 sed '/gnetlist -g/d' ${out} > ${out}.tmp2
238 if diff -w ${out}.tmp1 ${out}.tmp2 >/dev/null ; then
239 echo "PASS"
240 good=1
241 else
242 echo "FAILED: See diff -w ${ref} ${out}"
243 bad=1
245 elif test ! -f $out ; then
246 # No output file, but this is expected since there was no reference file
247 good=1
248 else
249 echo "No reference file. Skipping"
250 soso=1
253 pass=`expr $pass + $good`
254 fail=`expr $fail + $bad`
255 skip=`expr $skip + $soso`
257 cd $here
259 # Delete the run directory in prep for the next test
260 rm -fr ${rundir}
262 done
264 echo "Passed $pass, failed $fail, skipped $skip out of $tot tests."
266 rc=0
267 if test $pass -ne $tot ; then
268 rc=`expr $tot - $pass`
272 exit $rc