From 568c3624de786dd3240fbddea4f5035febe6ee01 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Thu, 25 Apr 2019 01:07:42 -0700 Subject: Improvements to the H5Fis_accessible() and H5Fis_hdf5() tests in tfile.c. * General code tidying. * Expanded tests to work with multi-file VFDs. --- src/H5FDfamily.c | 4 +- src/H5FDmulti.c | 52 ++++++------ src/H5Fint.c | 2 +- test/h5test.c | 56 ++++++++++--- test/h5test.h | 1 + test/tfile.c | 247 ++++++++++++++++++++++++++++++++++--------------------- 6 files changed, 227 insertions(+), 135 deletions(-) diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c index 047fb25..c8893f9 100644 --- a/src/H5FDfamily.c +++ b/src/H5FDfamily.c @@ -715,7 +715,7 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id, (0==file->nmembs ? flags : t_flags), file->memb_fapl_id, HADDR_UNDEF); } H5E_END_TRY; if (!file->memb[file->nmembs]) { - if (0==file->nmembs) + if (0 == file->nmembs) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open member file") H5E_clear_stack(NULL); break; @@ -723,7 +723,7 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id, file->nmembs++; } - /* If the file is reopened and there's only one member file existing, this file maybe + /* If the file is reopened and there's only one member file existing, this file may be * smaller than the size specified through H5Pset_fapl_family(). Update the actual * member size. */ diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c index fac0909..6cfef55 100644 --- a/src/H5FDmulti.c +++ b/src/H5FDmulti.c @@ -981,8 +981,7 @@ H5FD_multi_fapl_free(void *_fa) *------------------------------------------------------------------------- */ static H5FD_t * -H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, - haddr_t maxaddr) +H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) { H5FD_multi_t *file=NULL; hid_t close_fapl=-1; @@ -996,7 +995,7 @@ H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, /* Check arguments */ if (!name || !*name) H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADVALUE, "invalid file name", NULL) - if (0==maxaddr || HADDR_UNDEF==maxaddr) + if (0 == maxaddr || HADDR_UNDEF == maxaddr) H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADRANGE, "bogus maxaddr", NULL) /* @@ -1007,41 +1006,41 @@ H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, */ if(NULL == (file = (H5FD_multi_t *)calloc((size_t)1, sizeof(H5FD_multi_t)))) H5Epush_ret(func, H5E_ERR_CLS, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed", NULL) - if(H5P_FILE_ACCESS_DEFAULT==fapl_id || H5FD_MULTI!=H5Pget_driver(fapl_id)) { + if(H5P_FILE_ACCESS_DEFAULT == fapl_id || H5FD_MULTI != H5Pget_driver(fapl_id)) { close_fapl = fapl_id = H5Pcreate(H5P_FILE_ACCESS); - if(H5Pset_fapl_multi(fapl_id, NULL, NULL, NULL, NULL, TRUE)<0) + if(H5Pset_fapl_multi(fapl_id, NULL, NULL, NULL, NULL, TRUE) < 0) H5Epush_goto(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTSET, "can't set property value", error) } fa = (const H5FD_multi_fapl_t *)H5Pget_driver_info(fapl_id); assert(fa); ALL_MEMBERS(mt) { - file->fa.memb_map[mt] = fa->memb_map[mt]; - file->fa.memb_addr[mt] = fa->memb_addr[mt]; - if (fa->memb_fapl[mt]>=0) - H5Iinc_ref(fa->memb_fapl[mt]); + file->fa.memb_map[mt] = fa->memb_map[mt]; + file->fa.memb_addr[mt] = fa->memb_addr[mt]; + if (fa->memb_fapl[mt] >= 0) + H5Iinc_ref(fa->memb_fapl[mt]); file->fa.memb_fapl[mt] = fa->memb_fapl[mt]; - if (fa->memb_name[mt]) - file->fa.memb_name[mt] = my_strdup(fa->memb_name[mt]); - else - file->fa.memb_name[mt] = NULL; + if (fa->memb_name[mt]) + file->fa.memb_name[mt] = my_strdup(fa->memb_name[mt]); + else + file->fa.memb_name[mt] = NULL; } END_MEMBERS; file->fa.relax = fa->relax; file->flags = flags; file->name = my_strdup(name); - if (close_fapl>=0) - if(H5Pclose(close_fapl)<0) + if (close_fapl >= 0) + if(H5Pclose(close_fapl) < 0) H5Epush_goto(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTCLOSEOBJ, "can't close property list", error) /* Compute derived properties and open member files */ - if (compute_next(file)<0) + if (compute_next(file) < 0) H5Epush_goto(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "compute_next() failed", error); - if (open_members(file)<0) + if (open_members(file) < 0) H5Epush_goto(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "open_members() failed", error); /* We must have opened at least the superblock file */ - if (H5FD_MEM_DEFAULT==(m=file->fa.memb_map[H5FD_MEM_SUPER])) + if (H5FD_MEM_DEFAULT == (m = file->fa.memb_map[H5FD_MEM_SUPER])) m = H5FD_MEM_SUPER; - if (NULL==file->memb[m]) + if (NULL == file->memb[m]) goto error; return (H5FD_t*)file; @@ -1049,13 +1048,14 @@ H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, error: /* Cleanup and fail */ if (file) { - ALL_MEMBERS(mt) { - if (file->memb[mt]) (void)H5FDclose(file->memb[mt]); - if (file->fa.memb_fapl[mt]>=0) (void)H5Idec_ref(file->fa.memb_fapl[mt]); - if (file->fa.memb_name[mt]) free(file->fa.memb_name[mt]); - } END_MEMBERS; - if (file->name) free(file->name); - free(file); + ALL_MEMBERS(mt) { + if (file->memb[mt]) (void)H5FDclose(file->memb[mt]); + if (file->fa.memb_fapl[mt] >= 0) (void)H5Idec_ref(file->fa.memb_fapl[mt]); + if (file->fa.memb_name[mt]) free(file->fa.memb_name[mt]); + } END_MEMBERS; + if (file->name) + free(file->name); + free(file); } return NULL; } diff --git a/src/H5Fint.c b/src/H5Fint.c index 5d03b3b..2e8771c 100644 --- a/src/H5Fint.c +++ b/src/H5Fint.c @@ -853,7 +853,7 @@ htri_t H5F__is_hdf5(const char *name, hid_t fapl_id) { H5FD_t *file = NULL; /* Low-level file struct */ - haddr_t sig_addr; /* Addess of hdf5 file signature */ + haddr_t sig_addr = HADDR_UNDEF; /* Addess of hdf5 file signature */ htri_t ret_value = FAIL; /* Return value */ FUNC_ENTER_PACKAGE diff --git a/test/h5test.c b/test/h5test.c index 8634a4d..3b17c72 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -115,8 +115,8 @@ const char *LIBVER_NAMES[] = { static H5E_auto2_t err_func = NULL; static herr_t h5_errors(hid_t estack, void *client_data); -static char * h5_fixname_real(const char *base_name, hid_t fapl, const char *suffix, - char *fullname, size_t size, hbool_t nest_printf); +static char *h5_fixname_real(const char *base_name, hid_t fapl, const char *_suffix, + char *fullname, size_t size, hbool_t nest_printf, hbool_t subst_for_superblock); /*------------------------------------------------------------------------- @@ -471,7 +471,33 @@ h5_test_init(void) char * h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) { - return (h5_fixname_real(base_name, fapl, ".h5", fullname, size, FALSE)); + return (h5_fixname_real(base_name, fapl, ".h5", fullname, size, FALSE, FALSE)); +} + + +/*------------------------------------------------------------------------- + * Function: h5_fixname_superblock + * + * Purpose: Like h5_fixname() but returns the name of the file you'd + * open to find the superblock. Useful for when you have to + * open a file with open(2) but the h5_fixname() string + * contains stuff like format strings. + * + * 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: Dana Robinson + * Spring 2019 + * + *------------------------------------------------------------------------- + */ +char * +h5_fixname_superblock(const char *base_name, hid_t fapl_id, char *fullname, size_t size) +{ + return (h5_fixname_real(base_name, fapl_id, ".h5", fullname, size, FALSE, TRUE)); } @@ -491,7 +517,7 @@ h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) char * h5_fixname_no_suffix(const char *base_name, hid_t fapl, char *fullname, size_t size) { - return (h5_fixname_real(base_name, fapl, NULL, fullname, size, FALSE)); + return (h5_fixname_real(base_name, fapl, NULL, fullname, size, FALSE, FALSE)); } @@ -517,7 +543,7 @@ h5_fixname_no_suffix(const char *base_name, hid_t fapl, char *fullname, size_t s char * h5_fixname_printf(const char *base_name, hid_t fapl, char *fullname, size_t size) { - return (h5_fixname_real(base_name, fapl, ".h5", fullname, size, TRUE)); + return (h5_fixname_real(base_name, fapl, ".h5", fullname, size, TRUE, FALSE)); } @@ -545,7 +571,7 @@ h5_fixname_printf(const char *base_name, hid_t fapl, char *fullname, size_t size */ static char * h5_fixname_real(const char *base_name, hid_t fapl, const char *_suffix, - char *fullname, size_t size, hbool_t nest_printf) + char *fullname, size_t size, hbool_t nest_printf, hbool_t subst_for_superblock) { const char *prefix = NULL; char *ptr, last = '\0'; @@ -565,17 +591,25 @@ h5_fixname_real(const char *base_name, hid_t fapl, const char *_suffix, return NULL; if(suffix) { - if(H5FD_FAMILY == driver) - suffix = nest_printf ? "%%05d.h5" : "%05d.h5"; - else if (H5FD_MULTI == driver) - suffix = NULL; + if(H5FD_FAMILY == driver) { + if(subst_for_superblock) + suffix = "00000.h5"; + else + suffix = nest_printf ? "%%05d.h5" : "%05d.h5"; + } + else if (H5FD_MULTI == driver) { + if(subst_for_superblock) + suffix = "-s.h5"; + else + 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); + 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 diff --git a/test/h5test.h b/test/h5test.h index ada52ad..448813e 100644 --- a/test/h5test.h +++ b/test/h5test.h @@ -133,6 +133,7 @@ extern "C" { H5TEST_DLL void h5_clean_files(const char *base_name[], hid_t fapl); H5TEST_DLL int h5_cleanup(const char *base_name[], hid_t fapl); H5TEST_DLL char *h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size); +H5TEST_DLL char *h5_fixname_superblock(const char *base_name, hid_t fapl, char *fullname, size_t size); H5TEST_DLL char *h5_fixname_no_suffix(const char *base_name, hid_t fapl, char *fullname, size_t size); H5TEST_DLL char *h5_fixname_printf(const char *base_name, hid_t fapl, char *fullname, size_t size); H5TEST_DLL hid_t h5_fileaccess(void); diff --git a/test/tfile.c b/test/tfile.c index acf2bd6..adeec94 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -1594,54 +1594,72 @@ test_file_perm2(void) ** H5Fis_accessible() API call. ** *****************************************************************/ +#define FILE_IS_ACCESSIBLE "tfile_is_accessible" static void test_file_is_accessible(const char *env_h5_drvr) { - hid_t fid; /* File opened with read-write permission */ - hid_t fcpl_id; /* File creation property list */ - hid_t fapl = -1; /* File access property list */ - int fd; /* POSIX file descriptor */ - char filename[FILENAME_LEN]; /* Filename to use */ - ssize_t nbytes; /* Number of bytes written */ - unsigned u; /* Local index variable */ - unsigned char buf[1024]; /* Buffer of data to write */ - htri_t status; /* Whether a file is an HDF5 file */ - hbool_t single_file_vfd; /* Whether VFD used is a single file */ - herr_t ret; + hid_t fid = H5I_INVALID_HID; /* File opened with read-write permission */ + hid_t fcpl_id = H5I_INVALID_HID; /* File creation property list */ + hid_t fapl_id = H5I_INVALID_HID; /* File access property list */ + int fd; /* POSIX file descriptor */ + char filename[FILENAME_LEN]; /* Filename to use */ + char sb_filename[FILENAME_LEN]; /* Name of file w/ superblock */ + ssize_t nbytes; /* Number of bytes written */ + unsigned u; /* Local index variable */ + unsigned char buf[1024]; /* Buffer of data to write */ + htri_t is_hdf5; /* Whether a file is an HDF5 file */ + int posix_ret; /* Return value from POSIX calls */ + herr_t ret; /* Return value from HDF5 calls */ /* Output message about test being performed */ MESSAGE(5, ("Testing Detection of HDF5 Files\n")); /* Get FAPL */ - fapl = h5_fileaccess(); - CHECK(fapl, FAIL, "H5Pcreate"); - h5_fixname(FILE1, fapl, filename, sizeof filename); + fapl_id = h5_fileaccess(); + CHECK(fapl_id, H5I_INVALID_HID, "H5Pcreate"); + + /* Fix up filenames + * For VFDs that create multiple files, we also need the name + * of the file with the superblock. With single-file VFDs, this + * will be equal to the one from h5_fixname(). + */ + h5_fixname(FILE_IS_ACCESSIBLE, fapl_id, filename, sizeof(filename)); + h5_fixname_superblock(FILE_IS_ACCESSIBLE, fapl_id, sb_filename, sizeof(filename)); + + /****************/ + /* Normal usage */ + /****************/ /* Create a file */ - fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); - CHECK(fid, FAIL, "H5Fcreate"); + fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); + CHECK(fid, H5I_INVALID_HID, "H5Fcreate"); /* Close file */ ret = H5Fclose(fid); CHECK(ret, FAIL, "H5Fclose"); /* Verify that the file is an HDF5 file */ - status = H5Fis_accessible(filename, fapl); - VERIFY(status, TRUE, "H5Fis_accessible"); + is_hdf5 = H5Fis_accessible(filename, fapl_id); + VERIFY(is_hdf5, TRUE, "H5Fis_accessible"); + /*******************************/ + /* Non-default user block size */ + /*******************************/ - /* This test is not currently working for the family VFD */ + /* This test is not currently working for the family VFD. + * There are failures when creating files with userblocks. + */ if(0 != HDstrcmp(env_h5_drvr, "family")) { /* Create a file creation property list with a non-default user block size */ fcpl_id = H5Pcreate(H5P_FILE_CREATE); - CHECK(fcpl_id, FAIL, "H5Pcreate"); + CHECK(fcpl_id, H5I_INVALID_HID, "H5Pcreate"); ret = H5Pset_userblock(fcpl_id, (hsize_t)2048); CHECK(ret, FAIL, "H5Pset_userblock"); /* Create file with non-default user block */ - fid = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl_id, fapl); - CHECK(fid, FAIL, "H5Fcreate"); + fid = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl_id, fapl_id); + CHECK(fid, H5I_INVALID_HID, "H5Fcreate"); /* Release file-creation property list */ ret = H5Pclose(fcpl_id); @@ -1652,37 +1670,53 @@ test_file_is_accessible(const char *env_h5_drvr) CHECK(ret, FAIL, "H5Fclose"); /* Verify that the file is an HDF5 file */ - status = H5Fis_accessible(filename, fapl); - VERIFY(status, TRUE, "H5Fis_accessible"); + is_hdf5 = H5Fis_accessible(filename, fapl_id); + VERIFY(is_hdf5, TRUE, "H5Fis_accessible"); } /* end if */ + /***********************/ + /* EMPTY non-HDF5 file */ + /***********************/ - /* This test only works for VFDs with a single file */ - single_file_vfd = (hbool_t)(HDstrcmp(env_h5_drvr, "split") && HDstrcmp(env_h5_drvr, "multi") && HDstrcmp(env_h5_drvr, "family")); - if(single_file_vfd) { - /* Create non-HDF5 file and check it */ - fd = HDopen(filename, O_RDWR|O_CREAT|O_TRUNC, H5_POSIX_CREATE_MODE_RW); - CHECK(fd, FAIL, "HDopen"); + /* Create non-HDF5 file and check it */ + fd = HDopen(sb_filename, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW); + CHECK(fd, (-1), "HDopen"); - /* Initialize information to write */ - for (u=0; u<1024; u++) - buf[u]=(unsigned char)u; + /* Close the file */ + posix_ret = HDclose(fd); + CHECK(posix_ret, (-1), "HDclose"); - /* Write some information */ - nbytes = HDwrite(fd, buf, (size_t)1024); - VERIFY(nbytes, 1024, "HDwrite"); + /* Verify that the file is NOT an HDF5 file */ + is_hdf5 = H5Fis_accessible(filename, fapl_id); + VERIFY(is_hdf5, FALSE, "H5Fis_accessible (empty non-HDF5 file)"); - /* Close the file */ - ret = HDclose(fd); - CHECK(ret, FAIL, "HDclose"); + /***************************/ + /* Non-empty non-HDF5 file */ + /***************************/ + + /* Create non-HDF5 file and check it */ + fd = HDopen(sb_filename, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW); + CHECK(fd, (-1), "HDopen"); + + /* Initialize information to write */ + for (u = 0; u < 1024; u++) + buf[u]=(unsigned char)u; + + /* Write some information */ + nbytes = HDwrite(fd, buf, (size_t)1024); + VERIFY(nbytes, 1024, "HDwrite"); + + /* Close the file */ + posix_ret = HDclose(fd); + CHECK(posix_ret, (-1), "HDclose"); + + /* Verify that the file is not an HDF5 file */ + is_hdf5 = H5Fis_accessible(filename, fapl_id); + VERIFY(is_hdf5, FALSE, "H5Fis_accessible (non-HDF5 file)"); - /* Verify that the file is not an HDF5 file */ - status = H5Fis_accessible(filename, fapl); - VERIFY(status, FALSE, "H5Fis_accessible"); - } /* end if */ /* Close property list */ - ret = H5Pclose(fapl); + ret = H5Pclose(fapl_id); CHECK(ret, FAIL, "H5Pclose"); } /* end test_file_is_accessible() */ @@ -1697,70 +1731,97 @@ test_file_is_accessible(const char *env_h5_drvr) *****************************************************************/ #ifndef H5_NO_DEPRECATED_SYMBOLS static void -test_file_ishdf5(void) +test_file_ishdf5(const char *env_h5_drvr) { - hid_t file; /* File opened with read-write permission */ - hid_t fcpl; /* File creation property list */ - hid_t fapl = -1; /* File access property list */ - int fd; /* File Descriptor */ - char filename[FILENAME_LEN]; /* Filename to use */ - ssize_t nbytes; /* Number of bytes written */ - unsigned u; /* Local index variable */ - unsigned char buf[1024]; /* Buffer of data to write */ - htri_t status; /* Whether a file is an HDF5 file */ - herr_t ret; + hid_t fid = H5I_INVALID_HID; /* File opened with read-write permission */ + hid_t fcpl_id = H5I_INVALID_HID; /* File creation property list */ + hid_t fapl_id = H5I_INVALID_HID; /* File access property list */ + int fd; /* POSIX file descriptor */ + char filename[FILENAME_LEN]; /* Filename to use */ + char sb_filename[FILENAME_LEN]; /* Name of file w/ superblock */ + ssize_t nbytes; /* Number of bytes written */ + unsigned u; /* Local index variable */ + unsigned char buf[1024]; /* Buffer of data to write */ + htri_t is_hdf5; /* Whether a file is an HDF5 file */ + int posix_ret; /* Return value from POSIX calls */ + herr_t ret; /* Return value from HDF5 calls */ /* Output message about test being performed */ MESSAGE(5, ("Testing Detection of HDF5 Files (using deprecated H5Fis_hdf5() call)\n")); /* Get FAPL */ - fapl = h5_fileaccess(); - CHECK(fapl, FAIL, "H5Pcreate"); - h5_fixname(FILE1, fapl, filename, sizeof filename); + fapl_id = h5_fileaccess(); + CHECK(fapl_id, H5I_INVALID_HID, "H5Pcreate"); + + /* Fix up filenames + * For VFDs that create multiple files, we also need the name + * of the file with the superblock. With single-file VFDs, this + * will be equal to the one from h5_fixname(). + */ + h5_fixname(FILE_IS_ACCESSIBLE, fapl_id, filename, sizeof(filename)); + h5_fixname_superblock(FILE_IS_ACCESSIBLE, fapl_id, sb_filename, sizeof(filename)); + + /****************/ + /* Normal usage */ + /****************/ /* Create a file */ - file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); - CHECK(file, FAIL, "H5Fcreate"); + fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); + CHECK(fid, H5I_INVALID_HID, "H5Fcreate"); /* Close file */ - ret = H5Fclose(file); + ret = H5Fclose(fid); CHECK(ret, FAIL, "H5Fclose"); /* Verify that the file is an HDF5 file */ - status = H5Fis_hdf5(filename); - VERIFY(status, TRUE, "H5Fis_hdf5"); + is_hdf5 = H5Fis_hdf5(sb_filename); + VERIFY(is_hdf5, TRUE, "H5Fis_hdf5"); + /*******************************/ + /* Non-default user block size */ + /*******************************/ - /* Create a file creation property list with a non-default user block size */ - fcpl = H5Pcreate(H5P_FILE_CREATE); - CHECK(fcpl, FAIL, "H5Pcreate"); + /* This test is not currently working for the family VFD. + * There are failures when creating files with userblocks. + */ + if(0 != HDstrcmp(env_h5_drvr, "family")) { + /* Create a file creation property list with a non-default user block size */ + fcpl_id = H5Pcreate(H5P_FILE_CREATE); + CHECK(fcpl_id, H5I_INVALID_HID, "H5Pcreate"); - ret = H5Pset_userblock(fcpl, (hsize_t)2048); - CHECK(ret, FAIL, "H5Pset_userblock"); + ret = H5Pset_userblock(fcpl_id, (hsize_t)2048); + CHECK(ret, FAIL, "H5Pset_userblock"); - /* Create file with non-default user block */ - file = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl); - CHECK(file, FAIL, "H5Fcreate"); + /* Create file with non-default user block */ + fid = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl_id, fapl_id); + CHECK(fid, H5I_INVALID_HID, "H5Fcreate"); - /* Release file-creation property list */ - ret = H5Pclose(fcpl); - CHECK(ret, FAIL, "H5Pclose"); + /* Release file creation property list */ + ret = H5Pclose(fcpl_id); + CHECK(ret, FAIL, "H5Pclose"); - /* Close file */ - ret = H5Fclose(file); - CHECK(ret, FAIL, "H5Fclose"); + /* Close file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); - /* Verify that the file is an HDF5 file */ - status = H5Fis_hdf5(filename); - VERIFY(status, TRUE, "H5Fis_hdf5"); + /* Verify that the file is an HDF5 file */ + is_hdf5 = H5Fis_hdf5(sb_filename); + VERIFY(is_hdf5, TRUE, "H5Fis_hdf5"); + } /* end if */ + /***************************/ + /* Non-empty non-HDF5 file */ + /***************************/ - /* Create non-HDF5 file and check it */ - fd = HDopen(filename, O_RDWR|O_CREAT|O_TRUNC, H5_POSIX_CREATE_MODE_RW); - CHECK(fd, FAIL, "HDopen"); + /* Create non-HDF5 file. Use the calculated superblock + * filename to avoid the format strings that will make + * open(2) sad. + */ + fd = HDopen(sb_filename, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW); + CHECK(fd, (-1), "HDopen"); /* Initialize information to write */ - for(u=0; u<1024; u++) + for(u = 0; u < 1024; u++) buf[u]=(unsigned char)u; /* Write some information */ @@ -1768,15 +1829,16 @@ test_file_ishdf5(void) VERIFY(nbytes, 1024, "HDwrite"); /* Close the file */ - ret = HDclose(fd); - CHECK(ret, FAIL, "HDclose"); + posix_ret = HDclose(fd); + CHECK(posix_ret, (-1), "HDclose"); /* Verify that the file is not an HDF5 file */ - status = H5Fis_hdf5(filename); - VERIFY(status, FALSE, "H5Fis_hdf5"); + is_hdf5 = H5Fis_hdf5(sb_filename); + VERIFY(is_hdf5, FALSE, "H5Fis_hdf5"); + /* Close property list */ - ret = H5Pclose(fapl); + ret = H5Pclose(fapl_id); CHECK(ret, FAIL, "H5Pclose"); } /* end test_file_ishdf5() */ @@ -7537,7 +7599,6 @@ test_deprec(void) void test_file(void) { - hbool_t single_file_vfd; /* Whether VFD used is a single file */ const char *env_h5_drvr; /* File Driver value from environment */ /* Output message about test being performed */ @@ -7547,7 +7608,6 @@ test_file(void) env_h5_drvr = HDgetenv("HDF5_DRIVER"); if(env_h5_drvr == NULL) env_h5_drvr = "nomatch"; - single_file_vfd = (hbool_t)(HDstrcmp(env_h5_drvr, "split") && HDstrcmp(env_h5_drvr, "multi") && HDstrcmp(env_h5_drvr, "family")); test_file_create(); /* Test file creation(also creation templates)*/ test_file_open(); /* Test file opening */ @@ -7593,10 +7653,7 @@ test_file(void) test_incr_filesize(); /* Test H5Fincrement_filesize() and H5Fget_eoa() */ test_min_dset_ohdr(); /* Test datset object header minimization */ #ifndef H5_NO_DEPRECATED_SYMBOLS - if(single_file_vfd) - test_file_ishdf5(); /* Test detecting HDF5 files correctly */ - else - MESSAGE(5, ("Skipping testing detection of HDF5 Files (using deprecated H5Fis_hdf5() call for non-single file VFDs)\n")); + test_file_ishdf5(env_h5_drvr); /* Test detecting HDF5 files correctly */ test_deprec(); /* Test deprecated routines */ #endif /* H5_NO_DEPRECATED_SYMBOLS */ } /* test_file() */ -- cgit v0.12