summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2017-07-03 20:32:23 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2017-07-03 20:32:23 (GMT)
commit99e44094f2a9552b77fc7b7a0ef70dcf29a97358 (patch)
treed541b0090f1c63f68532a39045f6c2d61fbb7424 /test
parent5262b98b34067c1aad30cb25f8e935711638f2c1 (diff)
parent9a749a64f06187bc5ae17e848eab9aacdfc57f8a (diff)
downloadhdf5-99e44094f2a9552b77fc7b7a0ef70dcf29a97358.zip
hdf5-99e44094f2a9552b77fc7b7a0ef70dcf29a97358.tar.gz
hdf5-99e44094f2a9552b77fc7b7a0ef70dcf29a97358.tar.bz2
Merge pull request #589 in HDFFV/hdf5 from ~DEROBINS/hdf5_der:tmisc19 to develop
* commit '9a749a64f06187bc5ae17e848eab9aacdfc57f8a': More minor whitespace cleanup Fixed a minor comment typo in H5R.c * Reverted removal of H5I_REFERENCE to avoid breaking binary compatibility. * Added a quick H5I_REFERENCE smoke check to test_misc19() in tmisc.c. Added missing free() call to test_misc19(). Purged the unused H5I_REFERENCE from the library. Added a test for VFD IDs to testhdf5.
Diffstat (limited to 'test')
-rw-r--r--test/h5test.c100
-rw-r--r--test/h5test.h1
-rw-r--r--test/tmisc.c98
3 files changed, 185 insertions, 14 deletions
diff --git a/test/h5test.c b/test/h5test.c
index 8db4388..af45589 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -104,6 +104,68 @@ 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);
+
+
+/* A non-usable VFD class and its functions.
+ *
+ * Usable for testing things like ID handling where we shouldn't mess with the real VFDs.
+ */
+static H5FD_t *dummy_vfd_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr);
+static H5FD_t *dummy_vfd_open(const char H5_ATTR_UNUSED *name, unsigned H5_ATTR_UNUSED flags, hid_t H5_ATTR_UNUSED fapl_id, haddr_t H5_ATTR_UNUSED maxaddr) { return NULL; }
+
+static herr_t dummy_vfd_close(H5FD_t *_file);
+static herr_t dummy_vfd_close(H5FD_t H5_ATTR_UNUSED *_file) { return FAIL; }
+
+static haddr_t dummy_vfd_get_eoa(const H5FD_t *file, H5FD_mem_t type);
+static haddr_t dummy_vfd_get_eoa(const H5FD_t H5_ATTR_UNUSED *file, H5FD_mem_t H5_ATTR_UNUSED type) { return HADDR_UNDEF; }
+
+static herr_t dummy_vfd_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t addr);
+static herr_t dummy_vfd_set_eoa(H5FD_t H5_ATTR_UNUSED *_file, H5FD_mem_t H5_ATTR_UNUSED type, haddr_t H5_ATTR_UNUSED addr) { return FAIL; }
+
+static haddr_t dummy_vfd_get_eof(const H5FD_t *file, H5FD_mem_t type);
+static haddr_t dummy_vfd_get_eof(const H5FD_t H5_ATTR_UNUSED *file, H5FD_mem_t H5_ATTR_UNUSED type) { return HADDR_UNDEF; }
+
+static herr_t dummy_vfd_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, haddr_t addr, size_t size, void *buf);
+static herr_t dummy_vfd_read(H5FD_t H5_ATTR_UNUSED *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUSED fapl_id, haddr_t H5_ATTR_UNUSED addr, size_t H5_ATTR_UNUSED size, void H5_ATTR_UNUSED *buf) { return FAIL; }
+
+static herr_t dummy_vfd_write(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, haddr_t addr, size_t size, const void *buf);
+static herr_t dummy_vfd_write(H5FD_t H5_ATTR_UNUSED *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUSED fapl_id, haddr_t H5_ATTR_UNUSED addr, size_t H5_ATTR_UNUSED size, const void H5_ATTR_UNUSED *buf) { return FAIL; }
+
+static H5FD_class_t dummy_vfd_class_g = {
+ "fake", /* name */
+ 1, /* maxaddr */
+ H5F_CLOSE_WEAK, /* fc_degree */
+ NULL, /* terminate */
+ NULL, /* sb_size */
+ NULL, /* sb_encode */
+ NULL, /* sb_decode */
+ 0, /* fapl_size */
+ NULL, /* fapl_get */
+ NULL, /* fapl_copy */
+ NULL, /* fapl_free */
+ 0, /* dxpl_size */
+ NULL, /* dxpl_copy */
+ NULL, /* dxpl_free */
+ dummy_vfd_open, /* open */
+ dummy_vfd_close, /* close */
+ NULL, /* cmp */
+ NULL, /* query */
+ NULL, /* get_type_map */
+ NULL, /* alloc */
+ NULL, /* free */
+ dummy_vfd_get_eoa, /* get_eoa */
+ dummy_vfd_set_eoa, /* set_eoa */
+ dummy_vfd_get_eof, /* get_eof */
+ NULL, /* get_handle */
+ dummy_vfd_read, /* read */
+ dummy_vfd_write, /* write */
+ NULL, /* flush */
+ NULL, /* truncate */
+ NULL, /* lock */
+ NULL, /* unlock */
+ H5FD_FLMAP_DEFAULT /* fl_map */
+};
+
/*-------------------------------------------------------------------------
* Function: h5_errors
@@ -1828,3 +1890,41 @@ error:
return FAIL;
} /* h5_wait_message() */
+/*-------------------------------------------------------------------------
+ * Function: h5_get_dummy_vfd_class()
+ *
+ * Purpose: Returns a disposable, generally non-functional,
+ * VFD class struct.
+ *
+ * In some of the test code, we need a disposable VFD but
+ * we don't want to mess with the real VFDs and we also
+ * don't have access to the internals of the real VFDs (which
+ * use static globals and functions) to easily duplicate
+ * them (e.g.: for testing VFD ID handling).
+ *
+ * This API call will return a pointer to a VFD class that
+ * can be used to construct a test VFD using H5FDregister().
+ *
+ * Return: Success: A pointer to a VFD class struct
+ * Failure: NULL
+ *
+ *-------------------------------------------------------------------------
+ */
+H5FD_class_t *
+h5_get_dummy_vfd_class(void)
+{
+ H5FD_class_t *vfd_class = NULL;
+
+ if(NULL == (vfd_class = (H5FD_class_t *)HDmalloc(sizeof(H5FD_class_t))))
+ TEST_ERROR;
+
+ HDmemcpy(vfd_class, &dummy_vfd_class_g, sizeof(H5FD_class_t));
+
+ return vfd_class;
+
+error:
+ if(vfd_class)
+ HDfree(vfd_class);
+ return NULL;
+} /* h5_get_dummy_vfd_class */
+
diff --git a/test/h5test.h b/test/h5test.h
index 0e23255..ce5c64d 100644
--- a/test/h5test.h
+++ b/test/h5test.h
@@ -136,6 +136,7 @@ H5TEST_DLL h5_stat_size_t h5_get_file_size(const char *filename, hid_t fapl);
H5TEST_DLL int print_func(const char *format, ...);
H5TEST_DLL int h5_make_local_copy(const char *origfilename, const char *local_copy_name);
H5TEST_DLL herr_t h5_verify_cached_stabs(const char *base_name[], hid_t fapl);
+H5TEST_DLL H5FD_class_t *h5_get_dummy_vfd_class(void);
/* Functions that will replace VFD-dependent functions that violate
* the single responsibility principle. Unlike their predecessors,
diff --git a/test/tmisc.c b/test/tmisc.c
index dc69e18..22ae558 100644
--- a/test/tmisc.c
+++ b/test/tmisc.c
@@ -29,7 +29,8 @@
#include "hdf5.h"
#include "testhdf5.h"
#include "H5srcdir.h"
-#include "H5Dpkg.h" /* Datasets */
+#include "H5Dpkg.h" /* Datasets */
+#include "H5Iprivate.h" /* IDs, can be removed when H5I_REFERENCE is gone */
/* Definitions for misc. test #1 */
#define MISC1_FILE "tmisc1.h5"
@@ -2984,19 +2985,21 @@ test_misc18(void)
static void
test_misc19(void)
{
- hid_t fid; /* File ID */
- hid_t sid; /* 'Space ID */
- hid_t did; /* Dataset ID */
- hid_t tid; /* 'Type ID */
- hid_t aid; /* Attribute ID */
- hid_t plid; /* Property List ID */
- hid_t pcid; /* Property Class ID */
- hid_t gid; /* Group ID */
- hid_t ecid; /* Error Class ID */
- hid_t emid; /* Error Message ID */
- hid_t esid; /* Error Stack ID */
- int rc; /* Reference count */
- herr_t ret; /* Generic return value */
+ hid_t fid = -1; /* File ID */
+ hid_t sid = -1; /* Dataspace ID */
+ hid_t did = -1; /* Dataset ID */
+ hid_t tid = -1; /* Datatype ID */
+ hid_t aid = -1; /* Attribute ID */
+ hid_t plid = -1; /* Property List ID */
+ hid_t pcid = -1; /* Property Class ID */
+ hid_t gid = -1; /* Group ID */
+ hid_t ecid = -1; /* Error Class ID */
+ hid_t emid = -1; /* Error Message ID */
+ hid_t esid = -1; /* Error Stack ID */
+ hid_t vfdid = -1; /* Virtual File Driver ID */
+ H5FD_class_t *vfd_cls = NULL; /* VFD class */
+ int rc; /* Reference count */
+ herr_t ret; /* Generic return value */
/* Check H5I operations on files */
@@ -3406,6 +3409,73 @@ test_misc19(void)
} H5E_END_TRY;
VERIFY(ret, FAIL, "H5Eclose_stack");
+
+/* Check H5I operations on virtual file drivers */
+
+ /* Get a VFD class to register */
+ vfd_cls = h5_get_dummy_vfd_class();
+ CHECK(vfd_cls, NULL, "h5_get_dummy_vfd_class");
+
+ /* Register a virtual file driver */
+ vfdid = H5FDregister(vfd_cls);
+ CHECK(vfdid, FAIL, "H5FDregister");
+
+ /* Check the reference count */
+ rc = H5Iget_ref(vfdid);
+ VERIFY(rc, 1, "H5Iget_ref");
+
+ /* Increment the reference count */
+ rc = H5Iinc_ref(vfdid);
+ VERIFY(rc, 2, "H5Iinc_ref");
+
+ /* Unregister the VFD normally */
+ ret = H5FDunregister(vfdid);
+ CHECK(ret, FAIL, "H5FDunregister");
+
+ /* Check the reference count */
+ rc = H5Iget_ref(vfdid);
+ VERIFY(rc, 1, "H5Iget_ref");
+
+ /* Unregister the VFD by decrementing the reference count */
+ rc = H5Idec_ref(vfdid);
+ VERIFY(rc, 0, "H5Idec_ref");
+
+ /* Try unregistering the VFD again (should fail) */
+ H5E_BEGIN_TRY {
+ ret = H5FDunregister(vfdid);
+ } H5E_END_TRY;
+ VERIFY(ret, FAIL, "H5FDunregister");
+
+ HDfree(vfd_cls);
+
+/* Check H5I operations on references */
+
+ /* Reference IDs are not used by the library so there's no
+ * way of testing if incr/decr, etc. work. Instead, just
+ * do a quick smoke check to ensure that a couple of basic
+ * calls return sane values.
+ *
+ * H5I_REFERENCE has been declared deprecated with a tentative
+ * removal version of HDF5 1.12.0.
+ *
+ * Delete this entire block when H5I_REFERENCE no longer exists.
+ *
+ * The H5Iprivate.h header was included to support H5I_nmembers()
+ * so that can also probably be removed as well.
+ */
+{
+ htri_t tf; /* Boolean generic return */
+ int64_t num_members; /* Number of members in type */
+
+ tf = H5Itype_exists(H5I_REFERENCE);
+ VERIFY(tf, TRUE, "H5Itype_exists");
+
+ num_members = 999;
+ num_members = H5I_nmembers(H5I_REFERENCE);
+ VERIFY(num_members, 0, "H5Inmembers");
+
+} /* end block */
+
} /* end test_misc19() */
/****************************************************************