source: git/tests/cavern.tst @ d7a2cf9

stereo-2025
Last change on this file since d7a2cf9 was d7a2cf9, checked in by Olly Betts <olly@…>, 9 months ago

Improve choice when inventing fixed point

We now avoid picking a fixed point which is only attached to nosurvey
legs if there's another option. The code was already meant to do this
but it was buggy and we seem to not have a testcase for this situation
before now.

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