/* * Copyright © 1998-2001 National Center for Supercomputing Applications * All rights reserved. * * Programmer: Robb Matzke * Thursday, November 19, 1998 * * Purpose: Provides support functions for most of the hdf5 tests cases. * */ #undef NDEBUG /*override -DNDEBUG */ #include "h5test.h" #ifdef WIN32 #include #include #endif /* WIN32 */ /* * Define these environment variables or constants to influence functions in * this test support library. The environment variable is used in preference * to the cpp constant. If neither is defined then use some default value. * * HDF5_DRIVER: This string describes what low level file driver to * use for HDF5 file access. The first word in the * value is the name of the driver and subsequent data * is interpreted according to the driver. See * h5_fileaccess() for details. * * HDF5_PREFIX: A string to add to the beginning of all serial test * file names. This can be used to run tests in a * different file system (e.g., "/tmp" or "/tmp/myname"). * The prefix will be separated from the base file name * by a slash. See h5_fixname() for details. * * HDF5_PARAPREFIX: A string to add to the beginning of all parallel test * file names. This can be used to tell MPIO what driver * to use (e.g., "gfs:", "ufs:", or "nfs:") or to use a * different file system (e.g., "/tmp" or "/tmp/myname"). * The prefix will be separated from the base file name * by a slash. See h5_fixname() for details. * */ /* * In a parallel machine, the filesystem suitable for compiling is * unlikely a parallel file system that is suitable for parallel I/O. * There is no standard pathname for the parallel file system. /tmp * is about the best guess. */ #ifndef HDF5_PARAPREFIX #ifdef __PUMAGON__ /* For the PFS of TFLOPS */ #define HDF5_PARAPREFIX "pfs:/pfs_grande/multi/tmp_1" #else #define HDF5_PARAPREFIX "/tmp" #endif #endif char *paraprefix = NULL; /* for command line option para-prefix */ /* * These are the letters that are appended to the file name when generating * names for the split and multi drivers. They are: * * m: All meta data when using the split driver. * s: The userblock, superblock, and driver info block * b: B-tree nodes * r: Dataset raw data * g: Global heap * l: local heap (object names) * o: object headers */ static const char *multi_letters = "msbrglo"; /*------------------------------------------------------------------------- * Function: h5_errors * * Purpose: Displays the error stack after printing "*FAILED*". * * Return: Success: 0 * * Failure: -1 * * Programmer: Robb Matzke * Wednesday, March 4, 1998 * * Modifications: * *------------------------------------------------------------------------- */ herr_t h5_errors(void UNUSED *client_data) { H5_FAILED(); H5Eprint (stdout); return 0; } /*------------------------------------------------------------------------- * Function: h5_cleanup * * Purpose: Cleanup temporary test files. * base_name contains the list of test file names. * The file access property list is also closed. * * Return: Non-zero if cleanup actions were performed; zero otherwise. * * Programmer: Albert Cheng * May 28, 1998 * * Modifications: * Albert Cheng, 2000-09-09 * Added the explicite base_name argument to replace the * global variable FILENAME. * *------------------------------------------------------------------------- */ int h5_cleanup(const char *base_name[], hid_t fapl) { char filename[1024]; char temp[2048]; int i, j; int retval=0; #ifndef H5_WANT_H5_V1_2_COMPAT hid_t driver; #endif /* H5_WANT_H5_V1_2_COMPAT */ if (!getenv("HDF5_NOCLEANUP")) { for (i=0; base_name[i]; i++) { if (NULL==h5_fixname(base_name[i], fapl, filename, sizeof filename)) { continue; } #ifdef H5_WANT_H5_V1_2_COMPAT switch (H5Pget_driver(fapl)) { case H5F_LOW_CORE: break; /*nothing to remove*/ case H5F_LOW_SPLIT: HDsnprintf(temp, sizeof temp, "%s.raw", filename); remove(temp); HDsnprintf(temp, sizeof temp, "%s.meta", filename); remove(temp); break; case H5F_LOW_FAMILY: for (j=0; /*void*/; j++) { HDsnprintf(temp, sizeof temp, filename, j); if (access(temp, F_OK)<0) break; remove(temp); } break; default: remove(filename); break; } #else /* H5_WANT_H5_V1_2_COMPAT */ driver = H5Pget_driver(fapl); if (H5FD_FAMILY==driver) { for (j=0; /*void*/; j++) { HDsnprintf(temp, sizeof temp, filename, j); if (access(temp, F_OK)<0) break; remove(temp); } } else if (H5FD_CORE==driver) { /*void*/ } else if (H5FD_MULTI==driver) { H5FD_mem_t mt; assert(strlen(multi_letters)==H5FD_MEM_NTYPES); for (mt=H5FD_MEM_DEFAULT; mt= size) { return NULL; /*buffer is too small*/ } else { strcpy(fullname, base_name); } #ifdef H5_WANT_H5_V1_2_COMPAT /* Append a suffix */ if ((driver = H5Pget_driver(fapl)) < 0) return NULL; switch (driver) { case H5F_LOW_SPLIT: case H5F_LOW_CORE: suffix = NULL; break; case H5F_LOW_FAMILY: suffix = "%05d.h5"; break; default: suffix = ".h5"; break; } #endif /* H5_WANT_H5_V1_2_COMPAT */ /* Append a suffix */ if (suffix) { if (strlen(fullname) + strlen(suffix) >= size) return NULL; strcat(fullname, suffix); } /* Remove any double slashes in the filename */ for (ptr = fullname, i = j = 0; ptr && i < size; i++, ptr++) { if (*ptr != '/' || last != '/') fullname[j++] = *ptr; last = *ptr; } return fullname; } /*------------------------------------------------------------------------- * Function: h5_fileaccess * * Purpose: Returns a file access template which is the default template * but with a file driver set according to the constant or * environment variable HDF5_DRIVER * * Return: Success: A file access property list * * Failure: -1 * * Programmer: Robb Matzke * Thursday, November 19, 1998 * * Modifications: * *------------------------------------------------------------------------- */ hid_t h5_fileaccess(void) { const char *val = NULL; const char *name; char s[1024]; hid_t fapl = -1; hsize_t fam_size = 100*1024*1024; /*100 MB*/ long verbosity = 1; H5FD_mem_t mt; /* First use the environment variable, then the constant */ val = getenv("HDF5_DRIVER"); #ifdef HDF5_DRIVER if (!val) val = HDF5_DRIVER; #endif if ((fapl=H5Pcreate(H5P_FILE_ACCESS))<0) return -1; if (!val || !*val) return fapl; /*use default*/ strncpy(s, val, sizeof s); s[sizeof(s)-1] = '\0'; if (NULL==(name=strtok(s, " \t\n\r"))) return fapl; if (!strcmp(name, "sec2")) { /* Unix read() and write() system calls */ if (H5Pset_fapl_sec2(fapl)<0) return -1; } else if (!strcmp(name, "stdio")) { /* Standard C fread() and fwrite() system calls */ if (H5Pset_fapl_stdio(fapl)<0) return -1; } else if (!strcmp(name, "core")) { /* In-core temporary file with 1MB increment */ if (H5Pset_fapl_core(fapl, 1024*1024, FALSE)<0) return -1; } else if (!strcmp(name, "split")) { /* Split meta data and raw data each using default driver */ if (H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT)<0) return -1; } else if (!strcmp(name, "multi")) { /* Multi-file driver, general case of the split driver */ H5FD_mem_t memb_map[H5FD_MEM_NTYPES]; hid_t memb_fapl[H5FD_MEM_NTYPES]; const char *memb_name[H5FD_MEM_NTYPES]; char sv[H5FD_MEM_NTYPES][1024]; haddr_t memb_addr[H5FD_MEM_NTYPES]; memset(memb_map, 0, sizeof memb_map); memset(memb_fapl, 0, sizeof memb_fapl); memset(memb_name, 0, sizeof memb_name); memset(memb_addr, 0, sizeof memb_addr); assert(strlen(multi_letters)==H5FD_MEM_NTYPES); for (mt=H5FD_MEM_DEFAULT; mt