hdf5/test/testhdf5.c

321 lines
12 KiB
C
Raw Normal View History

1997-07-31 05:17:56 +08:00
/****************************************************************************
* NCSA HDF *
* Software Development Group *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* For conditions of distribution and use, see the accompanying *
* hdf/COPYING file. *
* *
****************************************************************************/
#ifdef RCSID
static char RcsId[] = "@(#)$Revision$";
1997-07-31 05:17:56 +08:00
#endif
/* $Id$ */
/*
FILE
testhdf5.c - HDF5 testing framework main file.
1997-07-31 05:17:56 +08:00
REMARKS
General test wrapper for HDF5 base library test programs
1997-07-31 05:17:56 +08:00
DESIGN
Each test function should be implemented as function having no
parameters and returning void (i.e. no return value). They should be put
into the list of InitTest() calls in main() below. Functions which depend
on other functionality should be placed below the InitTest() call for the
base functionality testing.
Each test module should include testhdf5.h and define a unique set of
names for test files they create.
1997-07-31 05:17:56 +08:00
BUGS/LIMITATIONS
EXPORTED ROUTINES/VARIABLES:
Two variables are exported: num_errs, and Verbosity.
1997-07-31 05:17:56 +08:00
*/
#if defined __MWERKS__
#include <console.h>
#endif
#include <stdarg.h>
1997-07-31 05:17:56 +08:00
#define MAXNUMOFTESTS 30
#define HDF5_TEST_MASTER
/* Internal Variables */
static int Index = 0;
1997-07-31 05:17:56 +08:00
/* Global variables */
int num_errs;
int Verbosity;
1997-07-31 05:17:56 +08:00
/* ANY new test needs to have a prototype in tproto.h */
#include <testhdf5.h>
1997-07-31 05:17:56 +08:00
struct TestStruct {
int NumErrors;
char Description[64];
int SkipFlag;
char Name[16];
void (*Call) (void);
} Test[MAXNUMOFTESTS];
1997-07-31 05:17:56 +08:00
static void InitTest(const char *TheName, void (*TheCall) (void), const char *TheDescr);
static void usage(void);
1997-07-31 05:17:56 +08:00
static void
InitTest(const char *TheName, void (*TheCall) (void), const char *TheDescr)
1997-07-31 05:17:56 +08:00
{
if (Index >= MAXNUMOFTESTS) {
print_func("Uh-oh, too many tests added, increase MAXNUMOFTEST!\n");
exit(0);
} /* end if */
1997-07-31 05:17:56 +08:00
HDstrcpy(Test[Index].Description, TheDescr);
HDstrcpy(Test[Index].Name, TheName);
Test[Index].Call = TheCall;
Test[Index].NumErrors = -1;
Test[Index].SkipFlag = 0;
Index++;
}
static void
usage(void)
1997-07-31 05:17:56 +08:00
{
intn i;
1997-07-31 05:17:56 +08:00
print_func("Usage: testhdf5 [-v[erbose] (l[ow]|m[edium]|h[igh]|0-10)] \n");
print_func(" [-[e]x[clude] name+] \n");
print_func(" [-o[nly] name+] \n");
print_func(" [-b[egin] name] \n");
print_func(" [-s[ummary]] \n");
print_func(" [-c[leanoff]] \n");
print_func(" [-n[ocaching]] \n");
print_func(" [-h[elp]] \n");
print_func("\n\n");
print_func("verbose controls the amount of information displayed\n");
print_func("exclude to exclude tests by name\n");
print_func("only to name tests which should be run\n");
print_func("begin start at the name of the test givin\n");
print_func("summary prints a summary of test results at the end\n");
print_func("cleanoff does not delete *.hdf files after execution of tests\n");
print_func("nocaching do not turn on low-level DD caching\n");
print_func("help print out this information\n");
print_func("\n\n");
print_func("This program currently tests the following: \n\n");
print_func("%16s %s\n", "Name", "Description");
print_func("%16s %s\n", "----", "-----------");
for (i = 0; i < Index; i++)
print_func("%16s %s\n", Test[i].Name, Test[i].Description);
print_func("\n\n");
} /* end usage() */
1997-07-31 05:17:56 +08:00
/*
* This routine is designed to provide equivalent functionality to 'printf'
* and allow easy replacement for environments which don't have stdin/stdout
* available. (i.e. Windows & the Mac)
*/
int
print_func(const char *format,...)
1997-07-31 05:17:56 +08:00
{
va_list arglist;
int ret_value;
1997-07-31 05:17:56 +08:00
va_start(arglist, format);
ret_value = vprintf(format, arglist);
1997-07-31 05:17:56 +08:00
va_end(arglist);
return (ret_value);
1997-07-31 05:17:56 +08:00
}
/*-------------------------------------------------------------------------
* Function: cleanup
*
* Purpose: Cleanup temporary test files
*
* Return: none
*
* Programmer: Albert Cheng
* July 2, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static void
cleanup(void)
{
if (!getenv ("HDF5_NOCLEANUP")) {
MESSAGE(2, ("\nCleaning Up temp files...\n\n"));
/* call individual cleanup routines in each source module */
cleanup_metadata();
cleanup_file();
cleanup_heap();
cleanup_ohdr();
cleanup_stab();
cleanup_h5s();
cleanup_attr();
}
}
int
main(int argc, char *argv[])
1997-07-31 05:17:56 +08:00
{
int CLLoop; /* Command Line Loop */
int Loop, Loop1;
int Summary = 0;
int CleanUp = 1;
int Cache = 1;
uintn major, minor, release, patch;
1997-07-31 05:17:56 +08:00
#if defined __MWERKS__
argc = ccommand(&argv);
#endif
#if !(defined MAC || defined __MWERKS__ || defined SYMANTEC_C)
/* Un-buffer the stdout and stderr */
setbuf(stderr, NULL);
setbuf(stdout, NULL);
#endif
/*
* Turn off automatic error reporting since we do it ourselves. Besides,
* half the functions this test calls are private, so automatic error
* reporting wouldn't do much good since it's triggered at the API layer.
*/
H5Eset_auto (NULL, NULL);
1997-07-31 05:17:56 +08:00
/* Tests are generally arranged from least to most complexity... */
InitTest("metadata", test_metadata, "Encode/decode metadata code");
InitTest("file", test_file, "Low-Level File I/O");
InitTest("heap", test_heap, "Object and Name Heaps");
InitTest("ohdr", test_ohdr, "Object Headers");
InitTest("stab", test_stab, "Symbol Tables");
InitTest("h5s", test_h5s, "Dataspaces");
1998-04-24 06:24:52 +08:00
InitTest("attr", test_attr, "Attributes");
1997-07-31 05:17:56 +08:00
Verbosity = 4; /* Default Verbosity is Low */
1997-07-31 05:17:56 +08:00
H5version(&major, &minor, &release, &patch);
print_func("\nFor help use: testhdf5 -help\n");
[svn-r303] Changes since 19980228 ---------------------- ./html/Dataspaces.html ./html/Errors.html ./html/Files.html ./html/H5.api.html ./html/review1.html ./src/H5private.h ./src/H5public.h ./test/dsets.c ./test/dtypes.c Removed all the types like `int32' and `intn' into private headers since they violate the naming scheme and pollute application name space. Besides, our test files only use them in a handful of places and it's probably useless to export them to the app. The app is always written in terms of standard numeric types or its own numeric types and probably never in terms of HDF5 numeric types. If it were, then the user would have to copy from their type to hdf5 type for almost every hdf5 API function call! Same goes for return values. I also removed SUCCEED/FAIL from the API since apps should be checking against zero anyway. if (FAIL==(space=H5Screate_simple(...))) /*wrong*/ if ((space=H5Fcreate_simple(...)<0)) /*right*/ ./src/H5.c Changed arguments of H5version() from `uintn' to `unsigned'. ./src/H5Tpublic.h ./src/H5T.c Changed return type of H5Tget_nmembers() from `intn' to `int' ./src/H5A.c ./src/H5Aprivate.h ./src/H5Apublic.h Changed `H5Asearch_func_t' to `H5A_search_func_t' and moved its definition from the public to the private header file. ./html/H5.format.html Documented changes made to the external file list (H5O_EFL) message. ./src/H5D.c ./src/H5Dprivate.h ./src/H5E.c ./src/H5Epublic.h ./src/H5O.c ./src/H5Oefl.c ./src/H5Oprivate.h ./src/H5P.c ./src/H5Ppublic.h Added partial support for external raw data files. HDF5 can now describe external raw data files by listing the file names, offsets, and size for a dataset. However, we will restrict a dataset to be stored "contiguously" when the external file list is viewed as a single address space. The current implementation is unable to read/write to external files--that will come later this week as will documentation. For now, take a look at ./test/external.c, particularly the calls to H5Pset_external(). ./test/Makefile.in ./test/external.c [NEW] ./MANIFEST Added tests for external storage. Note: the read test is supposed to fail at this point since reading external datasets is not implemented yet. There is no write test. ./src/H5S.c ./src/H5Sprivate.h ./src/H5Ssimp.c Added H5S_get_npoints_max() to return the maximum possible number of data points in a data space. Added an extra argument to H5S_get_dims() which returns the maximum dims. ./src/H5F.c ./src/H5Fprivate.h ./src/H5Fpublic.h ./src/H5M.c [DEPRICATED] ./src/H5Mpublic.h [DEPRICATED] Changed `template' to `property list' in lots of places. ./src/H5Osdspace.c Removed an extra `\n' from a print statement. ./src/H5S_public.h Changed H5S_UNLIMITED to the maximum size_t value. ./test/extend.c "Extendable" is spelled "extendible". ./src/H5Farray.c ./src/H5V.c ./src/H5Vprivate.h ./test/hyperslab.c Strides are now type ssize_t instead of int. These have nothing to do with the sample granularity arguments for hyperslabs, which are also called "strides" in the code. ./test/tstab.c Changed assumptions about default address and length sizes.
1998-03-05 00:20:23 +08:00
print_func("Linked with hdf5-%u.%u.%u%c\n\n", (unsigned) major,
(unsigned) minor, (unsigned) release, 'a' + patch);
for (CLLoop = 1; CLLoop < argc; CLLoop++) {
if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-verbose") == 0) ||
(HDstrcmp(argv[CLLoop], "-v") == 0))) {
if (argv[CLLoop + 1][0] == 'l')
Verbosity = 4;
else if (argv[CLLoop + 1][0] == 'm')
Verbosity = 6;
else if (argv[CLLoop + 1][0] == 'h')
Verbosity = 10;
else
Verbosity = atoi(argv[CLLoop + 1]);
} /* end if */
if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-summary") == 0) ||
(HDstrcmp(argv[CLLoop], "-s") == 0)))
Summary = 1;
if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-help") == 0) ||
(HDstrcmp(argv[CLLoop], "-h") == 0))) {
usage();
exit(0);
}
if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-cleanoff") == 0) ||
(HDstrcmp(argv[CLLoop], "-c") == 0)))
CleanUp = 0;
if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-nocache") == 0) ||
(HDstrcmp(argv[CLLoop], "-n") == 0))) {
Cache = 0;
printf ("Cache = %d\n", Cache);
}
if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-exclude") == 0) ||
(HDstrcmp(argv[CLLoop], "-x") == 0))) {
Loop = CLLoop + 1;
while ((Loop < argc) && (argv[Loop][0] != '-')) {
for (Loop1 = 0; Loop1 < Index; Loop1++)
if (HDstrcmp(argv[Loop], Test[Loop1].Name) == 0)
Test[Loop1].SkipFlag = 1;
Loop++;
} /* end while */
} /* end if */
if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-begin") == 0) ||
(HDstrcmp(argv[CLLoop], "-b") == 0))) {
Loop = CLLoop + 1;
while ((Loop < argc) && (argv[Loop][0] != '-')) {
for (Loop1 = 0; Loop1 < Index; Loop1++) {
if (HDstrcmp(argv[Loop], Test[Loop1].Name) != 0)
Test[Loop1].SkipFlag = 1;
if (HDstrcmp(argv[Loop], Test[Loop1].Name) == 0)
Loop1 = Index;
} /* end for */
Loop++;
} /* end while */
} /* end if */
if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-only") == 0) ||
(HDstrcmp(argv[CLLoop], "-o") == 0))) {
for (Loop = 0; Loop < Index; Loop++)
Test[Loop].SkipFlag = 1;
Loop = CLLoop + 1;
while ((Loop < argc) && (argv[Loop][0] != '-')) {
for (Loop1 = 0; Loop1 < Index; Loop1++)
if (HDstrcmp(argv[Loop], Test[Loop1].Name) == 0)
Test[Loop1].SkipFlag = 0;
Loop++;
} /* end while */
} /* end if */
} /* end for */
1997-07-31 05:17:56 +08:00
#ifdef NOT_YET
if (Cache) /* turn on caching, unless we were instucted not to */
Hcache(CACHE_ALL_FILES, TRUE);
1997-07-31 05:17:56 +08:00
#endif /* NOT_YET */
for (Loop = 0; Loop < Index; Loop++) {
if (Test[Loop].SkipFlag) {
MESSAGE(2, ("Skipping -- %s \n", Test[Loop].Description));
} else {
MESSAGE(2, ("Testing -- %s (%s) \n", Test[Loop].Description,
Test[Loop].Name));
MESSAGE(5, ("===============================================\n"));
Test[Loop].NumErrors = num_errs;
(*Test[Loop].Call) ();
Test[Loop].NumErrors = num_errs - Test[Loop].NumErrors;
MESSAGE(5, ("===============================================\n"));
MESSAGE(5, ("There were %d errors detected.\n\n", (int) Test[Loop].NumErrors));
} /* end else */
} /* end for */
1997-07-31 05:17:56 +08:00
MESSAGE(2, ("\n\n"))
1997-07-31 05:17:56 +08:00
if (num_errs)
print_func("!!! %d Error(s) were detected !!!\n\n", (int) num_errs);
else
print_func("All tests were successful. \n\n");
if (Summary) {
print_func("Summary of Test Results:\n");
print_func("Name of Test Errors Description of Test\n");
print_func("---------------- ------ --------------------------------------\n");
1997-07-31 05:17:56 +08:00
for (Loop = 0; Loop < Index; Loop++) {
if (Test[Loop].NumErrors == -1)
print_func("%16s %6s %s\n", Test[Loop].Name, "N/A", Test[Loop].Description);
else
print_func("%16s %6d %s\n", Test[Loop].Name, (int) Test[Loop].NumErrors,
Test[Loop].Description);
} /* end for */
print_func("\n\n");
} /* end if */
if (CleanUp)
cleanup();
1997-07-31 05:17:56 +08:00
exit(0);
return (0);
} /* end main() */