From fbf7f470e2f8c29994829ada8b4c01590d4cacc7 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Thu, 1 Oct 2009 08:55:43 -0500 Subject: [svn-r17565] Fix for Bug 1562. H5DS.c checked for other locations which need to account for platform dependent types in dealing with ds_list_t. Added generator program for test files of LE and BE dimension scales. Tested: local linux, h5committest --- MANIFEST | 1 + hl/src/H5DS.c | 18 +- hl/test/Makefile.am | 11 + hl/test/Makefile.in | 39 +++- hl/test/gen_test_ds.c | 585 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 646 insertions(+), 8 deletions(-) create mode 100644 hl/test/gen_test_ds.c diff --git a/MANIFEST b/MANIFEST index 0e6f593..135e9c1 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1631,6 +1631,7 @@ ./hl/test/image24plane.txt ./hl/test/pal_rgb.h ./hl/test/sepia.pal +./hl/test/gen_test_ds.c ./hl/test/test_ds.c ./hl/test/test_image.c ./hl/test/test_lite.c diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index f75e926..e15c132 100644 --- a/hl/src/H5DS.c +++ b/hl/src/H5DS.c @@ -129,6 +129,7 @@ herr_t H5DSattach_scale(hid_t did, hssize_t nelmts; hid_t sid; /* space ID */ hid_t tid = -1; /* attribute type ID */ + hid_t ntid = -1; /* attribute native type ID */ hid_t aid = -1; /* attribute ID */ int rank; /* rank of dataset */ hsize_t *dims=NULL; /* dimension of the "REFERENCE_LIST" array */ @@ -472,6 +473,9 @@ herr_t H5DSattach_scale(hid_t did, if((tid = H5Aget_type(aid)) < 0) goto out; + + if((ntid = H5Tget_native_type(tid, H5T_DIR_DEFAULT)) < 0) + goto out; /* get and save the old reference(s) */ if((sid = H5Aget_space(aid)) < 0) @@ -487,7 +491,7 @@ herr_t H5DSattach_scale(hid_t did, if (dsbuf == NULL) goto out; - if (H5Aread(aid,tid,dsbuf) < 0) + if (H5Aread(aid,ntid,dsbuf) < 0) goto out; /* close */ @@ -495,6 +499,8 @@ herr_t H5DSattach_scale(hid_t did, goto out; if (H5Aclose(aid) < 0) goto out; + if (H5Tclose(ntid) < 0) + goto out; /*------------------------------------------------------------------------- * create a new attribute @@ -586,6 +592,7 @@ out: H5E_BEGIN_TRY { H5Sclose(sid); H5Aclose(aid); + H5Tclose(ntid); H5Tclose(tid); } H5E_END_TRY; return FAIL; @@ -631,6 +638,7 @@ herr_t H5DSdetach_scale(hid_t did, hid_t did_i; /* dataset ID in REFERENCE_LIST */ hid_t sid; /* space ID */ hid_t tid = -1; /* attribute type ID */ + hid_t ntid = -1; /* attribute native type ID */ hid_t aid = -1; /* attribute ID */ int rank; /* rank of dataset */ ds_list_t *dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */ @@ -823,6 +831,9 @@ herr_t H5DSdetach_scale(hid_t did, if((tid = H5Aget_type(aid)) < 0) goto out; + + if((ntid = H5Tget_native_type(tid, H5T_DIR_DEFAULT)) < 0) + goto out; /* get and save the old reference(s) */ if((sid = H5Aget_space(aid)) < 0) @@ -835,7 +846,7 @@ herr_t H5DSdetach_scale(hid_t did, if(dsbuf == NULL) goto out; - if (H5Aread(aid,tid,dsbuf) < 0) + if (H5Aread(aid,ntid,dsbuf) < 0) goto out; for(i=0; i +#include +#include "h5hltest.h" +#include "H5DSpublic.h" +#include "H5LTpublic.h" + +/* prototypes */ +herr_t create_long_dataset(hid_t fid, const char *dsname, const char *dsidx); +herr_t test_attach_scale(hid_t fid, hid_t did, const char *name, unsigned int idx); +herr_t test_set_scalename(hid_t fid, hid_t did, const char *name, const char *scalename, unsigned int idx); +herr_t test_cmp_scalename(hid_t fid, hid_t did, const char *name, const char *scalename, unsigned int idx); + +static int test_long_attachscales(const char *filename); +static int test_duplicatelong_attachscales(const char *filename); +static int test_long_scalenames(const char *filename); +static int test_samelong_scalenames(const char *filename); +static int test_foreign_scaleattached(const char *filename); + + +#define RANK 2 +#define DIM_DATA 12 +#define DIM1_SIZE 3 +#define DIM2_SIZE 4 +#define DIM3_SIZE 12 +#define DIM4_SIZE 2 +#define DIM0 0 +#define DIM1 1 +#define DIM2 2 +#define DIM3 3 + +#define DATASET_NAME "dset_" +#define DS_1_NAME "ds_1_" +#define DS_2_NAME "ds_2_" +#define DS_3_NAME "ds_3_" +#define DS_4_NAME "ds_4_" + +#define SCALE_1_NAME "scalename_1_" +#define SCALE_2_NAME "scalename_2_" +#define SCALE_3_NAME "scalename_3_" +#define SCALE_4_NAME "scalename_4_" + +#define FILENAME "test_ds_" +#define FILEEXT ".h5" + +/*------------------------------------------------------------------------- + * the main program + *------------------------------------------------------------------------- + */ +int main(int argc , char **argv) +{ + int nerrors=0; + char filename[65]; + + + if (argc < 2) { + printf("Usage: gen_test [le | be]\n"); + return 1; + } + + if ( argv[1] && (strcmp("le",argv[1])!=0) && (strcmp("be",argv[1])!=0) ) { + printf("Usage: gen_test [le | be]\n"); + return 1; + } + + /* create file to be used in following tests */ + strcpy(filename, FILENAME); + strcat(filename, argv[1]); + strcat(filename, FILEEXT); + if(H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT) < 0) { + nerrors = 1; + goto error; + } + nerrors += test_long_attachscales(filename) < 0 ? 1 : 0; + nerrors += test_duplicatelong_attachscales(filename) < 0 ? 1 : 0; + nerrors += test_samelong_scalenames(filename) < 0 ? 1 : 0; + nerrors += test_foreign_scaleattached(filename) < 0 ? 1 : 0; + + + if(nerrors) goto error; + printf("Dimension scales file generation passed.\n"); + return 0; + +error: + printf("***** %d DIMENSION SCALES FILE GENERATION FAILED! *****\n",nerrors); + return 1; +} + +/*------------------------------------------------------------------------- + * create "data" dataset + *------------------------------------------------------------------------- + */ + +herr_t create_long_dataset(hid_t fid, const char *dsname, const char *dsidx) +{ + int rank = 4; + int rankds = 1; + hsize_t dims[4] = {DIM1_SIZE,DIM2_SIZE,DIM3_SIZE,DIM4_SIZE}; + long buf[DIM_DATA*3*2] = {1,2,3,4,5,6,7,8,9,10,11,12, + 1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12, + 1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12, + 1,2,3,4,5,6,7,8,9,10,11,12}; + hsize_t s1_dim[1] = {DIM1_SIZE}; + hsize_t s2_dim[1] = {DIM2_SIZE}; + hsize_t s3_dim[1] = {DIM3_SIZE}; + hsize_t s4_dim[1] = {DIM4_SIZE}; + long s1_wbuf[DIM1_SIZE] = {10,20,30}; + long s2_wbuf[DIM2_SIZE] = {100,200,300,400}; + long s3_wbuf[DIM3_SIZE] = {10,10,10,20,20,20,30,30,30,40,40,40}; + long s4_wbuf[DIM4_SIZE] = {18,18}; + char name[32]; + + strcpy(name, dsname); + + /* make a dataset */ + if(H5LTmake_dataset_long(fid, name, rank, dims, buf) >= 0) { + /* make a DS dataset for the first dimension */ + char dsname[32]; + + strcpy(dsname, DS_1_NAME); + strcat(dsname, dsidx); + /* make a DS dataset for the first dimension */ + if(H5LTmake_dataset_long(fid, dsname, rankds, s1_dim, s1_wbuf) < 0) + return FAIL; + + strcpy(dsname, DS_2_NAME); + strcat(dsname, dsidx); + /* make a DS dataset for the first dimension */ + if(H5LTmake_dataset_long(fid, dsname, rankds, s2_dim, s2_wbuf) < 0) + return FAIL; + + strcpy(dsname, DS_3_NAME); + strcat(dsname, dsidx); + /* make a DS dataset for the first dimension */ + if(H5LTmake_dataset_long(fid, dsname, rankds, s3_dim, s3_wbuf) < 0) + return FAIL; + + strcpy(dsname, DS_4_NAME); + strcat(dsname, dsidx); + /* make a DS dataset for the first dimension */ + if(H5LTmake_dataset_long(fid, dsname, rankds, s4_dim, s4_wbuf) < 0) + return FAIL; + } + else + return FAIL; + return SUCCEED; +} + +herr_t test_attach_scale(hid_t fid, hid_t did, const char *name, unsigned int idx) +{ + herr_t ret_value = FAIL; + hid_t dsid = -1; + + if((dsid = H5Dopen2(fid, name, H5P_DEFAULT)) >= 0) { + if(H5DSis_attached(did, dsid, idx) == 0) { + if(H5DSattach_scale(did, dsid, idx) >= 0) { + if(H5DSis_attached(did, dsid, idx) > 0) { + /* printf(" scale attached "); */ + ret_value = SUCCEED; + } + else if(H5DSis_attached(did, dsid, idx) == 0) { + printf(" scale not attached "); + } + } + } + if(H5Dclose(dsid) < 0) + ret_value = FAIL; + } + + return ret_value; +} + +herr_t test_detach_scale(hid_t fid, hid_t did, const char *name, unsigned int idx) +{ + herr_t ret_value = FAIL; + hid_t dsid = -1; + + if((dsid = H5Dopen2(fid, name, H5P_DEFAULT)) >= 0) { + if(H5DSis_attached(did, dsid, idx) == 1) { + if(H5DSdetach_scale(did, dsid, idx) >= 0) { + if(H5DSis_attached(did, dsid, idx) == 0) { + ret_value = SUCCEED; + } + } + } + if(H5Dclose(dsid) < 0) + ret_value = FAIL; + } + + return ret_value; +} + +herr_t test_set_scalename(hid_t fid, hid_t did, const char *name, const char *scalename, unsigned int idx) +{ + herr_t ret_value = FAIL; + hid_t dsid = -1; + + if((dsid = H5Dopen2(fid, name, H5P_DEFAULT)) >= 0) { + if(H5DSis_attached(did, dsid, idx) == 1) { + if(H5DSset_scale(dsid, scalename) >= 0) { + if(H5DSis_attached(did, dsid, idx) == 1) { + ret_value = SUCCEED; + } + } + } + if(H5Dclose(dsid) < 0) + ret_value = FAIL; + } + + return ret_value; +} + +herr_t test_cmp_scalename(hid_t fid, hid_t did, const char *name, const char *scalename, unsigned int idx) +{ + herr_t ret_value = FAIL; + hid_t dsid = -1; + ssize_t name_len; + char *name_out=NULL; + + if((dsid = H5Dopen2(fid, name, H5P_DEFAULT)) >= 0) { + if(H5DSis_attached(did, dsid, idx) == 1) { + if((name_len=H5DSget_scale_name(dsid,NULL,(size_t)0)) > 0) { + name_out = (char*)malloc(name_len * sizeof (char)); + if(name_out != NULL) { + if(H5DSget_scale_name(dsid, name_out, (size_t)name_len) >= 0) { + if(strcmp(scalename,name_out)==0) { + ret_value = SUCCEED; + } + free(name_out); + name_out=NULL; + } + } + } + } + if(H5Dclose(dsid) < 0) + ret_value = FAIL; + } + + return ret_value; +} + +static int test_long_attachscales(const char *filename) +{ + hid_t fid = -1; + hid_t did = -1; + char dsname[32]; + char scalename[32]; + strcpy(dsname, DATASET_NAME); + strcat(dsname, "al"); + + TESTING2("test_long_attachscales"); + + if((fid = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + goto out; + + /* make a dataset */ + if(create_long_dataset(fid, dsname, "al", 0) < 0) + goto out; + + if((did = H5Dopen2(fid, dsname, H5P_DEFAULT)) >= 0) { + strcpy(scalename, DS_1_NAME); + strcat(scalename, "al"); + if(test_attach_scale(fid, did, scalename, DIM0) < 0) + goto out; + + strcpy(scalename, DS_2_NAME); + strcat(scalename, "al"); + if(test_attach_scale(fid, did, scalename, DIM1) < 0) + goto out; + + strcpy(scalename, DS_3_NAME); + strcat(scalename, "al"); + if(test_attach_scale(fid, did, scalename, DIM2) < 0) + goto out; + + strcpy(scalename, DS_4_NAME); + strcat(scalename, "al"); + if(test_attach_scale(fid, did, scalename, DIM3) < 0) + goto out; + + if(H5Dclose(did) < 0) + goto out; + } + else + goto out; + + PASSED(); + + H5Fclose(fid); + return SUCCEED; + +out: + H5E_BEGIN_TRY { + H5Dclose(did); + H5Fclose(fid); + } H5E_END_TRY; + + H5_FAILED(); + + return FAIL; +} + +static int test_duplicatelong_attachscales(const char *filename) +{ + hid_t fid = -1; + hid_t did = -1; + char dsname[32]; + char scalename[32]; + strcpy(dsname, DATASET_NAME); + strcat(dsname, "al2"); + + TESTING2("test_duplicatelong_attachscales"); + + if((fid = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + goto out; + + /* make a dataset 2 */ + if(create_long_dataset(fid, dsname, "al2", 0) < 0) + goto out; + + if((did = H5Dopen2(fid, dsname, H5P_DEFAULT)) >= 0) { + strcpy(scalename, DS_1_NAME); + strcat(scalename, "al"); + if(test_attach_scale(fid, did, scalename, DIM0) < 0) + goto out; + + strcpy(scalename, DS_2_NAME); + strcat(scalename, "al"); + if(test_attach_scale(fid, did, scalename, DIM1) < 0) + goto out; + + strcpy(scalename, DS_3_NAME); + strcat(scalename, "al"); + if(test_attach_scale(fid, did, scalename, DIM2) < 0) + goto out; + + strcpy(scalename, DS_4_NAME); + strcat(scalename, "al"); + if(test_attach_scale(fid, did, scalename, DIM3) < 0) + goto out; + + if(H5Dclose(did) < 0) + goto out; + } + else + goto out; + + PASSED(); + + H5Fclose(fid); + return SUCCEED; + +out: + H5E_BEGIN_TRY { + H5Dclose(did); + H5Fclose(fid); + } H5E_END_TRY; + + H5_FAILED(); + + return FAIL; +} + +static int test_long_scalenames(const char *filename) { + hid_t fid = -1; + hid_t did = -1; + char dsname[32]; + char scalename[32]; + char name[32]; + strcpy(dsname, DATASET_NAME); + strcat(dsname, "al"); + + if((fid = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + goto out; + + TESTING2("set long scale/cmp scale name"); + if((did = H5Dopen2(fid, dsname, H5P_DEFAULT)) >= 0) { + strcpy(scalename, DS_1_NAME); + strcat(scalename, "al"); + strcpy(name, SCALE_1_NAME); + strcat(name, "al"); + if(test_set_scalename(fid, did, scalename, name, DIM0) < 0) + goto out; + + if(test_cmp_scalename(fid, did, scalename, name, DIM0) < 0) + goto out; + + strcpy(scalename, DS_2_NAME); + strcat(scalename, "al"); + strcpy(name, SCALE_2_NAME); + strcat(name, "al"); + if(test_set_scalename(fid, did, scalename, name, DIM1) < 0) + goto out; + + if(test_cmp_scalename(fid, did, scalename, name, DIM1) < 0) + goto out; + + strcpy(scalename, DS_3_NAME); + strcat(scalename, "al"); + strcpy(name, SCALE_3_NAME); + strcat(name, "al"); + if(test_set_scalename(fid, did, scalename, name, DIM2) < 0) + goto out; + + if(test_cmp_scalename(fid, did, scalename, name, DIM2) < 0) + goto out; + + strcpy(scalename, DS_4_NAME); + strcat(scalename, "al"); + strcpy(name, SCALE_4_NAME); + strcat(name, "al"); + if(test_set_scalename(fid, did, scalename, name, DIM3) < 0) + goto out; + + if(test_cmp_scalename(fid, did, scalename, name, DIM3) < 0) + goto out; + + if(H5Dclose(did) < 0) + goto out; + } + else + goto out; + + PASSED(); + + H5Fclose(fid); + return SUCCEED; + +out: + H5E_BEGIN_TRY { + H5Dclose(did); + H5Fclose(fid); + } H5E_END_TRY; + + H5_FAILED(); + + return FAIL; +} + +static int test_samelong_scalenames(const char *filename) { + hid_t fid = -1; + hid_t did = -1; + char dsname[32]; + char scalename[32]; + char name[32]; + strcpy(dsname, DATASET_NAME); + strcat(dsname, "al2"); + + if((fid = open_test_file(fileext)) < 0) + goto out; + + TESTING2("set same long scale/cmp scale name"); + if((did = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) >= 0) { + strcpy(scalename, DS_1_NAME); + strcat(scalename, "al"); + strcpy(name, DS_1_NAME); + strcat(name, "al"); + if(test_set_scalename(fid, did, scalename, name, DIM0) < 0) + goto out; + + if(test_cmp_scalename(fid, did, scalename, name, DIM0) < 0) + goto out; + + strcpy(scalename, DS_2_NAME); + strcat(scalename, "al"); + strcpy(name, DS_2_NAME); + strcat(name, "al"); + if(test_set_scalename(fid, did, scalename, name, DIM1) < 0) + goto out; + + if(test_cmp_scalename(fid, did, scalename, name, DIM1) < 0) + goto out; + + strcpy(scalename, DS_3_NAME); + strcat(scalename, "al"); + strcpy(name, DS_3_NAME); + strcat(name, "al"); + if(test_set_scalename(fid, did, scalename, name, DIM2) < 0) + goto out; + + if(test_cmp_scalename(fid, did, scalename, name, DIM2) < 0) + goto out; + + strcpy(scalename, DS_4_NAME); + strcat(scalename, "al"); + strcpy(name, DS_4_NAME); + strcat(name, "al"); + if(test_set_scalename(fid, did, scalename, name, DIM3) < 0) + goto out; + + if(test_cmp_scalename(fid, did, scalename, name, DIM3) < 0) + goto out; + + if(H5Dclose(did) < 0) + goto out; + } + else + goto out; + + PASSED(); + + H5Fclose(fid); + return SUCCEED; + +out: + H5E_BEGIN_TRY { + H5Dclose(did); + H5Fclose(fid); + } H5E_END_TRY; + + H5_FAILED(); + + return FAIL; +} + +static int test_foreign_scaleattached(const char *filename) +{ + herr_t ret_value = FAIL; + hid_t fid = -1; + hid_t did = -1; + hid_t dsid = -1; + + TESTING2("test_foreign_scaleattached"); + + if((fid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) + goto out; + + if((did = H5Dopen2(fid, "/dset_al", H5P_DEFAULT)) >= 0) { + if((dsid = H5Dopen2(fid, "/ds_4_al", H5P_DEFAULT)) >= 0) { + if(H5DSis_attached(did, dsid, 3) == 1) { + ret_value = SUCCEED; + } + if(H5Dclose(dsid) < 0) + goto out; + } + if(H5Dclose(did) < 0) + goto out; + } + else + goto out; + + if(ret_value == FAIL) + goto out; + + PASSED(); + + H5Fclose(fid); + return 0; + +out: + H5E_BEGIN_TRY { + H5Dclose(did); + H5Fclose(fid); + } H5E_END_TRY; + + H5_FAILED(); + + return FAIL; +} -- cgit v0.12