summaryrefslogtreecommitdiffstats
path: root/tools/test
diff options
context:
space:
mode:
authorJacob Smith <jake.smith@hdfgroup.org>2019-07-29 19:58:39 (GMT)
committerJacob Smith <jake.smith@hdfgroup.org>2019-07-29 19:58:39 (GMT)
commit7d3e17076312ddf8083d749e51629f0ef90b38c7 (patch)
tree261fcc778a77ec05e543cb1faadf3ff558b24d9f /tools/test
parentded30348ae923a15f287b9a2f49a97ce5ac10da0 (diff)
downloadhdf5-7d3e17076312ddf8083d749e51629f0ef90b38c7.zip
hdf5-7d3e17076312ddf8083d749e51629f0ef90b38c7.tar.gz
hdf5-7d3e17076312ddf8083d749e51629f0ef90b38c7.tar.bz2
Refactoring.
Diffstat (limited to 'tools/test')
-rw-r--r--tools/test/h5repack/h5repackgentest.c235
1 files changed, 156 insertions, 79 deletions
diff --git a/tools/test/h5repack/h5repackgentest.c b/tools/test/h5repack/h5repackgentest.c
index c236d71..7242ebf 100644
--- a/tools/test/h5repack/h5repackgentest.c
+++ b/tools/test/h5repack/h5repackgentest.c
@@ -35,26 +35,104 @@
#define FILE_INT32LE "h5repack_int32le"
#define FILE_UINT8BE "h5repack_uint8be"
+#define H5REPACKGENTEST_OOPS ret_value = -1; goto done;
+
+#define H5REPACKGENTEST_COMMON_CLEANUP(dcpl, file, space) { \
+ if ((dcpl) != H5P_DEFAULT && (dcpl) != H5I_INVALID_HID) { \
+ (void)H5Pclose((dcpl)); \
+ } \
+ if ((file) != H5I_INVALID_HID) { (void)H5Fclose((file)); } \
+ if ((space) != H5I_INVALID_HID) { (void)H5Sclose((space)); } \
+}
+
+
+/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * Helper function to create and write a dataset to file.
+ * Returns 0 on success, -1 on failure.
+ */
+static int
+make_dataset(
+ hid_t file,
+ const char *dset_name,
+ hid_t mem_type_id,
+ hid_t space,
+ hid_t dcpl,
+ void *wdata)
+{
+ hid_t dset = H5I_INVALID_HID;
+ int ret_value = 0;
+
+ dset = H5Dcreate2(
+ file,
+ "dset",
+ mem_type_id,
+ space,
+ H5P_DEFAULT,
+ dcpl,
+ H5P_DEFAULT);
+ if (dset == H5I_INVALID_HID) {
+ H5REPACKGENTEST_OOPS;
+ }
+
+ if (H5Dwrite(
+ dset,
+ mem_type_id,
+ H5S_ALL,
+ H5S_ALL,
+ H5P_DEFAULT,
+ wdata)
+ < 0)
+ {
+ H5REPACKGENTEST_OOPS;
+ }
+
+done:
+ if (dset != H5I_INVALID_HID) { (void)H5Dclose(dset); }
+ return ret_value;
+} /* end make_dataset() */
+
+
+/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * Helper function to populate the DCPL external storage list.
+ * Returns 0 on success, -1 on failure.
+ */
+static int
+set_dcpl_external_list(
+ hid_t dcpl,
+ const char *filename,
+ hsize_t n_external_files,
+ hsize_t n_elts,
+ hsize_t elt_size)
+{
+ hsize_t i = 0;
+ char name[MAX_NAME_SIZE];
+
+ for (i = 0; i < n_external_files; i++) {
+ snprintf(name, MAX_NAME_SIZE, "%s_ex-%llu.dat", filename, i);
+ if (H5Pset_external(dcpl, name, 0, n_elts * elt_size) < 0) {
+ return -1;
+ }
+ }
+ return 0;
+} /* end set_dcpl_external_list() */
+
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- * TODO: error handling is a joke, but this seems normal for the tools'
- * gentest operations.
*/
-static void
+static int
generate_int32le(hbool_t external)
{
char filename[MAX_NAME_SIZE];
hid_t file = H5I_INVALID_HID;
- hid_t dset = H5I_INVALID_HID;
hid_t dcpl = H5P_DEFAULT;
- hid_t dspace = H5I_INVALID_HID;
+ hid_t space = H5I_INVALID_HID;
hsize_t dims[] = {8, 8, 8};
int32_t wdata[512]; /* 8^3, from dims */
int32_t n = 0;
int i = 0;
int j = 0;
int k = 0;
- herr_t ret = FAIL; /* error-checking */
+ int ret_value = 0;
/* generate values, alternating positive and negative
*/
@@ -73,68 +151,66 @@ generate_int32le(hbool_t external)
(external) ? "_ex" : "");
if (external) {
- char name[MAX_NAME_SIZE];
dcpl = H5Pcreate(H5P_DATASET_CREATE);
- HDassert(dcpl != H5I_INVALID_HID);
- snprintf(name, MAX_NAME_SIZE, "%s_ex-0.dat", FILE_INT32LE);
- ret = H5Pset_external(dcpl, name, 0, H5F_UNLIMITED);
- HDassert(ret >= 0);
+ if (dcpl == H5I_INVALID_HID) {
+ H5REPACKGENTEST_OOPS;
+ }
+ if (set_dcpl_external_list(
+ dcpl,
+ FILE_INT32LE,
+ 1,
+ 512,
+ sizeof(int32_t))
+ < 0)
+ {
+ H5REPACKGENTEST_OOPS;
+ }
}
- dspace = H5Screate_simple(3, dims, NULL);
- HDassert(dspace != H5I_INVALID_HID);
+ space = H5Screate_simple(3, dims, NULL);
+ if (space == H5I_INVALID_HID) {
+ H5REPACKGENTEST_OOPS;
+ }
file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- HDassert(file != H5I_INVALID_HID);
+ if (file == H5I_INVALID_HID) {
+ H5REPACKGENTEST_OOPS;
+ }
- dset = H5Dcreate2(
+ if (make_dataset(
file,
"dset",
H5T_STD_I32LE,
- dspace,
- H5P_DEFAULT,
+ space,
dcpl,
- H5P_DEFAULT);
- HDassert(dset != H5I_INVALID_HID);
-
- ret = H5Dwrite(
- dset,
- H5T_STD_I32LE,
- H5S_ALL,
- H5S_ALL,
- H5P_DEFAULT,
- wdata);
- HDassert(ret >= 0);
-
- if (dcpl != H5P_DEFAULT) {
- ret = H5Pclose(dcpl);
- HDassert(ret >= 0);
+ wdata)
+ < 0)
+ {
+ H5REPACKGENTEST_OOPS;
}
- ret = H5Dclose(dset);
- HDassert(ret >= 0);
- ret = H5Fclose(file);
- HDassert(ret >= 0);
- ret = H5Sclose(dspace);
- HDassert(ret >= 0);
+done:
+ H5REPACKGENTEST_COMMON_CLEANUP(dcpl, file, space);
+ return ret_value;
} /* end generate_int32le() */
-static void
+/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ */
+static int
generate_uint8be(hbool_t external)
{
char filename[MAX_NAME_SIZE];
hid_t file = H5I_INVALID_HID;
- hid_t dset = H5I_INVALID_HID;
hid_t dcpl = H5P_DEFAULT;
- hid_t dspace = H5I_INVALID_HID;
+ hid_t space = H5I_INVALID_HID;
hsize_t dims[] = {8, 8, 8};
uint8_t wdata[512]; /* 8^3, from dims */
uint8_t n = 0;
int i = 0;
int j = 0;
int k = 0;
- herr_t ret; /* error-checking */
+ int ret_value = 0;
/* Generate values, alternating positive and negative
* The latter half of the dataset is "overflow garbage" (TODO?)
@@ -154,52 +230,47 @@ generate_uint8be(hbool_t external)
(external) ? "_ex" : "");
if (external) {
- char name[MAX_NAME_SIZE];
dcpl = H5Pcreate(H5P_DATASET_CREATE);
- HDassert(dcpl != H5I_INVALID_HID);
- for (i = 0; i < 8; i++) {
- snprintf(name, MAX_NAME_SIZE, "%s_ex-%d.dat", FILE_UINT8BE, i);
- ret = H5Pset_external(dcpl, name, 0, 64 * sizeof(char));
- HDassert(ret >= 0);
+ if (dcpl == H5I_INVALID_HID) {
+ H5REPACKGENTEST_OOPS;
+ }
+ if (set_dcpl_external_list(
+ dcpl,
+ FILE_UINT8BE,
+ 8,
+ 64,
+ sizeof(uint8_t))
+ < 0)
+ {
+ H5REPACKGENTEST_OOPS;
}
}
- dspace = H5Screate_simple(3, dims, NULL);
- HDassert(dspace != H5I_INVALID_HID);
+ space = H5Screate_simple(3, dims, NULL);
+ if (space == H5I_INVALID_HID) {
+ H5REPACKGENTEST_OOPS;
+ }
file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- HDassert(file != H5I_INVALID_HID);
+ if (file == H5I_INVALID_HID) {
+ H5REPACKGENTEST_OOPS;
+ }
- dset = H5Dcreate2(
+ if (make_dataset(
file,
"dset",
H5T_STD_U8BE,
- dspace,
- H5P_DEFAULT,
+ space,
dcpl,
- H5P_DEFAULT);
- HDassert(dset != H5I_INVALID_HID);
-
- ret = H5Dwrite(
- dset,
- H5T_STD_U8BE,
- H5S_ALL,
- H5S_ALL,
- H5P_DEFAULT,
- wdata);
- HDassert(ret >= 0);
-
- if (dcpl != H5P_DEFAULT) {
- ret = H5Pclose(dcpl);
- HDassert(ret >= 0);
+ wdata)
+ < 0)
+ {
+ H5REPACKGENTEST_OOPS;
}
- ret = H5Dclose(dset);
- HDassert(ret >= 0);
- ret = H5Fclose(file);
- HDassert(ret >= 0);
- ret = H5Sclose(dspace);
- HDassert(ret >= 0);
+done:
+ H5REPACKGENTEST_COMMON_CLEANUP(dcpl, file, space);
+ return ret_value;
} /* end generate_uint8be() */
@@ -208,14 +279,20 @@ generate_uint8be(hbool_t external)
int
main(void)
{
- int i = 0;
+ int i = 0; /* loop variable */
+ int ret_value = 0;
for (i=0; i < 2; i++) {
hbool_t external = (i&1) ? TRUE : FALSE;
- generate_int32le(external);
- generate_uint8be(external);
+ if (ret_value == 0) { ret_value -= generate_int32le(external); }
+ if (ret_value == 0) { ret_value -= generate_uint8be(external); }
+ } /* end for external data storage or not */
+
+ if (ret_value != 0) {
+ /* TODO: print warning message? */
}
- return 0;
+
+ return ret_value;
} /* end main() */