summaryrefslogtreecommitdiffstats
path: root/test/gheap.c
diff options
context:
space:
mode:
authorLarry Knox <lrknox@hdfgroup.org>2019-12-24 21:12:08 (GMT)
committerLarry Knox <lrknox@hdfgroup.org>2019-12-24 21:12:08 (GMT)
commit5b9cf732caab9daa6ed1e00f2df4f5a792340196 (patch)
tree4c01c9bd71ba5e7d8d11b474f6896e6ffbf0416d /test/gheap.c
parent646fc294078f560fc9bef784cb1c4e27cdc51f5b (diff)
parente0fa36bfe008c03365ce8ea94d705f8fdebccdf0 (diff)
downloadhdf5-5b9cf732caab9daa6ed1e00f2df4f5a792340196.zip
hdf5-5b9cf732caab9daa6ed1e00f2df4f5a792340196.tar.gz
hdf5-5b9cf732caab9daa6ed1e00f2df4f5a792340196.tar.bz2
Merge pull request #2203 in HDFFV/hdf5 from ~LRKNOX/hdf5_lrk:1.10/master to 1.10/masterhdf5-1_10_6
* commit 'e0fa36bfe008c03365ce8ea94d705f8fdebccdf0': (166 commits) Update release date strings in README.txt and release_docs/RELEASE.txt Add release note about using ompio instead of romio when collective writes fail with OpenMPI. Fixed typos, grammatical errors, etc. Expanded entry for S3 and HDFS VFDs. Moved Mac 10.11 and 10.12 from Supported Platforms to More Platforms Tested. Add qualification to RELEASE.txt regarding performance improvements Standalone doesn't use h5test implementation. Add missing note Update COPYING file with new HDF5 license. Update bin/config.guess and config.sub to current version available from git.savannah.gnu.org. Fix include to correct memory calls - big-endian issue. Revert BLDLIBDIR value in junit.sh.in. Corrections to CMake functions Update version for HDF5 1.10.6 release. Remove autom4te.cache directory that shouldn't have been added. Remove duplicate instance Fix merge issue HDFFV-10979 - fix global name clash Correct clang search and java include Latest date first in RELEASE.txt Update RELEASE.txt with performance improvements and Steven Varga's bugfix. Update version numbers for shared lib files according to api compatibility report. Created hdf5_1_10_6 branch for HDF5 1.10.6 release preparation. Set version to 1.10.6-pre1. Switched default maintainer mode to disabled and default build mode to production. Added files produced by autogen.sh to commit except for src/H5config.h.in~ and src/H5public.h~. ...
Diffstat (limited to 'test/gheap.c')
-rw-r--r--test/gheap.c324
1 files changed, 163 insertions, 161 deletions
diff --git a/test/gheap.c b/test/gheap.c
index bf0f18a..32e2785 100644
--- a/test/gheap.c
+++ b/test/gheap.c
@@ -15,9 +15,9 @@
* Programmer: Robb Matzke <matzke@llnl.gov>
* Tuesday, March 31, 1998
*
- * Purpose: Tests the global heap. The global heap is the set of all
- * collections but the collections are not related to one
- * another by anything that appears in the file format.
+ * Purpose: Tests the global heap. The global heap is the set of all
+ * collections but the collections are not related to one
+ * another by anything that appears in the file format.
*/
#include "h5test.h"
#include "H5ACprivate.h"
@@ -60,33 +60,31 @@ const char *FILENAME[] = {
/*-------------------------------------------------------------------------
* Function: test_1
*
- * Purpose: Writes a sequence of objects to the global heap where each
- * object is larger than the one before.
+ * Purpose: Writes a sequence of objects to the global heap where each
+ * object is larger than the one before.
*
- * Return: Success: 0
+ * Return: Success: 0
*
- * Failure: number of errors
+ * Failure: number of errors
*
* Programmer: Robb Matzke
* Tuesday, March 31, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
test_1 (hid_t fapl)
{
- hid_t file = -1;
- H5F_t *f = NULL;
- H5HG_t *obj = NULL;
- uint8_t out[GHEAP_TEST_NOBJS];
- uint8_t in[GHEAP_TEST_NOBJS];
- size_t u;
- size_t size;
- herr_t status;
- int nerrors = 0;
- char filename[1024];
+ hid_t file = H5I_INVALID_HID;
+ H5F_t *f = NULL;
+ H5HG_t *obj = NULL;
+ uint8_t out[GHEAP_TEST_NOBJS];
+ uint8_t in[GHEAP_TEST_NOBJS];
+ size_t u;
+ size_t size;
+ herr_t status;
+ int nerrors = 0;
+ char filename[1024];
TESTING("monotonically increasing lengths");
@@ -97,10 +95,10 @@ test_1 (hid_t fapl)
/* Open a clean file */
h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
- goto error;
+ goto error;
if(NULL == (f = (H5F_t *)H5I_object(file))) {
H5_FAILED();
- puts(" Unable to create file");
+ HDputs(" Unable to create file");
goto error;
}
@@ -116,11 +114,12 @@ test_1 (hid_t fapl)
status = H5HG_insert(f, size, out, obj + u);
if(status < 0) {
H5_FAILED();
- puts(" Unable to insert object into global heap");
+ HDputs(" Unable to insert object into global heap");
nerrors++;
- } else if(u && H5F_addr_gt(obj[u - 1].addr, obj[u].addr)) {
+ }
+ else if(u && H5F_addr_gt(obj[u - 1].addr, obj[u].addr)) {
H5_FAILED();
- puts(" Collection addresses are not monotonically increasing");
+ HDputs(" Collection addresses are not monotonically increasing");
nerrors++;
}
}
@@ -134,11 +133,12 @@ test_1 (hid_t fapl)
H5Eclear2(H5E_DEFAULT);
if(NULL == H5HG_read(f, obj + u, in, NULL)) {
H5_FAILED();
- puts(" Unable to read object");
+ HDputs(" Unable to read object");
nerrors++;
- } else if(HDmemcmp(in, out, size)) {
+ }
+ else if(HDmemcmp(in, out, size)) {
H5_FAILED();
- puts(" Value read doesn't match value written");
+ HDputs(" Value read doesn't match value written");
nerrors++;
}
}
@@ -147,15 +147,17 @@ test_1 (hid_t fapl)
HDfree(obj);
obj = NULL;
- if(H5Fclose(file) < 0) goto error;
- if(nerrors) goto error;
+ if(H5Fclose(file) < 0)
+ goto error;
+ if(nerrors)
+ goto error;
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
- H5Fclose(file);
+ H5Fclose(file);
} H5E_END_TRY;
if(obj)
HDfree(obj);
@@ -166,32 +168,30 @@ error:
/*-------------------------------------------------------------------------
* Function: test_2
*
- * Purpose: Writes a sequence of objects to the global heap where each
- * object is smaller than the one before.
+ * Purpose: Writes a sequence of objects to the global heap where each
+ * object is smaller than the one before.
*
- * Return: Success: 0
+ * Return: Success: 0
*
- * Failure: number of errors
+ * Failure: number of errors
*
- * Programmer: Robb Matzke
+ * Programmer: Robb Matzke
* Tuesday, March 31, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
test_2 (hid_t fapl)
{
- hid_t file = -1;
- H5F_t *f = NULL;
- H5HG_t *obj = NULL;
- uint8_t out[GHEAP_TEST_NOBJS];
- uint8_t in[GHEAP_TEST_NOBJS];
- size_t u;
- size_t size;
- int nerrors = 0;
- char filename[1024];
+ hid_t file = H5I_INVALID_HID;
+ H5F_t *f = NULL;
+ H5HG_t *obj = NULL;
+ uint8_t out[GHEAP_TEST_NOBJS];
+ uint8_t in[GHEAP_TEST_NOBJS];
+ size_t u;
+ size_t size;
+ int nerrors = 0;
+ char filename[1024];
TESTING("monotonically decreasing lengths");
@@ -202,10 +202,10 @@ test_2 (hid_t fapl)
/* Open a clean file */
h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
- goto error;
+ goto error;
if(NULL == (f = (H5F_t *)H5I_object(file))) {
H5_FAILED();
- puts(" Unable to create file");
+ HDputs(" Unable to create file");
goto error;
}
@@ -216,9 +216,9 @@ test_2 (hid_t fapl)
size = GHEAP_TEST_NOBJS - u;
HDmemset(out, (int)('A' + u % 26), size);
H5Eclear2(H5E_DEFAULT);
- if (H5HG_insert (f, size, out, obj + u) < 0) {
+ if(H5HG_insert(f, size, out, obj + u) < 0) {
H5_FAILED();
- puts(" Unable to insert object into global heap");
+ HDputs(" Unable to insert object into global heap");
nerrors++;
}
}
@@ -232,11 +232,12 @@ test_2 (hid_t fapl)
H5Eclear2(H5E_DEFAULT);
if(NULL == H5HG_read(f, obj + u, in, NULL)) {
H5_FAILED();
- puts(" Unable to read object");
+ HDputs(" Unable to read object");
nerrors++;
- } else if (memcmp (in, out, size)) {
+ }
+ else if (memcmp (in, out, size)) {
H5_FAILED();
- puts(" Value read doesn't match value written");
+ HDputs(" Value read doesn't match value written");
nerrors++;
}
}
@@ -245,15 +246,17 @@ test_2 (hid_t fapl)
HDfree(obj);
obj = NULL;
- if (H5Fclose(file)<0) goto error;
- if (nerrors) goto error;
+ if(H5Fclose(file) < 0)
+ goto error;
+ if(nerrors)
+ goto error;
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
- H5Fclose(file);
+ H5Fclose(file);
} H5E_END_TRY;
if(obj)
HDfree(obj);
@@ -264,32 +267,30 @@ test_2 (hid_t fapl)
/*-------------------------------------------------------------------------
* Function: test_3
*
- * Purpose: Creates a few global heap objects and then removes them all.
- * The collection should also be removed.
+ * Purpose: Creates a few global heap objects and then removes them all.
+ * The collection should also be removed.
*
- * Return: Success: 0
+ * Return: Success: 0
*
- * Failure: number of errors
+ * Failure: number of errors
*
* Programmer: Robb Matzke
* Tuesday, March 31, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
test_3 (hid_t fapl)
{
- hid_t file = -1;
- H5F_t *f = NULL;
- H5HG_t *obj = NULL;
- uint8_t out[GHEAP_TEST_NOBJS];
- size_t u;
- size_t size;
- herr_t status;
- int nerrors = 0;
- char filename[1024];
+ hid_t file = H5I_INVALID_HID;
+ H5F_t *f = NULL;
+ H5HG_t *obj = NULL;
+ uint8_t out[GHEAP_TEST_NOBJS];
+ size_t u;
+ size_t size;
+ herr_t status;
+ int nerrors = 0;
+ char filename[1024];
TESTING("complete object removal");
@@ -300,11 +301,11 @@ test_3 (hid_t fapl)
/* Open a clean file */
h5_fixname(FILENAME[2], fapl, filename, sizeof filename);
if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
- goto error;
+ goto error;
if(NULL == (f = (H5F_t *)H5I_object(file))) {
- H5_FAILED();
- puts(" Unable to create file");
- goto error;
+ H5_FAILED();
+ HDputs(" Unable to create file");
+ goto error;
}
/* Create some stuff */
@@ -315,7 +316,7 @@ test_3 (hid_t fapl)
status = H5HG_insert(f, size, out, obj + u);
if (status<0) {
H5_FAILED();
- puts(" Unable to insert object into global heap");
+ HDputs(" Unable to insert object into global heap");
nerrors++;
}
}
@@ -325,7 +326,7 @@ test_3 (hid_t fapl)
status = H5HG_remove(f, obj + u);
if (status<0) {
H5_FAILED();
- puts(" Unable to remove object");
+ HDputs(" Unable to remove object");
nerrors++;
}
}
@@ -334,15 +335,17 @@ test_3 (hid_t fapl)
HDfree(obj);
obj = NULL;
- if (H5Fclose(file)<0) goto error;
- if (nerrors) goto error;
+ if(H5Fclose(file) < 0)
+ goto error;
+ if(nerrors)
+ goto error;
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
- H5Fclose(file);
+ H5Fclose(file);
} H5E_END_TRY;
if(obj)
HDfree(obj);
@@ -353,33 +356,31 @@ test_3 (hid_t fapl)
/*-------------------------------------------------------------------------
* Function: test_4
*
- * Purpose: Tests the H5HG_remove() feature by writing lots of objects
- * and occassionally removing some. When we're done they're all
- * removed.
+ * Purpose: Tests the H5HG_remove() feature by writing lots of objects
+ * and occassionally removing some. When we're done they're all
+ * removed.
*
- * Return: Success: 0
+ * Return: Success: 0
*
- * Failure: number of errors
+ * Failure: number of errors
*
* Programmer: Robb Matzke
* Tuesday, March 31, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
test_4 (hid_t fapl)
{
- hid_t file = -1;
- H5F_t *f = NULL;
- H5HG_t *obj = NULL;
- uint8_t out[GHEAP_TEST_NOBJS];
- size_t u;
- size_t size;
- herr_t status;
- int nerrors = 0;
- char filename[1024];
+ hid_t file = H5I_INVALID_HID;
+ H5F_t *f = NULL;
+ H5HG_t *obj = NULL;
+ uint8_t out[GHEAP_TEST_NOBJS];
+ size_t u;
+ size_t size;
+ herr_t status;
+ int nerrors = 0;
+ char filename[1024];
TESTING("partial object removal");
@@ -390,10 +391,10 @@ test_4 (hid_t fapl)
/* Open a clean file */
h5_fixname(FILENAME[3], fapl, filename, sizeof filename);
if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
- goto error;
+ goto error;
if(NULL == (f = (H5F_t *)H5I_object(file))) {
H5_FAILED();
- puts(" Unable to create file");
+ HDputs(" Unable to create file");
goto error;
}
@@ -405,21 +406,20 @@ test_4 (hid_t fapl)
status = H5HG_insert(f, size, out, obj + u);
if (status<0) {
H5_FAILED();
- puts(" Unable to insert object into global heap");
+ HDputs(" Unable to insert object into global heap");
nerrors++;
}
- /*
- * Remove every third one beginning with the second, but after the
- * next one has already been inserted. That is, insert A, B, C;
- * remove B, insert D, E, F; remove E; etc.
- */
+ /* Remove every third one beginning with the second, but after the
+ * next one has already been inserted. That is, insert A, B, C;
+ * remove B, insert D, E, F; remove E; etc.
+ */
if(1 == (u % 3)) {
H5Eclear2(H5E_DEFAULT);
status = H5HG_remove(f, obj + u - 1);
if (status<0) {
H5_FAILED();
- puts(" Unable to remove object");
+ HDputs(" Unable to remove object");
nerrors++;
}
HDmemset(obj + u - 1, 0, sizeof *obj);
@@ -430,15 +430,17 @@ test_4 (hid_t fapl)
HDfree(obj);
obj = NULL;
- if (H5Fclose(file)<0) goto error;
- if (nerrors) goto error;
+ if(H5Fclose(file) < 0)
+ goto error;
+ if(nerrors)
+ goto error;
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
- H5Fclose(file);
+ H5Fclose(file);
} H5E_END_TRY;
if(obj)
HDfree(obj);
@@ -449,32 +451,30 @@ test_4 (hid_t fapl)
/*-------------------------------------------------------------------------
* Function: test_ooo_indices
*
- * Purpose: Tests that indices can be stored out of order. This can
+ * Purpose: Tests that indices can be stored out of order. This can
* happen when the indices "wrap around" due to many
* insertions and deletions (for example, from rewriting a
* VL dataset).
*
- * Return: Success: 0
+ * Return: Success: 0
*
- * Failure: number of errors
+ * Failure: number of errors
*
* Programmer: Neil Fortner
* Monday, October 26, 2009
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
test_ooo_indices(hid_t fapl)
{
- hid_t file = -1;
- H5F_t *f = NULL;
+ hid_t file = H5I_INVALID_HID;
+ H5F_t *f = NULL;
unsigned i, j;
- H5HG_t *obj = NULL;
- herr_t status;
- int nerrors=0;
- char filename[1024];
+ H5HG_t *obj = NULL;
+ herr_t status;
+ int nerrors = 0;
+ char filename[1024];
TESTING("out of order indices");
@@ -487,16 +487,18 @@ test_ooo_indices(hid_t fapl)
goto error;
if(NULL == (f = (H5F_t *)H5I_object(file))) {
H5_FAILED();
- puts(" Unable to create file");
+ HDputs(" Unable to create file");
goto error;
- } /* end if */
+ }
/* Alternately insert 1000 entries and remove the previous group of 1000
- * entries, until the indices wrap around */
- for(i=0; i<66; i++) {
+ * entries, until the indices wrap around.
+ */
+ for(i = 0; i < 66; i++) {
/* Insert 1000 entries. The index into the obj array will alternate up
* and down by 1000 so the previous set of insertions is preserved and
- * can be deleted. */
+ * can be deleted.
+ */
for(j=1000*((~i&1)); j<1000*((~i&1)+1); j++) {
H5Eclear2(H5E_DEFAULT);
status = H5HG_insert(f, sizeof(j), &j, &obj[j]);
@@ -506,7 +508,7 @@ test_ooo_indices(hid_t fapl)
/* Check that the index is as expected */
if(obj[j].idx != ((1000 * i) + j - (1000 * ((~i & 1)))) % ((1u << 16) - 1) + 1)
GHEAP_REPEATED_ERR(" Unexpected global heap index");
- } /* end for */
+ }
/* Remove the previous 1000 entries */
if(i>0)
@@ -515,20 +517,21 @@ test_ooo_indices(hid_t fapl)
status = H5HG_remove(f, &obj[j]);
if (status<0)
GHEAP_REPEATED_ERR(" Unable to remove object from global heap");
- } /* end for */
- } /* end for */
+ }
+ }
/* The indices should have "wrapped around" on the last iteration */
HDassert(obj[534].idx == 65535);
HDassert(obj[535].idx == 1);
/* Reopen the file */
- if (H5Fclose(file)<0) goto error;
+ if (H5Fclose(file) < 0)
+ goto error;
if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
goto error;
if(NULL == (f = (H5F_t *)H5I_object(file))) {
H5_FAILED();
- puts(" Unable to open file");
+ HDputs(" Unable to open file");
goto error;
} /* end if */
@@ -538,14 +541,15 @@ test_ooo_indices(hid_t fapl)
goto error;
if(i != j) {
H5_FAILED();
- puts(" Incorrect read value");
+ HDputs(" Incorrect read value");
goto error;
- } /* end if */
- } /* end for */
-
- if (H5Fclose(file)<0) goto error;
- if (nerrors) goto error;
+ }
+ }
+ if(H5Fclose(file) < 0)
+ goto error;
+ if(nerrors)
+ goto error;
HDfree(obj);
obj = NULL;
@@ -554,7 +558,7 @@ test_ooo_indices(hid_t fapl)
error:
H5E_BEGIN_TRY {
- H5Fclose(file);
+ H5Fclose(file);
} H5E_END_TRY;
if(obj)
HDfree(obj);
@@ -563,60 +567,58 @@ test_ooo_indices(hid_t fapl)
/*-------------------------------------------------------------------------
- * Function: main
+ * Function: main
*
- * Purpose: Tests global heap.
+ * Purpose: Tests global heap.
*
- * Return: Success: zero
- *
- * Failure: non-zero
- *
- * Programmer: Robb Matzke
- * Tuesday, March 31, 1998
- *
- * Modifications:
+ * Return: EXIT_SUCCESS/EXIT_FAILURE
*
*-------------------------------------------------------------------------
*/
int
main (void)
{
- int nerrors=0;
- hid_t fapl;
+ int nerrors = 0;
+ hid_t fapl_id = H5I_INVALID_HID;
hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */
h5_reset();
- fapl = h5_fileaccess();
+ if ((fapl_id = h5_fileaccess()) < 0)
+ goto error;
/* Push API context */
if(H5CX_push() < 0) FAIL_STACK_ERROR
api_ctx_pushed = TRUE;
- nerrors += test_1(fapl);
- nerrors += test_2(fapl);
- nerrors += test_3(fapl);
- nerrors += test_4(fapl);
- nerrors += test_ooo_indices(fapl);
+ nerrors += test_1(fapl_id);
+ nerrors += test_2(fapl_id);
+ nerrors += test_3(fapl_id);
+ nerrors += test_4(fapl_id);
+ nerrors += test_ooo_indices(fapl_id);
/* Verify symbol table messages are cached */
- nerrors += (h5_verify_cached_stabs(FILENAME, fapl) < 0 ? 1 : 0);
+ nerrors += (h5_verify_cached_stabs(FILENAME, fapl_id) < 0 ? 1 : 0);
if (nerrors)
goto error;
- puts("All global heap tests passed.");
+
+ HDputs("All global heap tests passed.");
/* Pop API context */
if(api_ctx_pushed && H5CX_pop() < 0) FAIL_STACK_ERROR
api_ctx_pushed = FALSE;
- h5_cleanup(FILENAME, fapl);
- return 0;
+ h5_cleanup(FILENAME, fapl_id);
+ HDexit(EXIT_SUCCESS);
error:
- puts("*** TESTS FAILED ***");
+ H5E_BEGIN_TRY {
+ H5Pclose(fapl_id);
+ } H5E_END_TRY;
if(api_ctx_pushed) H5CX_pop();
- return 1;
-}
+ HDputs("*** TESTS FAILED ***");
+ HDexit(EXIT_FAILURE);
+} /* end main() */