summaryrefslogtreecommitdiffstats
path: root/test/tmisc.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/tmisc.c')
-rw-r--r--test/tmisc.c582
1 files changed, 381 insertions, 201 deletions
diff --git a/test/tmisc.c b/test/tmisc.c
index 6012588..4a77b51 100644
--- a/test/tmisc.c
+++ b/test/tmisc.c
@@ -5,12 +5,10 @@
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
- * the files COPYING and Copyright.html. COPYING can be found at the root *
- * of the source code distribution tree; Copyright.html can be found at the *
- * root level of an installed copy of the electronic HDF5 document set and *
- * is linked from the top-level documents page. It can also be found at *
- * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
- * access to either file, you may request a copy from help@hdfgroup.org. *
+ * 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. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/***********************************************************
@@ -23,15 +21,15 @@
*
*************************************************************/
-#define H5D_FRIEND /*suppress error about including H5Dpkg */
+#define H5D_FRIEND /*suppress error about including H5Dpkg */
/* Define this macro to indicate that the testing APIs should be available */
#define H5D_TESTING
-#include "hdf5.h"
#include "testhdf5.h"
#include "H5srcdir.h"
-#include "H5Dpkg.h" /* Datasets */
+#include "H5Dpkg.h" /* Datasets */
+#include "H5MMprivate.h" /* Memory */
/* Definitions for misc. test #1 */
#define MISC1_FILE "tmisc1.h5"
@@ -180,17 +178,12 @@ typedef struct
#define MISC13_GROUP1_NAME "Group1"
#define MISC13_GROUP2_NAME "Group2"
#define MISC13_DTYPE_NAME "Datatype"
-#define MISC13_RANK 2
-#define MISC13_DIM1 20
-#define MISC13_DIM2 30
+#define MISC13_RANK 1
+#define MISC13_DIM1 600
#define MISC13_CHUNK_DIM1 10
-#define MISC13_CHUNK_DIM2 15
#define MISC13_USERBLOCK_SIZE 512
#define MISC13_COPY_BUF_SIZE 4096
-unsigned m13_data[MISC13_DIM1][MISC13_DIM2]; /* Data to write to dataset */
-unsigned m13_rdata[MISC13_DIM1][MISC13_DIM2]; /* Data read from dataset */
-
/* Definitions for misc. test #14 */
#define MISC14_FILE "tmisc14.h5"
#define MISC14_DSET1_NAME "Dataset1"
@@ -325,6 +318,11 @@ unsigned m13_rdata[MISC13_DIM1][MISC13_DIM2]; /* Data read from dataset
#define MISC31_PROPNAME "misc31_prop"
#define MISC31_DTYPENAME "dtype"
+/* Definitions for misc. test #33 */
+/* Note that this test file is generated by "gen_bad_offset.c" */
+/* and bad offset values are written to that file for testing */
+#define MISC33_FILE "bad_offset.h5"
+
/****************************************************************
**
** test_misc1(): test unlinking a dataset from a group and immediately
@@ -724,7 +722,7 @@ create_struct3(void)
herr_t ret; /* For error checking */
str3hndl = (misc5_struct3_hndl *)HDmalloc(sizeof(misc5_struct3_hndl));
- CHECK(str3hndl,NULL,"malloc");
+ CHECK_PTR(str3hndl, "malloc");
str3hndl->st3h_base = H5Tcreate(H5T_COMPOUND, sizeof(misc5_struct3));
CHECK(str3hndl->st3h_base, FAIL, "H5Tcreate");
@@ -767,7 +765,7 @@ create_struct2(void)
herr_t ret; /* For error checking */
str2hndl = (misc5_struct2_hndl *)HDmalloc(sizeof(misc5_struct2_hndl));
- CHECK(str2hndl, NULL, "malloc");
+ CHECK_PTR(str2hndl, "HDmalloc");
str2hndl->st2h_base = H5Tcreate(H5T_COMPOUND, sizeof(misc5_struct2));
CHECK(str2hndl->st2h_base, FAIL, "H5Tcreate");
@@ -776,7 +774,7 @@ create_struct2(void)
CHECK(ret, FAIL, "H5Tinsert");
str2hndl->st2h_st3hndl = create_struct3();
- CHECK(str2hndl->st2h_st3hndl,NULL,"create_struct3");
+ CHECK_PTR(str2hndl->st2h_st3hndl, "create_struct3");
ret = H5Tinsert(str2hndl->st2h_base, "st2_el2", HOFFSET(misc5_struct2, st2_el2), str2hndl->st2h_st3hndl->st3h_id);
CHECK(ret,FAIL,"H5Tinsert");
@@ -812,7 +810,7 @@ set_struct2(misc5_struct2 *buf)
buf->st2_el2.len = MISC5_DBGNELM3;
buf->st2_el2.p = HDmalloc((buf->st2_el2.len)*sizeof(misc5_struct3));
- CHECK(buf->st2_el2.p,NULL,"malloc");
+ CHECK_PTR(buf->st2_el2.p, "HDmalloc");
for(i=0; i<(buf->st2_el2.len); i++)
set_struct3(&(((misc5_struct3 *)(buf->st2_el2.p))[i]));
@@ -833,7 +831,7 @@ create_struct1(void)
herr_t ret; /* For error checking */
str1hndl = (misc5_struct1_hndl *)HDmalloc(sizeof(misc5_struct1_hndl));
- CHECK(str1hndl, NULL, "malloc");
+ CHECK_PTR(str1hndl, "HDmalloc");
str1hndl->st1h_base = H5Tcreate(H5T_COMPOUND, sizeof(misc5_struct1));
CHECK(str1hndl->st1h_base, FAIL, "H5Tcreate");
@@ -842,7 +840,7 @@ create_struct1(void)
CHECK(ret, FAIL, "H5Tinsert");
str1hndl->st1h_st2hndl=create_struct2();
- CHECK(str1hndl->st1h_st2hndl,NULL,"create_struct2");
+ CHECK_PTR(str1hndl->st1h_st2hndl, "create_struct2");
ret = H5Tinsert(str1hndl->st1h_base, "st1_el2", HOFFSET(misc5_struct1, st1_el2), str1hndl->st1h_st2hndl->st2h_id);
CHECK(ret,FAIL,"H5Tinsert");
@@ -878,7 +876,7 @@ set_struct1(misc5_struct1 *buf)
buf->st1_el2.len=MISC5_DBGNELM2;
buf->st1_el2.p=HDmalloc((buf->st1_el2.len)*sizeof(misc5_struct2));
- CHECK(buf->st1_el2.p,NULL,"malloc");
+ CHECK_PTR(buf->st1_el2.p, "HDmalloc");
for(i=0; i<(buf->st1_el2.len); i++)
set_struct2(&(((misc5_struct2 *)(buf->st1_el2.p))[i]));
@@ -914,7 +912,7 @@ test_misc5(void)
/* Create the memory structure to write */
str1hndl = create_struct1();
- CHECK(str1hndl, NULL, "create_struct1");
+ CHECK_PTR(str1hndl, "create_struct1");
/* Create the dataspace */
dims[0] = MISC5_NELMTOPLVL;
@@ -928,7 +926,7 @@ test_misc5(void)
/* Create the variable-length buffer */
buf.len = MISC5_DBGNELM1;
buf.p = HDmalloc((buf.len) * sizeof(misc5_struct1));
- CHECK(buf.p, NULL, "malloc");
+ CHECK_PTR(buf.p, "HDmalloc");
/* Create the top-level VL information */
for(i = 0; i < MISC5_DBGNELM1; i++)
@@ -1254,10 +1252,10 @@ test_misc8(void)
/* Allocate space for the data to write & read */
wdata = (int *)HDmalloc(sizeof(int) * MISC8_DIM0 * MISC8_DIM1);
- CHECK(wdata,NULL,"malloc");
+ CHECK_PTR(wdata, "HDmalloc");
#ifdef VERIFY_DATA
rdata = (int *)HDmalloc(sizeof(int) * MISC8_DIM0 * MISC8_DIM1);
- CHECK(rdata,NULL,"malloc");
+ CHECK_PTR(rdata, "HDmalloc");
#endif /* VERIFY_DATA */
/* Initialize values */
@@ -1817,11 +1815,11 @@ test_misc11(void)
unsigned sym_ik; /* Symbol table B-tree initial 'K' value */
unsigned istore_ik; /* Indexed storage B-tree initial 'K' value */
unsigned sym_lk; /* Symbol table B-tree leaf 'K' value */
- unsigned nindexes; /* Shared message number of indexes */
+ unsigned nindexes; /* Shared message number of indexes */
H5F_info2_t finfo; /* global information about file */
H5F_fspace_strategy_t strategy; /* File space strategy */
- hsize_t threshold; /* Free-space section threshold */
- hbool_t persist; /* To persist free-space or not */
+ hsize_t threshold; /* Free-space section threshold */
+ hbool_t persist; /* To persist free-space or not */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
@@ -1860,7 +1858,7 @@ test_misc11(void)
/* This should fail as (32770*2) will exceed ^16 - 2 bytes for storing btree entries */
H5E_BEGIN_TRY {
- ret=H5Pset_sym_k(fcpl, 32770, 0);
+ ret=H5Pset_sym_k(fcpl, 32770, 0);
} H5E_END_TRY;
VERIFY(ret, FAIL, "H5Pset_sym_k");
@@ -1869,7 +1867,7 @@ test_misc11(void)
/* This should fail as (32770*2) will exceed ^16 - 2 bytes for storing btree entries */
H5E_BEGIN_TRY {
- ret=H5Pset_istore_k(fcpl, 32770);
+ ret=H5Pset_istore_k(fcpl, 32770);
} H5E_END_TRY;
VERIFY(ret, FAIL, "H5Pset_istore_k");
@@ -1981,19 +1979,19 @@ test_misc12(void)
"las palabras del que murio en la cruz."
};
char *rdata [MISC12_SPACE1_DIM1+MISC12_APPEND_SIZE]; /* Information read in */
- hid_t fid1;
- hid_t dataset;
- hid_t sid1, space, memspace;
- hid_t tid1, cparms;
- hsize_t dims1[] = {MISC12_SPACE1_DIM1};
- hsize_t dimsn[] = {MISC12_APPEND_SIZE};
- hsize_t maxdims1[1] = {H5S_UNLIMITED};
- hsize_t chkdims1[1] = {MISC12_CHUNK_SIZE};
+ hid_t fid1;
+ hid_t dataset;
+ hid_t sid1, space, memspace;
+ hid_t tid1, cparms;
+ hsize_t dims1[] = {MISC12_SPACE1_DIM1};
+ hsize_t dimsn[] = {MISC12_APPEND_SIZE};
+ hsize_t maxdims1[1] = {H5S_UNLIMITED};
+ hsize_t chkdims1[1] = {MISC12_CHUNK_SIZE};
hsize_t newsize[1] = {MISC12_SPACE1_DIM1+MISC12_APPEND_SIZE};
- hsize_t offset[1] = {MISC12_SPACE1_DIM1};
+ hsize_t offset[1] = {MISC12_SPACE1_DIM1};
hsize_t count[1] = {MISC12_APPEND_SIZE};
int i; /* counting variable */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing VL-type in chunked dataset\n"));
@@ -2085,38 +2083,36 @@ test_misc12(void)
/* Various routines for misc. 13 test */
static void
-init_data(void)
+misc13_init_data(unsigned *original_data)
{
- unsigned u,v; /* Local index variables */
+ unsigned u;
- for(u=0; u<MISC13_DIM1; u++)
- for(v=0; v<MISC13_DIM2; v++)
- m13_data[u][v]=(u*MISC13_DIM2)+v;
+ for(u = 0; u < MISC13_DIM1; u++)
+ original_data[u] = u;
}
-static int
-verify_data(void)
+static hbool_t
+misc13_verify_data_match(const unsigned *original_data, const unsigned *read_data)
{
- unsigned u,v; /* Local index variables */
+ unsigned u;
- for(u=0; u<MISC13_DIM1; u++)
- for(v=0; v<MISC13_DIM2; v++)
- if(m13_data[u][v]!=m13_rdata[u][v])
- return(-1);
- return(0);
+ for(u = 0; u < MISC13_DIM1; u++)
+ if(original_data[u] != read_data[u])
+ return FALSE;
+
+ return TRUE;
}
static void
-create_dataset(hid_t loc_id, const char *name, hid_t dcpl)
+misc13_create_dataset(hid_t loc_id, const char *name, hid_t dcpl, const unsigned *data)
{
- hid_t dsid; /* Dataset ID */
- hid_t sid; /* Dataspace ID */
- hsize_t dims[MISC13_RANK]; /* Dataset dimensions */
- herr_t ret; /* Generic return value */
+ hid_t dsid = -1; /* Dataset ID */
+ hid_t sid = -1; /* Dataspace ID */
+ hsize_t dims[MISC13_RANK]; /* Dataset dimensions */
+ herr_t ret; /* Generic return value */
/* Create dataspace for use with dataset */
dims[0] = MISC13_DIM1;
- dims[1] = MISC13_DIM2;
sid = H5Screate_simple(MISC13_RANK, dims, NULL);
CHECK(sid, FAIL, "H5Screate_simple");
@@ -2125,7 +2121,7 @@ create_dataset(hid_t loc_id, const char *name, hid_t dcpl)
CHECK(dsid, FAIL, "H5Dcreate2");
/* Write some data to dataset */
- ret = H5Dwrite(dsid, H5T_NATIVE_UINT, H5S_ALL, H5S_ALL, H5P_DEFAULT, m13_data);
+ ret = H5Dwrite(dsid, H5T_NATIVE_UINT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
CHECK(ret, FAIL, "H5Dwrite");
/* Close the contiguous dataset */
@@ -2135,64 +2131,74 @@ create_dataset(hid_t loc_id, const char *name, hid_t dcpl)
/* Close the dataspace */
ret = H5Sclose(sid);
CHECK(ret, FAIL, "H5Sclose");
-}
+
+} /* end misc13_create_dataset() */
static void
-verify_dataset(hid_t loc_id, const char *name)
+misc13_verify_dataset(hid_t loc_id, const char *name, const unsigned *data)
{
- hid_t dsid; /* Dataset ID */
- herr_t ret; /* Generic return value */
+ unsigned *read_data = NULL; /* Data to write to dataset */
+ hid_t dsid = -1; /* Dataset ID */
+ herr_t ret; /* Generic return value */
+
+ /* Create a data buffer for the dataset read */
+ read_data = (unsigned *)HDcalloc(MISC13_DIM1, sizeof(unsigned));
+ CHECK_PTR(read_data, "HDcalloc");
/* Open the contiguous dataset in the root group */
dsid = H5Dopen2(loc_id, name, H5P_DEFAULT);
CHECK(dsid, FAIL, "H5Dopen2");
/* Read the data */
- ret = H5Dread(dsid, H5T_NATIVE_UINT, H5S_ALL, H5S_ALL, H5P_DEFAULT, m13_rdata);
+ ret = H5Dread(dsid, H5T_NATIVE_UINT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_data);
CHECK(ret, FAIL, "H5Dread");
- /* Verify that the data is correct */
- ret=verify_data();
- CHECK(ret, FAIL, "verify_data");
+ /* Verify that the data are correct */
+ ret = misc13_verify_data_match(data, read_data);
+ CHECK(ret, FAIL, "misc13_verify_data_match");
/* Close the contiguous dataset */
ret = H5Dclose(dsid);
CHECK(ret, FAIL, "H5Dclose");
-}
+
+ /* Free the dataset read buffer */
+ HDfree(read_data);
+
+} /* end misc13_verify_dataset() */
static void
-create_hdf_file(const char *name)
+misc13_create_hdf_file(const char *name, const unsigned *data)
{
- hid_t fid; /* File ID */
- hid_t gid,gid2; /* Group IDs */
- hid_t tid; /* Datatype ID */
- hid_t dcpl; /* Dataset creation property list ID */
- hsize_t chunk_dims[MISC13_RANK]; /* Chunk dimensions */
- herr_t ret; /* Generic return value */
+ hid_t fid = -1; /* File ID */
+ hid_t gid1 = -1; /* Group ID (level 1) */
+ hid_t gid2 = -1; /* Group ID (level 2) */
+ hid_t tid = -1; /* Datatype ID */
+ hid_t dcplid = -1; /* Dataset creation property list ID */
+ hsize_t chunk_dims[MISC13_RANK]; /* Chunk dimensions */
+ herr_t ret; /* Generic return value */
/* Create file */
- fid=H5Fcreate(name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ fid = H5Fcreate(name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fcreate");
/* Create DCPL for use with datasets */
- dcpl = H5Pcreate(H5P_DATASET_CREATE);
- CHECK(dcpl, FAIL, "H5Pcreate");
+ dcplid = H5Pcreate(H5P_DATASET_CREATE);
+ CHECK(dcplid, FAIL, "H5Pcreate");
/* Set the DCPL to be chunked */
- ret = H5Pset_layout(dcpl, H5D_CHUNKED);
+ ret = H5Pset_layout(dcplid, H5D_CHUNKED);
CHECK(ret, FAIL, "H5Pset_layout");
/* Use chunked storage for this DCPL */
chunk_dims[0] = MISC13_CHUNK_DIM1;
- chunk_dims[1] = MISC13_CHUNK_DIM2;
- ret = H5Pset_chunk(dcpl, MISC13_RANK, chunk_dims);
+ ret = H5Pset_chunk(dcplid, MISC13_RANK, chunk_dims);
CHECK(ret, FAIL, "H5Pset_chunk");
/* Create contiguous dataset in root group */
- create_dataset(fid, MISC13_DSET1_NAME, H5P_DEFAULT);
+ misc13_create_dataset(fid, MISC13_DSET1_NAME, H5P_DEFAULT, data);
/* Create chunked dataset in root group */
- create_dataset(fid, MISC13_DSET2_NAME, dcpl);
+ misc13_create_dataset(fid, MISC13_DSET2_NAME, dcplid, data);
/* Create a datatype to commit to the file */
tid = H5Tcopy(H5T_NATIVE_INT);
@@ -2207,11 +2213,11 @@ create_hdf_file(const char *name)
CHECK(ret, FAIL, "H5Tclose");
/* Create a group in the root group */
- gid = H5Gcreate2(fid, MISC13_GROUP1_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- CHECK(gid, FAIL, "H5Gcreate2");
+ gid1 = H5Gcreate2(fid, MISC13_GROUP1_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(gid1, FAIL, "H5Gcreate2");
/* Create another group in the new group */
- gid2 = H5Gcreate2(gid, MISC13_GROUP2_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ gid2 = H5Gcreate2(gid1, MISC13_GROUP2_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(gid2, FAIL, "H5Gcreate2");
/* Close the second group */
@@ -2219,17 +2225,17 @@ create_hdf_file(const char *name)
CHECK(ret, FAIL, "H5Gclose");
/* Create contiguous dataset in new group */
- create_dataset(gid, MISC13_DSET1_NAME, H5P_DEFAULT);
+ misc13_create_dataset(gid1, MISC13_DSET1_NAME, H5P_DEFAULT, data);
/* Create chunked dataset in new group */
- create_dataset(gid, MISC13_DSET2_NAME, dcpl);
+ misc13_create_dataset(gid1, MISC13_DSET2_NAME, dcplid, data);
/* Create a datatype to commit to the new group */
tid = H5Tcopy(H5T_NATIVE_INT);
CHECK(tid, FAIL, "H5Tcopy");
/* Create a named datatype in the new group */
- ret = H5Tcommit2(gid, MISC13_DTYPE_NAME, tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ ret = H5Tcommit2(gid1, MISC13_DTYPE_NAME, tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(ret, FAIL, "H5Tcommit2");
/* Close named datatype */
@@ -2237,65 +2243,66 @@ create_hdf_file(const char *name)
CHECK(ret, FAIL, "H5Tclose");
/* Close the first group */
- ret = H5Gclose(gid);
+ ret = H5Gclose(gid1);
CHECK(ret, FAIL, "H5Gclose");
/* Close the DCPL */
- ret = H5Pclose(dcpl);
+ ret = H5Pclose(dcplid);
CHECK(ret, FAIL, "H5Pclose");
/* Close the file */
ret = H5Fclose(fid);
- HDassert(ret >= 0);
CHECK(ret, FAIL, "H5Fclose");
-}
+
+} /* end misc13_create_hdf_file() */
static void
-insert_user_block(const char *old_name, const char *new_name,const char *str,size_t size)
+misc13_insert_user_block(const char *old_name, const char *new_name, const char *str, size_t size)
{
- FILE *new_fp, *old_fp; /* Pointers to new & old files */
- void *user_block; /* Pointer to user block to write to file */
- void *copy_buf; /* Pointer to buffer for copying data */
+ FILE *new_fp = NULL; /* Pointers to new & old files */
+ FILE *old_fp = NULL;
+ void *user_block = NULL; /* Pointer to user block to write to file */
+ void *copy_buf = NULL; /* Pointer to buffer for copying data */
size_t written; /* Amount of data written to new file */
size_t read_in; /* Amount of data read in from old file */
int ret; /* Generic status value */
/* Allocate space for the user block */
user_block = HDcalloc(size, (size_t)1);
- CHECK(user_block, NULL, "HDcalloc");
+ CHECK_PTR(user_block, "HDcalloc");
/* Copy in the user block data */
- HDmemcpy(user_block,str,strlen(str));
+ HDmemcpy(user_block, str, strlen(str));
/* Open the new file */
- new_fp=HDfopen(new_name,"wb");
- CHECK(new_fp, NULL, "HDfopen");
+ new_fp = HDfopen(new_name,"wb");
+ CHECK_PTR(new_fp, "HDfopen");
/* Write the user block to the new file */
written = HDfwrite(user_block, (size_t)1, size, new_fp);
VERIFY(written, size, "HDfwrite");
/* Open the old file */
- old_fp=HDfopen(old_name,"rb");
- CHECK(old_fp, NULL, "HDfopen");
+ old_fp = HDfopen(old_name,"rb");
+ CHECK_PTR(old_fp, "HDfopen");
/* Allocate space for the copy buffer */
copy_buf = HDmalloc((size_t)MISC13_COPY_BUF_SIZE);
- CHECK(copy_buf, NULL, "HDmalloc");
+ CHECK_PTR(copy_buf, "HDmalloc");
/* Copy data from the old file to the new file */
while((read_in = HDfread(copy_buf, (size_t)1, (size_t)MISC13_COPY_BUF_SIZE, old_fp)) > 0) {
/* Write the data to the new file */
written = HDfwrite(copy_buf, (size_t)1, read_in, new_fp);
VERIFY(written, read_in, "HDfwrite");
- } /* end while */
+ }
/* Close the old file */
- ret=HDfclose(old_fp);
+ ret = HDfclose(old_fp);
VERIFY(ret, 0, "HDfclose");
/* Close the new file */
- ret=HDfclose(new_fp);
+ ret = HDfclose(new_fp);
VERIFY(ret, 0, "HDfclose");
/* Free the copy buffer */
@@ -2303,81 +2310,84 @@ insert_user_block(const char *old_name, const char *new_name,const char *str,siz
/* Free the user block */
HDfree(user_block);
-}
+
+} /* end misc13_insert_user_block() */
static void
-verify_file(const char *name, hsize_t blk_size, unsigned check_new_data)
+misc13_verify_file(const char *name, const unsigned *data, hsize_t userblock_size,
+ hbool_t check_for_new_dataset)
{
- hid_t fid; /* File ID */
- hid_t gid,gid2; /* Group IDs */
- hid_t tid; /* Datatype ID */
- hid_t fcpl; /* File creation property list ID */
- hsize_t userblock; /* Userblock size retrieved from FCPL */
- herr_t ret; /* Generic return value */
+ hid_t fid = -1; /* File ID */
+ hid_t gid1 = -1; /* Group IDs */
+ hid_t gid2 = -1; /* Group IDs */
+ hid_t tid = -1; /* Datatype ID */
+ hid_t fcplid = -1; /* File creation property list ID */
+ hsize_t ub_size_out; /* Userblock size retrieved from FCPL */
+ herr_t ret; /* Generic return value */
/* Open the file */
- fid=H5Fopen(name, H5F_ACC_RDONLY, H5P_DEFAULT);
+ fid = H5Fopen(name, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fopen");
/* Get the file's FCPL */
- fcpl=H5Fget_create_plist(fid);
- CHECK(fcpl, FAIL, "H5Fget_create_plist");
+ fcplid = H5Fget_create_plist(fid);
+ CHECK(fcplid, FAIL, "H5Fget_create_plist");
/* Get the user block size for the file */
- ret=H5Pget_userblock(fcpl,&userblock);
+ ret = H5Pget_userblock(fcplid, &ub_size_out);
CHECK(ret, FAIL, "H5Pget_userblock");
/* Check the userblock size */
- VERIFY(userblock, blk_size, "H5Pget_userblock");
+ VERIFY(userblock_size, ub_size_out, "H5Pget_userblock");
/* Close the FCPL */
- ret = H5Pclose(fcpl);
+ ret = H5Pclose(fcplid);
CHECK(ret, FAIL, "H5Pclose");
/* Verify the contiguous dataset in the root group */
- verify_dataset(fid,MISC13_DSET1_NAME);
+ misc13_verify_dataset(fid, MISC13_DSET1_NAME, data);
/* Verify the chunked dataset in the root group */
- verify_dataset(fid,MISC13_DSET2_NAME);
+ misc13_verify_dataset(fid, MISC13_DSET2_NAME, data);
/* Verify the "new" contiguous dataset in the root group, if asked */
- if(check_new_data)
- verify_dataset(fid,MISC13_DSET3_NAME);
+ if(check_for_new_dataset)
+ misc13_verify_dataset(fid, MISC13_DSET3_NAME, data);
/* Open the named datatype in the root group */
tid = H5Topen2(fid, MISC13_DTYPE_NAME, H5P_DEFAULT);
CHECK(tid, FAIL, "H5Topen2");
/* Verify the type is correct */
- VERIFY(H5Tequal(tid,H5T_NATIVE_INT), TRUE, "H5Tequal");
+ VERIFY(H5Tequal(tid, H5T_NATIVE_INT), TRUE, "H5Tequal");
/* Close named datatype */
- ret=H5Tclose(tid);
+ ret = H5Tclose(tid);
CHECK(ret, FAIL, "H5Tclose");
/* Open the first group */
- gid = H5Gopen2(fid, MISC13_GROUP1_NAME, H5P_DEFAULT);
- CHECK(gid, FAIL, "H5Gopen2");
+ gid1 = H5Gopen2(fid, MISC13_GROUP1_NAME, H5P_DEFAULT);
+ CHECK(gid1, FAIL, "H5Gopen2");
/* Verify the contiguous dataset in the first group */
- verify_dataset(gid,MISC13_DSET1_NAME);
+ misc13_verify_dataset(gid1, MISC13_DSET1_NAME, data);
/* Verify the chunked dataset in the first group */
- verify_dataset(gid,MISC13_DSET2_NAME);
+ misc13_verify_dataset(gid1, MISC13_DSET2_NAME, data);
/* Open the named datatype in the first group */
- tid = H5Topen2(gid,MISC13_DTYPE_NAME, H5P_DEFAULT);
+ tid = H5Topen2(gid1, MISC13_DTYPE_NAME, H5P_DEFAULT);
CHECK(tid, FAIL, "H5Topen2");
/* Verify the type is correct */
- VERIFY(H5Tequal(tid,H5T_NATIVE_INT), TRUE, "H5Tequal");
+ VERIFY(H5Tequal(tid, H5T_NATIVE_INT), TRUE, "H5Tequal");
/* Close named datatype */
- ret=H5Tclose(tid);
+ ret = H5Tclose(tid);
CHECK(ret, FAIL, "H5Tclose");
/* Open the second group */
- gid2 = H5Gopen2(gid, MISC13_GROUP2_NAME, H5P_DEFAULT);
+ gid2 = H5Gopen2(gid1, MISC13_GROUP2_NAME, H5P_DEFAULT);
CHECK(gid2, FAIL, "H5Gopen2");
/* Close the second group */
@@ -2385,31 +2395,33 @@ verify_file(const char *name, hsize_t blk_size, unsigned check_new_data)
CHECK(ret, FAIL, "H5Gclose");
/* Close the first group */
- ret = H5Gclose(gid);
+ ret = H5Gclose(gid1);
CHECK(ret, FAIL, "H5Gclose");
/* Close the file */
ret = H5Fclose(fid);
CHECK(ret, FAIL, "H5Fclose");
-}
+
+} /* end misc13_verify_file() */
static void
-add_to_new_file(const char *name)
+misc13_add_to_new_file(const char *name, const unsigned *data)
{
- hid_t fid; /* File ID */
+ hid_t fid = -1; /* File ID */
herr_t ret; /* Generic return value */
/* Open the file */
- fid=H5Fopen(name, H5F_ACC_RDWR, H5P_DEFAULT);
+ fid = H5Fopen(name, H5F_ACC_RDWR, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fopen");
/* Create new contiguous dataset in root group */
- create_dataset(fid, MISC13_DSET3_NAME, H5P_DEFAULT);
+ misc13_create_dataset(fid, MISC13_DSET3_NAME, H5P_DEFAULT, data);
/* Close the file */
ret = H5Fclose(fid);
CHECK(ret, FAIL, "H5Fclose");
-}
+
+} /* end misc13_add_to_new_file() */
/****************************************************************
**
@@ -2420,26 +2432,44 @@ add_to_new_file(const char *name)
static void
test_misc13(void)
{
+ unsigned *data = NULL; /* Data to write to dataset */
+ hsize_t userblock_size; /* Correct size of userblock */
+ hbool_t check_for_new_dataset; /* Whether to check for the post-userblock-creation dataset */
+
+ /* Create a data buffer for the datasets */
+ data = (unsigned *)HDcalloc(MISC13_DIM1, sizeof(unsigned));
+ CHECK_PTR(data, "HDcalloc");
+
/* Initialize data to write */
- init_data();
+ misc13_init_data(data);
/* Create first file, with no user block */
- create_hdf_file(MISC13_FILE_1);
+ misc13_create_hdf_file(MISC13_FILE_1, data);
/* Verify file contents are correct */
- verify_file(MISC13_FILE_1,(hsize_t)0,0);
+ userblock_size = 0;
+ check_for_new_dataset = FALSE;
+ misc13_verify_file(MISC13_FILE_1, data, userblock_size, check_for_new_dataset);
/* Create a new file by inserting a user block in front of the first file */
- insert_user_block(MISC13_FILE_1, MISC13_FILE_2, "Test String", (size_t)MISC13_USERBLOCK_SIZE);
+ misc13_insert_user_block(MISC13_FILE_1, MISC13_FILE_2, "Test String", (size_t)MISC13_USERBLOCK_SIZE);
/* Verify file contents are still correct */
- verify_file(MISC13_FILE_2,(hsize_t)MISC13_USERBLOCK_SIZE,0);
+ userblock_size = MISC13_USERBLOCK_SIZE;
+ check_for_new_dataset = FALSE;
+ misc13_verify_file(MISC13_FILE_2, data, userblock_size, check_for_new_dataset);
/* Make certain we can modify the new file */
- add_to_new_file(MISC13_FILE_2);
+ misc13_add_to_new_file(MISC13_FILE_2, data);
/* Verify file contents are still correct */
- verify_file(MISC13_FILE_2,(hsize_t)MISC13_USERBLOCK_SIZE,1);
+ userblock_size = MISC13_USERBLOCK_SIZE;
+ check_for_new_dataset = TRUE;
+ misc13_verify_file(MISC13_FILE_2, data, userblock_size, check_for_new_dataset);
+
+ /* Free the dataset buffer */
+ HDfree(data);
+
} /* end test_misc13() */
/****************************************************************
@@ -2715,10 +2745,10 @@ test_misc16(void)
herr_t ret; /* Generic return value */
char wdata[MISC16_SPACE_DIM][MISC16_STR_SIZE];
char rdata[MISC16_SPACE_DIM][MISC16_STR_SIZE]; /* Information read in */
- hid_t dataset; /* Dataset ID */
- hid_t sid; /* Dataspace ID */
- hid_t tid; /* Datatype ID */
- hsize_t dims[] = {MISC16_SPACE_DIM};
+ hid_t dataset; /* Dataset ID */
+ hid_t sid; /* Dataspace ID */
+ hid_t tid; /* Datatype ID */
+ hsize_t dims[] = {MISC16_SPACE_DIM};
int i;
/* Initialize the data */
@@ -2800,10 +2830,10 @@ test_misc17(void)
herr_t ret; /* Generic return value */
char wdata[MISC17_SPACE_DIM1][MISC17_SPACE_DIM2];
char rdata[MISC17_SPACE_DIM1][MISC17_SPACE_DIM2]; /* Information read in */
- hid_t dataset; /* Dataset ID */
- hid_t sid; /* Dataspace ID */
- hid_t tid; /* Datatype ID */
- hsize_t dims[] = {MISC17_SPACE_DIM1, MISC17_SPACE_DIM2};
+ hid_t dataset; /* Dataset ID */
+ hid_t sid; /* Dataspace ID */
+ hid_t tid; /* Datatype ID */
+ hsize_t dims[] = {MISC17_SPACE_DIM1, MISC17_SPACE_DIM2};
int i;
/* Initialize the data */
@@ -2986,19 +3016,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 */
@@ -3408,6 +3440,45 @@ 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_PTR(vfd_cls, "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);
+
} /* end test_misc19() */
/****************************************************************
@@ -3726,13 +3797,13 @@ test_misc22(void)
/* compute the correct PPB that should be set by SZIP */
if(offsets[k] == 0)
- correct = prec[j];
+ correct = prec[j];
else
correct = H5Tget_size(idts[i]) * 8;
if(correct > 24) {
- if(correct <= 32)
+ if(correct <= 32)
correct = 32;
- else if(correct <= 64)
+ else if(correct <= 64)
correct = 64;
} /* end if */
@@ -4685,7 +4756,7 @@ test_misc25b(void)
CHECK(ret, FAIL, "H5Fclose");
} /* end test_misc25b() */
-
+
/****************************************************************
**
** test_misc25c(): Exercise another null object header message merge bug.
@@ -4819,7 +4890,7 @@ test_misc25c(void)
CHECK(ret, FAIL, "H5Fclose");
} /* end test_misc25c() */
-
+
/****************************************************************
**
** test_misc26(): Regression test: ensure that copying filter
@@ -4905,7 +4976,7 @@ test_misc26(void)
CHECK_I(ret, "H5Pclose");
}
-
+
/****************************************************************
**
** test_misc27(): Ensure that objects with incorrect # of object
@@ -4950,7 +5021,7 @@ test_misc27(void)
CHECK(ret, FAIL, "H5Fclose");
} /* end test_misc27() */
-
+
/****************************************************************
**
** test_misc28(): Ensure that the dataset chunk cache will hold
@@ -5127,7 +5198,7 @@ test_misc28(void)
CHECK_I(ret, "H5Pclose");
} /* end test_misc28() */
-
+
/****************************************************************
**
** test_misc29(): Ensure that speculative metadata reads don't
@@ -5167,7 +5238,7 @@ test_misc30_get_info_cb(hid_t loc_id, const char *name, const H5L_info_t H5_ATTR
{
H5O_info_t object_info;
- return H5Oget_info_by_name(loc_id, name, &object_info, H5P_DEFAULT);
+ return H5Oget_info_by_name(loc_id, name, &object_info, H5P_DEFAULT);
}
static int
@@ -5176,7 +5247,7 @@ test_misc30_get_info(hid_t loc_id)
return H5Literate(loc_id, H5_INDEX_NAME, H5_ITER_INC, NULL, test_misc30_get_info_cb, NULL);
}
-
+
/****************************************************************
**
** test_misc30(): Exercise local heap code that loads prefix
@@ -5208,15 +5279,15 @@ test_misc30(void)
CHECK(ret, FAIL, "H5Gclose");
ret = H5Fclose(fid);
CHECK(ret, FAIL, "H5Fclose");
-
+
for(i = 0; i < 20; i++) {
char gname[32];
fid = H5Fopen(MISC30_FILE, H5F_ACC_RDWR, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fopen");
-
+
if(get_info) {
- ret = test_misc30_get_info(fid);
+ ret = test_misc30_get_info(fid);
CHECK(ret, FAIL, "test_misc30_get_info");
}
@@ -5228,20 +5299,20 @@ test_misc30(void)
CHECK(ret, FAIL, "H5Gclose");
ret = H5Fclose(fid);
CHECK(ret, FAIL, "H5Fclose");
- }
-
+ }
+
fid = H5Fopen(MISC30_FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fopen");
ret = H5Fget_filesize(fid, &file_size[get_info]);
CHECK(fid, FAIL, "H5Fget_filesize");
ret = H5Fclose(fid);
CHECK(ret, FAIL, "H5Fclose");
- }
-
+ }
+
VERIFY(file_size[0], file_size[1], "test_misc30");
} /* end test_misc30() */
-
+
/****************************************************************
**
** test_misc31(): Test reentering library through deprecated
@@ -5332,14 +5403,14 @@ test_misc31(void)
CHECK(ret, FAIL, "H5Fclose");
ret = H5Tclose(dtype_id);
CHECK(ret, FAIL, "H5Tclose");
-
+
#else /* H5_NO_DEPRECATED_SYMBOLS */
/* Output message about test being skipped */
MESSAGE(5, (" ...Skipped"));
#endif /* H5_NO_DEPRECATED_SYMBOLS */
} /* end test_misc31() */
-
+
/****************************************************************
*
* test_misc32(): Simple test of filter memory allocation
@@ -5403,10 +5474,117 @@ test_misc32(void)
resized = H5resize_memory(NULL, 0);
CHECK_PTR_NULL(resized, "H5resize_memory"); /*BAD*/
#endif /* NDEBUG */
-
+
} /* end test_misc32() */
-
+/****************************************************************
+**
+** test_misc33(): Test for H5FFV-10216
+** --verify that H5HL_offset_into() returns error if the
+** input parameter "offset" exceeds heap data block size.
+** --case (1), (2), (3) are scenarios that will traverse to the
+** the 3 locations in the file having bad offset values to
+** the heap. (See description in gen_bad_offset.c)
+**
+****************************************************************/
+static void
+test_misc33(void)
+{
+ hid_t fid = -1; /* File ID */
+ const char *testfile = H5_get_srcdir_filename(MISC33_FILE); /* Corrected test file name */
+ H5O_info_t oinfo; /* Structure for object metadata information */
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing that bad offset into the heap returns error"));
+
+ /* Open the test file */
+ fid = H5Fopen(testfile, H5F_ACC_RDWR, H5P_DEFAULT);
+ CHECK(fid, FAIL, "H5Fopen");
+
+ /* Case (1) */
+ H5E_BEGIN_TRY {
+ ret = H5Oget_info_by_name(fid, "/soft_two", &oinfo, H5P_DEFAULT);
+ } H5E_END_TRY;
+ VERIFY(ret, FAIL, "H5Oget_info_by_name");
+
+ /* Case (2) */
+ H5E_BEGIN_TRY {
+ ret = H5Oget_info_by_name(fid, "/dsetA", &oinfo, H5P_DEFAULT);
+ } H5E_END_TRY;
+ VERIFY(ret, FAIL, "H5Oget_info_by_name");
+
+ /* Case (3) */
+ H5E_BEGIN_TRY {
+ ret = H5Oget_info_by_name(fid, "/soft_one", &oinfo, H5P_DEFAULT);
+ } H5E_END_TRY;
+ VERIFY(ret, FAIL, "H5Oget_info_by_name");
+
+ /* Close the file */
+ ret = H5Fclose(fid);
+ CHECK(fid, FAIL, "H5Fclose");
+
+} /* end test_misc33() */
+
+/****************************************************************
+**
+** test_misc34(): Ensure zero-size memory allocations work
+**
+****************************************************************/
+static void
+test_misc34(void)
+{
+ void *mem = NULL; /* allocated buffer */
+ char *dup = NULL; /* 'duplicated' string */
+ size_t sz = 0; /* buffer size */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing O and NULL behavior in H5MM API calls"));
+
+ /* H5MM_xfree(): Ensure that passing NULL is allowed and returns NULL */
+ mem = H5MM_xfree(mem);
+ CHECK_PTR_NULL(mem, "H5MM_xfree");
+
+ /* H5MM_malloc(): Ensure that size 0 returns NULL */
+ mem = H5MM_malloc(sz);
+ CHECK_PTR_NULL(mem, "H5MM_malloc");
+ mem = H5MM_xfree(mem);
+
+ /* H5MM_calloc(): Ensure that size 0 returns NULL */
+ mem = H5MM_calloc(sz);
+ CHECK_PTR_NULL(mem, "H5MM_calloc");
+ mem = H5MM_xfree(mem);
+
+ /* H5MM_realloc(): Check behavior:
+ *
+ * H5MM_realloc(NULL, size) <==> H5MM_malloc(size)
+ * H5MM_realloc(ptr, 0) <==> H5MM_xfree(ptr)
+ * H5MM_realloc(NULL, 0) <==> NULL
+ */
+ mem = H5MM_xfree(mem);
+
+ sz = 1024;
+ mem = H5MM_realloc(mem, sz);
+ CHECK_PTR(mem, "H5MM_realloc (case 1)");
+ /* Don't free mem here! */
+
+ sz = 0;
+ mem = H5MM_realloc(mem, sz);
+ CHECK_PTR_NULL(mem, "H5MM_realloc (case 2)");
+ mem = H5MM_xfree(mem);
+
+ mem = H5MM_realloc(mem, sz);
+ CHECK_PTR_NULL(mem, "H5MM_realloc (case 3)");
+ mem = H5MM_xfree(mem);
+
+ /* H5MM_xstrdup(): Ensure NULL returns NULL */
+ dup = H5MM_xstrdup((const char *)mem);
+ CHECK_PTR_NULL(dup, "H5MM_xstrdup");
+ dup = (char *)H5MM_xfree((void *)dup);
+
+} /* end test_misc34() */
+
+
/****************************************************************
**
** test_misc(): Main misc. test routine.
@@ -5454,18 +5632,20 @@ test_misc(void)
test_misc30(); /* Exercise local heap loading bug where free lists were getting dropped */
test_misc31(); /* Test Reentering library through deprecated routines after H5close() */
test_misc32(); /* Test filter memory allocation functions */
+ test_misc33(); /* Test to verify that H5HL_offset_into() returns error if offset exceeds heap block */
+ test_misc34(); /* Test behavior of 0 and NULL in H5MM API calls */
} /* test_misc() */
-
+
/*-------------------------------------------------------------------------
- * Function: cleanup_misc
+ * Function: cleanup_misc
*
- * Purpose: Cleanup temporary test files
+ * Purpose: Cleanup temporary test files
*
- * Return: none
+ * Return: none
*
- * Programmer: Albert Cheng
+ * Programmer: Albert Cheng
* July 2, 1998
*
* Modifications:
@@ -5511,5 +5691,5 @@ cleanup_misc(void)
HDremove(MISC29_COPY_FILE);
HDremove(MISC30_FILE);
HDremove(MISC31_FILE);
-}
+} /* end cleanup_misc() */