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
RevLine 
[fbc3a20]1#!/bin/sh
[b4fe9fb]2#
3# Survex test suite - cavern tests
[fdffa7d]4# Copyright (C) 1999-2024 Olly Betts
[b4fe9fb]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
[d333899]18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
[fbc3a20]19
[d4d8efe]20testdir=`echo $0 | sed 's!/[^/]*$!!' || echo '.'`
21
[ed34f49]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
[6b8ff5b]28# allow us to run tests standalone more easily
[d4d8efe]29: ${srcdir="$testdir"}
[87fcddb]30if [ -z "$SURVEXLIB" ] ; then
31  SURVEXLIB=`cd "$srcdir/../lib" && pwd`
32  export SURVEXLIB
[ed34f49]33fi
[647407d]34
[64b4d1c]35# force VERBOSE if we're run on a subset of tests
36test -n "$*" && VERBOSE=1
37
[6448891]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
[d4d8efe]50: ${CAVERN="$testdir"/../src/cavern}
51: ${DIFFPOS="$testdir"/../src/diffpos}
[fdffa7d]52: ${DUMP3D="$testdir"/../src/dump3d}
[79b32a95]53: ${SURVEXPORT="$testdir"/../src/survexport}
[647407d]54
[e0c8f98]55: ${TESTS=${*:-"singlefix singlereffix oneleg midpoint noose cross firststn\
[107b8bd]56 deltastar deltastar2 bug3 calibrate_tape nosurvey2 cartesian cartesian2\
[e1cbc0d]57 lengthunits angleunits cmd_alias cmd_alias_bad cmd_truncate cmd_truncate_bad\
58 cmd_case cmd_case_bad cmd_fix\
[4772e46]59 cmd_solve cmd_entrance cmd_entrance_bad cmd_sd cmd_sd_bad cmd_fix_bad cmd_set\
[5d59477]60 cmd_set_bad cmd_set_dot_in_name\
61 beginroot revcomplist break_replace_pfx bug0 bug1 bug2 bug4 bug5\
[cfa16ef]62 expobug require export export2 includecomment\
[68f7ba4]63 self_loop self_eq_loop reenterwarn cmd_default cmd_default_bad\
64 cmd_prefix cmd_prefix_bad\
[b9c82c2]65 cmd_begin_bad cmd_equate_bad cmd_export_bad\
[cfa16ef]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\
[c6ff64b]70 hanging_cpt badinc badinc2 badinc3 badinc4 badinc5.mak nonexistent_file ONELEG\
[2b0cec5]71 stnsurvey1 stnsurvey2\
[0af7076]72 tapelessthandepth longname chinabug chinabug2\
[54c4612]73 multinormal multinormignall multidiving multicylpolar multicartesian\
74 multinosurv multinormalbad multibug\
[e0c7cd1]75 cmd_title cmd_titlebad cmd_dummy cmd_infer cmd_date cmd_datebad cmd_datebad2\
[4fb15a1]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\
[5d1c60c]79 omitclino back back2 bad_back\
[a26c346]80 notentranceorexport inferunknown inferexports bad_units_factor\
[699bf50]81 bad_units_qlist\
[b4fe9fb]82 percent_gradient dotinsurvey leandroclino lowsd revdir gettokennullderef\
[d7a2cf9]83 nosurveyhanging nosurveyhanging2\
84 cmd_solve_nothing cmd_solve_nothing_implicit\
[abe7192]85 cmd_cartesian cmd_cartesian_bad\
[58edecc]86 cmd_calibrate cmd_declination cmd_declination_auto cmd_declination_auto_bad\
87 cmd_declination_conv cmd_declination_conv_proj_bug\
[850fdc4]88 lech level 2fixbug dot17 3dcorner\
[be4d0a0]89 unconnected-bug\
[1fbe9d43]90 backread.dat corrections.dat depthguage.dat flags.dat karstcompat.dat\
91 lrud.dat nomeasure.dat noteam.dat\
[ec580039]92 badmak.mak\
[d624d86]93 fixfeet.mak utm.mak\
[bf3acff]94 clptest.dat clptest.clp\
[725d3b1]95 walls.srv\
[21f084b]96 badopts.srv\
[d5a206ec]97 wallsbaddatum.wpj\
[4a0ab33]98 wallsdecl.wpj\
[ab83a74]99 passage hanging_lrud equatenosuchstn surveytypo\
[da96015]100 skipafterbadomit passagebad badreadingdotplus badcalibrate calibrate_clino\
[c092d72]101 badunits badbegin anonstn anonstnbad anonstnrev doubleinc reenterlots\
[567efed]102 cs csbad csbadsdfix csfeet cslonglat omitfixaroundsolve repeatreading\
[65b2851]103 mixedeols utf8bom nonewlineateof suspectreadings cmd_data_default\
[63ae487]104 cmd_data_ignore\
[5a0ab6a]105 quadrant_bearing bad_quadrant_bearing\
[05b9de76]106 samename tabinhighlight legacytokens\
[ab83a74]107 3dexport \
108 dxffullcoords dxfsurfequate\
[87f6c03]109 gpxexport hpglexport jsonexport kmlexport pltexport svgexport\
[c092d72]110"}}
[cd971de]111
[2b0cec5]112# Test file stnsurvey3.svx missing: pos=fail # We exit before the error count.
113
[cd971de]114LC_ALL=C
115export LC_ALL
[6e47b72]116SURVEXLANG=en
[cd971de]117export SURVEXLANG
[4515ba18]118
[43e8c72]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
[b1200a6]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
[67a2822]130vg_error=123
[9f5bcd3]131vg_log=$testdir/vg.log
[67a2822]132if [ -n "$VALGRIND" ] ; then
133  rm -f "$vg_log"
134  CAVERN="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $CAVERN"
[38c4c5c]135  DIFFPOS="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DIFFPOS"
[fdffa7d]136  DUMP3D="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DUMP3D"
[79b32a95]137  SURVEXPORT="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $SURVEXPORT"
[67a2822]138fi
139
[4515ba18]140for file in $TESTS ; do
[2b0cec5]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= ;;
[a69860f]146    *.*) realfile=$srcdir/$file ;;
147    *) realfile=$srcdir/$file.svx ;;
[2b0cec5]148  esac
149
[858a791]150  if [ x"$file" = xONELEG ] && [ -f "ONELEG.SVX" ] ; then
151    echo "Case insensitive filing system - skipping ONELEG testcase"
152    continue
153  fi
154
[2b0cec5]155  if [ -n "$realfile" ] && [ ! -r "$realfile" ] ; then
[a69860f]156    echo "Don't know how to run test '$file'"
157    exit 1
[2b0cec5]158  fi
159
160  echo "$file"
161
[db26f60]162  # how many warnings to expect (or empty not to check)
[b97d134]163  warn=
[db26f60]164
165  # how many errors to expect (or empty not to check)
[b97d134]166  error=
[2b0cec5]167
[db26f60]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
[371385f]172  # 3d : Convert to 3D with survexport, compare dump3d to <testcase_name>.dump
[db26f60]173  # dxf : Convert to DXF with survexport and compare with <testcase_name>.dxf
[aaeb71f]174  # gpx : Convert to GPX with survexport and compare with <testcase_name>.gpx
[4fcdd51a]175  # json : Convert to JSON with survexport and compare with <testcase_name>.json
[aaeb71f]176  # kml : Convert to KML with survexport and compare with <testcase_name>.kml
[3ee5c47]177  # plt : Convert to PLT with survexport and compare with <testcase_name>.plt
[8c4cefb]178  # svg : Convert to SVG with survexport and compare with <testcase_name>.svg
[db26f60]179  pos=
180
[0d3c93b]181  case $file in
[52f46ed]182    backread.dat|clptest.dat|clptest.clp|depthguage.dat|karstcompat.dat)
[fdffa7d]183      pos=dump
184      warn=0
185      ;;
[52f46ed]186    flags.dat)
187      pos=dump
188      warn=1
189      ;;
[2b0cec5]190    *.dat)
[838a7f4c]191      # .dat files can't start with a comment.  All the other .dat tests
192      # have the same settings.
[2b0cec5]193      pos=yes
194      warn=0
195      ;;
196    nonexistent_file*|ONELEG)
[3ebfd6a]197      # These testcase files don't exist (or for ONELEG exist with a different
198      # case).  They all have the same settings.
[2b0cec5]199      pos=fail
200      ;;
[d5a206ec]201    wallsbaddatum.wpj)
202      # .wpj files can't start with a comment.
203      pos=fail
204      warn=0
205      err=1
206      ;;
[4a0ab33]207    *.wpj)
208      # .wpj files can't start with a comment.
209      pos=dump
210      warn=0
211      ;;
[2b0cec5]212    *)
[aaeb71f]213      survexportopts=
[2b0cec5]214      read header < "$realfile"
215      set dummy $header
[f9aaa2c]216      while shift && [ -n "$1" ] ; do
[2b0cec5]217        case $1 in
218          pos=*) pos=`expr "$1" : 'pos=\(.*\)'` ;;
219          warn=*) warn=`expr "$1" : 'warn=\(.*\)'` ;;
220          error=*) error=`expr "$1" : 'error=\(.*\)'` ;;
[aaeb71f]221          survexportopt=*)
222            survexportopts="$survexportopts "`expr "$1" : 'survexportopt=\(.*\)'`
223            ;;
[2b0cec5]224        esac
225      done
226      ;;
[cfa16ef]227  esac
[4a2bb00]228
[aba729d]229  basefile=$srcdir/$file
[2b0cec5]230  case $file in
231  *.*)
232    input="./$file"
[aba729d]233    basefile=`echo "$basefile"|sed 's/\.[^.]*$//'` ;;
[2b0cec5]234  *)
[aba729d]235    input="./$file.svx" ;;
[2b0cec5]236  esac
[aba729d]237  outfile=$basefile.out
[cccc545]238  outfile2=$basefile.altout
[aba729d]239  posfile=$basefile.pos
[2b0cec5]240  rm -f tmp.*
241  pwd=`pwd`
242  cd "$srcdir"
[fdffa7d]243  srcdir=. SOURCE_DATE_EPOCH=1 $CAVERN "$input" --output="$pwd/tmp" > "$pwd/tmp.out"
[2b0cec5]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
[837e8bb]262    w=`sed '$!d;s/^There were \([0-9]*\).*/\1/p;d' tmp.out`
263    if test x"${w:-0}" != x"$warn" ; then
[2b0cec5]264      test -n "$VERBOSE" && echo "Got $w warnings, expected $warn"
265      exit 1
266    fi
267  fi
268  if test -n "$error" ; then
[837e8bb]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
[2b0cec5]271      test -n "$VERBOSE" && echo "Got $e errors, expected $error"
272      exit 1
273    fi
274  fi
[f5012ca]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"
[2b0cec5]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
[67a2822]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
[2b0cec5]299    [ "$exitcode" = 0 ] || exit 1
300    ;;
[fdffa7d]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
[6448891]317      $DIFF "$expectedfile" "$tmpfile" || exit 1
[fdffa7d]318    else
[6448891]319      $QUIET_DIFF "$expectedfile" "$tmpfile" || exit 1
[fdffa7d]320    fi
321    ;;
[87f6c03]322  dxf|gpx|hpgl|json|kml|plt|svg)
[aaeb71f]323    # $pos gives us the file extension here.
324    expectedfile=$basefile.$pos
325    tmpfile=tmp.$pos
[2b0cec5]326    if test -n "$VERBOSE" ; then
[aaeb71f]327      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile"
[2b0cec5]328      exitcode=$?
[cfa16ef]329    else
[aaeb71f]330      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile" > /dev/null
[2b0cec5]331      exitcode=$?
[cfa16ef]332    fi
[2b0cec5]333    if [ -n "$VALGRIND" ] ; then
334      if [ $exitcode = "$vg_error" ] ; then
335        cat "$vg_log"
336        rm "$vg_log"
[62e7e3c]337        exit 1
338      fi
[2b0cec5]339      rm "$vg_log"
[cfa16ef]340    fi
[2b0cec5]341    [ "$exitcode" = 0 ] || exit 1
[aaeb71f]342
343    # Normalise exported file if required.
344    case $pos in
[02cc72e]345      dxf)
346        # On x86 excess precision can result in -0.00 for some coordinates.
[d5db568]347        sed 's/-0\.00\>/ 0.00/g' < "$tmpfile" > tmp.tmp
[02cc72e]348        mv tmp.tmp "$tmpfile"
349        ;;
[ea4ac75]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        ;;
[aaeb71f]355      gpx)
[24f2d99]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
[aaeb71f]357        mv tmp.tmp "$tmpfile"
358        ;;
359    esac
360
[371385f]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
[2b0cec5]388    if test -n "$VERBOSE" ; then
[6448891]389      $DIFF "$expectedfile" "$tmpfile" || exit 1
[2b0cec5]390    else
[6448891]391      $QUIET_DIFF "$expectedfile" "$tmpfile" || exit 1
[aaeb71f]392    fi
393    ;;
[2b0cec5]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
[cd971de]405
[aba729d]406  if test -f "$outfile" ; then
[cccc545]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.
[6448891]412    if $QUIET_DIFF "$outfile" tmp.out ; then
[cccc545]413      : # Matches.
[6448891]414    elif [ -f "$outfile2" ] && $QUIET_DIFF "$outfile2" tmp.out ; then
[cccc545]415      : # Matches alternative output (e.g. due to older PROJ).
[2b0cec5]416    else
[6448891]417      test -z "$VERBOSE" || $DIFF "$outfile" tmp.out
[cccc545]418      exit 1
[cd971de]419    fi
[cfa16ef]420  fi
[2b0cec5]421  rm -f tmp.*
[4a2bb00]422done
[cfcfd28]423test -n "$VERBOSE" && echo "Test passed"
[fbc3a20]424exit 0
Note: See TracBrowser for help on using the repository browser.