diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2019-04-25 08:07:42 (GMT) |
---|---|---|
committer | Dana Robinson <derobins@hdfgroup.org> | 2019-04-25 08:07:42 (GMT) |
commit | 568c3624de786dd3240fbddea4f5035febe6ee01 (patch) | |
tree | 6dd9ff590e14a0a574b649579fa452163d051935 /test | |
parent | 4fbe80acc27bc0e84eec9880c3c4257802e5bae5 (diff) | |
download | hdf5-568c3624de786dd3240fbddea4f5035febe6ee01.zip hdf5-568c3624de786dd3240fbddea4f5035febe6ee01.tar.gz hdf5-568c3624de786dd3240fbddea4f5035febe6ee01.tar.bz2 |
Improvements to the H5Fis_accessible() and H5Fis_hdf5() tests
in tfile.c.
* General code tidying.
* Expanded tests to work with multi-file VFDs.
Diffstat (limited to 'test')
-rw-r--r-- | test/h5test.c | 56 | ||||
-rw-r--r-- | test/h5test.h | 1 | ||||
-rw-r--r-- | test/tfile.c | 247 |
3 files changed, 198 insertions, 106 deletions
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() */ |