#!/bin/sh
# Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
# LLNL-CODE-425250.
# All rights reserved.
# 
# This file is part of Silo. For details, see silo.llnl.gov.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 
#    * Redistributions of source code must retain the above copyright
#      notice, this list of conditions and the disclaimer below.
#    * Redistributions in binary form must reproduce the above copyright
#      notice, this list of conditions and the disclaimer (as noted
#      below) in the documentation and/or other materials provided with
#      the distribution.
#    * Neither the name of the LLNS/LLNL nor the names of its
#      contributors may be used to endorse or promote products derived
#      from this software without specific prior written permission.
# 
# THIS SOFTWARE  IS PROVIDED BY  THE COPYRIGHT HOLDERS  AND CONTRIBUTORS
# "AS  IS" AND  ANY EXPRESS  OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT
# LIMITED TO, THE IMPLIED  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A  PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN  NO  EVENT SHALL  LAWRENCE
# LIVERMORE  NATIONAL SECURITY, LLC,  THE U.S.  DEPARTMENT OF  ENERGY OR
# CONTRIBUTORS BE LIABLE FOR  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR  CONSEQUENTIAL DAMAGES  (INCLUDING, BUT NOT  LIMITED TO,
# PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS  OF USE,  DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER  IN CONTRACT, STRICT LIABILITY,  OR TORT (INCLUDING
# NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT  OF THE USE  OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# 
# This work was produced at Lawrence Livermore National Laboratory under
# Contract No.  DE-AC52-07NA27344 with the DOE.
# 
# Neither the  United States Government nor  Lawrence Livermore National
# Security, LLC nor any of  their employees, makes any warranty, express
# or  implied,  or  assumes  any  liability or  responsibility  for  the
# accuracy, completeness,  or usefulness of  any information, apparatus,
# product, or  process disclosed, or  represents that its use  would not
# infringe privately-owned rights.
# 
# Any reference herein to  any specific commercial products, process, or
# services by trade name,  trademark, manufacturer or otherwise does not
# necessarily  constitute or imply  its endorsement,  recommendation, or
# favoring  by  the  United  States  Government  or  Lawrence  Livermore
# National Security,  LLC. The views  and opinions of  authors expressed
# herein do not necessarily state  or reflect those of the United States
# Government or Lawrence Livermore National Security, LLC, and shall not
# be used for advertising or product endorsement purposes.
#
# Testsuite for Silo
AT_INIT(VALGRIND="$VALGRIND" STARGS="$STARGS")
AT_COPYRIGHT([This work was performed under the auspices of 
the U.S. Department of Energy by 
Lawrence Livermore National Laboratory 
in part under Contract W-7405-Eng-48 and 
in part under Contract DE-AC52-07NA27344.])

