summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2007-02-21 15:41:41 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2007-02-21 15:41:41 (GMT)
commitc508fda8185affc2186288f6c0ce63fe0c2b916c (patch)
tree992b007fe854509b92f9fab758dadcd295f361ab /test
parent6ef05d4933a8fd67151e2865948cd97101468cc9 (diff)
downloadhdf5-c508fda8185affc2186288f6c0ce63fe0c2b916c.zip
hdf5-c508fda8185affc2186288f6c0ce63fe0c2b916c.tar.gz
hdf5-c508fda8185affc2186288f6c0ce63fe0c2b916c.tar.bz2
[svn-r13364] Bug fix (#717): the library failed to read the address of heap when the VL data is rewritten
with short length. Corrected the way that pointer advances along the data buffer.
Diffstat (limited to 'test')
-rw-r--r--test/tvltypes.c297
1 files changed, 297 insertions, 0 deletions
diff --git a/test/tvltypes.c b/test/tvltypes.c
index 8179ec5..0fac92a 100644
--- a/test/tvltypes.c
+++ b/test/tvltypes.c
@@ -41,6 +41,7 @@
#define SPACE3_DIM1 128
#define L1_INCM 16
#define L2_INCM 8
+#define L3_INCM 3
void *test_vltypes_alloc_custom(size_t size, void *info);
void test_vltypes_free_custom(void *mem, void *info);
@@ -1679,6 +1680,301 @@ test_vltypes_vlen_vlen_atomic(void)
/****************************************************************
**
+** test_vltypes_compound_vlstr(): Test VL datatype code.
+** Tests VL datatypes of compound datatypes with VL string.
+** Dataset is extensible chunked, and data is rewritten with
+** shorter VL data.
+**
+****************************************************************/
+static void
+test_vltypes_compound_vlstr(void)
+{
+ typedef enum {
+ red,
+ blue,
+ green
+ } e1;
+ typedef struct {
+ char *string;
+ e1 color;
+ } s2;
+ typedef struct { /* Struct that the compound type are composed of */
+ hvl_t v;
+ } s1;
+ s1 wdata[SPACE1_DIM1]; /* data to write */
+ s1 wdata2[SPACE1_DIM1]; /* data to write */
+ s1 rdata[SPACE1_DIM1]; /* data to read */
+ s1 rdata2[SPACE1_DIM1]; /* data to read */
+ char str[64] = "a\0";
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset, dset2; /* Dataset ID */
+ hid_t sid1, sid2, filespace, filespace2; /* Dataspace ID */
+ hid_t tid1, tid2, tid3, tid4, tid5; /* Datatype IDs */
+ hid_t cparms;
+ hsize_t dims1[] = {SPACE1_DIM1};
+ hsize_t chunk_dims[] = {SPACE1_DIM1/2};
+ hsize_t maxdims[] = {H5S_UNLIMITED};
+ hsize_t size[] = {SPACE1_DIM1};
+ hsize_t offset[] = {0};
+ unsigned i,j; /* counting variables */
+ s2 *t1, *t2; /* Temporary pointer to VL information */
+ int val;
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing VL Datatype of Compound Datatype with VL String Functionality\n"));
+
+ /* Allocate and initialize VL data to write */
+ for(i=0; i<SPACE1_DIM1; i++) {
+ wdata[i].v.p=(s2*)HDmalloc((i+L3_INCM)*sizeof(s2));
+ wdata[i].v.len=i+L3_INCM;
+ for(t1=(wdata[i].v).p, j=0; j<(i+L3_INCM); j++, t1++) {
+ strcat(str, "m");
+ t1->string = (char*)HDmalloc(strlen(str)*sizeof(char)+1);
+ strcpy(t1->string, str);
+ t1->color = blue;
+ }
+ } /* end for */
+
+ /* Create file */
+ fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(fid1, FAIL, "H5Fcreate");
+
+ /* Create dataspace for datasets */
+ sid1 = H5Screate_simple(SPACE1_RANK, dims1, maxdims);
+ CHECK(sid1, FAIL, "H5Screate_simple");
+
+ /* Create a VL string type*/
+ tid4 = H5Tcopy (H5T_C_S1);
+ CHECK(tid4, FAIL, "H5Tcopy");
+ ret = H5Tset_size (tid4,H5T_VARIABLE);
+ CHECK(ret, FAIL, "H5Tset_size");
+
+ /* Create an enum type */
+ tid3 = H5Tenum_create(H5T_STD_I32LE);
+ val = 0;
+ ret = H5Tenum_insert(tid3, "RED", &val);
+ CHECK(ret, FAIL, "H5Tenum_insert");
+ val = 1;
+ ret = H5Tenum_insert(tid3, "BLUE", &val);
+ CHECK(ret, FAIL, "H5Tenum_insert");
+ val = 2;
+ ret = H5Tenum_insert(tid3, "GREEN", &val);
+ CHECK(ret, FAIL, "H5Tenum_insert");
+
+ /* Create the first layer compound type */
+ tid5 = H5Tcreate(H5T_COMPOUND, sizeof(s2));
+ CHECK(tid5, FAIL, "H5Tcreate");
+ /* Insert fields */
+ ret=H5Tinsert(tid5, "string", HOFFSET(s2, string), tid4);
+ CHECK(ret, FAIL, "H5Tinsert");
+ /* Insert fields */
+ ret=H5Tinsert(tid5, "enumerate", HOFFSET(s2, color), tid3);
+ CHECK(ret, FAIL, "H5Tinsert");
+
+
+ /* Create a VL datatype of first layer compound type */
+ tid1 = H5Tvlen_create (tid5);
+ CHECK(tid1, FAIL, "H5Tvlen_create");
+
+ /* Create the base compound type */
+ tid2 = H5Tcreate(H5T_COMPOUND, sizeof(s1));
+ CHECK(tid2, FAIL, "H5Tcreate");
+
+ /* Insert fields */
+ ret=H5Tinsert(tid2, "v", HOFFSET(s1, v), tid1);
+ CHECK(ret, FAIL, "H5Tinsert");
+
+ /* Modify dataset creation properties, i.e. enable chunking */
+ cparms = H5Pcreate (H5P_DATASET_CREATE);
+ ret = H5Pset_chunk ( cparms, SPACE1_RANK, chunk_dims);
+ CHECK(ret, FAIL, "H5Pset_chunk");
+
+ /* Create a dataset */
+ dataset=H5Dcreate(fid1,"Dataset1",tid2,sid1,cparms);
+ CHECK(dataset, FAIL, "H5Dcreate");
+
+ /* Extend the dataset. This call assures that dataset is 4.*/
+ ret = H5Dextend (dataset, size);
+ CHECK(ret, FAIL, "H5Dextend");
+
+ /* Select a hyperslab */
+ filespace = H5Dget_space (dataset);
+ ret = H5Sselect_hyperslab (filespace, H5S_SELECT_SET, offset, NULL,
+ dims1, NULL);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Write dataset to disk */
+ ret=H5Dwrite(dataset,tid2,sid1,filespace,H5P_DEFAULT,wdata);
+ CHECK(ret, FAIL, "H5Dwrite");
+
+ ret=H5Fflush(fid1,H5F_SCOPE_GLOBAL);
+ CHECK(ret, FAIL, "H5Fflush");
+
+ /* Close Dataset */
+ ret = H5Dclose(dataset);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ /* Close disk dataspace */
+ ret = H5Sclose(filespace);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /* Close datatype */
+ ret = H5Tclose(tid4);
+ CHECK(ret, FAIL, "H5Tclose");
+
+ /* Close datatype */
+ ret = H5Tclose(tid5);
+ CHECK(ret, FAIL, "H5Tclose");
+
+ /* Close datatype */
+ ret = H5Tclose(tid3);
+ CHECK(ret, FAIL, "H5Tclose");
+
+ /* Close datatype */
+ ret = H5Tclose(tid2);
+ CHECK(ret, FAIL, "H5Tclose");
+
+ /* Close datatype */
+ ret = H5Tclose(tid1);
+ CHECK(ret, FAIL, "H5Tclose");
+
+ /* Close Property list */
+ ret = H5Pclose(cparms);
+ CHECK(ret, FAIL, "H5Pclose");
+
+ /* Close file */
+ ret = H5Fclose(fid1);
+ CHECK(ret, FAIL, "H5Fclose");
+
+
+ /* Open file */
+ fid1 = H5Fopen(FILENAME, H5F_ACC_RDWR, H5P_DEFAULT);
+ CHECK(fid1, FAIL, "H5Fopen");
+
+ /* Open the dataset */
+ dset2=H5Dopen(fid1,"Dataset1");
+ CHECK(dset2, FAIL, "H5Dopen");
+
+ /* Get the data type */
+ tid2 = H5Dget_type(dset2);
+ CHECK(tid2, FAIL, "H5Dget_type");
+
+ /* Read dataset from disk */
+ ret=H5Dread(dset2,tid2,H5S_ALL,H5S_ALL,H5P_DEFAULT,rdata);
+ CHECK(ret, FAIL, "H5Dread");
+
+ /* Compare data read in */
+ for(i=0; i<SPACE1_DIM1; i++) {
+ if(wdata[i].v.len!=rdata[i].v.len) {
+ TestErrPrintf("%d: VL data length don't match!, wdata[%d].v.len=%d, rdata[%d].v.len=%d\n",__LINE__,(int)i,(int)wdata[i].v.len,(int)i,(int)rdata[i].v.len);
+ continue;
+ } /* end if */
+
+ for(t1=wdata[i].v.p, t2=rdata[i].v.p, j=0; j<rdata[i].v.len; j++, t1++, t2++) {
+ if( strcmp(t1->string, t2->string) ) {
+ TestErrPrintf("VL data values don't match!, t1->string=%s, t2->string=%s\n",t1->string, t2->string);
+ continue;
+ } /* end if */
+ if(t1->color != t2->color) {
+ TestErrPrintf("VL data values don't match!, t1->color=%d, t2->color=%d\n",t1->color, t2->color);
+ continue;
+ } /* end if */
+ } /* end for */
+ } /* end for */
+
+ /* Reclaim the VL data */
+ ret=H5Dvlen_reclaim(tid2,sid1,H5P_DEFAULT,rdata);
+ CHECK(ret, FAIL, "H5Dvlen_reclaim");
+
+ /* Reclaim the write VL data */
+ ret=H5Dvlen_reclaim(tid2,sid1,H5P_DEFAULT,wdata);
+ CHECK(ret, FAIL, "H5Dvlen_reclaim");
+
+ /* Use this part for new data */
+ strcpy(str, "bbbbbbbb\0");
+ for(i=0; i<SPACE1_DIM1; i++) {
+ wdata2[i].v.p=(s2*)HDmalloc((i+1)*sizeof(s2));
+ wdata2[i].v.len=i+1;
+ for(t1=(s2*)(wdata2[i].v).p, j=0; j<i+1; j++, t1++) {
+ strcat(str, "pp");
+ t1->string = (char*)HDmalloc(strlen(str)*sizeof(char)+1);
+ strcpy(t1->string, str);
+ t1->color = green;
+ }
+ } /* end for */
+
+ /* Select a hyperslab */
+ filespace2 = H5Dget_space (dset2);
+ ret = H5Sselect_hyperslab (filespace2, H5S_SELECT_SET, offset, NULL,
+ dims1, NULL);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Create dataspace for datasets */
+ sid2 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
+ CHECK(sid1, FAIL, "H5Screate_simple");
+
+ /* Write dataset to disk */
+ ret=H5Dwrite(dset2,tid2,sid2,filespace2,H5P_DEFAULT, &wdata2);
+ CHECK(ret, FAIL, "H5Dwrite");
+
+ /* Read dataset from disk */
+ ret=H5Dread(dset2,tid2,H5S_ALL,H5S_ALL,H5P_DEFAULT,rdata2);
+ CHECK(ret, FAIL, "H5Dread");
+
+ /* Compare data read in */
+ for(i=0; i<SPACE1_DIM1; i++) {
+ if(wdata2[i].v.len!=rdata2[i].v.len) {
+ TestErrPrintf("%d: VL data length don't match!, wdata2[%d].v.len=%d, rdata2[%d].v.len=%d\n",__LINE__,(int)i,(int)wdata2[i].v.len,(int)i,(int)rdata2[i].v.len);
+ continue;
+ } /* end if */
+
+ for(t1=wdata2[i].v.p, t2=rdata2[i].v.p, j=0; j<rdata2[i].v.len; j++, t1++, t2++) {
+ if( strcmp(t1->string, t2->string) ) {
+ TestErrPrintf("VL data values don't match!, t1->string=%s, t2->string=%s\n",t1->string, t2->string);
+ continue;
+ } /* end if */
+ if(t1->color != t2->color) {
+ TestErrPrintf("VL data values don't match!, t1->color=%d, t2->color=%d\n",t1->color, t2->color);
+ continue;
+ } /* end if */
+ } /* end for */
+ } /* end for */
+
+ /* Reclaim the write VL data */
+ ret=H5Dvlen_reclaim(tid2,sid1,H5P_DEFAULT,wdata2);
+ CHECK(ret, FAIL, "H5Dvlen_reclaim");
+
+ /* Reclaim the VL data */
+ ret=H5Dvlen_reclaim(tid2,sid1,H5P_DEFAULT,rdata2);
+ CHECK(ret, FAIL, "H5Dvlen_reclaim");
+
+ ret = H5Dclose(dset2);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ /* Close disk dataspace */
+ ret = H5Sclose(sid1);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /* Close disk dataspace */
+ ret = H5Sclose(sid2);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /* Close disk dataspace */
+ ret = H5Sclose(filespace2);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /* Close datatype */
+ ret = H5Tclose(tid2);
+ CHECK(ret, FAIL, "H5Tclose");
+
+ /* Close file */
+ ret = H5Fclose(fid1);
+ CHECK(ret, FAIL, "H5Fclose");
+} /* end test_vltypes_compound_vlstr() */
+
+/****************************************************************
+**
** rewrite_longer_vltypes_vlen_vlen_atomic(): Test basic VL datatype code.
** Tests VL datatype with VL datatypes of atomic datatypes.
**
@@ -2053,6 +2349,7 @@ test_vltypes(void)
rewrite_longer_vltypes_vlen_vlen_atomic(); /*overwrite with VL data of longer sequence*/
rewrite_shorter_vltypes_vlen_vlen_atomic(); /*overwrite with VL data of shorted sequence*/
test_vltypes_compound_vlen_vlen(); /* Test compound datatypes with VL atomic components */
+ test_vltypes_compound_vlstr(); /* Test data rewritten of nested VL data */
} /* test_vltypes() */