/*------------------------------------------------------------------------- * 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 * *------------------------------------------------------------------------- */ int h5_cleanup(const char *base_name[], hid_t fapl) { int retval = 0; if(GetTestCleanup()) { int i; for(i = 0; base_name[i]; i++) { char filename[1024]; char temp[2048]; hid_t driver; if(NULL == h5_fixname(base_name[i], fapl, filename, sizeof(filename))) continue; driver = H5Pget_driver(fapl); if(driver == H5FD_FAMILY) { int j; for(j = 0; /*void*/; j++) { HDsnprintf(temp, sizeof temp, filename, j); if(HDaccess(temp, F_OK) < 0) break; HDremove(temp); } /* end for */ } 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; HDassert(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*/ } /* end for */ } else { HDremove(filename); } } /* end for */ retval = 1; } /* end if */ H5Pclose(fapl); return retval; }
/*------------------------------------------------------------------------- * Function: test_create * * Purpose: Creates a named object that refers to indexed storage of raw * data. No raw data is stored. * * Return: Success: SUCCEED * * Failure: FAIL * * Programmer: Robb Matzke * Wednesday, October 15, 1997 * * Modifications: * *------------------------------------------------------------------------- */ static herr_t test_create(hid_t f, const char *prefix) { hid_t dataset; /* Dataset ID */ hsize_t dims[H5O_LAYOUT_NDIMS+1]; /* Dimensions of dataset */ hsize_t my_chunk_dims[H5O_LAYOUT_NDIMS+1]; /* Dimensions of chunks */ char name[256]; /* Dataset name */ unsigned u; /* Local index variable */ TESTING("istore create"); dims[0] = my_chunk_dims[0] = 1; for (u = 1; u <= H5S_MAX_RANK; u++) { /* Initialize the dimension size in this new dimension */ dims[u] = my_chunk_dims[u] = 2; /* Create chunked dataset of this dimensionality */ HDsnprintf(name, sizeof name, "%s_%02u", prefix, u); if ((dataset=new_object(f, name, (int)u, dims, my_chunk_dims)) < 0) return FAIL; /* Close dataset created */ if(H5Dclose(dataset) < 0) return FAIL; } PASSED(); return SUCCEED; }
/*------------------------------------------------------------------------- * Function: test_multi_opens * * Purpose: Private function for test_multi() to tests wrong ways of * reopening multi file. * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * Thursday, May 19, 2005 * *------------------------------------------------------------------------- */ static herr_t test_multi_opens(char *fname) { hid_t file; char super_name[1024]; /*name string "%%s-s.h5"*/ char sf_name[1024]; /*name string "multi_file-s.h5"*/ /* Case: reopen with the name of super file and default property list */ HDsnprintf(super_name, sizeof(super_name), "%%s-%c.h5", 's'); HDsnprintf(sf_name, sizeof(sf_name), super_name, fname); H5E_BEGIN_TRY { file = H5Fopen(sf_name, H5F_ACC_RDWR, H5P_DEFAULT); } H5E_END_TRY; return(file >= 0 ? -1 : 0); }
/*------------------------------------------------------------------------- * Function: test_family_opens * * Purpose: Private function for test_family() to tests wrong ways of * reopening family file. * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * Thursday, May 19, 2005 * *------------------------------------------------------------------------- */ static herr_t test_family_opens(char *fname, hid_t fa_pl) { hid_t file; char first_name[1024]; char wrong_name[1024]; int i; /* Case 1: reopen file with 1st member file name and default property list */ HDsnprintf(first_name, sizeof(first_name), fname, 0); H5E_BEGIN_TRY { file = H5Fopen(first_name, H5F_ACC_RDWR, H5P_DEFAULT); } H5E_END_TRY; if(file >= 0) TEST_ERROR /* Case 2: reopen file with correct name template but default property list */ H5E_BEGIN_TRY { file = H5Fopen(fname, H5F_ACC_RDWR, H5P_DEFAULT); } H5E_END_TRY; if(file >= 0) TEST_ERROR /* Case 3: reopen file with wrong member size */ if(H5Pset_fapl_family(fa_pl, (hsize_t)128, H5P_DEFAULT) < 0) TEST_ERROR; H5E_BEGIN_TRY { file = H5Fopen(fname, H5F_ACC_RDWR, fa_pl); } H5E_END_TRY; if(file >= 0) TEST_ERROR /* Case 4: reopen file with wrong name template */ HDstrcpy(wrong_name, fname); for(i = 0; i < 1024; i++) if(wrong_name[i] == '5') { wrong_name[i] = '4'; break; } if(H5Pset_fapl_family(fa_pl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0) TEST_ERROR; H5E_BEGIN_TRY { file = H5Fopen(wrong_name, H5F_ACC_RDWR, fa_pl); } H5E_END_TRY; if(file >= 0) TEST_ERROR return 0; error: return -1; } /* end test_family_opens() */
/*------------------------------------------------------------------------- * Function: enough_room * * Purpose: Tries to create a bunch of sparse files to see if quotas will * get in the way. Some systems also have problems opening * enough files and we'll check that too. * * Return: Success: Non-zero * * Failure: zero * * Programmer: Robb Matzke * Thursday, August 6, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int enough_room(hid_t fapl) { int ret_value=0; int fd[68]; size_t i, size = (size_t)1 << 30; char filename[1024], name[1024]; /* Initialize file descriptors */ for (i=0; i<NELMTS(fd); i++) fd[i] = -1; /* Get file name template */ HDassert(H5FD_FAMILY==H5Pget_driver(fapl)); h5_fixname(FILENAME[0], fapl, filename, sizeof(filename)); /* Create files */ for (i=0; i<NELMTS(fd); i++) { HDsnprintf(name, sizeof(name), filename, i); if ((fd[i]=HDopen(name, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) { goto done; } if ((off_t)size != HDlseek(fd[i], (off_t)size, SEEK_SET)) { goto done; } if (1!=HDwrite(fd[i], "X", (size_t)1)) { goto done; } } ret_value = 1; done: for (i=0; i<NELMTS(fd) && fd[i]>=0; i++) { HDsnprintf(name, sizeof(name), filename, i); if(HDclose(fd[i]) < 0) ret_value=0; HDremove(name); } return ret_value; }
/*------------------------------------------------------------------------- * Function: H5O_efl_debug * * Purpose: Prints debugging info for a message. * * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke * Tuesday, November 25, 1997 * *------------------------------------------------------------------------- */ static herr_t H5O_efl_debug(H5F_t H5_ATTR_UNUSED *f, hid_t H5_ATTR_UNUSED dxpl_id, const void *_mesg, FILE * stream, int indent, int fwidth) { const H5O_efl_t *mesg = (const H5O_efl_t *) _mesg; size_t u; FUNC_ENTER_NOAPI_NOINIT_NOERR /* check args */ HDassert(f); HDassert(mesg); HDassert(stream); HDassert(indent >= 0); HDassert(fwidth >= 0); HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, "Heap address:", mesg->heap_addr); HDfprintf(stream, "%*s%-*s %u/%u\n", indent, "", fwidth, "Slots used/allocated:", mesg->nused, mesg->nalloc); for(u = 0; u < mesg->nused; u++) { char buf[64]; HDsnprintf(buf, sizeof(buf), "File %u", (unsigned)u); HDfprintf(stream, "%*s%s:\n", indent, "", buf); HDfprintf(stream, "%*s%-*s \"%s\"\n", indent+3, "", MAX (fwidth-3, 0), "Name:", mesg->slot[u].name); HDfprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0), "Name offset:", (unsigned long)(mesg->slot[u].name_offset)); HDfprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0), "Offset of data in file:", (unsigned long)(mesg->slot[u].offset)); HDfprintf(stream, "%*s%-*s %lu\n", indent+3, "", MAX (fwidth-3, 0), "Bytes reserved for data:", (unsigned long)(mesg->slot[u].size)); } /* end for */ FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5O_efl_debug() */
/*------------------------------------------------------------------------- * Function: test_long_desc * * Purpose: Test long error description handling * * Return: Success: 0 * * Failure: -1 * * Programmer: Quincey Koziol * January 19, 2005 * *------------------------------------------------------------------------- */ static herr_t test_long_desc(void) { const char *format = "Testing very long description string, %s"; char *long_desc = NULL; char *full_desc = NULL; size_t u; const char *test_FUNC = "test_long_desc"; /* Allocate space for the error description info */ if(NULL == (long_desc = (char*)HDmalloc(LONG_DESC_SIZE))) TEST_ERROR; if(NULL == (full_desc = (char*)HDmalloc(LONG_DESC_SIZE + 128))) TEST_ERROR; /* Create the long part of the error description */ for(u = 0; u < LONG_DESC_SIZE; u++) long_desc[u] = 'A' + (u % 26); long_desc[LONG_DESC_SIZE - 1] = '\0'; /* Clear the default error stack */ if(H5Eclear2(H5E_DEFAULT) < 0) TEST_ERROR; /* Push an error with a long description */ if(H5Epush(H5E_DEFAULT, __FILE__, test_FUNC, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, format, long_desc) < 0) TEST_ERROR; /* Create the string that should be in the description. Must use HDsnprintf here * because snprintf is _snprintf on Windows */ HDsnprintf(full_desc, (size_t)(LONG_DESC_SIZE + 128), format, long_desc); /* Make certain that the description is correct */ if(H5Ewalk2(H5E_DEFAULT, H5E_WALK_UPWARD, long_desc_cb, full_desc) < 0) TEST_ERROR; /* Clear the default error stack again */ if(H5Eclear2(H5E_DEFAULT) < 0) TEST_ERROR; HDfree(long_desc); HDfree(full_desc); return(0); error: if(long_desc) HDfree(long_desc); if(full_desc) HDfree(full_desc); return(-1); } /* end test_long_desc() */
/*-------------------------------------------------------------------------- * Function: H5L_build_name * * Purpose: Prepend PREFIX to FILE_NAME and store in FULL_NAME * * Return: Non-negative on success/Negative on failure * * Programmer: Vailin Choi, April 2, 2008 * * Modification: Raymond Lu, 14 Jan. 2009 * Added support for OpenVMS pathname --------------------------------------------------------------------------*/ static herr_t H5L_build_name(char *prefix, char *file_name, char **full_name/*out*/) { size_t prefix_len; /* length of prefix */ size_t fname_len; /* Length of external link file name */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT prefix_len = HDstrlen(prefix); fname_len = HDstrlen(file_name); /* Allocate a buffer to hold the filename + prefix + possibly the delimiter + terminating null byte */ if(NULL == (*full_name = (char *)H5MM_malloc(prefix_len + fname_len + 2))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate filename buffer") /* Compose the full file name */ HDsnprintf(*full_name, (prefix_len + fname_len + 2), "%s%s%s", prefix, (H5_CHECK_DELIMITER(prefix[prefix_len - 1]) ? "" : H5_DIR_SEPS), file_name); done: FUNC_LEAVE_NOAPI(ret_value) } /* H5L_build_name() */
static int encode_plist(hid_t plist_id, int little_endian, int word_length, const char *filename_prefix) { int fd = 0; /* file descriptor */ herr_t ret = 0; void *temp_buf = NULL; size_t temp_size = 0; ssize_t write_size; char filename[1024]; /* Generate filename */ if((ret = HDsnprintf(filename, sizeof(filename), "%s%d%s", filename_prefix, word_length, little_endian ? "le" : "be")) < 0) HDassert(ret > 0); /* first call to encode returns only the size of the buffer needed */ if((ret = H5Pencode(plist_id, NULL, &temp_size)) < 0) HDassert(ret > 0); temp_buf = (void *)HDmalloc(temp_size); HDassert(temp_buf); if((ret = H5Pencode(plist_id, temp_buf, &temp_size)) < 0) HDassert(ret > 0); fd = HDopen(filename, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW); HDassert(fd > 0); write_size = HDwrite(fd, temp_buf, temp_size); HDassert(write_size == (ssize_t)temp_size); HDclose(fd); HDfree(temp_buf); return 1; }
/*------------------------------------------------------------------------- * Function: h5_get_file_size * * Purpose: Get the current size of a file (in bytes) * * Return: Success: Size of file in bytes * Failure: -1 * * Programmer: Quincey Koziol * Saturday, March 22, 2003 * *------------------------------------------------------------------------- */ h5_stat_size_t h5_get_file_size(const char *filename, hid_t fapl) { char temp[2048]; /* Temporary buffer for file names */ h5_stat_t sb; /* Structure for querying file info */ int j = 0; if(fapl == H5P_DEFAULT) { /* Get the file's statistics */ if(0 == HDstat(filename, &sb)) return((h5_stat_size_t)sb.st_size); } /* end if */ else { hid_t driver; /* VFD used for file */ /* Get the driver used when creating the file */ if((driver = H5Pget_driver(fapl)) < 0) return(-1); /* Check for simple cases */ if(driver == H5FD_SEC2 || driver == H5FD_STDIO || driver == H5FD_CORE || #ifdef H5_HAVE_PARALLEL driver == H5FD_MPIO || #endif /* H5_HAVE_PARALLEL */ #ifdef H5_HAVE_WINDOWS driver == H5FD_WINDOWS || #endif /* H5_HAVE_WINDOWS */ #ifdef H5_HAVE_DIRECT driver == H5FD_DIRECT || #endif /* H5_HAVE_DIRECT */ driver == H5FD_LOG) { /* Get the file's statistics */ if(0 == HDstat(filename, &sb)) return((h5_stat_size_t)sb.st_size); } /* end if */ else if(driver == H5FD_MULTI) { H5FD_mem_t mt; h5_stat_size_t tot_size = 0; HDassert(HDstrlen(multi_letters) == H5FD_MEM_NTYPES); for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t, mt)) { /* Create the filename to query */ HDsnprintf(temp, sizeof temp, "%s-%c.h5", filename, multi_letters[mt]); /* Check for existence of file */ if(0 == HDaccess(temp, F_OK)) { /* Get the file's statistics */ if(0 != HDstat(temp, &sb)) return(-1); /* Add to total size */ tot_size += (h5_stat_size_t)sb.st_size; } /* end if */ } /* end for */ /* Return total size */ return(tot_size); } /* end if */ else if(driver == H5FD_FAMILY) { h5_stat_size_t tot_size = 0; /* Try all filenames possible, until we find one that's missing */ for(j = 0; /*void*/; j++) { /* Create the filename to query */ HDsnprintf(temp, sizeof temp, filename, j); /* Check for existence of file */ if(HDaccess(temp, F_OK) < 0) break; /* Get the file's statistics */ if(0 != HDstat(temp, &sb)) return(-1); /* Add to total size */ tot_size += (h5_stat_size_t)sb.st_size; } /* end for */ /* Return total size */ return(tot_size); } /* end if */ else { HDassert(0 && "Unknown VFD!"); } /* end else */ } /* end else */ return(-1); } /* end get_file_size() */
/*------------------------------------------------------------------------- * 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: traverse_cb * * Purpose: Iterator callback for traversing objects in file *------------------------------------------------------------------------- */ static herr_t traverse_cb(hid_t loc_id, const char *path, const H5L_info_t *linfo, void *_udata) { trav_ud_traverse_t *udata = (trav_ud_traverse_t *)_udata; /* User data */ char *new_name = NULL; const char *full_name; const char *already_visited = NULL; /* Whether the link/object was already visited */ /* Create the full path name for the link */ if(udata->is_absolute) { size_t base_len = HDstrlen(udata->base_grp_name); size_t add_slash = base_len ? ((udata->base_grp_name)[base_len - 1] != '/') : 1; size_t new_name_len = base_len + add_slash + HDstrlen(path) + 1; if(NULL == (new_name = (char*)HDmalloc(new_name_len))) return(H5_ITER_ERROR); if(add_slash) HDsnprintf(new_name, new_name_len, "%s/%s", udata->base_grp_name, path); else HDsnprintf(new_name, new_name_len, "%s%s", udata->base_grp_name, path); full_name = new_name; } /* end if */ else full_name = path; /* Perform the correct action for different types of links */ if(linfo->type == H5L_TYPE_HARD) { H5O_info_t oinfo; /* Get information about the object */ if(H5Oget_info_by_name2(loc_id, path, &oinfo, udata->fields, H5P_DEFAULT) < 0) { if(new_name) HDfree(new_name); return(H5_ITER_ERROR); } /* end if */ /* If the object has multiple links, add it to the list of addresses * already visited, if it isn't there already */ if(oinfo.rc > 1) if(NULL == (already_visited = trav_addr_visited(udata->seen, oinfo.addr))) trav_addr_add(udata->seen, oinfo.addr, full_name); /* Make 'visit object' callback */ if(udata->visitor->visit_obj) if((*udata->visitor->visit_obj)(full_name, &oinfo, already_visited, udata->visitor->udata) < 0) { if(new_name) HDfree(new_name); return(H5_ITER_ERROR); } /* end if */ } /* end if */ else { /* Make 'visit link' callback */ if(udata->visitor->visit_lnk) if((*udata->visitor->visit_lnk)(full_name, linfo, udata->visitor->udata) < 0) { if(new_name) HDfree(new_name); return(H5_ITER_ERROR); } /* end if */ } /* end else */ if(new_name) HDfree(new_name); return(H5_ITER_CONT); } /* end traverse_cb() */
/*------------------------------------------------------------------------- * Function: test_family_compat * * Purpose: Tests the backward compatibility for FAMILY driver. * See if we can open files created with v1.6 library. * The source file was created by the test/file_handle.c * of the v1.6 library. Then tools/misc/h5repart.c was * used to concantenated. The command was "h5repart -m 5k * family_file%05d.h5 family_v16_%05d.h5". * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * June 3, 2005 * *------------------------------------------------------------------------- */ static herr_t test_family_compat(void) { hid_t file = (-1), fapl; hid_t dset; char dname[]="dataset"; char filename[1024]; char pathname[1024], pathname_individual[1024]; char newname[1024], newname_individual[1024]; int counter = 0; TESTING("FAMILY file driver backward compatibility"); /* Set property list and file name for FAMILY driver */ fapl = h5_fileaccess(); if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE2, H5P_DEFAULT) < 0) TEST_ERROR; h5_fixname(COMPAT_BASENAME, fapl, filename, sizeof filename); h5_fixname(FILENAME[3], fapl, newname, sizeof newname); pathname[0] = '\0'; HDstrcat(pathname, filename); /* The following code makes the copies of the family files in the source directory. * Since we're going to open the files with write mode, this protects the original * files. */ HDsnprintf(newname_individual, sizeof(newname_individual), newname, counter); HDsnprintf(pathname_individual, sizeof(pathname_individual), pathname, counter); while(h5_make_local_copy(pathname_individual, newname_individual) >= 0) { counter++; HDsnprintf(newname_individual, sizeof(newname_individual), newname, counter); HDsnprintf(pathname_individual, sizeof(pathname_individual), pathname, counter); } /* Make sure we can open the file. Use the read and write mode to flush the * superblock. */ if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; if((dset = H5Dopen2(file, dname, H5P_DEFAULT)) < 0) TEST_ERROR; if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Open the file again to make sure it isn't corrupted. */ if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; if((dset = H5Dopen2(file, dname, H5P_DEFAULT)) < 0) TEST_ERROR; if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; h5_cleanup(FILENAME, fapl); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(file); H5Pclose(fapl); } H5E_END_TRY; return -1; } /* end test_family_compat() */
hsize_t diff_attr(hid_t loc1_id, hid_t loc2_id, const char *path1, const char *path2, diff_opt_t *options) { hid_t attr1_id=-1; /* attr ID */ hid_t attr2_id=-1; /* attr ID */ hid_t space1_id=-1; /* space ID */ hid_t space2_id=-1; /* space ID */ hid_t ftype1_id=-1; /* file data type ID */ hid_t ftype2_id=-1; /* file data type ID */ int vstrtype1=0; /* ftype1 is a variable string */ int vstrtype2=0; /* ftype2 is a variable string */ hid_t mtype1_id=-1; /* memory data type ID */ hid_t mtype2_id=-1; /* memory data type ID */ size_t msize1; /* memory size of memory type */ size_t msize2; /* memory size of memory type */ void *buf1=NULL; /* data buffer */ void *buf2=NULL; /* data buffer */ int buf1hasdata=0; /* buffer has data */ int buf2hasdata=0; /* buffer has data */ hsize_t nelmts1; /* number of elements in dataset */ int rank1; /* rank of dataset */ int rank2; /* rank of dataset */ hsize_t dims1[H5S_MAX_RANK];/* dimensions of dataset */ hsize_t dims2[H5S_MAX_RANK];/* dimensions of dataset */ char *name1; char *name2; char np1[512]; char np2[512]; unsigned u; /* Local index variable */ hsize_t nfound = 0; hsize_t nfound_total = 0; int j; table_attrs_t * match_list_attrs = NULL; if( build_match_list_attrs(loc1_id, loc2_id, &match_list_attrs, options) < 0) goto error; /* if detect any unique extra attr */ if(match_list_attrs->nattrs_only1 || match_list_attrs->nattrs_only2) { /* exit will be 1 */ options->contents = 0; } for(u = 0; u < (unsigned)match_list_attrs->nattrs; u++) { if( (match_list_attrs->attrs[u].exist[0]) && (match_list_attrs->attrs[u].exist[1]) ) { name1 = name2 = match_list_attrs->attrs[u].name; /*-------------- * attribute 1 */ if((attr1_id = H5Aopen(loc1_id, name1, H5P_DEFAULT)) < 0) goto error; /*-------------- * attribute 2 */ if((attr2_id = H5Aopen(loc2_id, name2, H5P_DEFAULT)) < 0) goto error; /* get the datatypes */ if((ftype1_id = H5Aget_type(attr1_id)) < 0) goto error; vstrtype1 = H5Tis_variable_str(ftype1_id); if((ftype2_id = H5Aget_type(attr2_id)) < 0) goto error; vstrtype2 = H5Tis_variable_str(ftype2_id); /* no compare if either one but not both are variable string type */ if (vstrtype1 != vstrtype2){ if ((options->m_verbose||options->m_list_not_cmp)) parallel_print("Not comparable: one of attribute <%s/%s> or <%s/%s> is of variable length type\n", path1, name1, path2, name2); options->not_cmp = 1; return 0; } if((mtype1_id = h5tools_get_native_type(ftype1_id))<0) goto error; if((mtype2_id = h5tools_get_native_type(ftype2_id))<0) goto error; if((msize1 = H5Tget_size(mtype1_id))==0) goto error; if((msize2 = H5Tget_size(mtype2_id))==0) goto error; /* get the dataspace */ if((space1_id = H5Aget_space(attr1_id)) < 0) goto error; if((space2_id = H5Aget_space(attr2_id)) < 0) goto error; /* get dimensions */ if((rank1 = H5Sget_simple_extent_dims(space1_id, dims1, NULL)) < 0) goto error; if((rank2 = H5Sget_simple_extent_dims(space2_id, dims2, NULL)) < 0) goto error; /*---------------------------------------------------------------------- * check for comparable TYPE and SPACE *---------------------------------------------------------------------- */ /* pass dims1 and dims2 for maxdims as well since attribute's maxdims * are always same */ if( diff_can_type(ftype1_id, ftype2_id, rank1, rank2, dims1, dims2, dims1, dims2, name1, name2, options, 0) != 1 ) { if(H5Tclose(ftype1_id) < 0) goto error; if(H5Tclose(ftype2_id) < 0) goto error; if(H5Sclose(space1_id) < 0) goto error; if(H5Sclose(space2_id) < 0) goto error; if(H5Aclose(attr1_id) < 0) goto error; if(H5Aclose(attr2_id) < 0) goto error; if(H5Tclose(mtype1_id) < 0) goto error; if(H5Tclose(mtype2_id) < 0) goto error; continue; } /*----------------------------------------------------------------- * "upgrade" the smaller memory size *------------------------------------------------------------------ */ if (FAIL == match_up_memsize (ftype1_id, ftype2_id, &mtype1_id, &mtype2_id, &msize1, &msize2)) goto error; /*--------------------------------------------------------------------- * read *---------------------------------------------------------------------- */ nelmts1 = 1; for(j = 0; j < rank1; j++) nelmts1 *= dims1[j]; buf1 = (void *)HDmalloc((size_t)(nelmts1 * msize1)); buf2 = (void *)HDmalloc((size_t)(nelmts1 * msize2)); if(buf1 == NULL || buf2 == NULL){ parallel_print( "cannot read into memory\n" ); goto error; } if(H5Aread(attr1_id,mtype1_id,buf1) < 0){ parallel_print("Failed reading attribute1 %s/%s\n", path1, name1); goto error; }else buf1hasdata = 1; if(H5Aread(attr2_id,mtype2_id,buf2) < 0){ parallel_print("Failed reading attribute2 %s/%s\n", path2, name2); goto error; }else buf2hasdata = 1; /* format output string */ HDsnprintf(np1, sizeof(np1), "%s of <%s>", name1, path1); HDsnprintf(np2, sizeof(np1), "%s of <%s>", name2, path2); /*--------------------------------------------------------------------- * array compare *---------------------------------------------------------------------- */ /* always print name */ /* verbose (-v) and report (-r) mode */ if(options->m_verbose || options->m_report) { do_print_attrname("attribute", np1, np2); nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, options, np1, np2, mtype1_id, attr1_id, attr2_id); print_found(nfound); } /* quiet mode (-q), just count differences */ else if(options->m_quiet) { nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, options, np1, np2, mtype1_id, attr1_id, attr2_id); } /* the rest (-c, none, ...) */ else { nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, options, np1, np2, mtype1_id, attr1_id, attr2_id); /* print info if compatible and difference found */ if(nfound) { do_print_attrname("attribute", np1, np2); print_found(nfound); } /* end if */ } /* end else */ /*---------------------------------------------------------------------- * close *---------------------------------------------------------------------- */ /* Free buf1 and buf2, check both VLEN-data VLEN-string to reclaim any * VLEN memory first */ if(TRUE == h5tools_detect_vlen(mtype1_id)) H5Dvlen_reclaim(mtype1_id, space1_id, H5P_DEFAULT, buf1); HDfree(buf1); buf1 = NULL; if(TRUE == h5tools_detect_vlen(mtype2_id)) H5Dvlen_reclaim(mtype2_id, space2_id, H5P_DEFAULT, buf2); HDfree(buf2); buf2 = NULL; if(H5Tclose(ftype1_id) < 0) goto error; if(H5Tclose(ftype2_id) < 0) goto error; if(H5Sclose(space1_id) < 0) goto error; if(H5Sclose(space2_id) < 0) goto error; if(H5Aclose(attr1_id) < 0) goto error; if(H5Aclose(attr2_id) < 0) goto error; if(H5Tclose(mtype1_id) < 0) goto error; if(H5Tclose(mtype2_id) < 0) goto error; nfound_total += nfound; } } /* u */ table_attrs_free(match_list_attrs); return nfound_total; error: H5E_BEGIN_TRY { if(buf1) { if(buf1hasdata && TRUE == h5tools_detect_vlen(mtype1_id)) H5Dvlen_reclaim(mtype1_id, space1_id, H5P_DEFAULT, buf1); HDfree(buf1); } /* end if */ if(buf2) { if(buf2hasdata && TRUE == h5tools_detect_vlen(mtype2_id)) H5Dvlen_reclaim(mtype2_id, space2_id, H5P_DEFAULT, buf2); HDfree(buf2); } /* end if */ table_attrs_free(match_list_attrs); H5Tclose(ftype1_id); H5Tclose(ftype2_id); H5Tclose(mtype1_id); H5Tclose(mtype2_id); H5Sclose(space1_id); H5Sclose(space2_id); H5Aclose(attr1_id); H5Aclose(attr2_id); } H5E_END_TRY; options->err_stat = 1; return nfound_total; }
/*------------------------------------------------------------------------- * Function: test_logging_api * * Purpose: Tests the API calls that affect mdc logging * * Return: Success: 0 * Failure: -1 *------------------------------------------------------------------------- */ static herr_t test_logging_api(void) { hid_t fapl = -1; hbool_t is_enabled; hbool_t is_enabled_out; hbool_t start_on_access; hbool_t start_on_access_out; char *location = NULL; size_t size; hid_t fid; hid_t gid; hbool_t is_currently_logging; char group_name[8]; char filename[1024]; int i; TESTING("metadata cache log api calls"); fapl = h5_fileaccess(); h5_fixname(FILE_NAME, fapl, filename, sizeof filename); /* Set up metadata cache logging */ is_enabled = TRUE; start_on_access = FALSE; if(H5Pset_mdc_log_options(fapl, is_enabled, LOG_LOCATION, start_on_access) < 0) TEST_ERROR; /* Check to make sure that the property list getter returns the correct * location string buffer size; */ is_enabled_out = FALSE; start_on_access_out = TRUE; location = NULL; size = 999; if(H5Pget_mdc_log_options(fapl, &is_enabled_out, location, &size, &start_on_access_out) < 0) TEST_ERROR; if(size != strlen(LOG_LOCATION) + 1) TEST_ERROR; /* Check to make sure that the property list getter works */ if(NULL == (location = (char *)HDcalloc(size, sizeof(char)))) TEST_ERROR; if(H5Pget_mdc_log_options(fapl, &is_enabled_out, location, &size, &start_on_access_out) < 0) TEST_ERROR; if((is_enabled != is_enabled_out) || (start_on_access != start_on_access_out) || HDstrcmp(LOG_LOCATION, location)) TEST_ERROR; /* Create a file */ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) TEST_ERROR; if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; if(H5Pclose(fapl) < 0) TEST_ERROR; /* Check to see if the logging flags were set correctly */ is_enabled = FALSE; is_currently_logging = TRUE; if((H5Fget_mdc_logging_status(fid, &is_enabled, &is_currently_logging) < 0) || (is_enabled != TRUE) || (is_currently_logging != FALSE)) TEST_ERROR; /* Turn on logging and check flags */ if(H5Fstart_mdc_logging(fid) < 0) TEST_ERROR; is_enabled = FALSE; is_currently_logging = FALSE; if((H5Fget_mdc_logging_status(fid, &is_enabled, &is_currently_logging) < 0) || (is_enabled != TRUE) || (is_currently_logging != TRUE)) TEST_ERROR; /* Perform some manipulations */ for(i = 0; i < N_GROUPS; i++) { HDmemset(group_name, 0, 8); HDsnprintf(group_name, 8, "%d", i); if((gid = H5Gcreate2(fid, group_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; if(H5Gclose(gid) < 0) TEST_ERROR; } /* Turn off logging and check flags */ if(H5Fstop_mdc_logging(fid) < 0) TEST_ERROR; is_enabled = FALSE; is_currently_logging = TRUE; if((H5Fget_mdc_logging_status(fid, &is_enabled, &is_currently_logging) < 0) || (is_enabled != TRUE) || (is_currently_logging != FALSE)) TEST_ERROR; /* Clean up */ HDfree(location); if(H5Fclose(fid) < 0) TEST_ERROR; PASSED(); return 0; error: return 1; } /* test_logging_api() */
/* * 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: H5HG_debug * * Purpose: Prints debugging information about a global heap collection. * * Return: Non-negative on success/Negative on failure * * Programmer: Robb Matzke * [email protected] * Mar 27, 1998 * *------------------------------------------------------------------------- */ herr_t H5HG_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int fwidth) { unsigned u, nused, maxobj; unsigned j, k; H5HG_heap_t *h = NULL; uint8_t *p = NULL; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) /* check arguments */ HDassert(f); HDassert(H5F_addr_defined (addr)); HDassert(stream); HDassert(indent >= 0); HDassert(fwidth >= 0); if(NULL == (h = H5HG_protect(f, dxpl_id, addr, H5AC__READ_ONLY_FLAG))) HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect global heap collection"); HDfprintf(stream, "%*sGlobal Heap Collection...\n", indent, ""); HDfprintf(stream, "%*s%-*s %d\n", indent, "", fwidth, "Dirty:", (int)(h->cache_info.is_dirty)); HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, "Total collection size in file:", (unsigned long)(h->size)); for(u = 1, nused = 0, maxobj = 0; u < h->nused; u++) if(h->obj[u].begin) { nused++; if (u>maxobj) maxobj = u; } HDfprintf(stream, "%*s%-*s %u/%lu/", indent, "", fwidth, "Objects defined/allocated/max:", nused, (unsigned long)h->nalloc); if(nused) HDfprintf(stream, "%u\n", maxobj); else HDfprintf(stream, "NA\n"); HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, "Free space:", (unsigned long)(h->obj[0].size)); for(u = 1; u < h->nused; u++) if(h->obj[u].begin) { char buf[64]; HDsnprintf(buf, sizeof(buf), "Object %u", u); HDfprintf(stream, "%*s%s\n", indent, "", buf); HDfprintf(stream, "%*s%-*s %lu\n", indent + 3, "", MIN(fwidth - 3, 0), "Obffset in block:", (unsigned long)(h->obj[u].begin - h->chunk)); HDfprintf(stream, "%*s%-*s %d\n", indent + 3, "", MIN(fwidth - 3, 0), "Reference count:", h->obj[u].nrefs); HDfprintf(stream, "%*s%-*s %lu/%lu\n", indent + 3, "", MIN(fwidth - 3, 0), "Size of object body:", (unsigned long)(h->obj[u].size), (unsigned long)H5HG_ALIGN(h->obj[u].size)); p = h->obj[u].begin + H5HG_SIZEOF_OBJHDR(f); for(j = 0; j < h->obj[u].size; j += 16) { HDfprintf(stream, "%*s%04u: ", indent + 6, "", j); for(k = 0; k < 16; k++) { if(8 == k) HDfprintf(stream, " "); if(j + k < h->obj[u].size) HDfprintf(stream, "%02x ", p[j + k]); else HDfputs(" ", stream); } for(k = 0; k < 16 && j + k < h->obj[u].size; k++) { if(8 == k) HDfprintf(stream, " "); HDfputc(p[j + k]>' ' && p[j + k] <= '~' ? p[j + k] : '.', stream); } HDfprintf(stream, "\n"); } } done: if (h && H5AC_unprotect(f, dxpl_id, H5AC_GHEAP, addr, h, H5AC__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release object header"); FUNC_LEAVE_NOAPI(ret_value); } /* end H5HG_debug() */