h5test.h

00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00002  * Copyright by The HDF Group.                                               *
00003  * Copyright by the Board of Trustees of the University of Illinois.         *
00004  * All rights reserved.                                                      *
00005  *                                                                           *
00006  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
00007  * terms governing use, modification, and redistribution, is contained in    *
00008  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
00009  * of the source code distribution tree; Copyright.html can be found at the  *
00010  * root level of an installed copy of the electronic HDF5 document set and   *
00011  * is linked from the top-level documents page.  It can also be found at     *
00012  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
00013  * access to either file, you may request a copy from help@hdfgroup.org.     *
00014  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00015 
00016 /*
00017  * Programmer:  Robb Matzke <matzke@llnl.gov>
00018  *              Friday, November 20, 1998
00019  *
00020  * Purpose:     Test support stuff.
00021  */
00022 #ifndef _H5TEST_H
00023 #define _H5TEST_H
00024 
00025 #include "hdf5.h"
00026 #include "H5private.h"
00027 
00028 #ifdef H5_STDC_HEADERS
00029 #   include <signal.h>
00030 #   include <stdarg.h>
00031 #endif
00032 
00033 /*
00034  * Predefined test verbosity levels.
00035  *
00036  * Convention:
00037  *
00038  * The higher the verbosity value, the more information printed.
00039  * So, output for higher verbosity also include output of all lower
00040  * verbosity.
00041  *
00042  *  Value     Description
00043  *  0         None:   No informational message.
00044  *  1                 "All tests passed"
00045  *  2                 Header of overall test
00046  *  3         Default: header and results of individual test
00047  *  4
00048  *  5         Low:    Major category of tests.
00049  *  6
00050  *  7         Medium: Minor category of tests such as functions called.
00051  *  8
00052  *  9         High:   Highest level.  All information.
00053  */
00054 #define VERBO_NONE 0     /* None    */
00055 #define VERBO_DEF  3     /* Default */
00056 #define VERBO_LO   5     /* Low     */
00057 #define VERBO_MED  7     /* Medium  */
00058 #define VERBO_HI   9     /* High    */
00059 
00060 /*
00061  * Verbose queries
00062  * Only None needs an exact match.  The rest are at least as much.
00063  */
00064 
00065 /* A macro version of HDGetTestVerbosity(). */
00066 /* Should be used internally by the libtest.a only. */
00067 #define HDGetTestVerbosity() (TestVerbosity)
00068 
00069 #define VERBOSE_NONE    (HDGetTestVerbosity()==VERBO_NONE)
00070 #define VERBOSE_DEF     (HDGetTestVerbosity()>=VERBO_DEF)
00071 #define VERBOSE_LO      (HDGetTestVerbosity()>=VERBO_LO)
00072 #define VERBOSE_MED     (HDGetTestVerbosity()>=VERBO_MED)
00073 #define VERBOSE_HI      (HDGetTestVerbosity()>=VERBO_HI)
00074 
00075 /*
00076  * Test controls definitions.
00077  */
00078 #define SKIPTEST        1       /* Skip this test */
00079 #define ONLYTEST        2       /* Do only this test */
00080 #define BEGINTEST       3       /* Skip all tests before this test */
00081 
00082 /*
00083  * This contains the filename prefix specificied as command line option for
00084  * the parallel test files.
00085  */
00086 H5_DLLVAR char *paraprefix;
00087 #ifdef H5_HAVE_PARALLEL
00088 extern MPI_Info h5_io_info_g;         /* MPI INFO object for IO */
00089 #endif
00090 
00091 /*
00092  * Print the current location on the standard output stream.
00093  */
00094 #define AT()            printf ("        at %s:%d in %s()...\n",              \
00095                                 __FILE__, __LINE__, __FUNCTION__);
00096 
00097 /*
00098  * The name of the test is printed by saying TESTING("something") which will
00099  * result in the string `Testing something' being flushed to standard output.
00100  * If a test passes, fails, or is skipped then the PASSED(), H5_FAILED(), or
00101  * SKIPPED() macro should be called.  After H5_FAILED() or SKIPPED() the caller
00102  * should print additional information to stdout indented by at least four
00103  * spaces.  If the h5_errors() is used for automatic error handling then
00104  * the H5_FAILED() macro is invoked automatically when an API function fails.
00105  */
00106 #define TESTING(WHAT)   {printf("Testing %-62s",WHAT); fflush(stdout);}
00107 #define TESTING_2(WHAT) {printf(" Testing %-62s",WHAT); fflush(stdout);}
00108 #define PASSED()        {puts(" PASSED");fflush(stdout);}
00109 #define H5_FAILED()     {puts("*FAILED*");fflush(stdout);}
00110 #define H5_WARNING()    {puts("*WARNING*");fflush(stdout);}
00111 #define SKIPPED()       {puts(" -SKIP-");fflush(stdout);}
00112 #define TEST_ERROR      {H5_FAILED(); AT(); goto error;}
00113 #define STACK_ERROR     {H5Eprint2(H5E_DEFAULT, stdout); goto error;}
00114 #define FAIL_STACK_ERROR {H5_FAILED(); AT(); H5Eprint2(H5E_DEFAULT, stdout); \
00115     goto error;}
00116 #define FAIL_PUTS_ERROR(s) {H5_FAILED(); AT(); puts(s); goto error;}
00117 
00118 /*
00119  * Alarm definitions to wait up (terminate) a test that runs too long.
00120  */
00121 #define alarm_seconds   1200    /* default is 20 minutes */
00122 #define ALARM_ON        HDalarm(alarm_seconds)
00123 #define ALARM_OFF       HDalarm(0)
00124 /* set alarms to N seconds if N > 0, else use default alarm_seconds. */
00125 #define ALARM_SET(N)    HDalarm((N)>0 ? N : alarm_seconds)
00126 
00127 /*
00128  * The methods to compare the equality of floating-point values:
00129  *    1. XXX_ABS_EQUAL - check if the difference is smaller than the
00130  *       Epsilon value.  The Epsilon values, FLT_EPSILON, DBL_EPSILON,
00131  *       and LDBL_EPSILON, are defined by compiler in float.h.
00132  *    2. XXX_REL_EQUAL - check if the relative difference is smaller than a
00133  *       predefined value M.  See if two values are relatively equal.
00134  *       It's the test's responsibility not to pass in the value 0, which
00135  *       may cause the equation to fail.
00136  */
00137 #define FLT_ABS_EQUAL(X,Y)      ((float)fabs(X-Y)<FLT_EPSILON)
00138 #define DBL_ABS_EQUAL(X,Y)      (fabs(X-Y)<DBL_EPSILON)
00139 #define LDBL_ABS_EQUAL(X,Y)     (fabsl(X-Y)<LDBL_EPSILON)
00140 
00141 #define FLT_REL_EQUAL(X,Y,M)    (fabsf((Y-X)/X<M)
00142 #define DBL_REL_EQUAL(X,Y,M)    (fabs((Y-X)/X)<M)
00143 #define LDBL_REL_EQUAL(X,Y,M)    (fabsl((Y-X)/X)<M)
00144 
00145 #ifdef __cplusplus
00146 extern "C" {
00147 #endif
00148 
00149 /* Generally useful testing routines */
00150 H5TEST_DLL int h5_cleanup(const char *base_name[], hid_t fapl);
00151 H5TEST_DLL char *h5_fixname(const char *base_name, hid_t fapl, char *fullname,
00152                  size_t size);
00153 H5TEST_DLL hid_t h5_fileaccess(void);
00154 H5TEST_DLL void h5_no_hwconv(void);
00155 H5TEST_DLL const char *h5_rmprefix(const char *filename);
00156 H5TEST_DLL void h5_reset(void);
00157 H5TEST_DLL void h5_show_hostname(void);
00158 H5TEST_DLL h5_stat_size_t h5_get_file_size(const char *filename, hid_t fapl);
00159 H5TEST_DLL int print_func(const char *format, ...);
00160 H5TEST_DLL int h5_make_local_copy(char *origfilename, char *local_copy_name);
00161 
00162 /* Routines for operating on the list of tests (for the "all in one" tests) */
00163 H5TEST_DLL void TestUsage(void);
00164 H5TEST_DLL void AddTest(const char *TheName, void (*TheCall) (void),
00165              void (*Cleanup) (void), const char *TheDescr,
00166              const void *Parameters);
00167 H5TEST_DLL void TestInfo(const char *ProgName);
00168 H5TEST_DLL void TestParseCmdLine(int argc, char *argv[]);
00169 H5TEST_DLL void PerformTests(void);
00170 H5TEST_DLL void TestSummary(void);
00171 H5TEST_DLL void TestCleanup(void);
00172 H5TEST_DLL void TestInit(const char *ProgName, void (*private_usage)(void), int (*private_parser)(int ac, char *av[]));
00173 H5TEST_DLL int  GetTestVerbosity(void);
00174 H5TEST_DLL int  SetTestVerbosity(int newval);
00175 H5TEST_DLL int  GetTestSummary(void);
00176 H5TEST_DLL int  GetTestCleanup(void);
00177 H5TEST_DLL int  SetTestNoCleanup(void);
00178 H5TEST_DLL int  GetTestExpress(void);
00179 H5TEST_DLL int  SetTestExpress(int newval);
00180 H5TEST_DLL void ParseTestVerbosity(char *argv);
00181 H5TEST_DLL int  GetTestNumErrs(void);
00182 H5TEST_DLL void  IncTestNumErrs(void);
00183 H5TEST_DLL const void *GetTestParameters(void);
00184 H5TEST_DLL int  TestErrPrintf(const char *format, ...);
00185 H5TEST_DLL void SetTest(const char *testname, int action);
00186 
00187 #ifdef H5_HAVE_FILTER_SZIP
00188 H5TEST_DLL int h5_szip_can_encode(void);
00189 #endif /* H5_HAVE_FILTER_SZIP */
00190 
00191 #ifdef H5_HAVE_PARALLEL
00192 H5TEST_DLL int h5_set_info_object(void);
00193 H5TEST_DLL void h5_dump_info_object(MPI_Info info);
00194 H5TEST_DLL char* getenv_all(MPI_Comm comm, int root, const char* name);
00195 #endif
00196 
00197 /* Extern global variables */
00198 H5TEST_DLLVAR int TestVerbosity;
00199 
00200 #ifdef __cplusplus
00201 }
00202 #endif
00203 #endif