diff options
author | David Young <dyoung@hdfgroup.org> | 2019-12-09 16:30:58 (GMT) |
---|---|---|
committer | David Young <dyoung@hdfgroup.org> | 2019-12-09 16:30:58 (GMT) |
commit | c8f533cfc33ac743227cbed8eba361c715a2976f (patch) | |
tree | bcae5320f80bac774647cacbbd8493604f9384d2 /test/enc_dec_plist_cross_platform.c | |
parent | adcf8a315e82c0848d126e7e46b662930c081896 (diff) | |
download | hdf5-c8f533cfc33ac743227cbed8eba361c715a2976f.zip hdf5-c8f533cfc33ac743227cbed8eba361c715a2976f.tar.gz hdf5-c8f533cfc33ac743227cbed8eba361c715a2976f.tar.bz2 |
Merge all of my changes from merge-back-to-feature-vfd_swmr-attempt-1,
including the merge of `hdffv/hdf5/develop`, back to the branch that Vailin and
I share.
Now I need to put this branch on a fork with a less confusing name than
vchoi_fork!
Diffstat (limited to 'test/enc_dec_plist_cross_platform.c')
-rw-r--r-- | test/enc_dec_plist_cross_platform.c | 119 |
1 files changed, 58 insertions, 61 deletions
diff --git a/test/enc_dec_plist_cross_platform.c b/test/enc_dec_plist_cross_platform.c index 1fbb41b..cd77ba9 100644 --- a/test/enc_dec_plist_cross_platform.c +++ b/test/enc_dec_plist_cross_platform.c @@ -28,7 +28,7 @@ int main(void) { if(VERBOSE_MED) - printf("Encode/Decode property list endianess\n"); + HDprintf("Encode/Decode property list endianess\n"); /******* ENCODE/DECODE DCPLS *****/ TESTING("Default DCPL Encoding/Decoding"); @@ -156,78 +156,75 @@ error: return 1; } +static hid_t +read_and_decode_plist_file(const char *filename_prefix, unsigned config, char *filename, size_t filename_len) +{ + int fd; + size_t size; + const char *testfile; + void *buf = NULL; + hid_t plist = H5I_INVALID_HID; + + /* Generate filename from prefix and configuration word */ + if(HDsnprintf(filename, filename_len, "%s%s%s", filename_prefix, + config & CONFIG_64 ? "64" : "32", + config & CONFIG_LE ? "le" : "be") < 0) + TEST_ERROR + + /* Read file 1 */ + testfile = H5_get_srcdir_filename(filename); + if((fd = HDopen(testfile, O_RDONLY)) < 0) + TEST_ERROR + size = (size_t)HDlseek(fd, 0, SEEK_END); + HDlseek(fd, 0, SEEK_SET); + buf = HDmalloc(size); + if(HDread(fd, buf, size) < 0) + TEST_ERROR + HDclose(fd); + + /* Decode property lists */ + if((plist = H5Pdecode(buf)) < 0) + FAIL_STACK_ERROR +error: + if (buf != NULL) + HDfree(buf); + return plist; +} + static int test_plists(const char *filename_prefix) { - unsigned config_1, config_2; - int fd_1, fd_2; - size_t size_1 = 0, size_2 = 0; - void *buf_1 = NULL, *buf_2 = NULL; - hid_t plist_1, plist_2; - char filename[1024]; - const char *testfile; + int i; + unsigned config[2]; + hid_t plist[2]; + char filename[2][1024]; /* Iterate over all combinations of configurations */ - for(config_1 = 0; config_1 < (NCONFIG - 1); config_1++) - for(config_2 = config_1 + 1; config_2 < NCONFIG; config_2++) { - /* Generate filename for file 1 */ - if(HDsnprintf(filename, sizeof(filename), "%s%s%s", filename_prefix, - config_1 & CONFIG_64 ? "64" : "32", - config_1 & CONFIG_LE ? "le" : "be") < 0) - TEST_ERROR - - /* Read file 1 */ - testfile = H5_get_srcdir_filename(filename); - if((fd_1 = HDopen(testfile, O_RDONLY)) < 0) - TEST_ERROR - size_1 = (size_t)HDlseek(fd_1, (HDoff_t)0, SEEK_END); - HDlseek(fd_1, (HDoff_t)0, SEEK_SET); - buf_1 = (void *)HDmalloc(size_1); - if(HDread(fd_1, buf_1, size_1) < 0) - TEST_ERROR - HDclose(fd_1); - - /* Generate filename for file 2 */ - if(HDsnprintf(filename, sizeof(filename), "%s%s%s", filename_prefix, - config_2 & CONFIG_64 ? "64" : "32", - config_2 & CONFIG_LE ? "le" : "be") < 0) - TEST_ERROR - - /* Read file 1 */ - testfile = H5_get_srcdir_filename(filename); - if((fd_2 = HDopen(testfile, O_RDONLY)) < 0) - TEST_ERROR - size_2 = (size_t)HDlseek(fd_2, (HDoff_t)0, SEEK_END); - HDlseek(fd_2, (HDoff_t)0, SEEK_SET); - buf_2 = (void *)HDmalloc(size_2); - if(HDread(fd_2, buf_2, size_2) < 0) - TEST_ERROR - HDclose(fd_2); - - /* Decode property lists */ - if((plist_1 = H5Pdecode(buf_1)) < 0) - FAIL_STACK_ERROR - if((plist_2 = H5Pdecode(buf_2)) < 0) - FAIL_STACK_ERROR + for(config[0] = 0; config[0] < (NCONFIG - 1); config[0]++) { + for(config[1] = config[0] + 1; config[1] < NCONFIG; config[1]++) { + for (i = 0; i < 2; i++) { + plist[i] = read_and_decode_plist_file(filename_prefix, + config[i], filename[i], sizeof(filename[i])); + if (plist[i] == H5I_INVALID_HID) + goto error; + } /* Compare decoded property lists */ - if(!H5Pequal(plist_1, plist_2)) - FAIL_PUTS_ERROR("PLIST encoding/decoding comparison failed\n") - - /* Close */ - if((H5Pclose(plist_1)) < 0) - FAIL_STACK_ERROR - if((H5Pclose(plist_2)) < 0) - FAIL_STACK_ERROR + if(!H5Pequal(plist[0], plist[1])) + FAIL_PRINTF_ERROR("PLIST encoding/decoding comparison failed, " + "%s != %s\n", filename[0], filename[1]) - HDfree(buf_1); - HDfree(buf_2); - } /* end for */ + for (i = 0; i < 2; i++) { + if((H5Pclose(plist[i])) < 0) + FAIL_STACK_ERROR + } + } + } return 1; error: - printf("***** Plist Encode/Decode tests FAILED! *****\n"); + HDprintf("***** Plist Encode/Decode tests FAILED! *****\n"); return -1; } |