Skip to content

Commit

Permalink
Test H5Ovisit on file, nested groups, and attributes (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala authored Jan 10, 2024
1 parent 5a70ae8 commit a254a37
Show file tree
Hide file tree
Showing 2 changed files with 244 additions and 30 deletions.
255 changes: 231 additions & 24 deletions vol_object_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ static herr_t object_copy_soft_link_expand_callback(hid_t group, const char *nam
void *op_data);
static herr_t object_visit_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info,
void *op_data);
static herr_t object_visit_simple_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info,
void *op_data);
static herr_t object_visit_dset_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info,
void *op_data);
static herr_t object_visit_dtype_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info,
Expand Down Expand Up @@ -5057,15 +5059,23 @@ test_object_comments_invalid_params(void)
static int
test_object_visit(void)
{
size_t i;
hid_t file_id = H5I_INVALID_HID;
hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID;
hid_t group_id2 = H5I_INVALID_HID;
hid_t gcpl_id = H5I_INVALID_HID;
hid_t type_id = H5I_INVALID_HID;
hid_t dset_id = H5I_INVALID_HID;
hid_t dset_dtype = H5I_INVALID_HID;
hid_t fspace_id = H5I_INVALID_HID;
size_t i;
hid_t file_id = H5I_INVALID_HID;
hid_t file_id2 = H5I_INVALID_HID;
hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID;
hid_t group_id2 = H5I_INVALID_HID;
hid_t gcpl_id = H5I_INVALID_HID;
hid_t type_id = H5I_INVALID_HID;
hid_t dset_id = H5I_INVALID_HID;
hid_t dset_dtype = H5I_INVALID_HID;
hid_t fspace_id = H5I_INVALID_HID;
hid_t attr_id = H5I_INVALID_HID;
hid_t group_id3 = H5I_INVALID_HID;
hid_t group_id4 = H5I_INVALID_HID;
hid_t group_id5 = H5I_INVALID_HID;
hssize_t num_elems = 0;
size_t elem_size = 0;
char visit_filename[VOL_TEST_FILENAME_MAX_LENGTH];

TESTING_MULTIPART("object visiting");

Expand All @@ -5088,6 +5098,15 @@ test_object_visit(void)
goto error;
}

HDsnprintf(visit_filename, VOL_TEST_FILENAME_MAX_LENGTH, "%s%s", test_path_prefix,
OBJECT_VISIT_TEST_FILE_NAME);

