Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test H5Ovisit on file, nested groups, and attributes #58

Merged
merged 6 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 198 additions & 11 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 @@ -5059,13 +5061,19 @@ test_object_visit(void)
{
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;
char visit_filename[VOL_TEST_FILENAME_MAX_LENGTH];

TESTING_MULTIPART("object visiting");

Expand All @@ -5088,6 +5096,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 @@ -5127,13 +5144,42 @@ test_object_visit(void)
goto error;
}

if ((attr_id = H5Acreate(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 +5312,41 @@ test_object_visit(void)
}
PART_END(H5Ovisit_create_order_decreasing);

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

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);
}
jhendersonHDF marked this conversation as resolved.
Show resolved Hide resolved

PASSED();
}
PART_END(H5Ovisit_group);

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

/*
* XXX:
*/
i = 0;

SKIPPED();
PART_EMPTY(H5Ovisit_file);
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);
}

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 +5380,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) {
jhendersonHDF marked this conversation as resolved.
Show resolved Hide resolved
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 +5584,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);
}

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

SKIPPED();
PART_EMPTY(H5Ovisit_by_name_file);
PASSED();
}
PART_END(H5Ovisit_by_name_file);

Expand Down Expand Up @@ -5527,6 +5632,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 +5673,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 +5703,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 @@ -7038,6 +7182,14 @@ object_visit_callback(hid_t o_id, const char *name, const H5O_info2_t *object_in

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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest rearranging the group hierarchy or even putting the nested groups in the separate new file created so that you don't have to worry about decrementing the counter here in other unrelated parts of the H5Ovisit test. That way the two different parts aren't dependent on each other and won't get out of sync and require more strcmp logic here if more nested groups are added.


if (!HDstrncmp(name, ".", strlen(".") + 1) &&
(counter_val == 0 || counter_val == 4 || counter_val == 8 || counter_val == 12)) {
if (H5O_TYPE_GROUP == object_info->type)
Expand Down Expand Up @@ -7077,6 +7229,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 +7310,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 +7356,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(OBJECT_VISIT_TEST_FILE_NAME, H5P_DEFAULT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be filename instead of OBJECT_VISIT_TEST_FILE_NAME

}

int
Expand Down
17 changes: 11 additions & 6 deletions vol_object_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,17 @@ int vol_object_test(void);
#define OBJECT_COPY_INVALID_PARAMS_TEST_GROUP_NAME "object_copy_invalid_params_group"
#define OBJECT_COPY_INVALID_PARAMS_TEST_GROUP_NAME2 "object_copy_invalid_params_group_copy"

#define OBJECT_VISIT_TEST_NUM_OBJS_VISITED 4
#define OBJECT_VISIT_TEST_SUBGROUP_NAME "object_visit_test"
#define OBJECT_VISIT_TEST_SPACE_RANK 2
#define OBJECT_VISIT_TEST_GROUP_NAME "object_visit_test_group"
#define OBJECT_VISIT_TEST_DSET_NAME "object_visit_test_dset"
#define OBJECT_VISIT_TEST_TYPE_NAME "object_visit_test_type"
#define OBJECT_VISIT_TEST_NUM_OBJS_VISITED 4
#define OBJECT_VISIT_TEST_SUBGROUP_NAME "object_visit_test"
#define OBJECT_VISIT_TEST_SPACE_RANK 2
#define OBJECT_VISIT_TEST_GROUP_NAME "object_visit_test_group"
#define OBJECT_VISIT_TEST_DSET_NAME "object_visit_test_dset"
#define OBJECT_VISIT_TEST_TYPE_NAME "object_visit_test_type"
#define OBJECT_VISIT_TEST_ATTR_NAME "object_visit_test_attr"
#define OBJECT_VISIT_TEST_FILE_NAME "object_visit_test_file"
#define OBJECT_VISIT_TEST_GROUP_NAME_PARENT "object_visit_test_group_parent"
#define OBJECT_VISIT_TEST_GROUP_NAME_CHILD "object_visit_test_group_child"
#define OBJECT_VISIT_TEST_GROUP_NAME_GRANDCHILD "object_visit_test_group_grandchild"

#define OBJECT_VISIT_SOFT_LINK_TEST_NUM_OBJS_VISITED 1
#define OBJECT_VISIT_SOFT_LINK_TEST_SUBGROUP_NAME "object_visit_soft_link"
Expand Down