1 | #!/bin/sh |
---|
2 | # |
---|
3 | # Survex test suite - cavern tests |
---|
4 | # Copyright (C) 1999-2004,2005,2006,2010,2012,2013,2014 Olly Betts |
---|
5 | # |
---|
6 | # This program is free software; you can redistribute it and/or modify |
---|
7 | # it under the terms of the GNU General Public License as published by |
---|
8 | # the Free Software Foundation; either version 2 of the License, or |
---|
9 | # (at your option) any later version. |
---|
10 | # |
---|
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. |
---|
15 | # |
---|
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
19 | |
---|
20 | testdir=`echo $0 | sed 's!/[^/]*$!!' || echo '.'` |
---|
21 | |
---|
22 | # allow us to run tests standalone more easily |
---|
23 | : ${srcdir="$testdir"} |
---|
24 | |
---|
25 | # force VERBOSE if we're run on a subset of tests |
---|
26 | test -n "$*" && VERBOSE=1 |
---|
27 | |
---|
28 | test -x "$testdir"/../src/cavern || testdir=. |
---|
29 | |
---|
30 | # Make testdir absolute, so we can cd before running cavern to get a consistent |
---|
31 | # path in diagnostic messages. |
---|
32 | testdir=`(cd "$testdir" && pwd)` |
---|
33 | |
---|
34 | : ${CAVERN="$testdir"/../src/cavern} |
---|
35 | : ${DIFFPOS="$testdir"/../src/diffpos} |
---|
36 | : ${CAD3D="$testdir"/../src/cad3d} |
---|
37 | |
---|
38 | : ${TESTS=${*:-"singlefix singlereffix oneleg midpoint noose cross firststn\ |
---|
39 | deltastar deltastar2 bug3 calibrate_tape nosurvey2 cartesian cartesian2\ |
---|
40 | lengthunits angleunits cmd_alias cmd_truncate cmd_case cmd_fix cmd_solve\ |
---|
41 | cmd_entrance cmd_entrance_bad cmd_sd cmd_sd_bad cmd_fix_bad cmd_set\ |
---|
42 | cmd_set_bad beginroot revcomplist break_replace_pfx bug0 bug1 bug2 bug4 bug5\ |
---|
43 | expobug require export export2 includecomment\ |
---|
44 | self_loop self_eq_loop reenterwarn cmd_default cmd_prefix cmd_prefix_bad\ |
---|
45 | singlefixerr singlereffixerr\ |
---|
46 | begin_no_end end_no_begin end_no_begin_nest require_fail\ |
---|
47 | exporterr1 exporterr2 exporterr3 exporterr4 exporterr5\ |
---|
48 | exporterr1b exporterr2b exporterr3b exporterr6 exporterr6b\ |
---|
49 | hanging_cpt badinc badinc2 badinc3 badinc4 non_existant_file ONELEG\ |
---|
50 | stnsurvey1 stnsurvey2 stnsurvey3\ |
---|
51 | tapelessthandepth longname chinabug chinabug2\ |
---|
52 | multinormal multinormignall multidiving multicylpolar multicartesian\ |
---|
53 | multinosurv multinormalbad multibug\ |
---|
54 | cmd_title cmd_titlebad cmd_dummy cmd_infer cmd_date cmd_datebad cmd_datebad2\ |
---|
55 | cartes diving cylpolar normal normal_bad normignall nosurv cmd_flags\ |
---|
56 | bad_cmd_flags plumb unusedstation exportnakedbegin oldestyle bugdz\ |
---|
57 | baddatacylpolar badnewline badquantities imgoffbyone infereqtopofil 3sdfixbug\ |
---|
58 | omitclino back back2\ |
---|
59 | notentranceorexport inferunknown inferexports bad_units_factor\ |
---|
60 | bad_units_qlist\ |
---|
61 | percent_gradient dotinsurvey leandroclino lowsd revdir gettokennullderef\ |
---|
62 | nosurveyhanging cmd_solve_nothing cmd_solve_nothing_implicit\ |
---|
63 | lech level 2fixbug dot17 3dcorner\ |
---|
64 | declination.dat ignore.dat backread.dat nomeasure.dat\ |
---|
65 | surfequate passage hanging_lrud equatenosuchstn surveytypo\ |
---|
66 | skipafterbadomit passagebad badreadingdotplus badcalibrate calibrate_clino\ |
---|
67 | badunits badbegin anonstn anonstnbad anonstnrev doubleinc reenterlots\ |
---|
68 | cs csbad omitfixaroundsolve\ |
---|
69 | "}} |
---|
70 | |
---|
71 | LC_ALL=C |
---|
72 | export LC_ALL |
---|
73 | SURVEXLANG=en |
---|
74 | export SURVEXLANG |
---|
75 | |
---|
76 | vg_error=123 |
---|
77 | vg_log=$testdir/vg.log |
---|
78 | if [ -n "$VALGRIND" ] ; then |
---|
79 | rm -f "$vg_log" |
---|
80 | CAVERN="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $CAVERN" |
---|
81 | DIFFPOS="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DIFFPOS" |
---|
82 | CAD3D="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $CAD3D" |
---|
83 | fi |
---|
84 | |
---|
85 | for file in $TESTS ; do |
---|
86 | # how many warnings to expect |
---|
87 | warn= |
---|
88 | # how many errors to expect |
---|
89 | error= |
---|
90 | case $file in |
---|
91 | singlefix) pos=yes ; warn=1;; |
---|
92 | singlereffix) pos=yes ; warn=0 ;; |
---|
93 | oneleg) pos=yes ; warn=0 ;; |
---|
94 | midpoint) pos=yes ; warn=0 ;; |
---|
95 | noose) pos=yes ; warn=0 ;; |
---|
96 | cross) pos=yes ; warn=0 ;; |
---|
97 | firststn) pos=yes ; warn=0 ;; |
---|
98 | deltastar) pos=yes ; warn=0 ;; |
---|
99 | deltastar2) pos=yes ; warn=0 ;; |
---|
100 | bug3) pos=yes ; warn=0 ;; |
---|
101 | calibrate_tape) pos=yes ; warn=0 ;; |
---|
102 | nosurvey2) pos=yes ; warn=0 ;; |
---|
103 | cartesian) pos=yes ; warn=0 ;; |
---|
104 | cartesian2) pos=yes ; warn=0 ;; |
---|
105 | lengthunits) pos=yes ; warn=0 ;; |
---|
106 | angleunits) pos=yes ; warn=0 ;; |
---|
107 | cmd_alias) pos=yes ;; |
---|
108 | cmd_truncate) pos=yes ; warn=0 ;; |
---|
109 | cmd_case) pos=yes ; warn=0 ;; |
---|
110 | cmd_fix) pos=yes ; warn=1 ;; |
---|
111 | cmd_fix_bad) pos=fail ; error=10 ;; |
---|
112 | cmd_solve) pos=yes ; warn=0 ;; |
---|
113 | cmd_entrance) pos=no ; warn=0 ;; |
---|
114 | cmd_entrance_bad) pos=fail ; warn=0 ; error=1 ;; |
---|
115 | cmd_sd) pos=no ; warn=0 ;; |
---|
116 | cmd_sd_bad) pos=fail ; error=7 ;; |
---|
117 | cmd_set) pos=no ; warn=0 ;; |
---|
118 | cmd_set_bad) pos=fail ; error=8 ;; |
---|
119 | beginroot) pos=no ;; |
---|
120 | revcomplist) pos=no ; warn=0 ;; |
---|
121 | break_replace_pfx) pos=no ; warn=0 ;; |
---|
122 | bug0) pos=no ; warn=0 ;; |
---|
123 | bug1) pos=no ; warn=0 ;; |
---|
124 | bug2) pos=no ; warn=0 ;; |
---|
125 | bug4) pos=no ; warn=0 ;; |
---|
126 | bug5) pos=no ; warn=0 ;; |
---|
127 | expobug) pos=no ; warn=0 ;; |
---|
128 | require) pos=no ; warn=0 ;; |
---|
129 | export) pos=no ; warn=0 ;; |
---|
130 | export2) pos=no ; warn=0 ;; |
---|
131 | includecomment) pos=no ; warn=0 ;; |
---|
132 | self_loop) pos=fail ; warn=0 ; error=1 ;; |
---|
133 | self_eq_loop) pos=no ; warn=1 ;; |
---|
134 | reenterwarn) pos=no ; warn=2 ;; |
---|
135 | cmd_default) pos=no ; warn=3 ;; |
---|
136 | singlereffixerr) pos=no ; warn=0 ;; |
---|
137 | cmd_prefix) pos=no ; warn=1 ;; |
---|
138 | cmd_prefix_bad) pos=fail ; warn=1 ; error=1 ;; |
---|
139 | singlefixerr) pos=no ; warn=1 ;; |
---|
140 | tapelessthandepth) pos=no ; warn=1 ;; |
---|
141 | chinabug2) pos=no ; warn=0 ;; |
---|
142 | longname) pos=no ; warn=0 ;; |
---|
143 | chinabug) pos=fail ;; # We exit before the error count. |
---|
144 | begin_no_end) pos=fail ; error=1 ;; |
---|
145 | end_no_begin) pos=fail ; error=1 ;; |
---|
146 | end_no_begin_nest) pos=fail ; error=2 ;; |
---|
147 | require_fail) pos=fail ;; # We exit before the error count. |
---|
148 | exporterr1) pos=fail ; error=1 ;; |
---|
149 | exporterr2) pos=fail ; error=1 ;; |
---|
150 | exporterr3) pos=fail ; error=1 ;; |
---|
151 | exporterr4) pos=fail ; error=1 ;; |
---|
152 | exporterr5) pos=fail ; error=1 ;; |
---|
153 | exporterr1b) pos=fail ; error=1 ;; |
---|
154 | exporterr2b) pos=fail ; error=1 ;; |
---|
155 | exporterr3b) pos=fail ; error=1 ;; |
---|
156 | exporterr6) pos=fail ; error=1 ;; |
---|
157 | exporterr6b) pos=fail ; error=1 ;; |
---|
158 | hanging_cpt) pos=fail ;; # We exit before the error count. |
---|
159 | badinc) pos=fail ;; # We exit before the error count. |
---|
160 | badinc2) pos=fail ;; # We exit before the error count. |
---|
161 | badinc3) pos=fail ;; # We exit before the error count. |
---|
162 | badinc4) pos=fail ; error=3 ;; |
---|
163 | non_existant_file) pos=fail ;; # We exit before the error count. |
---|
164 | ONELEG) pos=fail ;; # We exit before the error count. |
---|
165 | stnsurvey1) pos=fail ; error=1 ;; |
---|
166 | stnsurvey2) pos=fail ; error=2 ;; |
---|
167 | stnsurvey3) pos=fail ;; # We exit before the error count. |
---|
168 | multinormal) pos=yes ; warn=0 ;; |
---|
169 | multinormignall) pos=yes ; warn=0 ;; |
---|
170 | multidiving) pos=yes ; warn=0 ;; |
---|
171 | multicylpolar) pos=yes ; warn=0 ;; |
---|
172 | multicartesian) pos=yes ; warn=0 ;; |
---|
173 | multinosurv) pos=yes ; warn=0 ;; |
---|
174 | multinormalbad) pos=fail ; error=1 ;; |
---|
175 | multibug) pos=no ; warn=0 ;; |
---|
176 | cmd_title) pos=no ; warn=0 ;; |
---|
177 | cmd_titlebad) pos=fail ; error=4 ;; |
---|
178 | cmd_dummy) pos=no ; warn=0 ;; |
---|
179 | cmd_infer) pos=yes ; warn=0 ;; |
---|
180 | cmd_date) pos=no ; warn=4 ;; |
---|
181 | cmd_datebad) pos=no ; warn=37 ;; |
---|
182 | cmd_datebad2) pos=fail ; warn=20 ; error=2 ;; |
---|
183 | cartes) pos=yes ; warn=0 ;; |
---|
184 | diving) pos=yes ; warn=0 ;; |
---|
185 | cylpolar) pos=yes ; warn=0 ;; |
---|
186 | normal) pos=yes ; warn=0 ;; |
---|
187 | normal_bad) pos=fail ; warn=0 ; error=3 ;; |
---|
188 | normignall) pos=yes ; warn=0 ;; |
---|
189 | nosurv) pos=yes ; warn=0 ;; |
---|
190 | cmd_flags) pos=no ; warn=0 ;; |
---|
191 | bad_cmd_flags) pos=fail ; error=19 ;; |
---|
192 | plumb) pos=yes ; warn=0 ;; |
---|
193 | unusedstation) pos=no ; warn=2 ;; |
---|
194 | oldestyle) pos=no ; warn=1 ;; |
---|
195 | exportnakedbegin) pos=fail ; error=1 ;; |
---|
196 | bugdz) pos=yes ; warn=0 ;; |
---|
197 | baddatacylpolar) pos=fail ; error=1 ;; |
---|
198 | badnewline) pos=fail ; error=2 ;; |
---|
199 | badquantities) pos=fail ; error=11 ;; |
---|
200 | imgoffbyone) pos=yes ;; # don't actually care about coords, just the names |
---|
201 | infereqtopofil) pos=yes ; warn=0 ;; |
---|
202 | 3sdfixbug) pos=yes ; warn=0 ;; |
---|
203 | omitclino) pos=yes ; warn=0 ;; |
---|
204 | back) pos=yes; warn=0 ;; |
---|
205 | back2) pos=yes; warn=6 ;; |
---|
206 | notentranceorexport) pos=fail; warn=0 ; error=1 ;; |
---|
207 | inferunknown) pos=fail; error=1 ;; |
---|
208 | inferexports) pos=no; warn=0 ;; |
---|
209 | bad_units_factor) pos=fail; error=6 ;; |
---|
210 | bad_units_qlist) pos=fail; error=3 ;; |
---|
211 | percent_gradient) pos=yes; warn=0 ;; |
---|
212 | dotinsurvey) pos=no; warn=2 ;; |
---|
213 | leandroclino) pos=yes; warn=0 ;; |
---|
214 | lowsd) pos=no; warn=0 ;; |
---|
215 | revdir) pos=yes; warn=0 ;; |
---|
216 | gettokennullderef) pos=fail ;; # We exit before the error count. |
---|
217 | lech) pos=no; warn=0 ;; |
---|
218 | level) pos=yes; warn=0 ;; |
---|
219 | 2fixbug) pos=no; warn=0 ;; |
---|
220 | declination.dat|ignore.dat|backread.dat|nomeasure.dat) pos=yes; warn=0 ;; |
---|
221 | dot17) pos=yes; warn=0 ;; |
---|
222 | 3dcorner) pos=yes; warn=0 ;; |
---|
223 | surfequate) pos=dxf; warn=0 ;; |
---|
224 | nosurveyhanging) pos=fail ;; # We exit before the error count. |
---|
225 | cmd_solve_hanging) pos=fail ; error=1 ;; |
---|
226 | cmd_solve_nothing*) pos=no; warn=0 ;; |
---|
227 | passage) pos=no; warn=0 ;; |
---|
228 | hanging_lrud) pos=fail; error=1 ;; |
---|
229 | equatenosuchstn) pos=fail; error=1 ;; |
---|
230 | surveytypo) pos=fail ;; # Actually, 2 errors, but we exit before the error count. |
---|
231 | skipafterbadomit) pos=fail; error=1 ;; |
---|
232 | passagebad) pos=fail; error=3 ;; |
---|
233 | badreadingdotplus) pos=fail ; error=3 ;; |
---|
234 | badcalibrate) pos=fail; error=3 ;; |
---|
235 | calibrate_clino) pos=yes; warn=8 ;; |
---|
236 | badunits) pos=fail; error=12 ;; |
---|
237 | badbegin) pos=fail; error=2 ;; |
---|
238 | anonstn) pos=yes; warn=0; error=0 ;; |
---|
239 | anonstnbad) pos=fail; warn=1; error=6 ;; |
---|
240 | anonstnrev) pos=yes; warn=0; error=0 ;; |
---|
241 | doubleinc) pos=no; warn=3; error=0 ;; |
---|
242 | reenterlots) pos=no; warn=11; error=0 ;; |
---|
243 | cs) pos=no; warn=0; error=0 ;; |
---|
244 | csbad) pos=fail; warn=0; error=23 ;; |
---|
245 | omitfixaroundsolve) pos=fail; warn=2; error=1 ;; |
---|
246 | *) echo "Warning: don't know how to run test '$file' - skipping it" |
---|
247 | file='' ;; |
---|
248 | esac |
---|
249 | |
---|
250 | if test -n "$file" ; then |
---|
251 | echo "$file" |
---|
252 | case $file in |
---|
253 | *.*) |
---|
254 | input="./$file" |
---|
255 | posfile="$srcdir"/`echo "$file"|sed 's/\.[^.]*$/.pos/'` |
---|
256 | dxffile="$srcdir"/`echo "$file"|sed 's/\.[^.]*$/.dxf/'` ;; |
---|
257 | *) |
---|
258 | input="./$file.svx" |
---|
259 | posfile="$srcdir/$file.pos" |
---|
260 | dxffile="$srcdir/$file.dxf" ;; |
---|
261 | esac |
---|
262 | rm -f tmp.* |
---|
263 | pwd=`pwd` |
---|
264 | cd "$srcdir" |
---|
265 | srcdir=. $CAVERN "$input" --output="$pwd/tmp" > "$pwd/tmp.out" |
---|
266 | exitcode=$? |
---|
267 | cd "$pwd" |
---|
268 | test -n "$VERBOSE" && cat tmp.out |
---|
269 | if [ -n "$VALGRIND" ] ; then |
---|
270 | if [ $exitcode = "$vg_error" ] ; then |
---|
271 | cat "$vg_log" |
---|
272 | rm "$vg_log" |
---|
273 | exit 1 |
---|
274 | fi |
---|
275 | rm "$vg_log" |
---|
276 | fi |
---|
277 | if test fail = "$pos" ; then |
---|
278 | # success gives 0, signal (128 + <signal number>) |
---|
279 | test $exitcode = 1 || exit 1 |
---|
280 | else |
---|
281 | test $exitcode = 0 || exit 1 |
---|
282 | fi |
---|
283 | if test -n "$warn" ; then |
---|
284 | w=`sed '$!d;s/^There were \([0-9]*\).*/\1/;s/^[^0-9].*$/0/' tmp.out` |
---|
285 | if test x"$w" != x"$warn" ; then |
---|
286 | test -n "$VERBOSE" && echo "Got $w warnings, expected $warn" |
---|
287 | exit 1 |
---|
288 | fi |
---|
289 | fi |
---|
290 | if test -n "$error" ; then |
---|
291 | e=`sed '$!d;s/^There were .* and \([0-9][0-9]*\).*/\1/;s/^[^0-9].*$/0/' tmp.out` |
---|
292 | if test x"$e" != x"$error" ; then |
---|
293 | test -n "$VERBOSE" && echo "Got $e errors, expected $error" |
---|
294 | exit 1 |
---|
295 | fi |
---|
296 | fi |
---|
297 | nan=`sed 's/.*\<[Nn]a[Nn]m\?\>.*/x/p;d' tmp.out` |
---|
298 | if test -n "$nan" ; then |
---|
299 | exit 1 |
---|
300 | fi |
---|
301 | |
---|
302 | case $pos in |
---|
303 | yes) |
---|
304 | if test -n "$VERBOSE" ; then |
---|
305 | $DIFFPOS "$posfile" tmp.3d |
---|
306 | exitcode=$? |
---|
307 | else |
---|
308 | $DIFFPOS "$posfile" tmp.3d > /dev/null |
---|
309 | exitcode=$? |
---|
310 | fi |
---|
311 | if [ -n "$VALGRIND" ] ; then |
---|
312 | if [ $exitcode = "$vg_error" ] ; then |
---|
313 | cat "$vg_log" |
---|
314 | rm "$vg_log" |
---|
315 | exit 1 |
---|
316 | fi |
---|
317 | rm "$vg_log" |
---|
318 | fi |
---|
319 | [ "$exitcode" = 0 ] || exit 1 |
---|
320 | ;; |
---|
321 | dxf) |
---|
322 | if test -n "$VERBOSE" ; then |
---|
323 | $CAD3D tmp.3d tmp.dxf |
---|
324 | exitcode=$? |
---|
325 | else |
---|
326 | $CAD3D tmp.3d tmp.dxf > /dev/null |
---|
327 | exitcode=$? |
---|
328 | fi |
---|
329 | if [ -n "$VALGRIND" ] ; then |
---|
330 | if [ $exitcode = "$vg_error" ] ; then |
---|
331 | cat "$vg_log" |
---|
332 | rm "$vg_log" |
---|
333 | exit 1 |
---|
334 | fi |
---|
335 | rm "$vg_log" |
---|
336 | fi |
---|
337 | [ "$exitcode" = 0 ] || exit 1 |
---|
338 | if test -n "$VERBOSE" ; then |
---|
339 | diff "$dxffile" tmp.dxf || exit 1 |
---|
340 | else |
---|
341 | cmp -s "$dxffile" tmp.dxf || exit 1 |
---|
342 | fi ;; |
---|
343 | no) |
---|
344 | test -f tmp.3d || exit 1 ;; |
---|
345 | fail) |
---|
346 | test -f tmp.3d && exit 1 |
---|
347 | # Check that last line doesn't contains "Bug in program detected" |
---|
348 | case `tail -n 1 tmp.out` in |
---|
349 | *"Bug in program detected"*) exit 1 ;; |
---|
350 | esac ;; |
---|
351 | *) |
---|
352 | echo "Bad value for pos: '$pos'" ; exit 1 ;; |
---|
353 | esac |
---|
354 | |
---|
355 | out=$srcdir/$file.out |
---|
356 | if test -f "$out" ; then |
---|
357 | # Check output is as expected. |
---|
358 | if test -n "$VERBOSE" ; then |
---|
359 | sed '1,/^Copyright/d;/^\(CPU t\|T\)ime used *[0-9][0-9.]*s$/d;s!.*/src/\(cavern: \)!\1!' tmp.out|diff "$out" - || exit 1 |
---|
360 | else |
---|
361 | sed '1,/^Copyright/d;/^\(CPU t\|T\)ime used *[0-9][0-9.]*s$/d;s!.*/src/\(cavern: \)!\1!' tmp.out|cmp -s "$out" - || exit 1 |
---|
362 | fi |
---|
363 | fi |
---|
364 | rm -f tmp.* |
---|
365 | fi |
---|
366 | done |
---|
367 | test -n "$VERBOSE" && echo "Test passed" |
---|
368 | exit 0 |
---|