From 4dd38b9f5ba09e863b9a062daf4759a0c85e5b63 Mon Sep 17 00:00:00 2001 From: Scot Breitenfeld Date: Sun, 5 Jun 2011 16:09:49 -0500 Subject: [svn-r20931] Purpose: brought revisions 20870 and 20923 from the trunk to fix bug HDFFV-7605 Tested: jam (intel compiler) --- hl/src/H5DS.c | 6 +- hl/test/test_ds.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 172 insertions(+), 5 deletions(-) diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index 379b220..16ab14f 100644 --- a/hl/src/H5DS.c +++ b/hl/src/H5DS.c @@ -813,8 +813,10 @@ herr_t H5DSdetach_scale(hid_t did, /* same object, reset. we want to detach only for this DIM */ if(did_oi.fileno == tmp_oi.fileno && did_oi.addr == tmp_oi.addr) { - /* copy the last one to replace the one which is found */ - dsbuf[ii] = dsbuf[nelmts-1]; + /* if we found not the last one, copy the last one to replace + the one which is found */ + if(ii < nelmts-1) + dsbuf[ii] = dsbuf[nelmts-1]; nelmts--; found_dset=1; break; diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c index a13dbcd..e8c4eff 100644 --- a/hl/test/test_ds.c +++ b/hl/test/test_ds.c @@ -81,8 +81,9 @@ static int test_types(void); static int test_iterators(void); static int test_data(void); static int read_data( const char* fname, int ndims, hsize_t *dims, float **buf ); +static int test_attach_detach(void); - +#define RANK1 1 #define RANK 2 #define DIM_DATA 12 #define DIM1_SIZE 3 @@ -136,7 +137,8 @@ static int read_data( const char* fname, int ndims, hsize_t *dims, float **buf ) #define FILE5 "test_ds7.h5" #define FILE6 "test_ds8.h5" #define FILE7 "test_ds9.h5" - +#define FILE8 "test_ds10.h5" + #define DIMENSION_LIST "DIMENSION_LIST" #define REFERENCE_LIST "REFERENCE_LIST" @@ -174,7 +176,7 @@ int main(void) nerrors += test_foreign_scaleattached(FOREIGN_FILE1) < 0 ? 1 : 0; nerrors += test_foreign_scaleattached(FOREIGN_FILE2) < 0 ? 1 : 0; nerrors += test_detachscales() < 0 ? 1 : 0; - + nerrors += test_attach_detach() < 0 ? 1 : 0; /* the following tests have not been rewritten to match those above */ nerrors += test_simple() < 0 ?1:0; nerrors += test_errors() < 0 ?1:0; @@ -4867,4 +4869,167 @@ out: H5_FAILED(); return FAIL; } +/*------------------------------------------------------------------------- + * Test attaching and detaching in different order + * Checks condition reported in Bug HDFFV-7605 + *------------------------------------------------------------------------- + */ + +static int test_attach_detach(void) +{ + hid_t fid; /* file ID */ + hid_t gid; /* group ID */ + hid_t sid; /* dataspace ID */ + hid_t dcpl_id; /* dataset creation property */ + hid_t dsid = -1; /* DS dataset ID */ + hid_t var1_id, var2_id; /* DS component name */ + hsize_t dims[RANK1] = {DIM1}; + + TESTING2("permutations of attaching and detaching"); + + if((fid = H5Fcreate(FILE8, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto out; + + if((gid = H5Gopen2(fid, "/", H5P_DEFAULT)) < 0) + goto out; + + /* Create dimension scale. */ + + if((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) + goto out; + + if((sid = H5Screate_simple(1, dims, dims)) < 0) + goto out; + + if((dsid = H5Dcreate2(gid, DS_3_NAME, H5T_IEEE_F32BE, sid, + H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) + goto out; + + if(H5Sclose(sid) < 0) + goto out; + if(H5Pclose(dcpl_id) < 0) + goto out; + + if(H5DSset_scale(dsid, DS_3_NAME) < 0) + goto out; + + /* Create a variable that uses this dimension scale. */ + + if((sid = H5Screate_simple(DIM1, dims, dims)) < 0) + goto out; + + if((var1_id = H5Dcreate2(gid, DS_31_NAME, H5T_NATIVE_FLOAT, sid, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto out; + + if(H5Sclose(sid) < 0) + goto out; + + if(H5DSattach_scale(var1_id, dsid, 0) < 0) + goto out; + + /* Create another variable that uses this dimension scale. */ + if((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) + goto out; + + if(H5Pset_attr_creation_order(dcpl_id, H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED) < 0) + goto out; + + if((sid = H5Screate_simple(DIM1, dims, dims)) < 0) + goto out; + + if((var2_id = H5Dcreate2(gid, DS_32_NAME, H5T_NATIVE_FLOAT, sid, + H5P_DEFAULT, H5P_DEFAULT,H5P_DEFAULT)) < 0) + goto out; + + if(H5Pclose(dcpl_id) < 0) + goto out; + + if(H5Sclose(sid) < 0) + goto out; + + if(H5DSattach_scale(var2_id, dsid, 0) < 0) + goto out; + + /* Detach the var2 scale */ + if(H5DSdetach_scale(var2_id, dsid, 0) < 0) + goto out; + + /* Check if in correct state of detached and attached */ + if(H5DSis_attached(var1_id, dsid, 0) == 0) /* should still be attached */ + goto out; + if(H5DSis_attached(var2_id, dsid, 0) != 0) /* should not be attached */ + goto out; + /* Detach the var1 scale */ + if(H5DSdetach_scale(var1_id, dsid, 0) < 0) + goto out; + + /* Check if in correct state of detached and attached */ + if(H5DSis_attached(var1_id, dsid, 0) != 0) /* should not be attached */ + goto out; + if(H5DSis_attached(var2_id, dsid, 0) != 0) /* should not be attached */ + goto out; + + /* Attach the DS again and remove them in the opposite order */ + + if(H5DSattach_scale(var1_id, dsid, 0) < 0) + goto out; + + if(H5DSattach_scale(var2_id, dsid, 0) < 0) + goto out; + + /* Detach the var1 scale */ + if(H5DSdetach_scale(var1_id, dsid, 0) < 0) + goto out; + + /* Check if in correct state of detached and attached */ + + if(H5DSis_attached(var1_id, dsid, 0) != 0) /* should not be attached */ + goto out; + if(H5DSis_attached(var2_id, dsid, 0) == 0) /* should still be attached */ + goto out; + + /* Detach the var2 scale */ + if(H5DSdetach_scale(var2_id, dsid, 0) < 0) + goto out; + + /* Check if in correct state of detached and attached */ + if(H5DSis_attached(var1_id, dsid, 0) != 0) /* should not be attached */ + goto out; + if(H5DSis_attached(var2_id, dsid, 0) != 0) /* should not be attached */ + goto out; + + /*------------------------------------------------------------------------- + * close + *------------------------------------------------------------------------- + */ + + if(H5Dclose(var1_id) < 0) + goto out; + if(H5Dclose(var2_id) < 0) + goto out; + if(H5Dclose(dsid) < 0) + goto out; + if(H5Gclose(gid) < 0) + goto out; + if(H5Fclose(fid) < 0) + goto out; + + PASSED(); + + return 0; + + /* error zone */ +out: + H5E_BEGIN_TRY + { + H5Dclose(var1_id); + H5Dclose(var2_id); + H5Dclose(dsid); + H5Gclose(gid); + H5Fclose(fid); + } H5E_END_TRY; + H5_FAILED(); + return FAIL; +} -- cgit v0.12