/* * Function: cleanup * Purpose: Cleanup the output file. * Returns: Nothing * Programmer: Bill Wendling, 06. June 2002 * Modifications: */ static void cleanup(void) { if (!HDgetenv("HDF5_NOCLEANUP")) HDunlink(filename); HDfree(filename); }
static void get_unique_name(void) { const char *prefix = NULL; const char *env = HDgetenv("HDF5_PREFIX"); if (env) prefix = env; if (option_prefix) prefix = option_prefix; if (prefix) /* 2 = 1 for '/' + 1 for null terminator */ filename = (char *) HDmalloc(HDstrlen(prefix) + HDstrlen(ZIP_PERF_FILE) + 2); else filename = (char *) HDmalloc(HDstrlen(ZIP_PERF_FILE) + 1); if (!filename) error("out of memory"); filename[0] = 0; if (prefix){ HDstrcpy(filename, prefix); HDstrcat(filename, "/"); } HDstrcat(filename, ZIP_PERF_FILE); }
/*---------------------------------------------------------------------------- * Name: h5_env_nocleanup_c * Purpose: Determines the state of the environment variable HDF5_NOCLEANUP * Input: none * Output: status: 1 - HDF5_NOCLEANUP is set * 0 - HDF5_NOCLEANUP is not set * Returns: none * Programmer: M.S. Breitenfeld * September 30, 3008 * Modifications: *---------------------------------------------------------------------------*/ void nh5_env_nocleanup_c(int_f *status) { *status = (int_f)0; if (HDgetenv("HDF5_NOCLEANUP")) *status = (int_f)1; } /* h5_env_nocleanup_c */
/*------------------------------------------------------------------------- * Function: h5_make_local_copy * * Purpose: Make copy of file. Some tests write to data files under that * are under version control. Those tests should make a copy of * the versioned file and write to the copy. This function * prepends srcdir to the name of the file to be copied and uses * the name of the copy as is. * * Return: Success: 0 * * Failure: -1 * * Programmer: Larry Knox * Monday, October 13, 2009 * * Modifications: * *------------------------------------------------------------------------- */ hid_t h5_make_local_copy(char *origfilename, char *local_copy_name) { int fd_old = (-1), fd_new = (-1); /* File descriptors for copying data */ ssize_t nread; /* Number of bytes read in */ char buf[READ_BUF_SIZE]; /* Buffer for copying data */ char filename[FILENAME_BUF_SIZE] = ""; #ifdef H5_VMS HDstrcat(filename, origfilename); #else char * srcdir = HDgetenv("srcdir"); /* The source directory */ if(srcdir && ((HDstrlen(srcdir) + HDstrlen(origfilename) + 6) < FILENAME_BUF_SIZE)) { HDstrcpy(filename, srcdir); HDstrcat(filename, "/"); } HDstrcat(filename, origfilename); #endif /* Copy old file into temporary file */ if((fd_old = HDopen(filename, O_RDONLY, 0666)) < 0) return -1; if((fd_new = HDopen(local_copy_name, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) return -1; /* Copy data */ while((nread = HDread(fd_old, buf, (size_t)READ_BUF_SIZE)) > 0) HDwrite(fd_new, buf, (size_t)nread); /* Close files */ if(HDclose(fd_old) < 0) return -1; if(HDclose(fd_new) < 0) return -1; return 0; }
/*----------------------------------------------------------- * PURPOSE : * if environment variable H5TOOLS_BUFSIZE is set, * update H5TOOLS_BUFSIZE and H5TOOLS_MALLOCSIZE from the env * This can be called from each tools main() as part of initial act. * Note: this is more of debugging purpose for now. */ int h5tools_getenv_update_hyperslab_bufsize(void) { const char *env_str = NULL; long hyperslab_bufsize_mb; /* check if environment variable is set for the hyperslab buffer size */ if (NULL != (env_str = HDgetenv ("H5TOOLS_BUFSIZE"))) { errno = 0; hyperslab_bufsize_mb = HDstrtol(env_str, (char**)NULL, 10); if (errno != 0 || hyperslab_bufsize_mb <= 0) { /* TODO: later when pubilshed HDfprintf(rawerrorstream,"Error: Invalid environment variable \"H5TOOLS_BUFSIZE\" : %s\n", env_str); */ goto error; } /* convert MB to byte */ H5TOOLS_BUFSIZE = hyperslab_bufsize_mb * 1024 * 1024; H5TOOLS_MALLOCSIZE = MAX(H5TOOLS_BUFSIZE, H5TOOLS_MALLOCSIZE); } return (1); error: return (-1); }
/* * Enable alarm on test execution, configurable by environment variable */ void TestAlarmOn(void) { char * env_val = HDgetenv("HDF5_ALARM_SECONDS"); /* Alarm environment */ unsigned long alarm_sec = H5_ALARM_SEC; /* Number of seconds before alarm goes off */ /* Get the alarm value from the environment variable, if set */ if(env_val != NULL) alarm_sec = (unsigned)HDstrtoul(env_val, (char **)NULL, 10); /* Set the number of seconds before alarm goes off */ HDalarm((unsigned)alarm_sec); }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Inspects the HDF5_DRIVER environment variable, which * determines the VFD that the test harness will use with * the majority of the tests. * * Return: VFD supports SWMR: EXIT_SUCCESS * * VFD does not support SWMR * or failure: EXIT_FAILURE * *------------------------------------------------------------------------- */ int main(void) { char *driver = NULL; driver = HDgetenv("HDF5_DRIVER"); if(H5FD__supports_swmr_test(driver)) return EXIT_SUCCESS; else return EXIT_FAILURE; } /* end main() */
/*------------------------------------------------------------------------- * Function: read_new * * Purpose: Test reading a file with "new style" (compact) groups * * Return: Success: 0 * * Failure: -1 * * Programmer: Quincey Koziol * Monday, October 24, 2005 * *------------------------------------------------------------------------- */ static int read_new(hid_t fapl) { hid_t fid = (-1); /* File ID */ hid_t gid = (-1); /* Group ID */ char *srcdir = HDgetenv("srcdir"); /*where the src code is located*/ char filename[512]=""; /* test file name */ TESTING("reading new groups"); /* Generate correct name for test file by prepending the source path */ if(srcdir && ((HDstrlen(srcdir) + HDstrlen(FILE_NEW_GROUPS) + 1) < sizeof(filename))) { HDstrcpy(filename, srcdir); HDstrcat(filename, "/"); } HDstrcat(filename, FILE_NEW_GROUPS); /* Open file */ if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR; /* Attempt to open root group */ if((gid = H5Gopen(fid, "/")) < 0) TEST_ERROR; /* Attempt to open new "empty" group (should fail) */ H5E_BEGIN_TRY { if(H5Gopen(gid, "empty") >= 0) TEST_ERROR; } H5E_END_TRY; /* Attempt to open new group with link messages (should fail) */ H5E_BEGIN_TRY { if(H5Gopen(gid, "links") >= 0) TEST_ERROR; } H5E_END_TRY; /* Close root group */ if(H5Gclose(gid) < 0) TEST_ERROR; /* Close first file */ if(H5Fclose(fid)<0) TEST_ERROR; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Gclose(gid); H5Fclose(fid); } H5E_END_TRY; return 1; } /* end read_new() */
/*------------------------------------------------------------------------- * Function: main * * Purpose: Test external link with environment variable HDF5_EXT_PREFIX * * Return: Success: exit(0) * Failure: exit(non-zero) * * Programmer: Vailin Choi; Nov 2010 * *------------------------------------------------------------------------- */ int main(void) { hid_t fapl; /* File access property lists */ int nerrors = 0; /* Error from tests */ const char *env_h5_drvr; /* File Driver value from environment */ env_h5_drvr = HDgetenv("HDF5_DRIVER"); if(env_h5_drvr == NULL) env_h5_drvr = "nomatch"; h5_reset(); fapl = h5_fileaccess(); nerrors += external_link_env(fapl, FALSE) < 0 ? 1 : 0; /* Set the "use the latest version of the format" bounds for creating objects in the file */ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) TEST_ERROR nerrors += external_link_env(fapl, TRUE) < 0 ? 1 : 0; /* Verify symbol table messages are cached */ nerrors += (h5_verify_cached_stabs(FILENAME, fapl) < 0 ? 1 : 0); h5_cleanup(FILENAME, fapl); /* Results */ if(nerrors) { printf("***** %d External Link (HDF5_EXT_PREFIX) test%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "s"); exit(1); } printf("All external Link (HDF5_EXT_PREFIX) tests passed.\n"); /* clean up tmp directory created by external link tests */ HDrmdir(TMPDIR); return 0; error: puts("*** TESTS FAILED ***"); return 1; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Part 2 of a two-part H5Fflush() test. * * Return: Success: 0 * * Failure: 1 * * Programmer: Robb Matzke * Friday, October 23, 1998 * * Modifications: * Leon Arber * Sept. 26, 2006, expand to check for case where the was file not flushed. * *------------------------------------------------------------------------- */ int main(int argc, char* argv[]) { hid_t fapl1, fapl2; H5E_auto2_t func; char name[1024]; const char *envval = NULL; int mpi_size, mpi_rank; MPI_Comm comm = MPI_COMM_WORLD; MPI_Info info = MPI_INFO_NULL; MPI_Init(&argc, &argv); MPI_Comm_size(comm, &mpi_size); MPI_Comm_rank(comm, &mpi_rank); fapl1 = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_mpio(fapl1, comm, info); fapl2 = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_mpio(fapl2, comm, info); if(mpi_rank == 0) TESTING("H5Fflush (part2 with flush)"); /* Don't run this test using the core or split file drivers */ envval = HDgetenv("HDF5_DRIVER"); if (envval == NULL) envval = "nomatch"; if (HDstrcmp(envval, "core") && HDstrcmp(envval, "split")) { /* Check the case where the file was flushed */ h5_fixname(FILENAME[0], fapl1, name, sizeof name); if(check_file(name, fapl1)) { H5_FAILED() goto error; } else if(mpi_rank == 0)
/*------------------------------------------------------------------------- * Function: h5_fixname * * Purpose: Create a file name from a file base name like `test' and * return it through the FULLNAME (at most SIZE characters * counting the null terminator). The full name is created by * prepending the contents of HDF5_PREFIX (separated from the * base name by a slash) and appending a file extension based on * the driver supplied, resulting in something like * `ufs:/u/matzke/test.h5'. * * Return: Success: The FULLNAME pointer. * * Failure: NULL if BASENAME or FULLNAME is the null * pointer or if FULLNAME isn't large enough for * the result. * * Programmer: Robb Matzke * Thursday, November 19, 1998 * *------------------------------------------------------------------------- */ char * h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) { const char *prefix = NULL; const char *suffix = ".h5"; /* suffix has default */ char *ptr, last = '\0'; size_t i, j; hid_t driver = -1; int isppdriver = 0; /* if the driver is MPI parallel */ if (!base_name || !fullname || size < 1) return NULL; HDmemset(fullname, 0, size); /* figure out the suffix */ if(H5P_DEFAULT != fapl) { if((driver = H5Pget_driver(fapl)) < 0) return NULL; if(H5FD_FAMILY == driver) suffix = "%05d.h5"; else if (H5FD_MULTI == driver) suffix = NULL; } /* Must first check fapl is not H5P_DEFAULT (-1) because H5FD_XXX * could be of value -1 if it is not defined. */ isppdriver = H5P_DEFAULT != fapl && (H5FD_MPIO==driver); /* Check HDF5_NOCLEANUP environment setting. * (The #ifdef is needed to prevent compile failure in case MPI is not * configured.) */ if(isppdriver) { #ifdef H5_HAVE_PARALLEL if(getenv_all(MPI_COMM_WORLD, 0, "HDF5_NOCLEANUP")) SetTestNoCleanup(); #endif /* H5_HAVE_PARALLEL */ } else { if(HDgetenv("HDF5_NOCLEANUP")) SetTestNoCleanup(); } /* Check what prefix to use for test files. Process HDF5_PARAPREFIX and * HDF5_PREFIX. * Use different ones depending on parallel or serial driver used. * (The #ifdef is needed to prevent compile failure in case MPI is not * configured.) */ if(isppdriver) { #ifdef H5_HAVE_PARALLEL /* * For parallel: * First use command line option, then the environment * variable, then try the constant */ static int explained = 0; prefix = (paraprefix ? paraprefix : getenv_all(MPI_COMM_WORLD, 0, "HDF5_PARAPREFIX")); if (!prefix && !explained) { /* print hint by process 0 once. */ int mpi_rank; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); if (mpi_rank == 0) printf("*** Hint ***\n" "You can use environment variable HDF5_PARAPREFIX to " "run parallel test files in a\n" "different directory or to add file type prefix. E.g.,\n" " HDF5_PARAPREFIX=pfs:/PFS/user/me\n" " export HDF5_PARAPREFIX\n" "*** End of Hint ***\n"); explained = TRUE; #ifdef HDF5_PARAPREFIX prefix = HDF5_PARAPREFIX; #endif /* HDF5_PARAPREFIX */ } #endif /* H5_HAVE_PARALLEL */ } else { /* * For serial: * First use the environment variable, then try the constant */ prefix = HDgetenv("HDF5_PREFIX"); #ifdef HDF5_PREFIX if (!prefix) prefix = HDF5_PREFIX; #endif /* HDF5_PREFIX */ } /* Prepend the prefix value to the base name */ if (prefix && *prefix) { if (isppdriver) { /* This is a parallel system */ char *subdir; if (!HDstrcmp(prefix, HDF5_PARAPREFIX)) { /* * If the prefix specifies the HDF5_PARAPREFIX directory, then * default to using the "/tmp/$USER" or "/tmp/$LOGIN" * directory instead. */ char *user, *login; user = HDgetenv("USER"); login = HDgetenv("LOGIN"); subdir = (user ? user : login); if (subdir) { for (i = 0; i < size && prefix[i]; i++) fullname[i] = prefix[i]; fullname[i++] = '/'; for (j = 0; i < size && subdir[j]; ++i, ++j) fullname[i] = subdir[j]; } } if (!fullname[0]) { /* We didn't append the prefix yet */ HDstrncpy(fullname, prefix, size); fullname[size -1] = '\0'; } if (HDstrlen(fullname) + HDstrlen(base_name) + 1 < size) { /* * Append the base_name with a slash first. Multiple * slashes are handled below. */ h5_stat_t buf; if (HDstat(fullname, &buf) < 0) /* The directory doesn't exist just yet */ if (HDmkdir(fullname, (mode_t)0755) < 0 && errno != EEXIST) /* * We couldn't make the "/tmp/${USER,LOGIN}" * subdirectory. Default to PREFIX's original * prefix value. */ HDstrcpy(fullname, prefix); HDstrcat(fullname, "/"); HDstrcat(fullname, base_name); } else { /* Buffer is too small */ return NULL; } } else { if (HDsnprintf(fullname, size, "%s/%s", prefix, base_name) == (int)size) /* Buffer is too small */ return NULL; } } else if (HDstrlen(base_name) >= size) { /* Buffer is too small */ return NULL; } else { HDstrcpy(fullname, base_name); } /* Append a suffix */ if (suffix) { if (HDstrlen(fullname) + HDstrlen(suffix) >= size) return NULL; HDstrcat(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: getenv_all * * Purpose: Used to get the environment that the root MPI task has. * name specifies which environment variable to look for * val is the string to which the value of that environment * variable will be copied. * * NOTE: The pointer returned by this function is only * valid until the next call to getenv_all and the data * stored there must be copied somewhere else before any * further calls to getenv_all take place. * * Return: pointer to a string containing the value of the environment variable * NULL if the varialbe doesn't exist in task 'root's environment. * * Programmer: Leon Arber * 4/4/05 * * Modifications: * Use original getenv if MPI is not initialized. This happens * one uses the PHDF5 library to build a serial nature code. * Albert 2006/04/07 * *------------------------------------------------------------------------- */ char * getenv_all(MPI_Comm comm, int root, const char* name) { int mpi_size, mpi_rank, mpi_initialized; int len; static char* env = NULL; assert(name); MPI_Initialized(&mpi_initialized); if(!mpi_initialized) { /* use original getenv */ if(env) HDfree(env); env = HDgetenv(name); } /* end if */ else { MPI_Comm_rank(comm, &mpi_rank); MPI_Comm_size(comm, &mpi_size); assert(root < mpi_size); /* The root task does the getenv call * and sends the result to the other tasks */ if(mpi_rank == root) { env = HDgetenv(name); if(env) { len = (int)HDstrlen(env); MPI_Bcast(&len, 1, MPI_INT, root, comm); MPI_Bcast(env, len, MPI_CHAR, root, comm); } else { /* len -1 indicates that the variable was not in the environment */ len = -1; MPI_Bcast(&len, 1, MPI_INT, root, comm); } } else { MPI_Bcast(&len, 1, MPI_INT, root, comm); if(len >= 0) { if(env == NULL) env = (char*) HDmalloc((size_t)len+1); else if(HDstrlen(env) < (size_t)len) env = (char*) HDrealloc(env, (size_t)len+1); MPI_Bcast(env, len, MPI_CHAR, root, comm); env[len] = '\0'; } else { if(env) HDfree(env); env = NULL; } } } #ifndef NDEBUG MPI_Barrier(comm); #endif return env; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: H5O_mtime_decode() test. * * Return: Success: * * Failure: * * Programmer: Robb Matzke * Thursday, July 30, 1998 * * Modifications: * Added checks for old and new modification time messages * in pre-created datafiles (generated with gen_old_mtime.c and * gen_new_mtime.c). * Quincey Koziol * Friday, January 3, 2003 * *------------------------------------------------------------------------- */ int main(void) { hid_t fapl, file, space, dset; hsize_t size[1] = {2}; time_t now; struct tm *tm; H5O_info_t oi1, oi2; signed char buf1[32], buf2[32]; char filename[1024]; h5_reset(); fapl = h5_fileaccess(); TESTING("modification time messages"); /* Create the file, create a dataset, then close the file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; if((space = H5Screate_simple(1, size, NULL)) < 0) TEST_ERROR; if((dset = H5Dcreate2(file, "dset", H5T_NATIVE_SCHAR, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; now = HDtime(NULL); if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Sclose(space) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* * Open the file and get the modification time. We'll test the * H5Oget_info() arguments too: being able to stat something without * knowing its name. */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR; if(H5Oget_info_by_name(file, "dset", &oi1, H5P_DEFAULT) < 0) TEST_ERROR; if((dset = H5Dopen2(file, "dset", H5P_DEFAULT)) < 0) TEST_ERROR; if(H5Oget_info(dset, &oi2) < 0) TEST_ERROR; if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Compare addresses & times from the two ways of calling H5Oget_info() */ if(oi1.addr != oi2.addr || oi1.mtime != oi2.mtime) { H5_FAILED(); puts(" Calling H5Oget_info() with the dataset ID returned"); puts(" different values than calling it with a file and dataset"); puts(" name."); goto error; } /* Compare times -- they must be within 60 seconds of one another */ if(0 == oi1.mtime) { SKIPPED(); puts(" The modification time could not be decoded on this OS."); puts(" Modification times will be mantained in the file but"); puts(" cannot be queried on this system. See H5O_mtime_decode()."); return 0; } else if(HDfabs(HDdifftime(now, oi1.mtime)) > 60.0) { H5_FAILED(); tm = HDlocaltime(&(oi1.mtime)); HDstrftime((char*)buf1, sizeof buf1, "%Y-%m-%d %H:%M:%S", tm); tm = HDlocaltime(&now); HDstrftime((char*)buf2, sizeof buf2, "%Y-%m-%d %H:%M:%S", tm); printf(" got: %s\n ans: %s\n", buf1, buf2); goto error; } PASSED(); /* Check opening existing file with old-style modification time information * and make certain that the time is correct */ TESTING("accessing old modification time messages"); { char testfile[512]=""; char *srcdir = HDgetenv("srcdir"); if(srcdir && ((HDstrlen(srcdir) + strlen(TESTFILE1) + 1) < sizeof(testfile))){ HDstrcpy(testfile, srcdir); HDstrcat(testfile, "/"); } HDstrcat(testfile, TESTFILE1); file = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT); if(file >= 0){ if(H5Oget_info_by_name(file, "/Dataset1", &oi1, H5P_DEFAULT) < 0) TEST_ERROR; if(oi1.mtime != MTIME1) { H5_FAILED(); /* If this fails, examine H5Omtime.c. Modification time is very * system dependant (e.g., on Windows DST must be hardcoded). */ puts(" Old modification time incorrect"); goto error; } if(H5Fclose(file) < 0) TEST_ERROR; } else { H5_FAILED(); printf("***cannot open the pre-created old modification test file (%s)\n", testfile); goto error; } /* end else */ } PASSED(); /* Check opening existing file with new-style modification time information * and make certain that the time is correct */ TESTING("accessing new modification time messages"); { char testfile[512]=""; char *srcdir = HDgetenv("srcdir"); if(srcdir && ((HDstrlen(srcdir) + strlen(TESTFILE2) + 1) < sizeof(testfile))){ HDstrcpy(testfile, srcdir); HDstrcat(testfile, "/"); } HDstrcat(testfile, TESTFILE2); file = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT); if(file >= 0){ if(H5Oget_info_by_name(file, "/Dataset1", &oi2, H5P_DEFAULT) < 0) TEST_ERROR; if(oi2.mtime != MTIME2) { H5_FAILED(); puts(" Modification time incorrect."); goto error; } if(H5Fclose(file) < 0) TEST_ERROR; } else { H5_FAILED(); printf("***cannot open the pre-created old modification test file (%s)\n", testfile); goto error; } /* end else */ } PASSED(); /* All looks good */ puts("All modification time tests passed."); h5_cleanup(FILENAME, fapl); return 0; /* Something broke */ error: return 1; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Exercise private object header behavior and routines * * Return: Success: 0 * Failure: 1 * * Programmer: Robb Matzke * Tuesday, November 24, 1998 * *------------------------------------------------------------------------- */ int main(void) { hid_t fapl = -1, file = -1; hid_t dset = -1; H5F_t *f = NULL; char filename[1024]; H5O_hdr_info_t hdr_info; /* Object info */ H5O_loc_t oh_loc, oh_loc2; /* Object header locations */ time_t time_new, ro; int chunkno; /* Chunk index for message */ int i; /* Local index variable */ hbool_t b; /* Index for "new format" loop */ herr_t ret; /* Generic return value */ /* Reset library */ h5_reset(); fapl = h5_fileaccess(); h5_fixname(FILENAME[0], fapl, filename, sizeof filename); /* Loop over old & new formats */ for(b = FALSE; b <= TRUE; b++) { /* Display info about testing */ if(b) HDputs("Using new file format:"); else HDputs("Using default file format:"); /* Set the format to use for the file */ if(H5Pset_libver_bounds(fapl, (b ? H5F_LIBVER_LATEST : H5F_LIBVER_EARLIEST), H5F_LIBVER_LATEST) < 0) FAIL_STACK_ERROR /* test on object continuation block */ if(test_cont(filename, fapl) < 0) FAIL_STACK_ERROR /* Create the file to operate on */ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR if(NULL == (f = (H5F_t *)H5I_object(file))) FAIL_STACK_ERROR /* * Test object header creation * (using default group creation property list only because it's convenient) */ TESTING("object header creation"); HDmemset(&oh_loc, 0, sizeof(oh_loc)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0) FAIL_STACK_ERROR PASSED(); /* create a new message */ TESTING("message creation"); time_new = 11111111; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(ro != time_new) TEST_ERROR PASSED(); /* * Test modification of an existing message. */ TESTING("message modification"); time_new = 33333333; if(H5O_msg_write(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(ro != time_new) TEST_ERROR /* Make certain that chunk #0 in the object header can be encoded with a 1-byte size */ if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.space.total >=256) TEST_ERROR PASSED(); /* * Test creation of a bunch of messages one after another to see * what happens when the object header overflows in core. * (Use 'old' MTIME message here, because it is large enough to be * replaced with a continuation message (the new one is too small) * and the library doesn't understand how to migrate more than one * message from an object header currently - QAK - 10/8/03) */ TESTING("object header overflow in memory"); for(i = 0; i < 40; i++) { time_new = (i + 1) * 1000 + 1000000; if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR } /* end for */ if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR /* Make certain that chunk #0 in the object header will be encoded with a 2-byte size */ if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.space.total < 256) TEST_ERROR PASSED(); /* Close & re-open file & object header */ /* (makes certain that an object header in the new format that transitions * between 1-byte chunk #0 size encoding and 2-byte chunk #0 size encoding * works correctly - QAK) */ TESTING("close & re-open object header"); if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR if(H5Fclose(file) < 0) FAIL_STACK_ERROR if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) FAIL_STACK_ERROR if(NULL == (f = (H5F_t *)H5I_object(file))) FAIL_STACK_ERROR oh_loc.file = f; if(H5O_open(&oh_loc) < 0) FAIL_STACK_ERROR PASSED(); /* * Test creation of a bunch of messages one after another to see * what happens when the object header overflows on disk. */ TESTING("object header overflow on disk"); for(i = 0; i < 10; i++) { time_new = (i + 1) * 1000 + 10; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR } /* end for */ PASSED(); /* * Delete all time messages. */ TESTING("message deletion"); if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_remove(&oh_loc, H5O_MTIME_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(H5O_msg_read(&oh_loc, H5O_MTIME_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR PASSED(); /* * Constant message handling. * (can't write to them, but should be able to remove them) */ TESTING("constant message handling"); time_new = 22222222; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, H5O_MSG_FLAG_CONSTANT, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(ro != time_new) TEST_ERROR time_new = 33333333; H5E_BEGIN_TRY { ret = H5O_msg_write(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT); } H5E_END_TRY; if(ret >= 0) TEST_ERROR if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR PASSED(); /* release resources */ TESTING("object header closing"); if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR PASSED(); /* * Test moving message to first chunk */ TESTING("locking messages"); HDmemset(&oh_loc, 0, sizeof(oh_loc)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR /* Create second object header, to guarantee that first object header uses multiple chunks */ HDmemset(&oh_loc2, 0, sizeof(oh_loc2)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc2/*out*/) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc2, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR /* Fill object header with messages, creating multiple chunks */ for(i = 0; i < 10; i++) { time_new = (i + 1) * 1000 + 10; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR } /* end for */ /* Get # of object header chunks */ if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.nchunks != 2) TEST_ERROR /* Add message to lock to object header */ time_new = 11111111; if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Verify chunk index for message */ if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR if(chunkno != 1) TEST_ERROR /* Lock the message into the chunk */ if(H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Attempt to lock the message twice */ H5E_BEGIN_TRY { ret = H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT); } H5E_END_TRY; if(ret >= 0) TEST_ERROR /* Delete all the other messages, which would move the message into * chunk #0, if it wasn't locked */ if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Verify chunk index for message */ if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR if(chunkno != 1) TEST_ERROR /* Unlock the message */ if(H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Attempt to unlock the message twice */ H5E_BEGIN_TRY { ret = H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT); } H5E_END_TRY; if(ret >= 0) TEST_ERROR /* Close object headers */ if(H5O_close(&oh_loc2) < 0) FAIL_STACK_ERROR if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR /* Open first object header */ HDmemset(&oh_loc, 0, sizeof(oh_loc)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR /* Create second object header, to guarantee that first object header uses multiple chunks */ HDmemset(&oh_loc2, 0, sizeof(oh_loc2)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc2/*out*/) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc2, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR /* Add message to move to object header */ time_new = 11111111; if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Verify chunk index for message */ if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR if(chunkno != 0) TEST_ERROR /* Lock the message into the chunk */ if(H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Fill object header with messages, creating multiple chunks */ /* (would normally move locked message to new chunk) */ for(i = 0; i < 10; i++) { time_new = (i + 1) * 1000 + 10; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR } /* end for */ /* Get # of object header chunks */ if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.nchunks != 2) TEST_ERROR /* Verify chunk index for message */ if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR if(chunkno != 0) TEST_ERROR /* Unlock the message */ if(H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Close object headers */ if(H5O_close(&oh_loc2) < 0) FAIL_STACK_ERROR if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR PASSED(); /* Test reading datasets with undefined object header messages */ HDputs("Accessing objects with unknown header messages:"); { hid_t file2; /* File ID for 'bogus' object file */ hid_t sid; /* Dataspace ID */ hid_t aid; /* Attribute ID */ char testpath[512] = ""; char testfile[512] = ""; char *srcdir = HDgetenv("srcdir"); /* Build path to all test files */ if(srcdir && ((HDstrlen(srcdir) + 2) < sizeof(testpath))) { HDstrcpy(testpath, srcdir); HDstrcat(testpath, "/"); } /* end if */ /* Build path to test file */ if(srcdir && ((HDstrlen(testpath) + HDstrlen(FILE_BOGUS) + 1) < sizeof(testfile))) HDstrcpy(testfile, testpath); HDstrcat(testfile, FILE_BOGUS); TESTING("object with unknown header message and no flags set"); /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) */ if((file2 = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) TEST_ERROR /* Open the dataset with the unknown header message, but no extra flags */ if((dset = H5Dopen2(file2, "/Dataset1", H5P_DEFAULT)) < 0) TEST_ERROR if(H5Dclose(dset) < 0) TEST_ERROR PASSED(); TESTING("object with unknown header message & 'fail if unknown and open for write' flag set"); /* Open the dataset with the unknown header message, and "fail if unknown and open for write" flag */ if((dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT)) < 0) TEST_ERROR if(H5Dclose(dset) < 0) TEST_ERROR PASSED(); TESTING("object with unknown header message & 'mark if unknown' flag set"); /* Copy object with "mark if unknown" flag on message into file that can be modified */ if(H5Ocopy(file2, "/Dataset3", file, "/Dataset3", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR /* Close the file we created (to flush changes to file) */ if(H5Fclose(file) < 0) TEST_ERROR /* Re-open the file created, with read-only permissions */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR /* Open the dataset with the "mark if unknown" message */ if((dset = H5Dopen2(file, "/Dataset3", H5P_DEFAULT)) < 0) TEST_ERROR /* Check that the "unknown" message was _NOT_ marked */ if(H5O_check_msg_marked_test(dset, FALSE) < 0) FAIL_STACK_ERROR /* Close the dataset */ if(H5Dclose(dset) < 0) TEST_ERROR /* Close the file we created (to flush change to object header) */ if(H5Fclose(file) < 0) TEST_ERROR /* Re-open the file created */ if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR /* Open the dataset with the "mark if unknown" message */ if((dset = H5Dopen2(file, "/Dataset3", H5P_DEFAULT)) < 0) TEST_ERROR /* Create data space */ if((sid = H5Screate(H5S_SCALAR)) < 0) FAIL_STACK_ERROR /* Create an attribute, to get the object header into write access */ if((aid = H5Acreate2(dset, "Attr", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR /* Close dataspace */ if(H5Sclose(sid) < 0) FAIL_STACK_ERROR /* Close attribute */ if(H5Aclose(aid) < 0) FAIL_STACK_ERROR /* Close the dataset */ if(H5Dclose(dset) < 0) TEST_ERROR /* Close the file we created (to flush change to object header) */ if(H5Fclose(file) < 0) TEST_ERROR /* Re-open the file created */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR /* Re-open the dataset with the "mark if unknown" message */ if((dset = H5Dopen2(file, "/Dataset3", H5P_DEFAULT)) < 0) TEST_ERROR /* Check that the "unknown" message was marked */ if(H5O_check_msg_marked_test(dset, TRUE) < 0) FAIL_STACK_ERROR /* Close the dataset */ if(H5Dclose(dset) < 0) TEST_ERROR /* Close the file with the bogus objects */ if(H5Fclose(file2) < 0) TEST_ERROR PASSED(); /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) with RW intent this time */ if((file2 = H5Fopen(testfile, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) TEST_ERROR TESTING("object with unknown header message & 'fail if unknown and open for write' flag set"); /* Attempt to open the dataset with the unknown header message, and "fail if unknown and open for write" flag */ H5E_BEGIN_TRY { dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT); } H5E_END_TRY; if(dset >= 0) { H5Dclose(dset); TEST_ERROR } /* end if */ /* Close the file with the bogus objects */ if(H5Fclose(file2) < 0) TEST_ERROR PASSED(); } /* Close the file we created */ if(H5Fclose(file) < 0) TEST_ERROR /* Test object header creation metadata cache issues */ if(test_ohdr_cache(filename, fapl) < 0) TEST_ERROR } /* end for */
/*------------------------------------------------------------------------- * Function: main * * Purpose: This function coordinates the test of flush/refresh * functionality verification. It accepts either one, two or * no command line parameters. The main test routine runs * with no command line parameters specified, while verification * routines run with one or two command line parameters. * * Note: This program should not be run manually, as the * test is controlled by the testflushrefresh.sh script. Running * the flushrefresh program manually will result in failure, as * it will time out waiting for a signal from the test script * which will never come. * * Return: 0 on Success, 1 on Failure * * Programmer: Mike McGreevy * July 1, 2010 * * Modifications: * *------------------------------------------------------------------------- */ int main(int argc, const char *argv[]) { /* Variables */ const char *envval = NULL; /* Initialize library */ if(H5open() < 0) TEST_ERROR; /* Parse command line options */ if (argc == 1) { /* No arguments supplied. Run main test routines if * using sec2 or stdio driver, otherwise don't run * anything. */ /* Determine driver being used */ envval = HDgetenv("HDF5_DRIVER"); if(envval == NULL) envval = ""; if (!HDstrcmp(envval, "sec2") || !HDstrcmp(envval, "stdio") || !HDstrcmp(envval, "")) { if (test_flush() != SUCCEED) TEST_ERROR; if (test_refresh() != SUCCEED) TEST_ERROR; } /* end if */ else { HDfprintf(stdout, "Skipping all flush/refresh tests (only run with sec2 or stdio file drivers).\n"); /* Test script is expecting some signals, so send them out to end it. */ if (end_verification() < 0) TEST_ERROR; if (end_verification() < 0) TEST_ERROR; } /* end else */ } else if (argc == 3) { /* Two arguments supplied. Pass them to flush verification routine. */ if (flush_verification(argv[1], argv[2]) != 0) PROCESS_ERROR; } else if (argc == 2) { /* One argument supplied. Pass it to refresh verification routine. */ if (refresh_verification(argv[1]) != 0) PROCESS_ERROR; } else { /* Illegal number of arguments supplied. Error. */ HDfprintf(stderr, "Error. %d is an Invalid number of arguments to main().\n", argc); PROCESS_ERROR } /* end if */ return SUCCEED; error: /* Return */ return FAIL; } /* main */
/* * Function: do_cleanupfile * Purpose: Cleanup temporary file unless HDF5_NOCLEANUP is set. * Return: void * Programmer: Albert Cheng 2001/12/12 * Modifications: Support for file drivers. Christian Chilan, April, 2008 */ static void do_cleanupfile(iotype iot, char *filename) { char temp[2048]; int j; hid_t driver; if (clean_file_g == -1) clean_file_g = (HDgetenv("HDF5_NOCLEANUP")==NULL) ? 1 : 0; if (clean_file_g){ switch (iot) { case POSIXIO: HDremove(filename); break; case HDF5: driver = H5Pget_driver(fapl); if (driver == H5FD_FAMILY) { for (j = 0; /*void*/; j++) { HDsnprintf(temp, sizeof temp, filename, j); if (HDaccess(temp, F_OK) < 0) break; HDremove(temp); } } else if (driver == H5FD_CORE) { hbool_t backing; /* Whether the core file has backing store */ H5Pget_fapl_core(fapl,NULL,&backing); /* If the file was stored to disk with bacing store, remove it */ if(backing) HDremove(filename); } else if (driver == H5FD_MULTI) { H5FD_mem_t mt; assert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES); for (mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) { HDsnprintf(temp, sizeof temp, "%s-%c.h5", filename, multi_letters[mt]); HDremove(temp); /*don't care if it fails*/ } } else { HDremove(filename); } H5Pclose(fapl); break; default: /* unknown request */ HDfprintf(stderr, "Unknown IO type request (%d)\n", (int)iot); HDassert(0 && "Unknown IO type"); break; } } }
/* * Function: sio_create_filename * Purpose: Create a new filename to write to. Determine the correct * suffix to append to the filename by the type of I/O we're * doing. Also, place in the /tmp/{$USER,$LOGIN} directory if * USER or LOGIN are specified in the environment. * Return: Pointer to filename or NULL * Programmer: Bill Wendling, 21. November 2001 * Modifications: Support for file drivers. Christian Chilan, April, 2008 */ static char * sio_create_filename(iotype iot, const char *base_name, char *fullname, size_t size, parameters *param) { const char *prefix, *suffix=""; char *ptr, last = '\0'; size_t i, j; vfdtype vfd; vfd = param->vfd; if (!base_name || !fullname || size < 1) return NULL; memset(fullname, 0, size); switch (iot) { case POSIXIO: suffix = ".posix"; break; case HDF5: suffix = ".h5"; if (vfd == family) suffix = "%05d.h5"; else if (vfd == multi) suffix = NULL; break; default: /* unknown request */ HDfprintf(stderr, "Unknown IO type request (%d)\n", (int)iot); HDassert(0 && "Unknown IO type"); break; } /* First use the environment variable and then try the constant */ prefix = HDgetenv("HDF5_PREFIX"); #ifdef HDF5_PREFIX if (!prefix) prefix = HDF5_PREFIX; #endif /* HDF5_PREFIX */ /* Prepend the prefix value to the base name */ if (prefix && *prefix) { /* If the prefix specifies the HDF5_PREFIX directory, then * default to using the "/tmp/$USER" or "/tmp/$LOGIN" * directory instead. */ register char *user, *login, *subdir; user = HDgetenv("USER"); login = HDgetenv("LOGIN"); subdir = (user ? user : login); if (subdir) { for (i = 0; i < size-1 && prefix[i]; i++) fullname[i] = prefix[i]; fullname[i++] = '/'; for (j = 0; i < size && subdir[j]; i++, j++) fullname[i] = subdir[j]; } else { /* We didn't append the prefix yet */ HDstrncpy(fullname, prefix, size); fullname[size - 1] = '\0'; } if ((HDstrlen(fullname) + HDstrlen(base_name) + 1) < size) { /* Append the base_name with a slash first. Multiple slashes are * handled below. */ h5_stat_t buf; if (HDstat(fullname, &buf) < 0) /* The directory doesn't exist just yet */ if (HDmkdir(fullname, 0755) < 0 && errno != EEXIST) { /* We couldn't make the "/tmp/${USER,LOGIN}" subdirectory. * Default to PREFIX's original prefix value. */ HDstrcpy(fullname, prefix); } HDstrcat(fullname, "/"); HDstrcat(fullname, base_name); } else { /* Buffer is too small */ return NULL; } } else if (strlen(base_name) >= size) { /* Buffer is too small */ return NULL; } else { HDstrcpy(fullname, base_name); } /* Append a suffix */ if (suffix) { if (HDstrlen(fullname) + HDstrlen(suffix) >= size) return NULL; HDstrcat(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; }
static void report_parameters(struct options *opts) { int i, rank; rank = opts->dset_rank; print_version("HDF5 Library"); /* print library version */ HDfprintf(output, "==== Parameters ====\n"); HDfprintf(output, "IO API="); print_io_api(opts->io_types); HDfprintf(output, "Number of iterations=%d\n", opts->num_iters); HDfprintf(output, "Dataset size="); for (i=0; i<rank; i++) recover_size_and_print((long long)opts->dset_size[i], " "); HDfprintf(output, "\n"); HDfprintf(output, "Transfer buffer size="); for (i=0; i<rank; i++) recover_size_and_print((long long)opts->buf_size[i], " "); HDfprintf(output, "\n"); if(opts->page_size) { HDfprintf(output, "Page Aggregation Enabled. Page size = %ld\n", opts->page_size); if(opts->page_buffer_size) HDfprintf(output, "Page Buffering Enabled. Page Buffer size = %ld\n", opts->page_buffer_size); else HDfprintf(output, "Page Buffering Disabled\n"); } else HDfprintf(output, "Page Aggregation Disabled\n"); HDfprintf(output, "Dimension access order="); for (i=0; i<rank; i++) recover_size_and_print((long long)opts->order[i], " "); HDfprintf(output, "\n"); if (opts->io_types & SIO_HDF5) { HDfprintf(output, "HDF5 data storage method="); if (opts->h5_use_chunks){ HDfprintf(output, "Chunked\n"); HDfprintf(output, "HDF5 chunk size="); for (i=0; i<rank; i++) recover_size_and_print((long long)opts->chk_size[i], " "); HDfprintf(output, "\n"); HDfprintf(output, "HDF5 dataset dimensions="); if (opts->h5_extendable) { HDfprintf(output, "Extendable\n"); } else { HDfprintf(output, "Fixed\n"); } } else { HDfprintf(output, "Contiguous\n"); } HDfprintf(output, "HDF5 file driver="); if (opts->vfd==sec2) { HDfprintf(output, "sec2\n"); } else if (opts->vfd==stdio) { HDfprintf(output, "stdio\n"); } else if (opts->vfd==core) { HDfprintf(output, "core\n"); } else if (opts->vfd==split) { HDfprintf(output, "split\n"); } else if (opts->vfd==multi) { HDfprintf(output, "multi\n"); } else if (opts->vfd==family) { HDfprintf(output, "family\n"); } else if (opts->vfd==direct) { HDfprintf(output, "direct\n"); } } { char *prefix = HDgetenv("HDF5_PREFIX"); HDfprintf(output, "Env HDF5_PREFIX=%s\n", (prefix ? prefix : "not set")); } HDfprintf(output, "==== End of Parameters ====\n"); HDfprintf(output, "\n"); }
/*------------------------------------------------------------------------- * 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; /* First use the environment variable, then the constant */ val = HDgetenv("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*/ HDstrncpy(s, val, sizeof s); s[sizeof(s)-1] = '\0'; if (NULL==(name=HDstrtok(s, " \t\n\r"))) return fapl; if (!HDstrcmp(name, "sec2")) { /* Unix read() and write() system calls */ if (H5Pset_fapl_sec2(fapl)<0) return -1; } else if (!HDstrcmp(name, "stdio")) { /* Standard C fread() and fwrite() system calls */ if (H5Pset_fapl_stdio(fapl)<0) return -1; } else if (!HDstrcmp(name, "core")) { /* In-memory driver settings (backing store on, 1 MB increment) */ if (H5Pset_fapl_core(fapl, (size_t)1, TRUE)<0) return -1; } else if (!HDstrcmp(name, "core_paged")) { /* In-memory driver with write tracking and paging on */ if (H5Pset_fapl_core(fapl, (size_t)1, TRUE)<0) return -1; if (H5Pset_core_write_tracking(fapl, TRUE, (size_t)4096)<0) return -1; } else if (!HDstrcmp(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 (!HDstrcmp(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]; H5FD_mem_t mt; HDmemset(memb_map, 0, sizeof memb_map); HDmemset(memb_fapl, 0, sizeof memb_fapl); HDmemset(memb_name, 0, sizeof memb_name); HDmemset(memb_addr, 0, sizeof memb_addr); HDassert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES); for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t, mt)) { memb_fapl[mt] = H5P_DEFAULT; sprintf(sv[mt], "%%s-%c.h5", multi_letters[mt]); memb_name[mt] = sv[mt]; memb_addr[mt] = (haddr_t)MAX(mt - 1, 0) * (HADDR_MAX / 10); } /* end for */ if (H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, FALSE)<0) { return -1; } } else if (!HDstrcmp(name, "family")) { hsize_t fam_size = 100*1024*1024; /*100 MB*/ /* Family of files, each 1MB and using the default driver */ if ((val=HDstrtok(NULL, " \t\n\r"))) fam_size = (hsize_t)(HDstrtod(val, NULL) * 1024*1024); if (H5Pset_fapl_family(fapl, fam_size, H5P_DEFAULT)<0) return -1; } else if (!HDstrcmp(name, "log")) { unsigned log_flags = H5FD_LOG_LOC_IO | H5FD_LOG_ALLOC; /* Log file access */ if ((val = HDstrtok(NULL, " \t\n\r"))) log_flags = (unsigned)HDstrtol(val, NULL, 0); if (H5Pset_fapl_log(fapl, NULL, log_flags, (size_t)0) < 0) return -1; } else if (!HDstrcmp(name, "direct")) { #ifdef H5_HAVE_DIRECT /* Linux direct read() and write() system calls. Set memory boundary, file block size, * and copy buffer size to the default values. */ if (H5Pset_fapl_direct(fapl, 1024, 4096, 8*4096)<0) return -1; #endif } else if(!HDstrcmp(name, "latest")) { /* use the latest format */ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) return -1; } else { /* Unknown driver */ return -1; } return fapl; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Part 1 of a two-part H5Fflush() test. * * Return: Success: 0 * * Failure: 1 * * Programmer: Robb Matzke * Friday, October 23, 1998 * * Modifications: * Leon Arber * Sept. 26, 2006, expand test to check for failure if H5Fflush is not called. * * *------------------------------------------------------------------------- */ int main(int argc, char* argv[]) { hid_t file1, file2, fapl; MPI_File *mpifh_p = NULL; char name[1024]; const char *envval = NULL; int mpi_size, mpi_rank; MPI_Comm comm = MPI_COMM_WORLD; MPI_Info info = MPI_INFO_NULL; MPI_Init(&argc, &argv); MPI_Comm_size(comm, &mpi_size); MPI_Comm_rank(comm, &mpi_rank); fapl = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_mpio(fapl, comm, info); if(mpi_rank == 0) TESTING("H5Fflush (part1)"); envval = HDgetenv("HDF5_DRIVER"); if(envval == NULL) envval = "nomatch"; if(HDstrcmp(envval, "split")) { /* Create the file */ h5_fixname(FILENAME[0], fapl, name, sizeof name); file1 = create_file(name, fapl); /* Flush and exit without closing the library */ if(H5Fflush(file1, H5F_SCOPE_GLOBAL) < 0) goto error; /* Create the other file which will not be flushed */ h5_fixname(FILENAME[1], fapl, name, sizeof name); file2 = create_file(name, fapl); if(mpi_rank == 0) PASSED(); fflush(stdout); fflush(stderr); } /* end if */ else { SKIPPED(); puts(" Test not compatible with current Virtual File Driver"); } /* end else */ /* * Some systems like AIX do not like files not closed when MPI_Finalize * is called. So, we need to get the MPI file handles, close them by hand. * Then the _exit is still needed to stop at_exit from happening in some systems. * Note that MPIO VFD returns the address of the file-handle in the VFD struct * because MPI_File_close wants to modify the file-handle variable. */ /* close file1 */ if(H5Fget_vfd_handle(file1, fapl, (void **)&mpifh_p) < 0) { printf("H5Fget_vfd_handle for file1 failed\n"); goto error; } /* end if */ if(MPI_File_close(mpifh_p) != MPI_SUCCESS) { printf("MPI_File_close for file1 failed\n"); goto error; } /* end if */ /* close file2 */ if(H5Fget_vfd_handle(file2, fapl, (void **)&mpifh_p) < 0) { printf("H5Fget_vfd_handle for file2 failed\n"); goto error; } /* end if */ if(MPI_File_close(mpifh_p) != MPI_SUCCESS) { printf("MPI_File_close for file2 failed\n"); goto error; } /* end if */ fflush(stdout); fflush(stderr); HD_exit(0); error: fflush(stdout); fflush(stderr); HD_exit(1); }
/*------------------------------------------------------------------------- * Function: external_link_env (moved from links.c) * * Purpose: Verify that the target file is found successfully in "tmp" directory * via searching the pathnames set in the environment variable HDF5_EXT_PREFIX. * 1. Target link: "extlinks_env1" * 2. Main file: "extlinks_env0" * 3. Target file is created in: "tmp/extlinks_env1" * 4. The environment variable "HDF5_EXT_PREFIX" is set to ".:tmp" * * Return: Success: 0 * Failure: -1 * * Programmer: Vailin Choi * Feb. 20, 2008 * * Modifications: * *------------------------------------------------------------------------- */ static int external_link_env(hid_t fapl, hbool_t new_format) { hid_t fid = (-1); /* File ID */ hid_t gid = (-1); /* Group IDs */ const char *envval = NULL; /* Pointer to environment variable */ char filename1[NAME_BUF_SIZE], filename2[NAME_BUF_SIZE], filename3[NAME_BUF_SIZE]; /* Holders for filename */ if(new_format) TESTING("external links via environment variable (w/new group format)") else TESTING("external links via environment variable") if ((envval = HDgetenv("HDF5_EXT_PREFIX")) == NULL) envval = "nomatch"; if (HDstrcmp(envval, ".:tmp")) TEST_ERROR /* Set up name for main file:"extlinks_env0" */ h5_fixname(FILENAME[0], fapl, filename1, sizeof filename1); /* Set up name for external linked target file: "extlinks_env1" */ h5_fixname(FILENAME[1], fapl, filename2, sizeof filename2); /* Create "tmp" directory */ if(HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) TEST_ERROR /* Set up name (location) for the target file: "tmp/extlinks1" */ h5_fixname(FILENAME[2], fapl, filename3, sizeof filename3); /* Create the target file in "tmp" directory */ if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR /* Closing for target file */ if(H5Gclose(gid) < 0) TEST_ERROR if(H5Fclose(fid) < 0) TEST_ERROR /* Create the main file */ if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR /* Create external link to target file */ if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR /* Open object through external link */ H5E_BEGIN_TRY { gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); } H5E_END_TRY; /* Should be able to find the target file from pathnames set via HDF5_EXT_PREFIX */ if (gid < 0) { H5_FAILED(); puts(" Should have found the file in tmp directory."); goto error; } /* closing for main file */ if(H5Gclose(gid) < 0) TEST_ERROR if(H5Fclose(fid) < 0) TEST_ERROR PASSED(); return 0; error: H5E_BEGIN_TRY { H5Gclose (gid); H5Fclose (fid); } H5E_END_TRY; return -1; } /* end external_link_env() */