summaryrefslogtreecommitdiffstats
path: root/test/tattr.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2004-10-19 03:31:14 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2004-10-19 03:31:14 (GMT)
commit2e242bfd2214ec9a804428763d0e158499dd04f5 (patch)
tree78f6200a4cf677cb8544782e37594b9b188c3b49 /test/tattr.c
parent45727db7998415ace57a84b20ef75d4298af16ab (diff)
downloadhdf5-2e242bfd2214ec9a804428763d0e158499dd04f5.zip
hdf5-2e242bfd2214ec9a804428763d0e158499dd04f5.tar.gz
hdf5-2e242bfd2214ec9a804428763d0e158499dd04f5.tar.bz2
[svn-r9434] Purpose:
Bug fix Description: Fix core dump when flushing a file with a newly created attribute which hasn't had a value written to it still open. Solution: Write the attribute fill value when appropriate. Platforms tested: FreeBSd 4.10 (sleipnir) Linux 2.4 (verbena) Solaris 2.7 (arabica)
Diffstat (limited to 'test/tattr.c')
-rw-r--r--test/tattr.c166
1 files changed, 101 insertions, 65 deletions
diff --git a/test/tattr.c b/test/tattr.c
index bfb5daf..c303171 100644
--- a/test/tattr.c
+++ b/test/tattr.c
@@ -169,9 +169,8 @@ test_attr_basic_write(void)
/* Verify values read in */
for(i=0; i<ATTR1_DIM1; i++)
- if(attr_data1[i]!=read_data1[i]) {
+ if(attr_data1[i]!=read_data1[i])
TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]);
- } /* end if */
/* Close attribute */
ret=H5Aclose(attr);
@@ -210,9 +209,8 @@ test_attr_basic_write(void)
/* Verify values read in */
for(i=0; i<ATTR1_DIM1; i++)
- if(attr_data1[i]!=read_data1[i]) {
+ if(attr_data1[i]!=read_data1[i])
TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]);
- } /* end if */
/* Close attribute */
ret=H5Aclose(attr);
@@ -244,9 +242,8 @@ test_attr_basic_write(void)
/* Verify values read in */
for(i=0; i<ATTR1_DIM1; i++)
- if(attr_data1a[i]!=read_data1[i]) {
+ if(attr_data1a[i]!=read_data1[i])
TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]);
- } /* end if */
/* Close attribute */
ret=H5Aclose(attr2);
@@ -352,9 +349,8 @@ test_attr_basic_read(void)
/* Verify values read in */
for(i=0; i<ATTR1_DIM1; i++)
- if(attr_data1[i]!=read_data1[i]) {
+ if(attr_data1[i]!=read_data1[i])
TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]);
- } /* end if */
/* Close attribute */
ret=H5Aclose(attr);
@@ -381,9 +377,8 @@ test_attr_basic_read(void)
/* Verify values read in */
for(i=0; i<ATTR2_DIM1; i++)
for(j=0; j<ATTR2_DIM2; j++)
- if(attr_data2[i][j]!=read_data2[i][j]) {
- TestErrPrintf("%d: attribute data different: attr_data2[%d][%d]=%d, read_data2[%d][%d]=%d\n",__LINE__, i,j,attr_data2[i][j],i,j,read_data1[i]);
- } /* end if */
+ if(attr_data2[i][j]!=read_data2[i][j])
+ TestErrPrintf("%d: attribute data different: attr_data2[%d][%d]=%d, read_data2[%d][%d]=%d\n",__LINE__, i,j,attr_data2[i][j],i,j,read_data1[i]);
/* Close attribute */
ret=H5Aclose(attr);
@@ -400,6 +395,72 @@ test_attr_basic_read(void)
/****************************************************************
**
+** test_attr_flush(): Test H5A (attribute) code for performing
+** I/O when H5Fflush is used.
+**
+****************************************************************/
+static void
+test_attr_flush(void)
+{
+ hid_t fil, /* File ID */
+ att, /* Attribute ID */
+ spc, /* Dataspace ID */
+ set; /* Dataset ID */
+ double wdata=3.14159; /* Data to write */
+ double rdata; /* Data read in */
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Attribute Flushing\n"));
+
+ fil = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(fil, FAIL, "H5Fcreate");
+
+ spc = H5Screate(H5S_SCALAR);
+ CHECK(spc, FAIL, "H5Screate");
+
+ set = H5Dcreate(fil, DSET1_NAME, H5T_NATIVE_DOUBLE, spc, H5P_DEFAULT);
+ CHECK(set, FAIL, "H5Dcreate");
+
+ att = H5Acreate(set, ATTR1_NAME, H5T_NATIVE_DOUBLE, spc, H5P_DEFAULT);
+ CHECK(att, FAIL, "H5Acreate");
+
+ ret=H5Aread(att, H5T_NATIVE_DOUBLE, &rdata);
+ CHECK(ret, FAIL, "H5Awrite");
+
+ if(rdata!=0.0)
+ TestErrPrintf("attribute value wrong: rdata=%f, should be %f\n",rdata,0.0);
+
+ ret=H5Fflush(fil, H5F_SCOPE_GLOBAL);
+ CHECK(ret, FAIL, "H5Fflush");
+
+ ret=H5Aread(att, H5T_NATIVE_DOUBLE, &rdata);
+ CHECK(ret, FAIL, "H5Awrite");
+
+ if(rdata!=0.0)
+ TestErrPrintf("attribute value wrong: rdata=%f, should be %f\n",rdata,0.0);
+
+ ret=H5Awrite(att, H5T_NATIVE_DOUBLE, &wdata);
+ CHECK(ret, FAIL, "H5Awrite");
+
+ ret=H5Aread(att, H5T_NATIVE_DOUBLE, &rdata);
+ CHECK(ret, FAIL, "H5Awrite");
+
+ if(rdata!=wdata)
+ TestErrPrintf("attribute value wrong: rdata=%f, should be %f\n",rdata,wdata);
+
+ ret=H5Sclose(spc);
+ CHECK(ret, FAIL, "H5Sclose");
+ ret=H5Aclose(att);
+ CHECK(ret, FAIL, "H5Aclose");
+ ret=H5Dclose(set);
+ CHECK(ret, FAIL, "H5Dclose");
+ ret=H5Fclose(fil);
+ CHECK(ret, FAIL, "H5Fclose");
+} /* test_attr_basic_flush() */
+
+/****************************************************************
+**
** test_attr_compound_write(): Test H5A (attribute) code.
** Tests compound datatype attributes
**
@@ -540,12 +601,10 @@ test_attr_compound_read(void)
VERIFY(rank, ATTR4_RANK, "H5Sget_simple_extent_ndims");
ret=H5Sget_simple_extent_dims(space,dims, NULL);
CHECK(ret, FAIL, "H5Sget_simple_extent_dims");
- if(dims[0]!=ATTR4_DIM1) {
+ if(dims[0]!=ATTR4_DIM1)
TestErrPrintf("attribute dimensions different: dims[0]=%d, should be %d\n",(int)dims[0],ATTR4_DIM1);
- } /* end if */
- if(dims[1]!=ATTR4_DIM2) {
+ if(dims[1]!=ATTR4_DIM2)
TestErrPrintf("attribute dimensions different: dims[1]=%d, should be %d\n",(int)dims[1],ATTR4_DIM2);
- } /* end if */
H5Sclose(space);
/* Verify Datatype */
@@ -559,9 +618,8 @@ test_attr_compound_read(void)
fieldname=H5Tget_member_name(type,i);
if(!(HDstrcmp(fieldname,ATTR4_FIELDNAME1) ||
HDstrcmp(fieldname,ATTR4_FIELDNAME2) ||
- HDstrcmp(fieldname,ATTR4_FIELDNAME3))) {
+ HDstrcmp(fieldname,ATTR4_FIELDNAME3)))
TestErrPrintf("invalid field name for field #%d: %s\n",i,fieldname);
- } /* end if */
free(fieldname);
} /* end for */
offset=H5Tget_member_offset(type,0);
@@ -616,9 +674,8 @@ test_attr_compound_read(void)
/* Verify Name */
name_len=H5Aget_name(attr,ATTR_NAME_LEN, attr_name);
VERIFY(name_len, HDstrlen(ATTR4_NAME), "H5Aget_name");
- if(HDstrcmp(attr_name,ATTR4_NAME)) {
+ if(HDstrcmp(attr_name,ATTR4_NAME))
TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,ATTR4_NAME);
- } /* end if */
/* Close attribute datatype */
ret=H5Tclose(type);
@@ -712,7 +769,7 @@ test_attr_scalar_read(void)
hid_t fid1; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
hid_t sid; /* Dataspace ID */
- hid_t attr; /* Attribute ID */
+ hid_t attr; /* Attribute ID */
H5S_class_t stype; /* Dataspace class */
float rdata=0.0; /* Buffer for reading 1st attribute */
herr_t ret; /* Generic return value */
@@ -937,9 +994,8 @@ test_attr_mult_read(void)
VERIFY(rank, ATTR1_RANK, "H5Sget_simple_extent_ndims");
ret=H5Sget_simple_extent_dims(space,dims, NULL);
CHECK(ret, FAIL, "H5Sget_simple_extent_dims");
- if(dims[0]!=ATTR1_DIM1) {
+ if(dims[0]!=ATTR1_DIM1)
TestErrPrintf("attribute dimensions different: dims[0]=%d, should be %d\n",(int)dims[0],ATTR1_DIM1);
- } /* end if */
H5Sclose(space);
/* Verify Datatype */
@@ -959,25 +1015,22 @@ test_attr_mult_read(void)
/* Verify values read in */
for(i=0; i<ATTR1_DIM1; i++)
- if(attr_data1[i]!=read_data1[i]) {
+ if(attr_data1[i]!=read_data1[i])
TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]);
- } /* end if */
/* Verify Name */
name_len=H5Aget_name(attr, ATTR_NAME_LEN, attr_name);
VERIFY(name_len, HDstrlen(ATTR1_NAME), "H5Aget_name");
- if(HDstrcmp(attr_name,ATTR1_NAME)) {
+ if(HDstrcmp(attr_name,ATTR1_NAME))
TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,ATTR1_NAME);
- } /* end if */
/* Verify Name with too small of a buffer */
name_len=H5Aget_name(attr,HDstrlen(ATTR1_NAME), attr_name);
VERIFY(name_len, HDstrlen(ATTR1_NAME), "H5Aget_name");
HDstrcpy(temp_name,ATTR1_NAME); /* make a copy of the name */
temp_name[HDstrlen(ATTR1_NAME)-1]='\0'; /* truncate it to match the one retrieved */
- if(HDstrcmp(attr_name,temp_name)) {
+ if(HDstrcmp(attr_name,temp_name))
TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,temp_name);
- } /* end if */
/* Close attribute */
ret=H5Aclose(attr);
@@ -994,12 +1047,10 @@ test_attr_mult_read(void)
VERIFY(rank, ATTR2_RANK, "H5Sget_simple_extent_ndims");
ret=H5Sget_simple_extent_dims(space,dims, NULL);
CHECK(ret, FAIL, "H5Sget_simple_extent_dims");
- if(dims[0]!=ATTR2_DIM1) {
+ if(dims[0]!=ATTR2_DIM1)
TestErrPrintf("attribute dimensions different: dims[0]=%d, should be %d\n",(int)dims[0],ATTR2_DIM1);
- } /* end if */
- if(dims[1]!=ATTR2_DIM2) {
+ if(dims[1]!=ATTR2_DIM2)
TestErrPrintf("attribute dimensions different: dims[1]=%d, should be %d\n",(int)dims[1],ATTR2_DIM2);
- } /* end if */
H5Sclose(space);
/* Verify Datatype */
@@ -1020,25 +1071,22 @@ test_attr_mult_read(void)
/* Verify values read in */
for(i=0; i<ATTR2_DIM1; i++)
for(j=0; j<ATTR2_DIM2; j++)
- if(attr_data2[i][j]!=read_data2[i][j]) {
- TestErrPrintf("%d: attribute data different: attr_data2[%d][%d]=%d, read_data2[%d][%d]=%d\n",__LINE__,i,j,attr_data2[i][j],i,j,read_data2[i][j]);
- } /* end if */
+ if(attr_data2[i][j]!=read_data2[i][j])
+ TestErrPrintf("%d: attribute data different: attr_data2[%d][%d]=%d, read_data2[%d][%d]=%d\n",__LINE__,i,j,attr_data2[i][j],i,j,read_data2[i][j]);
/* Verify Name */
name_len=H5Aget_name(attr,ATTR_NAME_LEN, attr_name);
VERIFY(name_len, HDstrlen(ATTR2_NAME), "H5Aget_name");
- if(HDstrcmp(attr_name,ATTR2_NAME)) {
+ if(HDstrcmp(attr_name,ATTR2_NAME))
TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,ATTR2_NAME);
- } /* end if */
/* Verify Name with too small of a buffer */
name_len=H5Aget_name(attr,HDstrlen(ATTR2_NAME), attr_name);
VERIFY(name_len, HDstrlen(ATTR2_NAME), "H5Aget_name");
HDstrcpy(temp_name,ATTR2_NAME); /* make a copy of the name */
temp_name[HDstrlen(ATTR2_NAME)-1]='\0'; /* truncate it to match the one retrieved */
- if(HDstrcmp(attr_name,temp_name)) {
+ if(HDstrcmp(attr_name,temp_name))
TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,temp_name);
- } /* end if */
/* Close attribute */
ret=H5Aclose(attr);
@@ -1055,15 +1103,12 @@ test_attr_mult_read(void)
VERIFY(rank, ATTR3_RANK, "H5Sget_simple_extent_ndims");
ret=H5Sget_simple_extent_dims(space,dims, NULL);
CHECK(ret, FAIL, "H5Sget_simple_extent_dims");
- if(dims[0]!=ATTR3_DIM1) {
+ if(dims[0]!=ATTR3_DIM1)
TestErrPrintf("attribute dimensions different: dims[0]=%d, should be %d\n",(int)dims[0],ATTR3_DIM1);
- } /* end if */
- if(dims[1]!=ATTR3_DIM2) {
+ if(dims[1]!=ATTR3_DIM2)
TestErrPrintf("attribute dimensions different: dims[1]=%d, should be %d\n",(int)dims[1],ATTR3_DIM2);
- } /* end if */
- if(dims[2]!=ATTR3_DIM3) {
+ if(dims[2]!=ATTR3_DIM3)
TestErrPrintf("attribute dimensions different: dims[2]=%d, should be %d\n",(int)dims[2],ATTR3_DIM3);
- } /* end if */
H5Sclose(space);
/* Verify Datatype */
@@ -1085,25 +1130,22 @@ test_attr_mult_read(void)
for(i=0; i<ATTR3_DIM1; i++)
for(j=0; j<ATTR3_DIM2; j++)
for(k=0; k<ATTR3_DIM3; k++)
- if(attr_data3[i][j][k]!=read_data3[i][j][k]) {
+ if(attr_data3[i][j][k]!=read_data3[i][j][k])
TestErrPrintf("%d: attribute data different: attr_data3[%d][%d][%d]=%f, read_data3[%d][%d][%d]=%f\n",__LINE__,i,j,k,attr_data3[i][j][k],i,j,k,read_data3[i][j][k]);
- } /* end if */
/* Verify Name */
name_len=H5Aget_name(attr,ATTR_NAME_LEN, attr_name);
VERIFY(name_len, HDstrlen(ATTR3_NAME), "H5Aget_name");
- if(HDstrcmp(attr_name,ATTR3_NAME)) {
+ if(HDstrcmp(attr_name,ATTR3_NAME))
TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,ATTR3_NAME);
- } /* end if */
/* Verify Name with too small of a buffer */
name_len=H5Aget_name(attr,HDstrlen(ATTR3_NAME), attr_name);
VERIFY(name_len, HDstrlen(ATTR3_NAME), "H5Aget_name");
HDstrcpy(temp_name,ATTR3_NAME); /* make a copy of the name */
temp_name[HDstrlen(ATTR3_NAME)-1]='\0'; /* truncate it to match the one retrieved */
- if(HDstrcmp(attr_name,temp_name)) {
+ if(HDstrcmp(attr_name,temp_name))
TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,temp_name);
- } /* end if */
/* Close attribute */
ret=H5Aclose(attr);
@@ -1130,23 +1172,20 @@ herr_t attr_op1(hid_t UNUSED loc_id, const char *name, void *op_data)
switch(*count) {
case 0:
- if(HDstrcmp(name,ATTR1_NAME)) {
+ if(HDstrcmp(name,ATTR1_NAME))
TestErrPrintf("attribute name different: name=%s, should be %s\n",name,ATTR1_NAME);
- } /* end if */
(*count)++;
break;
case 1:
- if(HDstrcmp(name,ATTR2_NAME)) {
+ if(HDstrcmp(name,ATTR2_NAME))
TestErrPrintf("attribute name different: name=%s, should be %s\n",name,ATTR2_NAME);
- } /* end if */
(*count)++;
break;
case 2:
- if(HDstrcmp(name,ATTR3_NAME)) {
+ if(HDstrcmp(name,ATTR3_NAME))
TestErrPrintf("attribute name different: name=%s, should be %s\n",name,ATTR3_NAME);
- } /* end if */
(*count)++;
break;
@@ -1282,9 +1321,8 @@ test_attr_delete(void)
/* Verify Name */
name_len=H5Aget_name(attr,ATTR_NAME_LEN,attr_name);
VERIFY(name_len, HDstrlen(ATTR1_NAME), "H5Aget_name");
- if(HDstrcmp(attr_name,ATTR1_NAME)) {
+ if(HDstrcmp(attr_name,ATTR1_NAME))
TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,ATTR1_NAME);
- } /* end if */
/* Close attribute */
ret=H5Aclose(attr);
@@ -1297,9 +1335,8 @@ test_attr_delete(void)
/* Verify Name */
name_len=H5Aget_name(attr,ATTR_NAME_LEN, attr_name);
VERIFY(name_len, HDstrlen(ATTR3_NAME), "H5Aget_name");
- if(HDstrcmp(attr_name,ATTR3_NAME)) {
+ if(HDstrcmp(attr_name,ATTR3_NAME))
TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,ATTR3_NAME);
- } /* end if */
/* Close attribute */
ret=H5Aclose(attr);
@@ -1320,9 +1357,8 @@ test_attr_delete(void)
/* Verify Name */
name_len=H5Aget_name(attr,ATTR_NAME_LEN, attr_name);
VERIFY(name_len, HDstrlen(ATTR3_NAME), "H5Aget_name");
- if(HDstrcmp(attr_name,ATTR3_NAME)) {
+ if(HDstrcmp(attr_name,ATTR3_NAME))
TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,ATTR3_NAME);
- } /* end if */
/* Close attribute */
ret=H5Aclose(attr);
@@ -1379,9 +1415,8 @@ test_attr_dtype_shared(void)
/* Get size of file */
empty_filesize=h5_get_file_size(FILENAME);
- if(empty_filesize==0) {
+ if(empty_filesize==0)
TestErrPrintf("Line %d: file size wrong!\n",__LINE__);
- } /* end if */
/* Re-open file */
file_id=H5Fopen(FILENAME,H5F_ACC_RDWR,H5P_DEFAULT);
@@ -1534,6 +1569,7 @@ test_attr(void)
/* These next two tests use the same file information */
test_attr_basic_write(); /* Test basic H5A writing code */
test_attr_basic_read(); /* Test basic H5A reading code */
+ test_attr_flush(); /* Test H5A I/O in the presence of H5Fflush calls */
/* These next two tests use the same file information */
test_attr_compound_write(); /* Test complex datatype H5A writing code */