From 9ae37d08d95beac5bada3ffddbe3fd367723cefc Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Mon, 30 Sep 2019 15:02:02 -0500 Subject: fix for statement declare variable --- MANIFEST | 1 + src/H5FDhdfs.c | 63 +++--- src/H5FDros3.c | 53 ++--- test/CMakeLists.txt | 1 + test/external.c | 400 +++++++++++++++++++++---------------- test/external_fname.h | 37 ++++ tools/libtest/h5tools_test_utils.c | 3 +- 7 files changed, 331 insertions(+), 227 deletions(-) create mode 100644 test/external_fname.h diff --git a/MANIFEST b/MANIFEST index 74a69b3..eaa2ded 100644 --- a/MANIFEST +++ b/MANIFEST @@ -979,6 +979,7 @@ ./test/external_common.c ./test/external_common.h ./test/external_env.c +./test/external_fname.h ./test/error_test.c ./test/err_compat.c ./test/filter_error.h5 diff --git a/src/H5FDhdfs.c b/src/H5FDhdfs.c index 83d0202..819d200 100644 --- a/src/H5FDhdfs.c +++ b/src/H5FDhdfs.c @@ -64,7 +64,7 @@ static hid_t H5FD_HDFS_g = 0; #define HDFS_STATS_START_POWER 10 #define HDFS_STATS_BIN_COUNT 16 /* MUST BE GREATER THAN 0 */ - + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Calculate `BASE ^ (START_POWER + (INTERVAL * bin_i))` * Stores result at `(unsigned long long *) out_ptr`. @@ -87,7 +87,7 @@ static hid_t H5FD_HDFS_g = 0; /* array to hold pre-computed boundaries for stats bins */ static unsigned long long hdfs_stats_boundaries[HDFS_STATS_BIN_COUNT]; - + /*************************************************************************** * * Structure: hdfs_statsbin @@ -137,7 +137,7 @@ typedef struct { */ #define HDFS_HDFST_MAGIC 0x1AD5DE84 - + /*************************************************************************** * * Structure: hdfs_t @@ -186,7 +186,7 @@ typedef struct { hdfsFile file; } hdfs_t; - + /*-------------------------------------------------------------------------- * Function: H5FD_hdfs_handle_open * @@ -313,7 +313,7 @@ done: } /* H5FD_hdfs_handle_open() */ - + /*-------------------------------------------------------------------------- * Function: H5FD_hdfs_handle_close * @@ -375,7 +375,7 @@ done: #endif /* H5_HAVE_LIBHDFS */ - + /*************************************************************************** * * Structure: H5FD_hdfs_t @@ -529,7 +529,7 @@ static const H5FD_class_t H5FD_hdfs_g = { H5FL_DEFINE_STATIC(H5FD_hdfs_t); #endif /* H5_HAVE_LIBHDFS */ - + /*------------------------------------------------------------------------- * Function: H5FD__init_package * @@ -559,7 +559,7 @@ done: } /* H5FD__init_package() */ - + /*------------------------------------------------------------------------- * Function: H5FD_hdfs_init * @@ -581,6 +581,7 @@ hid_t H5FD_hdfs_init(void) { hid_t ret_value = H5I_INVALID_HID; /* Return value */ + unsigned int bin_i; FUNC_ENTER_NOAPI(FAIL) @@ -598,7 +599,7 @@ H5FD_hdfs_init(void) #if HDFS_STATS /* pre-compute statsbin boundaries */ - for (unsigned bin_i = 0; bin_i < HDFS_STATS_BIN_COUNT; bin_i++) { + for (bin_i = 0; bin_i < HDFS_STATS_BIN_COUNT; bin_i++) { unsigned long long value = 0; HDFS_STATS_POW(bin_i, &value) hdfs_stats_boundaries[bin_i] = value; @@ -612,7 +613,7 @@ done: } /* end H5FD_hdfs_init() */ - + /*--------------------------------------------------------------------------- * Function: H5FD_hdfs_term * @@ -643,7 +644,7 @@ H5FD_hdfs_term(void) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5FD_hdfs_term() */ - + /*------------------------------------------------------------------------- * Function: H5Pset_fapl_hdfs * @@ -696,7 +697,7 @@ done: } /* H5Pset_fapl_hdfs() */ - + /*------------------------------------------------------------------------- * Function: H5FD_hdfs_validate_config() * @@ -747,7 +748,7 @@ done: } /* H5FD_hdfs_validate_config() */ - + /*------------------------------------------------------------------------- * Function: H5Pget_fapl_hdfs * @@ -808,7 +809,7 @@ done: } /* H5Pget_fapl_hdfs() */ - + /*------------------------------------------------------------------------- * Function: H5FD_hdfs_fapl_get * @@ -855,7 +856,7 @@ done: } /* H5FD_hdfs_fapl_get() */ - + /*------------------------------------------------------------------------- * Function: H5FD_hdfs_fapl_copy * @@ -899,7 +900,7 @@ done: } /* H5FD_hdfs_fapl_copy() */ - + /*------------------------------------------------------------------------- * Function: H5FD_hdfs_fapl_free * @@ -930,7 +931,7 @@ H5FD_hdfs_fapl_free(void *_fa) } /* H5FD_hdfs_fapl_free() */ #if HDFS_STATS - + /*---------------------------------------------------------------------------- * * Function: hdfs_reset_stats() @@ -989,7 +990,7 @@ done: } /* hdfs_reset_stats */ #endif /* HDFS_STATS */ - + /*------------------------------------------------------------------------- * * Function: H5FD_hdfs_open() @@ -1138,7 +1139,7 @@ done: #endif /* H5_HAVE_LIBHDFS */ #if HDFS_STATS - + /*---------------------------------------------------------------------------- * * Function: hdfs_fprint_stats() @@ -1425,7 +1426,7 @@ done: } /* hdfs_fprint_stats */ #endif /* HDFS_STATS */ - + /*------------------------------------------------------------------------- * * Function: H5FD_hdfs_close() @@ -1508,7 +1509,7 @@ done: #endif /* H5_HAVE_LIBHDFS */ - + /*------------------------------------------------------------------------- * * Function: H5FD_hdfs_cmp() @@ -1592,7 +1593,7 @@ H5FD_hdfs_cmp( #endif /* H5_HAVE_LIBHDFS */ - + /*------------------------------------------------------------------------- * Function: H5FD_hdfs_query * @@ -1631,7 +1632,7 @@ H5FD_hdfs_query( FUNC_LEAVE_NOAPI(SUCCEED) } /* H5FD_hdfs_query() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_hdfs_get_eoa() @@ -1689,7 +1690,7 @@ H5FD_hdfs_get_eoa( #endif /* H5_HAVE_LIBHDFS */ - + /*------------------------------------------------------------------------- * * Function: H5FD_hdfs_set_eoa() @@ -1749,7 +1750,7 @@ H5FD_hdfs_set_eoa( #endif /* H5_HAVE_LIBHDFS */ - + /*------------------------------------------------------------------------- * * Function: H5FD_hdfs_get_eof() @@ -1807,7 +1808,7 @@ H5FD_hdfs_get_eof( #endif /* H5_HAVE_LIBHDFS */ - + /*------------------------------------------------------------------------- * * Function: H5FD_hdfs_get_handle() @@ -1880,7 +1881,7 @@ done: #endif /* H5_HAVE_LIBHDFS */ - + /*------------------------------------------------------------------------- * * Function: H5FD_hdfs_read() @@ -2014,7 +2015,7 @@ done: #endif /* H5_HAVE_LIBHDFS */ - + /*------------------------------------------------------------------------- * * Function: H5FD_hdfs_write() @@ -2059,7 +2060,7 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* H5FD_hdfs_write() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_hdfs_truncate() @@ -2103,7 +2104,7 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_hdfs_truncate() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_hdfs_lock() @@ -2136,7 +2137,7 @@ H5FD_hdfs_lock( FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5FD_hdfs_lock() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_hdfs_unlock() diff --git a/src/H5FDros3.c b/src/H5FDros3.c index a369ca2..75fcfd7 100644 --- a/src/H5FDros3.c +++ b/src/H5FDros3.c @@ -68,7 +68,7 @@ static hid_t H5FD_ROS3_g = 0; #define ROS3_STATS_START_POWER 10 #define ROS3_STATS_BIN_COUNT 16 /* MUST BE GREATER THAN 0 */ - + /* * Calculate `BASE ^ (START_POWER + (INTERVAL * bin_i))` * Stores result at `(unsigned long long *) out_ptr`. @@ -278,7 +278,7 @@ static const H5FD_class_t H5FD_ros3_g = { /* Declare a free list to manage the H5FD_ros3_t struct */ H5FL_DEFINE_STATIC(H5FD_ros3_t); - + /*------------------------------------------------------------------------- * Function: H5FD__init_package * @@ -307,7 +307,7 @@ done: } /* end H5FD__init_package() */ - + /*------------------------------------------------------------------------- * Function: H5FD_ros3_init * @@ -325,6 +325,7 @@ hid_t H5FD_ros3_init(void) { hid_t ret_value = H5I_INVALID_HID; + unsigned int bin_i; FUNC_ENTER_NOAPI(FAIL) @@ -338,7 +339,7 @@ H5FD_ros3_init(void) #if ROS3_STATS /* pre-compute statsbin boundaries */ - for (unsigned bin_i = 0; bin_i < ROS3_STATS_BIN_COUNT; bin_i++) { + for (bin_i = 0; bin_i < ROS3_STATS_BIN_COUNT; bin_i++) { unsigned long long value = 0; ROS3_STATS_POW(bin_i, &value) ros3_stats_boundaries[bin_i] = value; @@ -353,7 +354,7 @@ done: } /* end H5FD_ros3_init() */ - + /*--------------------------------------------------------------------------- * Function: H5FD_ros3_term * @@ -381,7 +382,7 @@ H5FD_ros3_term(void) } /* end H5FD_ros3_term() */ - + /*------------------------------------------------------------------------- * Function: H5Pset_fapl_ros3 * @@ -430,7 +431,7 @@ done: } /* end H5Pset_fapl_ros3() */ - + /*------------------------------------------------------------------------- * Function: H5FD_ros3_validate_config() * @@ -481,7 +482,7 @@ done: } /* end H5FD_ros3_validate_config() */ - + /*------------------------------------------------------------------------- * Function: H5Pget_fapl_ros3 * @@ -540,7 +541,7 @@ done: } /* end H5Pget_fapl_ros3() */ - + /*------------------------------------------------------------------------- * Function: H5FD_ros3_fapl_get * @@ -589,7 +590,7 @@ done: } /* end H5FD_ros3_fapl_get() */ - + /*------------------------------------------------------------------------- * Function: H5FD_ros3_fapl_copy * @@ -634,7 +635,7 @@ done: } /* end H5FD_ros3_fapl_copy() */ - + /*------------------------------------------------------------------------- * Function: H5FD_ros3_fapl_free * @@ -665,7 +666,7 @@ H5FD_ros3_fapl_free(void *_fa) } /* end H5FD_ros3_fapl_free() */ #if ROS3_STATS - + /*---------------------------------------------------------------------------- * * Function: ros3_reset_stats() @@ -723,7 +724,7 @@ done: #endif /* ROS3_STATS */ - + /*------------------------------------------------------------------------- * * Function: H5FD_ros3_open() @@ -880,7 +881,7 @@ done: } /* end H5FD_ros3_open() */ #if ROS3_STATS - + /*---------------------------------------------------------------------------- * * Function: ros3_fprint_stats() @@ -1169,7 +1170,7 @@ done: } /* ros3_fprint_stats */ #endif /* ROS3_STATS */ - + /*------------------------------------------------------------------------- * * Function: H5FD_ros3_close() @@ -1230,7 +1231,7 @@ done: } /* end H5FD_ros3_close() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_ros3_cmp() @@ -1395,7 +1396,7 @@ done: } /* H5FD_ros3_cmp() */ - + /*------------------------------------------------------------------------- * Function: H5FD_ros3_query * @@ -1436,7 +1437,7 @@ H5FD_ros3_query(const H5FD_t H5_ATTR_UNUSED *_file, } /* H5FD_ros3_query() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_ros3_get_eoa() @@ -1472,7 +1473,7 @@ H5FD_ros3_get_eoa(const H5FD_t *_file, } /* end H5FD_ros3_get_eoa() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_ros3_set_eoa() @@ -1509,7 +1510,7 @@ H5FD_ros3_set_eoa(H5FD_t *_file, } /* H5FD_ros3_set_eoa() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_ros3_get_eof() @@ -1544,7 +1545,7 @@ H5FD_ros3_get_eof(const H5FD_t *_file, } /* end H5FD_ros3_get_eof() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_ros3_get_handle() @@ -1587,7 +1588,7 @@ done: } /* end H5FD_ros3_get_handle() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_ros3_read() @@ -1685,7 +1686,7 @@ done: } /* end H5FD_ros3_read() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_ros3_write() @@ -1728,7 +1729,7 @@ done: } /* H5FD_ros3_write() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_ros3_truncate() @@ -1770,7 +1771,7 @@ done: } /* end H5FD_ros3_truncate() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_ros3_lock() @@ -1801,7 +1802,7 @@ H5FD_ros3_lock(H5FD_t H5_ATTR_UNUSED *_file, } /* end H5FD_ros3_lock() */ - + /*------------------------------------------------------------------------- * * Function: H5FD_ros3_unlock() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ef89fee..d879726 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,6 +22,7 @@ set (TEST_LIB_HEADERS ${HDF5_TEST_SOURCE_DIR}/h5test.h ${HDF5_TEST_SOURCE_DIR}/cache_common.h ${HDF5_TEST_SOURCE_DIR}/external_common.h + ${HDF5_TEST_SOURCE_DIR}/external_fname.h ${HDF5_TEST_SOURCE_DIR}/swmr_common.h ) diff --git a/test/external.c b/test/external.c index c9f0a9e..4d9fef0 100644 --- a/test/external.c +++ b/test/external.c @@ -15,9 +15,13 @@ * Programmer: Robb Matzke * Tuesday, March 3, 1998 * - * Purpose: Tests datasets stored in external raw files. + * Purpose: Tests datasets stored in external raw files. */ #include "external_common.h" +#include "external_fname.h" + +#define AEF_EXNAME_MAX_LEN 12 /* string buffer size for external file name */ + /* used in __add_external_files() */ /*------------------------------------------------------------------------- @@ -26,7 +30,7 @@ * Purpose: Determines whether two files contain the same data. * * Return: Success: nonzero if same, zero if different. - * Failure: zero + * Failure: zero * * Programmer: Robb Matzke * Wednesday, March 4, 1998 @@ -36,14 +40,17 @@ static hbool_t files_have_same_contents(const char *name1, const char *name2) { - int fd1 = 0, fd2 = 0; - ssize_t n1, n2; - char buf1[1024], buf2[1024]; + int fd1 = 0; + int fd2 = 0; + ssize_t n1 = 0; + ssize_t n2 = 0; + char buf1[1024]; + char buf2[1024]; hbool_t ret = FALSE; /* not equal until proven otherwise */ - if((fd1 = HDopen(name1, O_RDONLY)) < 0) + if ((fd1 = HDopen(name1, O_RDONLY)) < 0) goto out; - if((fd2 = HDopen(name2, O_RDONLY)) < 0) + if ((fd2 = HDopen(name2, O_RDONLY)) < 0) goto out; /* Loop until files are empty or we encounter a problem */ @@ -96,23 +103,21 @@ out: static int test_non_extendible(hid_t file) { - hid_t dcpl = -1; /* dataset creation properties */ - hid_t space = -1; /* data space */ - hid_t dset = -1; /* dataset */ - hsize_t cur_size[1]; /* data space current size */ - hsize_t max_size[1]; /* data space maximum size */ - int n; /* number of external files */ - char name[256]; /* external file name */ - off_t file_offset; /* external file offset */ - hsize_t file_size; /* sizeof external file segment */ - haddr_t dset_addr; /* address of dataset */ + hid_t dcpl = -1; /* dataset creation properties */ + hid_t space = -1; /* data space */ + hid_t dset = -1; /* dataset */ + hsize_t cur_size[1] = {100}; /* data space current size */ + hsize_t max_size[1] = {100}; /* data space maximum size */ + int n = 0; /* number of external files */ + off_t file_offset = 0; /* external file offset */ + hsize_t file_size = 0; /* sizeof external file segment */ + haddr_t dset_addr = HADDR_UNDEF; /* address of dataset */ TESTING("fixed-size data space, exact storage"); - /* Create the dataset */ + /* Create the dataset and close */ if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) FAIL_STACK_ERROR - cur_size[0] = max_size[0] = 100; if(H5Pset_external(dcpl, "ext1.data", (off_t)0, (hsize_t)(max_size[0] * sizeof(int))) < 0) FAIL_STACK_ERROR if((space = H5Screate_simple(1, cur_size, max_size)) < 0) @@ -147,27 +152,23 @@ test_non_extendible(hid_t file) HDputs(" Returned external count is wrong."); HDprintf(" got: %d\n ans: 1\n", n); goto error; - } /* end if */ + } - HDstrcpy(name + sizeof(name) - 4, "..."); - if(H5Pget_external(dcpl, 0, sizeof(name) - 4, name, &file_offset, &file_size) < 0) + /* Verify external file settings */ + if(H5Pget_external(dcpl, 0, 0, NULL, &file_offset, &file_size) < 0) FAIL_STACK_ERROR - - /* Check file offset */ if(file_offset != 0) { H5_FAILED(); HDputs(" Wrong file offset."); HDprintf(" got: %lu\n ans: 0\n", (unsigned long)file_offset); goto error; - } /* end if */ - - /* Check file size */ + } if(file_size != (max_size[0] * sizeof(int))) { H5_FAILED(); HDputs(" Wrong file size."); HDprintf(" got: %lu\n ans: %lu\n", (unsigned long)file_size, (unsigned long)max_size[0]*sizeof(int)); goto error; - } /* end if */ + } /* Done (dataspace was previously closed) */ if(H5Pclose(dcpl) < 0) FAIL_STACK_ERROR @@ -194,7 +195,7 @@ test_non_extendible(hid_t file) * Return: Success: 0 * Failure: 1 * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Monday, November 23, 1998 * *------------------------------------------------------------------------- @@ -202,18 +203,17 @@ test_non_extendible(hid_t file) static int test_too_small(hid_t file) { - hid_t dcpl = -1; /* dataset creation properties */ - hid_t space = -1; /* data space */ - hid_t dset = -1; /* dataset */ - hsize_t cur_size[1]; /* current data space size */ - hsize_t max_size[1]; /* maximum data space size */ + hid_t dcpl = -1; /* dataset creation properties */ + hid_t space = -1; /* data space */ + hid_t dset = -1; /* dataset */ + hsize_t cur_size[1] = {100}; /* current data space size */ + hsize_t max_size[1] = {100}; /* maximum data space size */ TESTING("external storage is too small"); if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) FAIL_STACK_ERROR - cur_size[0] = max_size[0] = 100; - if(H5Pset_external(dcpl, "ext1.data", (off_t)0, (hsize_t)(max_size[0] * sizeof(int) - 1)) < 0) + if(H5Pset_external(dcpl, "ext1.data", (off_t)0, (hsize_t)(max_size[0] * sizeof(int) - 1)) < 0) /* note -1 */ FAIL_STACK_ERROR if((space = H5Screate_simple(1, cur_size, max_size)) < 0) FAIL_STACK_ERROR @@ -248,10 +248,10 @@ test_too_small(hid_t file) * represent the current data and large enough to represent the * eventual size of the data. * - * Return: Success: 0 - * Failure: 1 + * Return: Success: 0 + * Failure: 1 * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Monday, November 23, 1998 * *------------------------------------------------------------------------- @@ -259,18 +259,16 @@ test_too_small(hid_t file) static int test_large_enough_current_eventual(hid_t file) { - hid_t dcpl = -1; /* dataset creation properties */ - hid_t space = -1; /* data space */ - hid_t dset = -1; /* dataset */ - hsize_t cur_size[1]; /* current data space size */ - hsize_t max_size[1]; /* maximum data space size */ + hid_t dcpl = -1; /* dataset creation properties */ + hid_t space = -1; /* data space */ + hid_t dset = -1; /* dataset */ + hsize_t cur_size[1] = {100}; /* current data space size */ + hsize_t max_size[1] = {200}; /* maximum data space size */ TESTING("extendible dataspace, exact external size"); if((dcpl = H5Pcreate (H5P_DATASET_CREATE)) < 0) FAIL_STACK_ERROR - cur_size[0] = 100; - max_size[0] = 200; if(H5Pset_external(dcpl, "ext1.data", (off_t)0, (hsize_t)(max_size[0] * sizeof(int))) < 0) FAIL_STACK_ERROR if((space = H5Screate_simple(1, cur_size, max_size)) < 0) @@ -312,19 +310,17 @@ error: static int test_large_enough_current_not_eventual(hid_t file) { - hid_t dcpl = -1; /* dataset creation properties */ - hid_t space = -1; /* data space */ - hid_t dset = -1; /* dataset */ - hsize_t cur_size[1]; /* current data space size */ - hsize_t max_size[1]; /* maximum data space size */ + hid_t dcpl = -1; /* dataset creation properties */ + hid_t space = -1; /* data space */ + hid_t dset = -1; /* dataset */ + hsize_t cur_size[1] = {100}; /* current data space size */ + hsize_t max_size[1] = {200}; /* maximum data space size */ TESTING("extendible dataspace, external storage is too small"); if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) FAIL_STACK_ERROR - cur_size[0] = 100; - max_size[0] = 200; - if(H5Pset_external(dcpl, "ext1.data", (off_t)0, (hsize_t)(max_size[0] * sizeof(int) - 1)) < 0) + if(H5Pset_external(dcpl, "ext1.data", (off_t)0, (hsize_t)(max_size[0] * sizeof(int) - 1)) < 0) /* note -1 */ FAIL_STACK_ERROR if((space = H5Screate_simple(1, cur_size, max_size)) < 0) FAIL_STACK_ERROR @@ -368,15 +364,14 @@ test_large_enough_current_not_eventual(hid_t file) static int test_unlimited(hid_t file) { - hid_t dcpl = -1; /* dataset creation properties */ - hid_t space = -1; /* data space */ - hid_t dset = -1; /* dataset */ - hsize_t cur_size[1]; /* data space current size */ - hsize_t max_size[1]; /* data space maximum size */ - int n; /* number of external files */ - char name[256]; /* external file name */ - off_t file_offset; /* external file offset */ - hsize_t file_size; /* sizeof external file segment */ + hid_t dcpl = -1; /* dataset creation properties */ + hid_t space = -1; /* data space */ + hid_t dset = -1; /* dataset */ + hsize_t cur_size[1] = {100}; /* data space current size */ + hsize_t max_size[1] = {H5S_UNLIMITED}; /* data space maximum size */ + int n; /* number of external files */ + off_t file_offset; /* external file offset */ + hsize_t file_size; /* sizeof external file segment */ TESTING("unlimited dataspace, unlimited external storage"); @@ -385,8 +380,6 @@ test_unlimited(hid_t file) FAIL_STACK_ERROR if(H5Pset_external(dcpl, "ext1.data", (off_t)0, H5F_UNLIMITED) < 0) FAIL_STACK_ERROR - cur_size[0] = 100; - max_size[0] = H5S_UNLIMITED; if((space = H5Screate_simple(1, cur_size, max_size)) < 0) FAIL_STACK_ERROR if((dset = H5Dcreate2(file, "dset5", H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) @@ -410,22 +403,20 @@ test_unlimited(hid_t file) goto error; } /* end if */ - HDstrcpy(name + sizeof(name) - 4, "..."); - if(H5Pget_external(dcpl, 0, sizeof(name) - 4, name, &file_offset, &file_size) < 0) + if(H5Pget_external(dcpl, 0, 0, NULL, &file_offset, &file_size) < 0) FAIL_STACK_ERROR if(file_offset != 0) { H5_FAILED(); HDputs(" Wrong file offset."); HDprintf(" got: %lu\n ans: 0\n", (unsigned long)file_offset); goto error; - } /* end if */ - + } if(H5F_UNLIMITED != file_size) { H5_FAILED(); HDputs(" Wrong file size."); HDprintf(" got: %lu\n ans: INF\n", (unsigned long)file_size); goto error; - } /* end if */ + } if(H5Pclose(dcpl) < 0) FAIL_STACK_ERROR if(H5Dclose(dset) < 0) FAIL_STACK_ERROR @@ -444,6 +435,56 @@ test_unlimited(hid_t file) /*------------------------------------------------------------------------- + * Function: __add_external_files + * + * Purpose: Add external file names to the DCPL with the given properties. + * Used in test_multiple_files(). + * Limit to no more than 999 external files. + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Jacob Smith + * 29 Sep 2019 + * + *------------------------------------------------------------------------- + */ +static int +__add_external_files( + hid_t dcpl_id, + unsigned int n_external_files, + off_t offset, + hsize_t max_ext_size) +{ + char exname[AEF_EXNAME_MAX_LEN+1]; + unsigned int i = 0; + + if (dcpl_id < 0) { + return -1; + } + for (i = 0; i < n_external_files; i++) { + if (HDsnprintf( + exname, + AEF_EXNAME_MAX_LEN, + "ext%d.data", + i+1) + > AEF_EXNAME_MAX_LEN) + { + HDfprintf(stderr, "External file %d overflows name buffer\n", i+1); + fflush(stderr); + return -1; + } + if (H5Pset_external(dcpl_id, exname, offset, max_ext_size) < 0) { + HDfprintf(stderr, "Problem adding external file %s\n", exname); + fflush(stderr); + return -1; + } + } + return 0; +} /* end __add_external_files() */ + + +/*------------------------------------------------------------------------- * Function: test_multiple_files * * Purpose: Test multiple external files for a dataset. @@ -459,35 +500,55 @@ test_unlimited(hid_t file) static int test_multiple_files(hid_t file) { - hid_t dcpl = -1; /* dataset creation properties */ - hid_t space = -1; /* dataspace */ - hid_t dset = -1; /* dataset */ - hsize_t cur_size[1]; /* data space current size */ - hsize_t max_size[1]; /* data space maximum size */ + hid_t dcpl = -1; /* dataset creation properties */ + hid_t space = -1; /* dataspace */ + hid_t dset = -1; /* dataset */ + hsize_t cur_size[1] = {100}; /* data space current size */ + hsize_t max_size[1] = {100}; /* data space maximum size */ + hsize_t max_ext_size; /* maximum size of external files */ + unsigned int n_external_files = 4; TESTING("multiple external files"); if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) FAIL_STACK_ERROR - cur_size[0] = max_size[0] = 100; + max_ext_size = (hsize_t)(sizeof(int) * max_size[0] / n_external_files); + + if (__add_external_files(dcpl, n_external_files, 0, max_ext_size) < 0) { + FAIL_STACK_ERROR; + } - if(H5Pset_external(dcpl, "ext1.data", (off_t)0, (hsize_t)(max_size[0]*sizeof(int)/4)) < 0) - FAIL_STACK_ERROR - if(H5Pset_external(dcpl, "ext2.data", (off_t)0, (hsize_t)(max_size[0]*sizeof(int)/4)) < 0) - FAIL_STACK_ERROR - if(H5Pset_external(dcpl, "ext3.data", (off_t)0, (hsize_t)(max_size[0]*sizeof(int)/4)) < 0) - FAIL_STACK_ERROR - if(H5Pset_external(dcpl, "ext4.data", (off_t)0, (hsize_t)(max_size[0]*sizeof(int)/4)) < 0) - FAIL_STACK_ERROR if((space = H5Screate_simple(1, cur_size, max_size)) < 0) FAIL_STACK_ERROR + if((dset = H5Dcreate2(file, "dset6", H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR if(H5Dclose(dset) < 0) FAIL_STACK_ERROR - if(H5Sclose(space) < 0) FAIL_STACK_ERROR if(H5Pclose(dcpl) < 0) FAIL_STACK_ERROR + /* Re-use space below */ + + /* ---------------------------------------------- + * Verify that too-small external files will fail + */ + if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) + FAIL_STACK_ERROR + + max_ext_size -= 1; + + if (__add_external_files(dcpl, n_external_files, 0, max_ext_size) < 0) { + FAIL_STACK_ERROR; + } + + H5E_BEGIN_TRY { + dset = H5Dcreate2(file, "dset7", H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT); + } H5E_END_TRY; + if(dset >= 0) + FAIL_PUTS_ERROR(" Small external files succeeded instead of failing."); + + if(H5Pclose(dcpl) < 0) FAIL_STACK_ERROR + if(H5Sclose(space) < 0) FAIL_STACK_ERROR PASSED(); return 0; @@ -519,9 +580,9 @@ error: static int test_add_to_unlimited(void) { - hid_t dcpl = -1; /* dataset creation properties */ - herr_t status; /* function return status */ - int n; /* number of external files */ + hid_t dcpl = -1; /* dataset creation properties */ + herr_t status = FAIL; /* function return status */ + int n = 0; /* number of external files */ TESTING("external file following unlimited file"); @@ -570,12 +631,12 @@ test_add_to_unlimited(void) static int test_overflow(void) { - hid_t dcpl = -1; /* dataset creation properties */ - herr_t status; /* return status */ + hid_t dcpl = -1; /* dataset creation properties */ + herr_t status = FAIL; /* return status */ TESTING("address overflow in external files"); - if((dcpl=H5Pcreate(H5P_DATASET_CREATE)) < 0) + if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) FAIL_STACK_ERROR if(H5Pset_external(dcpl, "ext1.data", (off_t)0, H5F_UNLIMITED-1) < 0) FAIL_STACK_ERROR @@ -615,19 +676,19 @@ test_overflow(void) static int test_read_file_set(hid_t fapl) { - hid_t file = -1; /* file to write to */ - hid_t dcpl = -1; /* dataset creation properties */ - hid_t space = -1; /* data space */ - hid_t dset = -1; /* dataset */ - hid_t grp = -1; /* group to emit diagnostics */ - size_t i; /* miscellaneous counter */ - char filename[1024]; /* file names */ - int part[PART_SIZE]; /* raw data buffer (partial) */ + hid_t file = -1; /* file to write to */ + hid_t dcpl = -1; /* dataset creation properties */ + hid_t space = -1; /* data space */ + hid_t dset = -1; /* dataset */ + hid_t grp = -1; /* group to emit diagnostics */ + size_t i = 0; /* miscellaneous counter */ + char filename[1024]; /* file names */ + int part[PART_SIZE]; /* raw data buffer (partial) */ int whole[TOTAL_SIZE]; /* raw data buffer (total) */ - hsize_t cur_size; /* current data space size */ - hid_t hs_space = -1; /* hyperslab data space */ - hsize_t hs_start = 30; /* hyperslab starting offset */ - hsize_t hs_count = 25; /* hyperslab size */ + hsize_t cur_size; /* current data space size */ + hid_t hs_space = -1; /* hyperslab data space */ + hsize_t hs_start = 30; /* hyperslab starting offset */ + hsize_t hs_count = 25; /* hyperslab size */ TESTING("read external dataset"); @@ -656,7 +717,7 @@ test_read_file_set(hid_t fapl) HDsnprintf(filename, sizeof(filename), "extern_%dr.raw", (int) i + 1); if(H5Pset_external(dcpl, filename, (off_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0) FAIL_STACK_ERROR - } /* end for */ + } /* Create the dataspace */ cur_size = TOTAL_SIZE; @@ -733,19 +794,19 @@ test_read_file_set(hid_t fapl) static int test_write_file_set(hid_t fapl) { - hid_t file = -1; /* file to which to write */ - hid_t dcpl = -1; /* dataset creation properties */ - hid_t mem_space = -1; /* memory data space */ - hid_t file_space = -1; /* file data space */ - hid_t dset = -1; /* dataset */ - unsigned i; /* miscellaneous counter */ - int part[PART_SIZE]; /* raw data buffer (partial) */ - int whole[TOTAL_SIZE]; /* raw data buffer (total) */ - hsize_t cur_size = 100; /* current data space size */ - hsize_t max_size = 200; /* maximum data space size */ - hsize_t hs_start = 100; /* hyperslab starting offset */ - hsize_t hs_count = 100; /* hyperslab size */ - char filename[1024]; /* file name */ + hid_t file = -1; /* file to which to write */ + hid_t dcpl = -1; /* dataset creation properties */ + hid_t mem_space = -1; /* memory data space */ + hid_t file_space = -1; /* file data space */ + hid_t dset = -1; /* dataset */ + unsigned i = 0; /* miscellaneous counter */ + int part[PART_SIZE]; /* raw data buffer (partial) */ + int whole[TOTAL_SIZE]; /* raw data buffer (total) */ + hsize_t cur_size = 100; /* current data space size */ + hsize_t max_size = 200; /* maximum data space size */ + hsize_t hs_start = 100; /* hyperslab starting offset */ + hsize_t hs_count = 100; /* hyperslab size */ + char filename[1024]; /* file name */ TESTING("write external dataset"); @@ -858,16 +919,16 @@ test_write_file_set(hid_t fapl) static int test_path_absolute(hid_t fapl) { - hid_t file = -1; /* file to write to */ - hid_t dcpl = -1; /* dataset creation properties */ - hid_t space = -1; /* data space */ - hid_t dset = -1; /* dataset */ - size_t i; /* miscellaneous counter */ - char cwdpath[1024]; /* working directory */ - char filename[1536]; /* file name */ - int part[PART_SIZE]; /* raw data buffer (partial) */ + hid_t file = -1; /* file to write to */ + hid_t dcpl = -1; /* dataset creation properties */ + hid_t space = -1; /* data space */ + hid_t dset = -1; /* dataset */ + size_t i = 0; /* miscellaneous counter */ + char cwdpath[1024]; /* working directory */ + char filename[1024]; /* file name */ + int part[PART_SIZE]; /* raw data buffer (partial) */ int whole[TOTAL_SIZE]; /* raw data buffer (total) */ - hsize_t cur_size; /* current data space size */ + hsize_t cur_size; /* current data space size */ TESTING("absolute filenames for external file"); @@ -948,16 +1009,16 @@ error: static int test_path_relative(hid_t fapl) { - hid_t file = -1; /* file to write to */ - hid_t dcpl = -1; /* dataset creation properties */ - hid_t space = -1; /* data space */ - hid_t dset = -1; /* dataset */ - size_t i; /* miscellaneous counters */ - char cwdpath[1024]; /* working directory */ - char filename[1024]; /* file name */ - int part[PART_SIZE]; /* raw data buffer (partial) */ + hid_t file = -1; /* file to write to */ + hid_t dcpl = -1; /* dataset creation properties */ + hid_t space = -1; /* data space */ + hid_t dset = -1; /* dataset */ + size_t i = 0; /* miscellaneous counters */ + char cwdpath[1024]; /* working directory */ + char filename[1024]; /* file name */ + int part[PART_SIZE]; /* raw data buffer (partial) */ int whole[TOTAL_SIZE]; /* raw data buffer (total) */ - hsize_t cur_size; /* current data space size */ + hsize_t cur_size; /* current data space size */ TESTING("filenames relative to current directory for external file"); @@ -1038,21 +1099,21 @@ error: static int test_path_relative_cwd(hid_t fapl) { - hid_t file = -1; /* file to write to */ - hid_t dcpl = -1; /* dataset creation properties */ - hid_t space = -1; /* data space */ - hid_t dapl = -1; /* dataset access property list */ - hid_t dapl2 = -1; /* copy of dapl */ - hid_t dset = -1; /* dataset */ - hid_t dset2 = -1; /* dataset, opened a second time */ - hid_t dset3 = -1; /* dataset, opened with different prefix */ - size_t i; /* miscellaneous counters */ - char cwdpath[1024]; /* working directory */ - char filename[1024]; /* file name */ - int part[PART_SIZE]; /* raw data buffer (partial) */ + hid_t file = -1; /* file to write to */ + hid_t dcpl = -1; /* dataset creation properties */ + hid_t space = -1; /* data space */ + hid_t dapl = -1; /* dataset access property list */ + hid_t dapl2 = -1; /* copy of dapl */ + hid_t dset = -1; /* dataset */ + hid_t dset2 = -1; /* dataset, opened a second time */ + hid_t dset3 = -1; /* dataset, opened with different prefix */ + size_t i = 0; /* miscellaneous counters */ + char cwdpath[1024]; /* working directory */ + char filename[1024]; /* file name */ + int part[PART_SIZE]; /* raw data buffer (partial) */ int whole[TOTAL_SIZE]; /* raw data buffer (total) */ - hsize_t cur_size; /* current data space size */ - char buffer[1024]; /* buffer to read efile_prefix */ + hsize_t cur_size; /* current data space size */ + char buffer[1024]; /* buffer to read efile_prefix */ TESTING("filenames relative to HDF5 file for external file"); @@ -1194,14 +1255,14 @@ error: static int test_h5d_get_access_plist(hid_t fapl_id) { - hid_t fid = -1; /* file to write to */ - hid_t dcpl_id = -1; /* dataset creation properties */ - hid_t dapl_id = -1; /* dataset access properties */ - hid_t sid = -1; /* data space */ - hid_t did = -1; /* dataset */ - hsize_t dims = 0; /* dataset size */ - char *buffer = NULL; /* saved prefix name from dapl */ - char filename[1024]; /* file names */ + hid_t fid = -1; /* file to write to */ + hid_t dcpl_id = -1; /* dataset creation properties */ + hid_t dapl_id = -1; /* dataset access properties */ + hid_t sid = -1; /* data space */ + hid_t did = -1; /* dataset */ + hsize_t dims = 0; /* dataset size */ + char *buffer = NULL; /* saved prefix name from dapl */ + char filename[1024]; /* file names */ TESTING("H5Dget_access_plist() returns correct prefix"); @@ -1284,7 +1345,7 @@ test_h5d_get_access_plist(hid_t fapl_id) * * Return: EXIT_SUCCESS/EXIT_FAILURE * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Tuesday, March 3, 1998 * *------------------------------------------------------------------------- @@ -1292,13 +1353,13 @@ test_h5d_get_access_plist(hid_t fapl_id) int main(void) { - hid_t fapl_id_old = -1; /* file access properties (old format) */ - hid_t fapl_id_new = -1; /* file access properties (new format) */ - hid_t fid = -1; /* file for test_1* functions */ - hid_t gid = -1; /* group to emit diagnostics */ - char filename[1024]; /* file name for test_1* funcs */ - unsigned latest_format; /* default or latest file format */ - int nerrors = 0; /* number of errors */ + hid_t fapl_id_old = -1; /* file access properties (old format) */ + hid_t fapl_id_new = -1; /* file access properties (new format) */ + hid_t fid = -1; /* file for test_1* functions */ + hid_t gid = -1; /* group to emit diagnostics */ + char filename[1024]; /* file name for test_1* funcs */ + unsigned latest_format; /* default or latest file format */ + int nerrors = 0; /* number of errors */ h5_reset(); @@ -1324,11 +1385,11 @@ main(void) if(latest_format) { HDputs("\nTesting with the latest file format:"); current_fapl_id = fapl_id_new; - } /* end if */ + } else { HDputs("Testing with the default file format:"); current_fapl_id = fapl_id_old; - } /* end else */ + } /* Create the common file used by some of the tests */ if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, current_fapl_id)) < 0) @@ -1364,7 +1425,7 @@ main(void) /* Close the common file */ if(H5Fclose(fid) < 0) FAIL_STACK_ERROR - } /* end for */ + } /* end for old and new format */ if(nerrors > 0) goto error; @@ -1386,7 +1447,7 @@ main(void) HDremove("extern_4w.raw"); HDrmdir("extern_dir"); - } /* end if */ + } return EXIT_SUCCESS; @@ -1401,3 +1462,4 @@ error: HDprintf("%d TEST%s FAILED.\n", nerrors, 1 == nerrors ? "" : "s"); return EXIT_FAILURE; } /* end main() */ + diff --git a/test/external_fname.h b/test/external_fname.h new file mode 100644 index 0000000..c5111b6 --- /dev/null +++ b/test/external_fname.h @@ -0,0 +1,37 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Programmer: Quincey Koziol + * July, 2019 + * + * Purpose: Private declaration for external.c and external_env.c + */ +#ifndef _EXTERNAL_FNAME_H +#define _EXTERNAL_FNAME_H + +/* Include test header files */ +#include "h5test.h" + +static const char *EXT_FNAME[] = { + "extern_1", + "extern_2", + "extern_3", + "extern_4", + "extern_dir/file_1", + "extern_5", + NULL +}; + +#endif /* _EXTERNAL_FNAME_H */ + diff --git a/tools/libtest/h5tools_test_utils.c b/tools/libtest/h5tools_test_utils.c index 7908519..120f803 100644 --- a/tools/libtest/h5tools_test_utils.c +++ b/tools/libtest/h5tools_test_utils.c @@ -1134,6 +1134,7 @@ test_set_configured_fapl(void) #endif /* H5_HAVE_LIBHDFS */ }; /* testcases `cases` array */ + unsigned int i; #ifdef H5_HAVE_ROS3_VFD n_cases += 5; @@ -1145,7 +1146,7 @@ test_set_configured_fapl(void) TESTING("programmatic fapl set"); - for (unsigned i = 0; i < n_cases; i++) { + for (i = 0; i < n_cases; i++) { int result; testcase C = cases[i]; -- cgit v0.12