source: git/tests/cavern.tst

walls-data-hanging-as-warning
Last change on this file was 9914d6b, checked in by Olly Betts <olly@…>, 6 days ago

Merge branch 'master' into walls-data

  • Property mode set to 100755
File size: 10.9 KB
Line 
1#!/bin/sh
2#
3# Survex test suite - cavern tests
4# Copyright (C) 1999-2024 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
20testdir=`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
26test -n "$*" && VERBOSE=1
27
28test -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.
32testdir=`(cd "$testdir" && pwd)`
33
34: ${CAVERN="$testdir"/../src/cavern}
35: ${DIFFPOS="$testdir"/../src/diffpos}
36: ${DUMP3D="$testdir"/../src/dump3d}
37: ${SURVEXPORT="$testdir"/../src/survexport}
38
39: ${TESTS=${*:-"singlefix singlereffix oneleg midpoint noose cross firststn\
40 deltastar deltastar2 bug3 calibrate_tape nosurvey2 cartesian cartesian2\
41 lengthunits angleunits cmd_alias cmd_alias_bad cmd_truncate cmd_case cmd_fix\
42 cmd_solve cmd_entrance cmd_entrance_bad cmd_sd cmd_sd_bad cmd_fix_bad cmd_set\
43 cmd_set_bad cmd_set_dot_in_name\
44 beginroot revcomplist break_replace_pfx bug0 bug1 bug2 bug4 bug5\
45 expobug require export export2 includecomment\
46 self_loop self_eq_loop reenterwarn cmd_default cmd_prefix cmd_prefix_bad\
47 cmd_begin_bad cmd_equate_bad cmd_export_bad\
48 singlefixerr singlereffixerr\
49 begin_no_end end_no_begin end_no_begin_nest require_fail\
50 exporterr1 exporterr2 exporterr3 exporterr4 exporterr5\
51 exporterr1b exporterr2b exporterr3b exporterr6 exporterr6b\
52 hanging_cpt badinc badinc2 badinc3 badinc4 badinc5.mak nonexistent_file ONELEG\
53 stnsurvey1 stnsurvey2\
54 tapelessthandepth longname chinabug chinabug2\
55 multinormal multinormignall multidiving multicylpolar multicartesian\
56 multinosurv multinormalbad multibug\
57 cmd_title cmd_titlebad cmd_dummy cmd_infer cmd_date cmd_datebad cmd_datebad2\
58 cartes diving cylpolar normal normal_bad normignall nosurv cmd_flags\
59 bad_cmd_flags plumb unusedstation exportnakedbegin oldestyle bugdz\
60 baddatacylpolar badnewline badquantities imgoffbyone infereqtopofil 3sdfixbug\
61 omitclino back back2 bad_back\
62 notentranceorexport inferunknown inferexports bad_units_factor\
63 bad_units_qlist\
64 percent_gradient dotinsurvey leandroclino lowsd revdir gettokennullderef\
65 nosurveyhanging cmd_solve_nothing cmd_solve_nothing_implicit\
66 cmd_calibrate cmd_declination cmd_declination_auto cmd_declination_auto_bad\
67 cmd_declination_conv cmd_declination_conv_proj_bug\
68 lech level 2fixbug dot17 3dcorner\
69 unconnected-bug\
70 backread.dat corrections.dat depthguage.dat flags.dat karstcompat.dat\
71 lrud.dat nomeasure.dat noteam.dat\
72 badmak.mak\
73 fixfeet.mak utm.mak\
74 clptest.dat clptest.clp\
75 walls.srv\
76 surfequate passage hanging_lrud equatenosuchstn surveytypo\
77 skipafterbadomit passagebad badreadingdotplus badcalibrate calibrate_clino\
78 badunits badbegin anonstn anonstnbad anonstnrev doubleinc reenterlots\
79 cs csbad csbadsdfix csfeet cslonglat omitfixaroundsolve repeatreading\
80 mixedeols utf8bom nonewlineateof suspectreadings cmd_data_default\
81 quadrant_bearing bad_quadrant_bearing\
82 samename\
83 gpxexport jsonexport kmlexport pltexport svgexport\
84"}}
85
86# Test file stnsurvey3.svx missing: pos=fail # We exit before the error count.
87
88LC_ALL=C
89export LC_ALL
90SURVEXLANG=en
91export SURVEXLANG
92
93# Suppress checking for leaks on exit if we're build with lsan - we don't
94# generally waste effort to free all allocations as the OS will reclaim
95# memory on exit.
96LSAN_OPTIONS=leak_check_at_exit=0
97export LSAN_OPTIONS
98
99# Allow datestamps in 3d files (we normalise the expected output for GPX
100# etc) to allow for the datestamp not being fixed, but under SOURCE_DATE_EPOCH
101# the datestamp is omitted entirely which would break those testcases.
102unset SOURCE_DATE_EPOCH
103
104vg_error=123
105vg_log=$testdir/vg.log
106if [ -n "$VALGRIND" ] ; then
107  rm -f "$vg_log"
108  CAVERN="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $CAVERN"
109  DIFFPOS="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DIFFPOS"
110  DUMP3D="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DUMP3D"
111  SURVEXPORT="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $SURVEXPORT"
112fi
113
114for file in $TESTS ; do
115  case $file in
116    nonexistent_file*|ONELEG)
117      # ONELEG tests that we don't apply special handling to command line
118      # arguments, only those in *include.
119      realfile= ;;
120    *.*) realfile=$srcdir/$file ;;
121    *) realfile=$srcdir/$file.svx ;;
122  esac
123
124  if [ x"$file" = xONELEG ] && [ -f "ONELEG.SVX" ] ; then
125    echo "Case insensitive filing system - skipping ONELEG testcase"
126    continue
127  fi
128
129  if [ -n "$realfile" ] && [ ! -r "$realfile" ] ; then
130    echo "Don't know how to run test '$file'"
131    exit 1
132  fi
133
134  echo "$file"
135
136  # how many warnings to expect (or empty not to check)
137  warn=
138
139  # how many errors to expect (or empty not to check)
140  error=
141
142  # One of:
143  # yes : diffpos 3D file output with <testcase_name>.pos
144  # no : Check that a 3D file is produced, but not positions in it
145  # fail : Check that a 3D file is NOT produced
146  # dxf : Convert to DXF with survexport and compare with <testcase_name>.dxf
147  # gpx : Convert to GPX with survexport and compare with <testcase_name>.gpx
148  # json : Convert to JSON with survexport and compare with <testcase_name>.json
149  # kml : Convert to KML with survexport and compare with <testcase_name>.kml
150  # plt : Convert to PLT with survexport and compare with <testcase_name>.plt
151  # svg : Convert to SVG with survexport and compare with <testcase_name>.svg
152  pos=
153
154  case $file in
155    backread.dat|clptest.dat|clptest.clp|depthguage.dat|flags.dat|karstcompat.dat)
156      pos=dump
157      warn=0
158      ;;
159    *.dat)
160      # .dat files can't start with a comment.  All the other .dat tests
161      # have the same settings.
162      pos=yes
163      warn=0
164      ;;
165    nonexistent_file*|ONELEG)
166      # These testcase files don't exist (or for ONELEG exist with a different
167      # case).  They all have the same settings.
168      pos=fail
169      ;;
170    *)
171      survexportopts=
172      read header < "$realfile"
173      set dummy $header
174      while shift && [ -n "$1" ] ; do
175        case $1 in
176          pos=*) pos=`expr "$1" : 'pos=\(.*\)'` ;;
177          warn=*) warn=`expr "$1" : 'warn=\(.*\)'` ;;
178          error=*) error=`expr "$1" : 'error=\(.*\)'` ;;
179          survexportopt=*)
180            survexportopts="$survexportopts "`expr "$1" : 'survexportopt=\(.*\)'`
181            ;;
182        esac
183      done
184      ;;
185  esac
186
187  basefile=$srcdir/$file
188  case $file in
189  *.*)
190    input="./$file"
191    basefile=`echo "$basefile"|sed 's/\.[^.]*$//'` ;;
192  *)
193    input="./$file.svx" ;;
194  esac
195  outfile=$basefile.out
196  outfile2=$basefile.altout
197  posfile=$basefile.pos
198  rm -f tmp.*
199  pwd=`pwd`
200  cd "$srcdir"
201  srcdir=. SOURCE_DATE_EPOCH=1 $CAVERN "$input" --output="$pwd/tmp" > "$pwd/tmp.out"
202  exitcode=$?
203  cd "$pwd"
204  test -n "$VERBOSE" && cat tmp.out
205  if [ -n "$VALGRIND" ] ; then
206    if [ $exitcode = "$vg_error" ] ; then
207      cat "$vg_log"
208      rm "$vg_log"
209      exit 1
210    fi
211    rm "$vg_log"
212  fi
213  if test fail = "$pos" ; then
214    # success gives 0, signal (128 + <signal number>)
215    test $exitcode = 1 || exit 1
216  else
217    test $exitcode = 0 || exit 1
218  fi
219  if test -n "$warn" ; then
220    w=`sed '$!d;s/^There were \([0-9]*\).*/\1/p;d' tmp.out`
221    if test x"${w:-0}" != x"$warn" ; then
222      test -n "$VERBOSE" && echo "Got $w warnings, expected $warn"
223      exit 1
224    fi
225  fi
226  if test -n "$error" ; then
227    e=`sed '$!d;s/^There were .* and \([0-9][0-9]*\).*/\1/p;d' tmp.out`
228    if test x"${e:-0}" != x"$error" ; then
229      test -n "$VERBOSE" && echo "Got $e errors, expected $error"
230      exit 1
231    fi
232  fi
233  # Fail if nan, NaN, etc in output (which might be followed by m for metres or
234  # s for seconds).
235  if egrep -q '(^|[^A-Za-z0-9])nan[ms]?($|[^A-Za-z0-9])' tmp.out ; then
236    echo "Not-a-number appears in output"
237    exit 1
238  fi
239
240  case $pos in
241  yes)
242    if test -n "$VERBOSE" ; then
243      $DIFFPOS "$posfile" tmp.3d
244      exitcode=$?
245    else
246      $DIFFPOS "$posfile" tmp.3d > /dev/null
247      exitcode=$?
248    fi
249    if [ -n "$VALGRIND" ] ; then
250      if [ $exitcode = "$vg_error" ] ; then
251        cat "$vg_log"
252        rm "$vg_log"
253        exit 1
254      fi
255      rm "$vg_log"
256    fi
257    [ "$exitcode" = 0 ] || exit 1
258    ;;
259  dump)
260    expectedfile=$basefile.dump
261    tmpfile=tmp.dump
262    $DUMP3D --show-dates --legs tmp.3d > "$tmpfile"
263    exitcode=$?
264    if [ -n "$VALGRIND" ] ; then
265      if [ $exitcode = "$vg_error" ] ; then
266        cat "$vg_log"
267        rm "$vg_log"
268        exit 1
269      fi
270      rm "$vg_log"
271    fi
272    [ "$exitcode" = 0 ] || exit 1
273
274    if test -n "$VERBOSE" ; then
275      diff "$expectedfile" "$tmpfile" || exit 1
276    else
277      cmp -s "$expectedfile" "$tmpfile" || exit 1
278    fi
279    ;;
280  dxf|gpx|json|kml|plt|svg)
281    # $pos gives us the file extension here.
282    expectedfile=$basefile.$pos
283    tmpfile=tmp.$pos
284    if test -n "$VERBOSE" ; then
285      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile"
286      exitcode=$?
287    else
288      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile" > /dev/null
289      exitcode=$?
290    fi
291    if [ -n "$VALGRIND" ] ; then
292      if [ $exitcode = "$vg_error" ] ; then
293        cat "$vg_log"
294        rm "$vg_log"
295        exit 1
296      fi
297      rm "$vg_log"
298    fi
299    [ "$exitcode" = 0 ] || exit 1
300
301    # Normalise exported file if required.
302    case $pos in
303      gpx)
304        sed 's,<time>[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z</time>,<time>REDACTED</time>,;s,survex [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*,survex REDACTED,' < "$tmpfile" > tmp.tmp
305        mv tmp.tmp "$tmpfile"
306        ;;
307    esac
308
309    if test -n "$VERBOSE" ; then
310      diff "$expectedfile" "$tmpfile" || exit 1
311    else
312      cmp -s "$expectedfile" "$tmpfile" || exit 1
313    fi
314    ;;
315  no)
316    test -f tmp.3d || exit 1 ;;
317  fail)
318    test -f tmp.3d && exit 1
319    # Check that last line doesn't contains "Bug in program detected"
320    case `tail -n 1 tmp.out` in
321    *"Bug in program detected"*) exit 1 ;;
322    esac ;;
323  *)
324    echo "Bad value for pos: '$pos'" ; exit 1 ;;
325  esac
326
327  if test -f "$outfile" ; then
328    # Version and time used info from output, working around Apple's stone-age
329    # sed.
330    sed '1,/^Copyright/d;/^\(CPU \)*[Tt]ime used  *[0-9][0-9.]*s$/d;s!.*/src/\(cavern: \)!\1!' tmp.out > tmp.out2
331    mv tmp.out2 tmp.out
332    # Check output is as expected.
333    if cmp -s "$outfile" tmp.out ; then
334      : # Matches.
335    elif [ -f "$outfile2" ] && cmp -s "$outfile2" tmp.out ; then
336      : # Matches alternative output (e.g. due to older PROJ).
337    else
338      test -z "$VERBOSE" || diff "$outfile" tmp.out
339      exit 1
340    fi
341  fi
342  rm -f tmp.*
343done
344test -n "$VERBOSE" && echo "Test passed"
345exit 0
Note: See TracBrowser for help on using the repository browser.