AT_BANNER(Non-driver-specific)
AT_SETUP(version)
AT_DATA(expout,
This version of the Silo library is greater than or equal to 4
This version of the Silo library is NOT greater than or equal to 9
This version of the Silo library is greater than or equal to 4.6
This version of the Silo library is NOT greater than or equal to 90.5.2
DBVersion() returns "AT_PACKAGE_VERSION"
DBVersionGE(4,6,0) returns 1
DBVersionGE(90,5,2) returns 0
On file handle returned from DBCreate...
    DBFileVersion() returns "AT_PACKAGE_VERSION"
    DBFileVersionGE(4,6,0) returns 1
    DBFileVersionGE(90,5,2) returns 0
On file handle returned from DBOpen...
    DBFileVersion() returns "AT_PACKAGE_VERSION"
    DBFileVersionGE(4,6,0) returns 1
    DBFileVersionGE(90,5,2) returns 0
On old silo file handle returned from DBOpen...
    DBFileVersion() returns "unknown; 4.5 or older"
    DBFileVersionGE(3,0,0) returns -1
    DBFileVersionGE(4,6,0) returns 0
    DBFileVersionGE(90,5,2) returns 0
)
AT_CHECK($VALGRIND version $STARGS,,expout,ignore)
AT_CLEANUP
AT_SETUP(namescheme)
AT_CHECK($VALGRIND namescheme,,ignore)
AT_CLEANUP
AT_SETUP(realloc_obj_and_opts)
AT_CHECK($VALGRIND realloc_obj_and_opts $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(point)
AT_CHECK($VALGRIND point $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(extface)
AT_CHECK($VALGRIND extface $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(testall -small)
AT_CHECK($VALGRIND testall -small $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(TestReadMask) # needs files generated by other execs 
AT_CHECK(extface $STARGS,,ignore) # don't valgrind these intermediate parts
AT_CHECK(point $STARGS,,ignore)
AT_CHECK(testall -small $STARGS,,ignore)
AT_CHECK($VALGRIND TestReadMask $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(array)
AT_CHECK($VALGRIND array $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(multi_test testread)
AT_CHECK($VALGRIND multi_test testread $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(multi_test earlyclose)
AT_CHECK($VALGRIND multi_test earlyclose $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(partial_io)
AT_CHECK($VALGRIND partial_io $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(simple)
AT_CHECK($VALGRIND simple $STARGS,0,ignore)
AT_CLEANUP
AT_SETUP(ucd)
AT_CHECK($VALGRIND ucd $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(ucdsamp3)
AT_CHECK($VALGRIND ucdsamp3 $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(testall -small -fortran)
AT_CHECK($VALGRIND testall -small -fortran $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(obj)
AT_CHECK($VALGRIND obj $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(onehex)
AT_CHECK($VALGRIND onehex $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(oneprism)
AT_CHECK($VALGRIND oneprism $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(onepyramid)
AT_CHECK($VALGRIND onepyramid $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(onetet)
AT_CHECK($VALGRIND onetet $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(subhex)
AT_CHECK($VALGRIND subhex $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(twohex)
AT_CHECK($VALGRIND twohex $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(multispec)
AT_CHECK($VALGRIND multispec $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(sami)
AT_CHECK($VALGRIND sami $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(specmix)
AT_CHECK($VALGRIND specmix $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(spec)
AT_CHECK($VALGRIND spec $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(group_test)
AT_CHECK($VALGRIND group_test 0 0 0 $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(listtypes)
AT_CHECK($VALGRIND ucd $STARGS,,ignore)
AT_CHECK(test -z "$STARGS" && $VALGRIND listtypes ucd.pdb || $VALGRIND listtypes ucd.h5,,ignore,ignore)
AT_CLEANUP
AT_SETUP(alltypes)
AT_CHECK($VALGRIND alltypes $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(wave)
AT_CHECK($VALGRIND wave $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(polyzl)
AT_CHECK($VALGRIND polyzl $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(csg)
AT_CHECK($VALGRIND csg $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(rocket)
AT_CHECK($VALGRIND rocket $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(mmadjacency)
AT_CHECK($VALGRIND mmadjacency $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(mat3d_3across)
AT_CHECK($VALGRIND mat3d_3across $STARGS)
AT_CLEANUP
AT_SETUP(ucd1d)
AT_CHECK($VALGRIND ucd1d $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(dir)
AT_CHECK($VALGRIND dir $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(quad)
AT_CHECK($VALGRIND quad $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(arbpoly2d)
AT_CHECK($VALGRIND arbpoly2d $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(readstuff) # needs data file from multi_test
AT_CHECK(multi_test $STARGS,,ignore) # don't valgrind these intermediate parts
AT_CHECK($VALGRIND readstuff $STARGS,ignore,ignore)
AT_CLEANUP
AT_SETUP(testfs)
AT_CHECK($VALGRIND testfs $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(empty)
AT_CHECK($VALGRIND empty $STARGS,,ignore,ignore)
AT_CLEANUP

AT_BANNER(pythonmodule)
AT_SETUP(read)
AT_KEYWORDS(python)
AT_CHECK(multi_test $STARGS hdf-friendly,,ignore) # generate data for python tests
AT_CHECK(test -z "$PYTHON" && exit 77 || env PYTHONPATH=../../../tools/python/.libs $PYTHON ../../test_read.py,,ignore,ignore)
AT_CLEANUP
AT_SETUP(write)
AT_KEYWORDS(python)
AT_DATA(expout,[toc=nvar = 12
var_names = (_fileinfo, _silolibinfo, t1, t10, t11, t2, t3, t4, t5, t6, t7, t8)
ndir = 1
dir_names = (a)

t2='hello'
t6=1.20,10.20
a/t8='x2'
t9=x3
/t5=1.20,10.00
])
AT_CHECK(test -z "$PYTHON" && exit 77 || env PYTHONPATH=../../../tools/python/.libs $PYTHON ../../test_write.py,,expout,ignore)
AT_CLEANUP
AT_SETUP(error handling)
AT_KEYWORDS(python)
AT_CHECK(multi_test $STARGS hdf-friendly,,ignore) # generate data for python tests
AT_CHECK(test -z "$PYTHON" && exit 77 || env PYTHONPATH=../../../tools/python/.libs $PYTHON ../../test_error.py,,ignore,ignore)
AT_CLEANUP
AT_SETUP(write objects)
AT_KEYWORDS(python)
AT_CHECK(test -z "$PYTHON" -o -z "$BROWSER" && exit 77 || $VALGRIND testonehex `pwd`,,ignore,ignore)
AT_CLEANUP

AT_BANNER(JSON (experimental))
AT_SETUP(json)
AT_KEYWORDS(json)
AT_CHECK(test ! \( -e ./json -o -e ../../json \) && exit 77 || onehex $STARGS,,ignore) # don't valgrind these intermediate parts
AT_CHECK(test ! \( -e ./json -o -e ../../json \) && exit 77 || $VALGRIND json $STARGS,ignore,ignore)
AT_CLEANUP

AT_BANNER(PDB Lite)
AT_SETUP(testpdb)
AT_CHECK(test ! \( -e ../src/score/lite_score.h -o -e ../../../src/pdb/lite_pdb.h \) -o "$STARGS" = DB_HDF5 && exit 77 || $VALGRIND testpdb,ignore,ignore)
AT_CLEANUP
AT_SETUP(pdbtst)
AT_CHECK(test ! \( -e ../src/score/lite_score.h -o -e ../../../src/pdb/lite_pdb.h \) -o "$STARGS" = DB_HDF5 && exit 77 || $VALGRIND pdbtst,ignore,ignore)
AT_CLEANUP

AT_BANNER(HDF5 Driver Specific)
AT_SETUP(grab)
AT_CHECK(test "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND grab,,ignore,ignore)
AT_CLEANUP
AT_SETUP(compression gzip)
AT_KEYWORDS(compression)
AT_CHECK(test "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND compression gzip,,ignore,ignore)
AT_CHECK(test "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND compression readonly,,ignore,ignore)
AT_CLEANUP
AT_SETUP(compression szip)
AT_KEYWORDS(compression)
AT_CHECK(test "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND compression szip,,ignore,ignore)
AT_CHECK(test "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND compression readonly,,ignore,ignore)
AT_CLEANUP
AT_SETUP(compression fpzip)
AT_KEYWORDS(compression)
AT_CHECK(test ! \( -e ../src/fpzip/read.o -o -e ../../../src/fpzip/read.o \) -o "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND compression fpzip,,ignore,ignore)
AT_CHECK(test ! \( -e ../src/fpzip/read.o -o -e ../../../src/fpzip/read.o \) -o "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND compression readonly,,ignore,ignore)
AT_CLEANUP
AT_SETUP(compression lossy3)
AT_KEYWORDS(compression)
AT_CHECK(test ! \( -e ../src/fpzip/read.o -o -e ../../../src/fpzip/read.o \) -o "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND compression lossy3,,ignore,ignore)
AT_CHECK(test ! \( -e ../src/fpzip/read.o -o -e ../../../src/fpzip/read.o \) -o "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND compression readonly,50,ignore,ignore)
AT_CLEANUP
AT_SETUP(compression minratio1000)
AT_KEYWORDS(compression)
AT_CHECK(test ! \( -e ../src/fpzip/read.o -o -e ../../../src/fpzip/read.o \) -o "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND compression minratio1000,1,ignore,ignore)
AT_CLEANUP
AT_SETUP(testhzip)
AT_KEYWORDS(compression)
AT_CHECK(test ! \( -e ../src/hzip/hzutil.o -o -e ../../../src/hzip/hzutil.o \) -o -z "$BROWSER" -o "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND testhzip `pwd`,,ignore,ignore)
AT_CLEANUP
AT_SETUP(checksums)
AT_CHECK(test -z "$BROWSER" -o "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND checksums `pwd`,,ignore,ignore)
AT_CLEANUP
AT_SETUP(xversion)
AT_CHECK(test -z "$BROWSER" -o "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND testxvers `pwd`,,ignore,ignore)
AT_CLEANUP
AT_SETUP(largefile)
AT_KEYWORDS(large)
AT_CHECK(test "$STARGS" != DB_HDF5 && exit 77 || $VALGRIND largefile,,ignore,ignore)
AT_CLEANUP

AT_BANNER(Fortran)
AT_SETUP(arrayf77)
AT_KEYWORDS(fortran)
AT_CHECK(test ! \( -f arrayf77 -o -f ../../arrayf77 \) && exit 77 || $VALGRIND arrayf77 $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(arrayf90)
AT_KEYWORDS(fortran)
AT_CHECK(test ! \( -f arrayf90 -o -f ../../arrayf90 \) && exit 77 || $VALGRIND arrayf90 $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(curvef77)
AT_KEYWORDS(fortran)
AT_CHECK(test ! \( -f curvef77 -o -f ../../curvef77 \) && exit 77 || $VALGRIND curvef77 $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(matf77)
AT_KEYWORDS(fortran)
AT_CHECK(test ! \( -f matf77 -o -f ../../matf77 \) && exit 77 || $VALGRIND matf77 $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(pointf77)
AT_KEYWORDS(fortran)
AT_CHECK(test ! \( -f pointf77 -o -f ../../pointf77 \) && exit 77 || $VALGRIND pointf77 $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(quadf77)
AT_KEYWORDS(fortran)
AT_CHECK(test ! \( -f quadf77 -o -f ../../quadf77 \) && exit 77 || $VALGRIND quadf77 $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(testallf77)
AT_KEYWORDS(fortran)
AT_CHECK(test ! \( -f testallf77 -o -f ../../testallf77 \) && exit 77 || $VALGRIND testallf77 $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(ucdf77)
AT_KEYWORDS(fortran)
AT_CHECK(test ! \( -f ucdf77 -o -f ../../ucdf77 \) && exit 77 || $VALGRIND ucdf77 $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(csgmesh)
AT_KEYWORDS(fortran)
AT_CHECK(test ! \( -f csgmesh -o -f ../../csgmesh \) && exit 77 || $VALGRIND csgmesh $STARGS,,ignore,ignore)
AT_CLEANUP

AT_BANNER(Special)
AT_SETUP(silock)
AT_KEYWORDS(tools)
AT_CHECK(testsilock `pwd` $STARGS,,ignore,ignore)
AT_CLEANUP
AT_SETUP(force single)
AT_KEYWORDS(conversions)
AT_CHECK(specmix $STARGS,,ignore)
AT_CHECK(test -z "$BROWSER" && exit 77 || $VALGRIND testdtypes `pwd` $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(multi_file)
AT_KEYWORDS(large)
AT_CHECK($VALGRIND multi_file $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(multi_file use-ns)
AT_KEYWORDS(large)
AT_CHECK($VALGRIND multi_file use-ns $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(testall -medium)
AT_KEYWORDS(large)
AT_CHECK($VALGRIND testall -medium $STARGS,,ignore)
AT_CLEANUP
AT_SETUP(testall -large)
AT_KEYWORDS(large)
AT_CHECK($VALGRIND testall -large $STARGS,,ignore)
AT_CLEANUP
#AT_SETUP(cpz1plt)
#AT_CHECK($VALGRIND cpz1plt $STARGS)   # Fails with: Missing input file "z1plt", cannot continue.
#AT_CLEANUP
#AT_SETUP(resample)
#AT_CHECK($VALGRIND resample $STARGS) # mpi test, mpirun
#AT_CLEANUP
#AT_SETUP(merge_block)
#AT_CHECK($VALGRIND merge_block $STARGS) # requires arguments
#AT_CLEANUP