if ((file_id2 = H5Fcreate(visit_filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't open file '%s'\n", OBJECT_VISIT_TEST_FILE_NAME);
goto error;
}

if ((container_group = H5Gopen2(file_id, OBJECT_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't open container group '%s'\n", OBJECT_TEST_GROUP_NAME);
Expand Down Expand Up @@ -5115,25 +5134,72 @@ test_object_visit(void)
goto error;
}

if ((fspace_id = generate_random_dataspace(OBJECT_VISIT_TEST_SPACE_RANK, NULL, NULL, FALSE)) < 0)
TEST_ERROR;
/* Make sure not to generate too much data for an attribute to hold */
do {
if (fspace_id != H5I_INVALID_HID)
H5Sclose(fspace_id);

if ((dset_dtype = generate_random_datatype(H5T_NO_CLASS, FALSE)) < 0)
TEST_ERROR;
if (dset_dtype != H5I_INVALID_HID)
H5Tclose(dset_dtype);

if ((fspace_id = generate_random_dataspace(OBJECT_VISIT_TEST_SPACE_RANK, NULL, NULL, FALSE)) < 0) {
TEST_ERROR;
}

if ((dset_dtype = generate_random_datatype(H5T_NO_CLASS, FALSE)) < 0) {
TEST_ERROR;
}

if ((num_elems = H5Sget_simple_extent_npoints(fspace_id)) < 0)
TEST_ERROR;

if ((elem_size = H5Tget_size(dset_dtype)) == 0)
TEST_ERROR;

} while ((num_elems * elem_size) > OBJECT_VISIT_TEST_TOTAL_DATA_SIZE_LIMIT);

if ((type_id = generate_random_datatype(H5T_NO_CLASS, FALSE)) < 0) {
H5_FAILED();
HDprintf(" couldn't create datatype '%s'\n", OBJECT_VISIT_TEST_TYPE_NAME);
goto error;
}

if ((attr_id = H5Acreate2(group_id, OBJECT_VISIT_TEST_ATTR_NAME, dset_dtype, fspace_id, H5P_DEFAULT,
H5P_DEFAULT)) == H5I_INVALID_HID) {
H5_FAILED();
HDprintf(" couldn't create attribute '%s' on group '%s'\n", OBJECT_VISIT_TEST_ATTR_NAME,
OBJECT_VISIT_TEST_SUBGROUP_NAME);
goto error;
}

if ((group_id2 = H5Gcreate2(group_id, OBJECT_VISIT_TEST_GROUP_NAME, H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) <
0) {
H5_FAILED();
HDprintf(" couldn't create group '%s'\n", OBJECT_VISIT_TEST_GROUP_NAME);
goto error;
}

if ((group_id3 = H5Gcreate2(file_id2, OBJECT_VISIT_TEST_GROUP_NAME_PARENT, H5P_DEFAULT, gcpl_id,
H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't create group '%s'\n", OBJECT_VISIT_TEST_GROUP_NAME_PARENT);
goto error;
}

if ((group_id4 = H5Gcreate2(group_id3, OBJECT_VISIT_TEST_GROUP_NAME_CHILD, H5P_DEFAULT, gcpl_id,
H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't create group '%s'\n", OBJECT_VISIT_TEST_GROUP_NAME_CHILD);
goto error;
}

if ((group_id5 = H5Gcreate2(group_id4, OBJECT_VISIT_TEST_GROUP_NAME_GRANDCHILD, H5P_DEFAULT, gcpl_id,
H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't create group '%s'\n", OBJECT_VISIT_TEST_GROUP_NAME_GRANDCHILD);
goto error;
}

if ((dset_id = H5Dcreate2(group_id, OBJECT_VISIT_TEST_DSET_NAME, dset_dtype, fspace_id, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT)) < 0) {
H5_FAILED();
Expand Down Expand Up @@ -5266,16 +5332,49 @@ test_object_visit(void)
}
PART_END(H5Ovisit_create_order_decreasing);

PART_BEGIN(H5Ovisit_group)
{
TESTING_2("H5Ovisit on a group");

i = 0;

if (H5Ovisit3(group_id3, H5_INDEX_CRT_ORDER, H5_ITER_INC, object_visit_simple_callback, &i,
H5O_INFO_ALL) < 0) {
H5_FAILED();
HDprintf(" H5Ovisit on a group failed!\n");
PART_ERROR(H5Ovisit_group);
}

if (i != OBJECT_VISIT_TEST_SUBGROUP_LAYERS) {
H5_FAILED();
HDprintf(" some objects were not visited!\n");
PART_ERROR(H5Ovisit_group);
}

PASSED();
}
PART_END(H5Ovisit_group);

PART_BEGIN(H5Ovisit_file)
{
TESTING_2("H5Ovisit on a file ID");

/*
* XXX:
*/
i = 0;

if (H5Ovisit3(file_id2, H5_INDEX_CRT_ORDER, H5_ITER_INC, object_visit_simple_callback, &i,
H5O_INFO_ALL) < 0) {
H5_FAILED();
HDprintf(" H5Ovisit on a file ID failed!\n");
PART_ERROR(H5Ovisit_file);
}

SKIPPED();
PART_EMPTY(H5Ovisit_file);
if (i != OBJECT_VISIT_TEST_NUM_OBJS_VISITED) {
H5_FAILED();
HDprintf(" some objects were not visited!\n");
PART_ERROR(H5Ovisit_file);
}

PASSED();
}
PART_END(H5Ovisit_file);

Expand Down Expand Up @@ -5309,6 +5408,30 @@ test_object_visit(void)
}
PART_END(H5Ovisit_dtype);

PART_BEGIN(H5Ovisit_attr)
{
TESTING_2("H5Ovisit on an attribute")

i = 0;

if (H5Ovisit3(attr_id, H5_INDEX_CRT_ORDER, H5_ITER_INC, object_visit_simple_callback, &i,
H5O_INFO_ALL) < 0) {
H5_FAILED();
HDprintf(" H5Ovisit on an attribute failed!\n");
PART_ERROR(H5Ovisit_attr);
}

/* Should have same effect as calling H5Ovisit on group_id */
if (i != OBJECT_VISIT_TEST_NUM_OBJS_VISITED) {
H5_FAILED();
HDprintf(" some objects were not visited!\n");
PART_ERROR(H5Ovisit_attr);
}

PASSED();
}
PART_END(H5Ovisit_attr);

PART_BEGIN(H5Ovisit_by_name_obj_name_increasing)
{
TESTING_2("H5Ovisit_by_name by object name in increasing order");
Expand Down Expand Up @@ -5489,12 +5612,22 @@ test_object_visit(void)
{
TESTING_2("H5Ovisit_by_name on a file ID");

/*
* XXX:
*/
i = 0;

if (H5Ovisit_by_name3(file_id2, "/", H5_INDEX_CRT_ORDER, H5_ITER_INC,
object_visit_simple_callback, &i, H5O_INFO_ALL, H5P_DEFAULT) < 0) {
H5_FAILED();
HDprintf(" H5Ovisit on a file ID failed!\n");
PART_ERROR(H5Ovisit_by_name_file);
}

SKIPPED();
PART_EMPTY(H5Ovisit_by_name_file);
if (i != OBJECT_VISIT_TEST_NUM_OBJS_VISITED) {
H5_FAILED();
HDprintf(" some objects were not visited!\n");
PART_ERROR(H5Ovisit_by_name_file);
}

PASSED();
}
PART_END(H5Ovisit_by_name_file);

Expand Down Expand Up @@ -5527,6 +5660,30 @@ test_object_visit(void)
PASSED();
}
PART_END(H5Ovisit_by_name_dtype);

PART_BEGIN(H5Ovisit_by_name_attr)
{
TESTING_2("H5Ovisit_by_name on an attribute")

i = 0;

if (H5Ovisit_by_name(attr_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, object_visit_simple_callback,
&i, H5O_INFO_ALL, H5P_DEFAULT) < 0) {
H5_FAILED();
HDprintf(" H5Ovisit_by_name on an attribute failed!\n");
PART_ERROR(H5Ovisit_by_name_attr);
}

/* Should have same effect as calling H5Ovisit on group_id */
if (i != OBJECT_VISIT_TEST_NUM_OBJS_VISITED) {
H5_FAILED();
HDprintf(" some objects were not visited!\n");
PART_ERROR(H5Ovisit_by_name_attr);
}

PASSED();
}
PART_END(H5Ovisit_by_name_attr);
}
END_MULTIPART;

Expand All @@ -5544,12 +5701,22 @@ test_object_visit(void)
TEST_ERROR;
if (H5Gclose(group_id2) < 0)
TEST_ERROR;
if (H5Gclose(group_id3) < 0)
TEST_ERROR;
if (H5Gclose(group_id4) < 0)
TEST_ERROR;
if (H5Gclose(group_id5) < 0)
TEST_ERROR;
if (H5Aclose(attr_id) < 0)
TEST_ERROR;
if (H5Gclose(group_id) < 0)
TEST_ERROR;
if (H5Gclose(container_group) < 0)
TEST_ERROR;
if (H5Fclose(file_id) < 0)
TEST_ERROR;
if (H5Fclose(file_id2) < 0)
TEST_ERROR;

PASSED();

Expand All @@ -5564,9 +5731,14 @@ test_object_visit(void)
H5Dclose(dset_id);
H5Pclose(gcpl_id);
H5Gclose(group_id2);
H5Gclose(group_id3);
H5Gclose(group_id4);
H5Gclose(group_id5);
H5Aclose(attr_id);
H5Gclose(group_id);
H5Gclose(container_group);
H5Fclose(file_id);
H5Fclose(file_id2);
}
H5E_END_TRY;

Expand Down Expand Up @@ -7077,6 +7249,26 @@ object_visit_callback(hid_t o_id, const char *name, const H5O_info2_t *object_in
return ret_val;
}

static herr_t
object_visit_simple_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info, void *op_data)
{
size_t *i = (size_t *)op_data;
herr_t ret_val = 0;

UNUSED(o_id);
UNUSED(object_info);

if (name)
goto done;

ret_val = -1;

done:
(*i)++;

return ret_val;
}

/*
* H5Ovisit callback for visiting a singular dataset.
*/
Expand Down Expand Up @@ -7138,6 +7330,14 @@ object_visit_soft_link_callback(hid_t o_id, const char *name, const H5O_info2_t

UNUSED(o_id);

if (!HDstrcmp(name, OBJECT_VISIT_TEST_GROUP_NAME_PARENT) ||
!HDstrcmp(name, OBJECT_VISIT_TEST_GROUP_NAME_PARENT "/" OBJECT_VISIT_TEST_GROUP_NAME_CHILD) ||
!HDstrcmp(name, OBJECT_VISIT_TEST_GROUP_NAME_PARENT "/" OBJECT_VISIT_TEST_GROUP_NAME_CHILD
"/" OBJECT_VISIT_TEST_GROUP_NAME_GRANDCHILD)) {
(*i)--;
goto done;
}

if (!HDstrncmp(name, ".", strlen(".") + 1) && (counter_val <= 5)) {
if (H5O_TYPE_GROUP == object_info->type)
goto done;
Expand Down Expand Up @@ -7176,7 +7376,14 @@ object_visit_noop_callback(hid_t o_id, const char *name, const H5O_info2_t *obje
static void
cleanup_files(void)
{
H5Fdelete(OBJECT_COPY_BETWEEN_FILES_TEST_FILE_NAME, H5P_DEFAULT);
char filename[VOL_TEST_FILENAME_MAX_LENGTH];

HDsnprintf(filename, VOL_TEST_FILENAME_MAX_LENGTH, "%s%s", test_path_prefix,
OBJECT_COPY_BETWEEN_FILES_TEST_FILE_NAME);
H5Fdelete(filename, H5P_DEFAULT);

HDsnprintf(filename, VOL_TEST_FILENAME_MAX_LENGTH, "%s%s", test_path_prefix, OBJECT_VISIT_TEST_FILE_NAME);
H5Fdelete(filename, H5P_DEFAULT);
}

int
Expand Down
Loading

0 comments on commit a254a37

Please sign in to comment.