Skip to content

Commit

Permalink
Correct free-list test
Browse files Browse the repository at this point in the history
Add some more API calls, to use block lists.  Also release memory on the free
lists before using data structures, so we're confident that the API routines
are allocating free-list memory correctly.

Signed-off-by: Quincey Koziol <[email protected]>
  • Loading branch information
qkoziol committed Nov 18, 2024
1 parent 4060515 commit f9900b4
Showing 1 changed file with 58 additions and 20 deletions.
78 changes: 58 additions & 20 deletions test/tmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ typedef struct {
#define MISC33_FILE "bad_offset.h5"

/* Definitions for misc. test #35 */
#define MISC35_FILE "tmisc35.h5"
#define MISC35_GROUPNAME "group"
#define MISC35_SPACE_RANK 3
#define MISC35_SPACE_DIM1 3
#define MISC35_SPACE_DIM2 15
Expand Down Expand Up @@ -6076,15 +6078,22 @@ test_misc34(void)
static void
test_misc35(void)
{
hid_t file, group;
hid_t sid = H5I_INVALID_HID; /* Dataspace ID */
hsize_t dims[] = {MISC35_SPACE_DIM1, MISC35_SPACE_DIM2, MISC35_SPACE_DIM3}; /* Dataspace dims */
hsize_t coord[MISC35_NPOINTS][MISC35_SPACE_RANK] = /* Coordinates for point selection */
{{0, 10, 5}, {1, 2, 7}, {2, 4, 9}, {0, 6, 11}, {1, 8, 13},
{2, 12, 0}, {0, 14, 2}, {1, 0, 4}, {2, 1, 6}, {0, 3, 8}};
#if !defined H5_NO_FREE_LISTS && !defined H5_USING_MEMCHECKER
size_t reg_size_start; /* Initial amount of regular memory allocated */
size_t arr_size_start; /* Initial amount of array memory allocated */
size_t blk_size_start; /* Initial amount of block memory allocated */
size_t fac_size_start; /* Initial amount of factory memory allocated */
#endif
size_t reg_size_mid; /* Mid-point amount of regular memory allocated */
size_t arr_size_mid; /* Mid-point amount of array memory allocated */
size_t blk_size_mid; /* Mid-point amount of block memory allocated */
size_t fac_size_mid; /* Mid-point amount of factory memory allocated */
size_t reg_size_final; /* Final amount of regular memory allocated */
size_t arr_size_final; /* Final amount of array memory allocated */
size_t blk_size_final; /* Final amount of block memory allocated */
Expand All @@ -6094,8 +6103,19 @@ test_misc35(void)
/* Output message about test being performed */
MESSAGE(5, ("Free-list API calls"));

#if !defined H5_NO_FREE_LISTS && !defined H5_USING_MEMCHECKER
/* Garbage collect the free lists, so there's nothing on the free lists */
/* (There may still be allocated memory of various free-list types) */
ret = H5garbage_collect();
CHECK(ret, FAIL, "H5garbage_collect");

/* Retrieve free list values */
ret = H5get_free_list_sizes(&reg_size_start, &arr_size_start, &blk_size_start, &fac_size_start);
CHECK(ret, FAIL, "H5get_free_list_sizes");
#endif

/* Create dataspace */
/* (Allocates array free-list nodes) */
/* (Allocates regular, array, and factory free-list nodes) */
sid = H5Screate_simple(MISC35_SPACE_RANK, dims, NULL);
CHECK(sid, H5I_INVALID_HID, "H5Screate_simple");

Expand All @@ -6107,22 +6127,41 @@ test_misc35(void)
ret = H5Sclose(sid);
CHECK(ret, FAIL, "H5Sclose");

/* Create a file */
file = H5Fcreate(MISC35_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(file, FAIL, "H5Fcreate");

/* Create a group */
/* (Allocates block free-list nodes) */
group = H5Gcreate2(file, MISC35_GROUPNAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(group, FAIL, "H5Gcreate2");

ret = H5Gclose(group);
CHECK(ret, FAIL, "H5Gclose");

ret = H5Fclose(file);
CHECK(ret, FAIL, "H5Fclose");

/* Retrieve initial free list values */
ret = H5get_free_list_sizes(&reg_size_start, &arr_size_start, &blk_size_start, &fac_size_start);
ret = H5get_free_list_sizes(&reg_size_mid, &arr_size_mid, &blk_size_mid, &fac_size_mid);
CHECK(ret, FAIL, "H5get_free_list_sizes");

#if !defined H5_NO_FREE_LISTS && !defined H5_USING_MEMCHECKER
/* All the free list values should be >0 */
CHECK(reg_size_start, 0, "H5get_free_list_sizes");
CHECK(arr_size_start, 0, "H5get_free_list_sizes");
CHECK(blk_size_start, 0, "H5get_free_list_sizes");
CHECK(fac_size_start, 0, "H5get_free_list_sizes");
/* All the mid-point free list values should be >= previous values */
if (reg_size_mid < reg_size_start)
ERROR("reg_size_mid < reg_size_start");
if (arr_size_mid < arr_size_start)
ERROR("arr_size_mid < arr_size_start");
if (blk_size_mid < blk_size_start)
ERROR("blk_size_mid < blk_size_start");
if (fac_size_mid < fac_size_start)
ERROR("fac_size_mid < fac_size_start");
#else
/* All the values should be == 0 */
VERIFY(reg_size_start, 0, "H5get_free_list_sizes");
VERIFY(arr_size_start, 0, "H5get_free_list_sizes");
VERIFY(blk_size_start, 0, "H5get_free_list_sizes");
VERIFY(fac_size_start, 0, "H5get_free_list_sizes");
VERIFY(reg_size_mid, 0, "H5get_free_list_sizes - regular");
VERIFY(arr_size_mid, 0, "H5get_free_list_sizes - array");
VERIFY(blk_size_mid, 0, "H5get_free_list_sizes - block");
VERIFY(fac_size_mid, 0, "H5get_free_list_sizes - factory");
#endif

/* Garbage collect the free lists */
Expand All @@ -6134,15 +6173,14 @@ test_misc35(void)
CHECK(ret, FAIL, "H5get_free_list_sizes");

/* All the free list values should be <= previous values */
if (reg_size_final > reg_size_start)
ERROR("reg_size_final > reg_size_start");
if (arr_size_final > arr_size_start)
ERROR("arr_size_final > arr_size_start");
if (blk_size_final > blk_size_start)
ERROR("blk_size_final > blk_size_start");
if (fac_size_final > fac_size_start)
ERROR("fac_size_final > fac_size_start");

if (reg_size_final > reg_size_mid)
ERROR("reg_size_final > reg_size_mid");
if (arr_size_final > arr_size_mid)
ERROR("arr_size_final > arr_size_mid");
if (blk_size_final > blk_size_mid)
ERROR("blk_size_final > blk_size_mid");
if (fac_size_final > fac_size_mid)
ERROR("fac_size_final > fac_size_mid");
} /* end test_misc35() */

/* Context to pass to 'atclose' callbacks */
Expand Down

0 comments on commit f9900b4

Please sign in to comment.