From 9155785889af8ae809fb5e9cdbb330710a174d72 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 18 Jan 2007 09:32:27 -0500 Subject: [svn-r13152] Description: Add anotherdense/shared attribute test. Clean up minor attribute/object header codelets, in preparation for adding creation index to attributes. Tested on: Mac OS X/32 10.4.8 (amazon) FreeBSD/32 6.2 (duty) --- src/H5Adense.c | 5 ++ src/H5Apkg.h | 2 +- src/H5Oattr.c | 10 +-- src/H5Oattribute.c | 2 +- src/H5Omessage.c | 25 ++++---- src/H5SM.c | 5 ++ test/tattr.c | 179 +++++++++++++++++++++++++++++++++++------------------ 7 files changed, 148 insertions(+), 80 deletions(-) diff --git a/src/H5Adense.c b/src/H5Adense.c index e9eeafa..0418427 100644 --- a/src/H5Adense.c +++ b/src/H5Adense.c @@ -48,6 +48,11 @@ /****************/ /* Fractal heap creation parameters for "dense" attribute storage */ +/* (Note that these parameters have been tuned so that the resulting heap ID + * is exactly 8 bytes. This is an efficient size and is also the same as + * the size of the shared message heap IDs, think carefully before + * changing it. -QAK) + */ #define H5A_FHEAP_MAN_WIDTH 4 #define H5A_FHEAP_MAN_START_BLOCK_SIZE 512 #define H5A_FHEAP_MAN_MAX_DIRECT_SIZE (64 * 1024) diff --git a/src/H5Apkg.h b/src/H5Apkg.h index 82471d1..ca4b50d 100644 --- a/src/H5Apkg.h +++ b/src/H5Apkg.h @@ -65,13 +65,13 @@ struct H5A_t { H5O_loc_t oloc; /* Object location for object attribute is on */ H5G_name_t path; /* Group hierarchy path */ char *name; /* Attribute's name */ + H5T_cset_t encoding; /* Character encoding of attribute name */ H5T_t *dt; /* Attribute's datatype */ size_t dt_size; /* Size of datatype on disk */ H5S_t *ds; /* Attribute's dataspace */ size_t ds_size; /* Size of dataspace on disk */ void *data; /* Attribute data (on a temporary basis) */ size_t data_size; /* Size of data on disk */ - H5T_cset_t encoding; /* Character encoding of attribute */ H5O_shared_t sh_loc; /* Location of shared message */ }; diff --git a/src/H5Oattr.c b/src/H5Oattr.c index c29c19e..d70aab0 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -834,7 +834,7 @@ H5O_attr_copy_file(H5F_t *file_src, const H5O_msg_class_t UNUSED *mesg_type, /* Don't have an opened group location for copy */ H5O_loc_reset(&(attr_dst->oloc)); H5G_name_reset(&(attr_dst->path)); - attr_dst->obj_opened = 0; + attr_dst->obj_opened = FALSE; /* Copy attribute's name */ attr_dst->name = H5MM_strdup(attr_src->name); @@ -1205,12 +1205,12 @@ H5O_attr_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE * stream, int in fprintf(stream, "%*s%-*s \"%s\"\n", indent, "", fwidth, "Name:", mesg->name); - fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, + HDfprintf(stream, "%*s%-*s %t\n", indent, "", fwidth, "Initialized:", - (unsigned int)mesg->initialized); - fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, + mesg->initialized); + HDfprintf(stream, "%*s%-*s %t\n", indent, "", fwidth, "Object opened:", - (unsigned int)mesg->obj_opened); + mesg->obj_opened); HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, "Object:", mesg->oloc.addr); diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c index 237e352..6cc3c02 100644 --- a/src/H5Oattribute.c +++ b/src/H5Oattribute.c @@ -252,7 +252,7 @@ HDfprintf(stderr, "%s: adding attribute, attr->name = '%s'\n", FUNC, attr->name) * "delete" callback until the reference count drops to zero. * However, attributes have already increased the reference * count on shared components before passing the attribute - * to the shared message code to manage, causing an assymetry + * to the shared message code to manage, causing an asymmetry * in the reference counting for any shared components. * * The alternate solution is to have the shared message's "try diff --git a/src/H5Omessage.c b/src/H5Omessage.c index 54bbdf4..2e01516 100644 --- a/src/H5Omessage.c +++ b/src/H5Omessage.c @@ -103,7 +103,7 @@ static unsigned H5O_new_mesg(H5F_t *f, H5O_t *oh, unsigned *flags, const H5O_msg_class_t *orig_type, const void *orig_mesg, H5O_shared_t *sh_mesg, const H5O_msg_class_t **new_type, const void **new_mesg, hid_t dxpl_id, unsigned *oh_flags_ptr); -static herr_t H5O_write_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned idx, +static herr_t H5O_copy_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned idx, const H5O_msg_class_t *type, const void *mesg, unsigned flags, unsigned update_flags, unsigned *oh_flags_ptr); @@ -272,8 +272,8 @@ H5O_msg_append_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, const H5O_msg_class_t *t if((idx = H5O_new_mesg(f, oh, &mesg_flags, type, mesg, &sh_mesg, &new_type, &new_mesg, dxpl_id, oh_flags_ptr)) == UFAIL) HGOTO_ERROR(H5E_OHDR, H5E_NOSPACE, FAIL, "unable to create new message") - /* Write the information to the message */ - if(H5O_write_mesg(f, dxpl_id, oh, idx, new_type, new_mesg, mesg_flags, update_flags, oh_flags_ptr) < 0) + /* Copy the information for the message */ + if(H5O_copy_mesg(f, dxpl_id, oh, idx, new_type, new_mesg, mesg_flags, update_flags, oh_flags_ptr) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, FAIL, "unable to write message") #ifdef H5O_DEBUG H5O_assert(oh); @@ -458,8 +458,8 @@ H5O_msg_write_real(H5F_t *f, H5O_t *oh, const H5O_msg_class_t *type, write_mesg = &sh_mesg; } /* end if */ - /* Write the information to the message */ - if(H5O_write_mesg(f, dxpl_id, oh, idx, write_type, write_mesg, mesg_flags, update_flags, oh_flags_ptr) < 0) + /* Copy the information for the message */ + if(H5O_copy_mesg(f, dxpl_id, oh, idx, write_type, write_mesg, mesg_flags, update_flags, oh_flags_ptr) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to write message") #ifdef H5O_DEBUG H5O_assert(oh); @@ -2001,9 +2001,10 @@ done: /*------------------------------------------------------------------------- - * Function: H5O_write_mesg + * Function: H5O_copy_mesg * - * Purpose: Write message to object header + * Purpose: Make a copy of the native object for an object header's + * native message info * * Return: Non-negative on success/Negative on failure * @@ -2013,14 +2014,14 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_write_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned idx, +H5O_copy_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned idx, const H5O_msg_class_t *type, const void *mesg, unsigned mesg_flags, unsigned update_flags, unsigned *oh_flags_ptr) { H5O_mesg_t *idx_msg; /* Pointer to message to modify */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5O_write_mesg) + FUNC_ENTER_NOAPI_NOINIT(H5O_copy_mesg) /* check args */ HDassert(f); @@ -2032,10 +2033,10 @@ H5O_write_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned idx, /* Set pointer to the correct message */ idx_msg = &oh->mesg[idx]; - /* Reset existing native information */ + /* Reset existing native information for the header's message */ H5O_msg_reset_real(type, idx_msg->native); - /* Copy the native value for the message */ + /* Copy the native object for the message */ if(NULL == (idx_msg->native = (type->copy)(mesg, idx_msg->native))) HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to copy message to object header") @@ -2053,7 +2054,7 @@ H5O_write_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned idx, done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_write_mesg() */ +} /* end H5O_copy_mesg() */ /*------------------------------------------------------------------------- diff --git a/src/H5SM.c b/src/H5SM.c index 43781f3..f37b913 100755 --- a/src/H5SM.c +++ b/src/H5SM.c @@ -35,6 +35,11 @@ /* Local Macros */ /****************/ /* Values used to create the SOHM heaps */ +/* (Note that these parameters have been tuned so that the resulting heap ID + * is exactly 8 bytes. This is an efficient size and is also the same as + * the size of the attribute heap IDs, think carefully before changing it. + * -QAK) + */ #define H5SM_FHEAP_MAN_WIDTH 4 #define H5SM_FHEAP_MAN_START_BLOCK_SIZE 1024 #define H5SM_FHEAP_MAN_MAX_DIRECT_SIZE (64 * 1024) diff --git a/test/tattr.c b/test/tattr.c index 0efe56b..31ffe2c 100644 --- a/test/tattr.c +++ b/test/tattr.c @@ -115,7 +115,6 @@ struct attr4_struct { #define ATTR5_RANK 0 float attr_data5=(float)-5.123; /* Test data for 5th attribute */ -#ifndef QAK herr_t attr_op1(hid_t loc_id, const char *name, void *op_data); @@ -3372,7 +3371,6 @@ test_attr_shared_rename(hid_t fcpl, hid_t fapl) ret = H5Sclose(big_sid); CHECK(ret, FAIL, "H5Sclose"); } /* test_attr_shared_rename() */ -#endif /* QAK */ /**************************************************************** ** @@ -3737,7 +3735,6 @@ test_attr_shared_delete(hid_t fcpl, hid_t fapl) CHECK(ret, FAIL, "H5Sclose"); } /* test_attr_shared_delete() */ -#ifndef QAK /**************************************************************** ** ** test_attr_shared_unlink(): Test basic H5A (attribute) code. @@ -3751,7 +3748,8 @@ test_attr_shared_unlink(hid_t fcpl, hid_t fapl) hid_t my_fcpl; /* File creation property list ID */ hid_t dataset, dataset2; /* Dataset IDs */ hid_t attr_tid; /* Attribute's datatype ID */ - hid_t sid; /* Dataspace ID */ + hid_t sid, big_sid; /* Dataspace IDs */ + hsize_t big_dims[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; /* Dimensions for "big" attribute */ hid_t attr; /* Attribute ID */ hid_t dcpl; /* Dataset creation property list ID */ char attrname[NAME_BUF_SIZE]; /* Name of attribute on first dataset */ @@ -3761,6 +3759,7 @@ test_attr_shared_unlink(hid_t fcpl, hid_t fapl) htri_t is_shared; /* Is attributes shared? */ hsize_t shared_refcount; /* Reference count of shared attribute */ unsigned attr_value; /* Attribute value */ + unsigned big_value[SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3]; /* Data for "big" attribute */ size_t mesg_count; /* # of shared messages */ unsigned test_shared; /* Index over shared component type */ unsigned u; /* Local index variable */ @@ -3771,6 +3770,17 @@ test_attr_shared_unlink(hid_t fcpl, hid_t fapl) /* Output message about test being performed */ MESSAGE(5, ("Testing Unlinking Object with Shared Attributes in Compact & Dense Storage\n")); + /* Initialize "big" attribute data */ + HDmemset(big_value, 1, sizeof(big_value)); + + /* Create dataspace for dataset */ + sid = H5Screate(H5S_SCALAR); + CHECK(sid, FAIL, "H5Screate"); + + /* Create "big" dataspace for "large" attributes */ + big_sid = H5Screate_simple(SPACE1_RANK, big_dims, NULL); + CHECK(sid, FAIL, "H5Screate_simple"); + /* Loop over type of shared components */ for(test_shared = 0; test_shared < 3; test_shared++) { /* Make copy of file creation property list */ @@ -3782,19 +3792,28 @@ test_attr_shared_unlink(hid_t fcpl, hid_t fapl) CHECK(attr_tid, FAIL, "H5Tcopy"); /* Special setup for each type of shared components */ - if(test_shared != 0) { + if(test_shared == 0) { + /* Make attributes > 500 bytes shared */ + ret = H5Pset_shared_mesg_nindexes(my_fcpl, (unsigned)1); + CHECK_I(ret, "H5Pset_shared_mesg_nindexes"); + ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)0, H5O_MESG_ATTR_FLAG, (unsigned)500); + } /* end if */ + else { /* Set up copy of file creation property list */ - /* Make attributes, datatypes & dataspaces > 1 byte shared (i.e. all of them :-) */ ret = H5Pset_shared_mesg_nindexes(my_fcpl, (unsigned)3); CHECK_I(ret, "H5Pset_shared_mesg_nindexes"); - ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)0, H5O_MESG_ATTR_FLAG, (unsigned)1); + + /* Make attributes > 500 bytes shared */ + ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)0, H5O_MESG_ATTR_FLAG, (unsigned)500); + + /* Make datatypes & dataspaces > 1 byte shared (i.e. all of them :-) */ CHECK_I(ret, "H5Pset_shared_mesg_index"); ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)1, H5O_MESG_DTYPE_FLAG, (unsigned)1); CHECK_I(ret, "H5Pset_shared_mesg_index"); ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)2, H5O_MESG_SDSPACE_FLAG, (unsigned)1); CHECK_I(ret, "H5Pset_shared_mesg_index"); - } /* end if */ + } /* end else */ /* Create file */ fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, my_fcpl, fapl); @@ -3834,10 +3853,6 @@ test_attr_shared_unlink(hid_t fcpl, hid_t fapl) CHECK(attr_tid, FAIL, "H5Topen"); } /* end if */ - /* Create dataspace for dataset */ - sid = H5Screate(H5S_SCALAR); - CHECK(sid, FAIL, "H5Screate"); - /* Set up to query the object creation properties */ dcpl = H5Pcreate(H5P_DATASET_CREATE); CHECK(dcpl, FAIL, "H5Pcreate"); @@ -3876,23 +3891,45 @@ test_attr_shared_unlink(hid_t fcpl, hid_t fapl) /* Create attribute name */ sprintf(attrname, "attr %02u", u); - /* Create attribute on first dataset */ - attr = H5Acreate(dataset, attrname, attr_tid, sid, H5P_DEFAULT); - CHECK(attr, FAIL, "H5Acreate"); + /* Alternate between creating "small" & "big" attributes */ + if(u % 2) { + /* Create "small" attribute on first dataset */ + attr = H5Acreate(dataset, attrname, attr_tid, sid, H5P_DEFAULT); + CHECK(attr, FAIL, "H5Acreate"); - /* Check that attribute is shared */ - is_shared = H5A_is_shared_test(attr); - VERIFY(is_shared, TRUE, "H5A_is_shared_test"); + /* Check that attribute is not shared */ + is_shared = H5A_is_shared_test(attr); + VERIFY(is_shared, FALSE, "H5A_is_shared_test"); - /* Check refcount for attribute */ - ret = H5A_get_shared_rc_test(attr, &shared_refcount); - CHECK(ret, FAIL, "H5A_get_shared_rc_test"); - VERIFY(shared_refcount, 1, "H5A_get_shared_rc_test"); + /* Write data into the attribute */ + attr_value = u + 1; + ret = H5Awrite(attr, attr_tid, &attr_value); + CHECK(ret, FAIL, "H5Awrite"); + } /* end if */ + else { + /* Create "big" attribute on first dataset */ + attr = H5Acreate(dataset, attrname, attr_tid, big_sid, H5P_DEFAULT); + CHECK(attr, FAIL, "H5Acreate"); + + /* Check that attribute is shared */ + is_shared = H5A_is_shared_test(attr); + VERIFY(is_shared, TRUE, "H5A_is_shared_test"); + + /* Check refcount for attribute */ + ret = H5A_get_shared_rc_test(attr, &shared_refcount); + CHECK(ret, FAIL, "H5A_get_shared_rc_test"); + VERIFY(shared_refcount, 1, "H5A_get_shared_rc_test"); + + /* Write data into the attribute */ + big_value[0] = u + 1; + ret = H5Awrite(attr, attr_tid, big_value); + CHECK(ret, FAIL, "H5Awrite"); - /* Write data into the attribute */ - attr_value = u + 1; - ret = H5Awrite(attr, attr_tid, &attr_value); - CHECK(ret, FAIL, "H5Awrite"); + /* Check refcount for attribute */ + ret = H5A_get_shared_rc_test(attr, &shared_refcount); + CHECK(ret, FAIL, "H5A_get_shared_rc_test"); + VERIFY(shared_refcount, 1, "H5A_get_shared_rc_test"); + } /* end else */ /* Close attribute */ ret = H5Aclose(attr); @@ -3906,28 +3943,45 @@ test_attr_shared_unlink(hid_t fcpl, hid_t fapl) VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test"); - /* Create attribute on second dataset */ - attr = H5Acreate(dataset2, attrname, attr_tid, sid, H5P_DEFAULT); - CHECK(attr, FAIL, "H5Acreate"); + /* Alternate between creating "small" & "big" attributes */ + if(u % 2) { + /* Create "small" attribute on second dataset */ + attr = H5Acreate(dataset2, attrname, attr_tid, sid, H5P_DEFAULT); + CHECK(attr, FAIL, "H5Acreate"); - /* Check that attribute is shared */ - is_shared = H5A_is_shared_test(attr); - VERIFY(is_shared, TRUE, "H5A_is_shared_test"); + /* Check that attribute is not shared */ + is_shared = H5A_is_shared_test(attr); + VERIFY(is_shared, FALSE, "H5A_is_shared_test"); - /* Check refcount for attribute */ - ret = H5A_get_shared_rc_test(attr, &shared_refcount); - CHECK(ret, FAIL, "H5A_get_shared_rc_test"); - VERIFY(shared_refcount, 1, "H5A_get_shared_rc_test"); + /* Write data into the attribute */ + attr_value = u + 1; + ret = H5Awrite(attr, attr_tid, &attr_value); + CHECK(ret, FAIL, "H5Awrite"); + } /* end if */ + else { + /* Create "big" attribute on second dataset */ + attr = H5Acreate(dataset2, attrname, attr_tid, big_sid, H5P_DEFAULT); + CHECK(attr, FAIL, "H5Acreate"); - /* Write data into the attribute */ - attr_value = u + 1; - ret = H5Awrite(attr, attr_tid, &attr_value); - CHECK(ret, FAIL, "H5Awrite"); + /* Check that attribute is shared */ + is_shared = H5A_is_shared_test(attr); + VERIFY(is_shared, TRUE, "H5A_is_shared_test"); - /* Check refcount for attribute */ - ret = H5A_get_shared_rc_test(attr, &shared_refcount); - CHECK(ret, FAIL, "H5A_get_shared_rc_test"); - VERIFY(shared_refcount, 2, "H5A_get_shared_rc_test"); + /* Check refcount for attribute */ + ret = H5A_get_shared_rc_test(attr, &shared_refcount); + CHECK(ret, FAIL, "H5A_get_shared_rc_test"); + VERIFY(shared_refcount, 1, "H5A_get_shared_rc_test"); + + /* Write data into the attribute */ + big_value[0] = u + 1; + ret = H5Awrite(attr, attr_tid, big_value); + CHECK(ret, FAIL, "H5Awrite"); + + /* Check refcount for attribute */ + ret = H5A_get_shared_rc_test(attr, &shared_refcount); + CHECK(ret, FAIL, "H5A_get_shared_rc_test"); + VERIFY(shared_refcount, 2, "H5A_get_shared_rc_test"); + } /* end else */ /* Close attribute */ ret = H5Aclose(attr); @@ -3946,10 +4000,6 @@ test_attr_shared_unlink(hid_t fcpl, hid_t fapl) ret = H5Tclose(attr_tid); CHECK(ret, FAIL, "H5Tclose"); - /* Close dataspace */ - ret = H5Sclose(sid); - CHECK(ret, FAIL, "H5Sclose"); - /* Close second dataset */ ret = H5Dclose(dataset2); CHECK(ret, FAIL, "H5Dclose"); @@ -3972,14 +4022,21 @@ test_attr_shared_unlink(hid_t fcpl, hid_t fapl) attr = H5Aopen_name(dataset, attrname); CHECK(attr, FAIL, "H5Acreate"); - /* Check that attribute is shared */ - is_shared = H5A_is_shared_test(attr); - VERIFY(is_shared, TRUE, "H5A_is_shared_test"); + if(u % 2) { + /* Check that attribute is not shared */ + is_shared = H5A_is_shared_test(attr); + VERIFY(is_shared, FALSE, "H5A_is_shared_test"); + } /* end if */ + else { + /* Check that attribute is shared */ + is_shared = H5A_is_shared_test(attr); + VERIFY(is_shared, TRUE, "H5A_is_shared_test"); - /* Check refcount for attribute */ - ret = H5A_get_shared_rc_test(attr, &shared_refcount); - CHECK(ret, FAIL, "H5A_get_shared_rc_test"); - VERIFY(shared_refcount, 1, "H5A_get_shared_rc_test"); + /* Check refcount for attribute */ + ret = H5A_get_shared_rc_test(attr, &shared_refcount); + CHECK(ret, FAIL, "H5A_get_shared_rc_test"); + VERIFY(shared_refcount, 1, "H5A_get_shared_rc_test"); + } /* end else */ /* Close attribute */ ret = H5Aclose(attr); @@ -4019,8 +4076,13 @@ test_attr_shared_unlink(hid_t fcpl, hid_t fapl) /* Check size of file */ filesize = h5_get_file_size(FILENAME); VERIFY(filesize, empty_filesize, "h5_get_file_size"); + + /* Close dataspaces */ + ret = H5Sclose(sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(big_sid); + CHECK(ret, FAIL, "H5Sclose"); } /* test_attr_shared_unlink() */ -#endif /* QAK */ /**************************************************************** ** @@ -4065,7 +4127,6 @@ test_attr(void) ret = H5Pset_shared_mesg_index(fcpl2, (unsigned)0, H5O_MESG_ATTR_FLAG, (unsigned)1); CHECK_I(ret, "H5Pset_shared_mesg_index"); -#ifndef QAK /* Loop over using new group format */ for(new_format = FALSE; new_format <= TRUE; new_format++) { hid_t my_fapl; @@ -4134,10 +4195,6 @@ test_attr(void) test_attr_shared_rename(fcpl2, fapl2); /* Test renaming shared attributes in compact & dense storage */ test_attr_shared_delete(fcpl2, fapl2); /* Test deleting shared attributes in compact & dense storage */ test_attr_shared_unlink(fcpl2, fapl2); /* Test unlinking object with shared attributes in compact & dense storage */ -#else /* QAK */ -HDfprintf(stderr, "Uncomment tests!\n"); - test_attr_shared_delete(fcpl2, fapl2); /* Test deleting shared attributes in compact & dense storage */ -#endif /* QAK */ /* Close FCPLs */ ret = H5Pclose(fcpl); -- cgit v0.12