Skip to content

Commit

Permalink
Backport to 1.12: Adds a quick for for some egregious chunk_info badn…
Browse files Browse the repository at this point in the history
…ess (HDFGroup#722)
  • Loading branch information
derobins authored and mkitti committed Aug 7, 2022
1 parent 441e02c commit 00cf651
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions test/chunk_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -1490,21 +1490,24 @@ typedef struct chunk_iter_info_t {
uint32_t nbytes;
} chunk_iter_info_t;

typedef struct chunk_iter_udata_t {
chunk_iter_info_t *chunk_info;
int last_index;
} chunk_iter_udata_t;

static int
iter_cb(const hsize_t *offset, uint32_t filter_mask, haddr_t addr, uint32_t nbytes, void *op_data)
{
chunk_iter_info_t **chunk_info = (chunk_iter_info_t **)op_data;
chunk_iter_udata_t *cidata = (chunk_iter_udata_t *)op_data;
int idx = cidata->last_index + 1;

(*chunk_info)->offset[0] = offset[0];
(*chunk_info)->offset[1] = offset[1];
(*chunk_info)->filter_mask = filter_mask;
(*chunk_info)->addr = addr;
(*chunk_info)->nbytes = nbytes;
cidata->chunk_info[idx].offset[0] = offset[0];
cidata->chunk_info[idx].offset[1] = offset[1];
cidata->chunk_info[idx].filter_mask = filter_mask;
cidata->chunk_info[idx].addr = addr;
cidata->chunk_info[idx].nbytes = nbytes;

/* printf("offset: [%lld, %lld], addr: %ld, size: %d, filter mask: %d\n", offset[0], offset[1], addr,
* nbytes, filter_mask); */

*chunk_info += 1;
cidata->last_index++;

return H5_ITER_CONT;
}
Expand Down Expand Up @@ -1564,8 +1567,9 @@ test_basic_query(hid_t fapl)
haddr_t addr = 0; /* Address of an allocated/written chunk */
hsize_t chk_index = 0; /* Index of a chunk */
hsize_t ii, jj; /* Array indices */
chunk_iter_info_t chunk_infos[2]; /* chunk infos filled up by iterator */
chunk_iter_info_t *cptr; /* pointer to array of chunks */
chunk_iter_info_t chunk_infos[2]; /* Chunk infos filled up by iterator */
chunk_iter_info_t *cptr; /* Pointer to array of chunks */
chunk_iter_udata_t udata; /* udata for iteration */
herr_t ret; /* Temporary returned value for verifying failure */

TESTING("basic operations");
Expand Down Expand Up @@ -1674,12 +1678,13 @@ test_basic_query(hid_t fapl)
if (verify_empty_chunk_info(dset, offset) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord on empty chunk failed\n");

/* iterate over all chunks */
cptr = &(chunk_infos[0]);
if (H5Dchunk_iter(dset, &iter_cb, &cptr) < 0)
/* Iterate over all chunks */
udata.chunk_info = chunk_infos;
udata.last_index = -1;
if (H5Dchunk_iter(dset, H5P_DEFAULT, &iter_cb, &udata) < 0)
TEST_ERROR;

VERIFY(cptr, &(chunk_infos[2]), "Iterator did not iterate all chunks");
VERIFY(udata.last_index, 1, "Iterator did not iterate all chunks");
VERIFY(chunk_infos[0].offset[0], 0, "Offset mismatch");
VERIFY(chunk_infos[0].offset[1], 0, "Offset mismatch");
VERIFY(chunk_infos[0].filter_mask, 0, "Filter mismatch");
Expand All @@ -1688,13 +1693,13 @@ test_basic_query(hid_t fapl)
VERIFY(chunk_infos[1].offset[0], 1, "Offset mismatch");
VERIFY(chunk_infos[1].offset[1], 1, "Offset mismatch");

/* iterate and stop after one iteration */
/* Iterate and stop after one iteration */
cptr = &(chunk_infos[0]);
if (H5Dchunk_iter(dset, &iter_cb_stop, &cptr) < 0)
TEST_ERROR;
VERIFY(cptr, &(chunk_infos[1]), "Verification of halted iterator failed\n");

/* iterate and fail after one iteration */
/* Iterate and fail after one iteration */
cptr = &(chunk_infos[0]);
H5E_BEGIN_TRY
{
Expand Down

0 comments on commit 00cf651

Please sign in to comment.