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