From 8a6d7d14f6f947dd4eacdfff6c86a23d8cb7be95 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Mon, 13 Oct 2008 14:08:35 -0500 Subject: [PATCH] [svn-r15854] Added a new test case. When a datatype is a SOHM type in one file, test that the second file using the same datatype actually save it in the file, too. Tested on kagiso. But the same change in v1.9 has been tested with h5committest. --- test/tsohm.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 181 insertions(+), 2 deletions(-) diff --git a/test/tsohm.c b/test/tsohm.c index 94fd128f0b..47c087e42b 100644 --- a/test/tsohm.c +++ b/test/tsohm.c @@ -23,6 +23,14 @@ #include "testhdf5.h" +/* + * This file needs to access private information from the H5F package. + * This file also needs to access the file testing code. + */ +#define H5F_PACKAGE +#define H5F_TESTING +#include "H5Fpkg.h" /* File access */ + /* Default SOHM values */ #define DEF_NUM_INDEXES 0 const unsigned def_type_flags[H5O_SHMESG_MAX_NINDEXES] = {0,0,0,0,0,0}; @@ -150,6 +158,10 @@ typedef struct size2_helper_struct { /* Number of dimensions in extend_dset test */ #define EXTEND_NDIMS 2 +/* Dimensions for external_dtype test */ +#define NX 10 +#define NY 10 + /* Helper function prototypes */ static hid_t make_dtype_1(void); static hid_t make_dtype_2(void); @@ -3783,6 +3795,174 @@ test_sohm_extend_dset(void) CHECK_I(ret, "test_sohm_extend_dset_helper"); } + +/*------------------------------------------------------------------------- + * Function: test_sohm_external_dtype + * + * Purpose: When a datatype is a SOHM type in one file, test that the + * second file using the same datatype actually save it in + * the file, too. + * + * Programmer: Raymond Lu + * 13 October, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static void +test_sohm_external_dtype(void) +{ + typedef struct s1_t { + int a; + int b; + } s1_t; + s1_t *s_ptr, *orig; + hid_t fcpl, file1, file2; + hid_t dataset1, dataset2; + hid_t s1_tid, dset1_tid, dset2_tid, space; + hsize_t dims[2] = {NX, NY}; + H5T_class_t dtype_class; + size_t dmsg_count; + unsigned x, i; + herr_t ret; + + fcpl = H5Pcreate(H5P_FILE_CREATE); + CHECK_I(fcpl, "H5Pcreate"); + + /* Set up index values for sohm */ + ret = H5Pset_shared_mesg_nindexes(fcpl, TEST_NUM_INDEXES); + CHECK_I(ret, "H5Pset_shared_mesg_nindexes"); + + for(x=0; xa = i*3 + 1; + s_ptr->b = i*3 + 2; + } + + /* Write the data to the dataset1 */ + ret = H5Dwrite(dataset1, s1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, orig); + CHECK_I(ret, "H5Dwrite"); + + ret = H5Dclose(dataset1); + CHECK_I(ret, "H5Dclose"); + + /* Create the second file for this test */ + file2 = H5Fcreate(FILENAME_DST, H5F_ACC_TRUNC, fcpl, H5P_DEFAULT); + CHECK_I(file2, "H5Fcreate"); + + /* Check on datatype storage status. It should be zero now. */ + ret = H5F_get_sohm_mesg_count_test(file2, H5O_DTYPE_ID, &dmsg_count); + CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test"); + VERIFY(dmsg_count, 0, "H5F_get_sohm_mesg_count_test"); + + /* Create a data set using the datatype of the dataset in the first file. */ + dataset2 = H5Dcreate2(file2, "dataset_2", dset1_tid, space, H5P_DEFAULT, H5P_DEFAULT, + H5P_DEFAULT); + CHECK_I(dataset2, "H5Dcreate2"); + + /* Check on datatype storage status. It should be 1 now. */ + ret = H5F_get_sohm_mesg_count_test(file2, H5O_DTYPE_ID, &dmsg_count); + CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test"); + VERIFY(dmsg_count, 1, "H5F_get_sohm_mesg_count_test"); + + /* Write the data to the dataset2 */ + ret = H5Dwrite(dataset2, s1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, orig); + CHECK_I(ret, "H5Dwrite"); + + ret = H5Dclose(dataset2); + CHECK_I(ret, "H5Dclose"); + + /* Close file 1 and the dataset's datatype in file 1. Verify that the datatype in + * file 2 is still accessible. */ + ret = H5Tclose(dset1_tid); + CHECK_I(ret, "H5Tclose"); + + ret = H5Fclose(file1); + CHECK_I(ret, "H5Fclose"); + + /* Open the dataset in file 2 */ + dataset2 = H5Dopen2(file2, "dataset_2", H5P_DEFAULT); + CHECK_I(dataset2, "H5Dopen2"); + + /* Retieve the dataset's datatype */ + dset2_tid = H5Dget_type(dataset2); + CHECK_I(dset2_tid, "H5Dget_type"); + + /* Verify the datatype is compound */ + dtype_class = H5Tget_class(dset2_tid); + VERIFY(dtype_class, H5T_COMPOUND, "H5Tget_class"); + + ret = H5Tclose(dset2_tid); + CHECK_I(ret, "H5Tclose"); + + ret = H5Dclose(dataset2); + CHECK_I(ret, "H5Dclose"); + + /* Finishing test and release resources */ + ret = H5Sclose(space); + CHECK_I(ret, "H5Sclose"); + + ret = H5Tclose(s1_tid); + CHECK_I(ret, "H5Tclose"); + + ret = H5Pclose(fcpl); + CHECK_I(ret, "H5Pclose"); + + ret = H5Fclose(file2); + CHECK_I(ret, "H5Fclose"); + + free(orig); +} + /**************************************************************** ** @@ -3808,11 +3988,10 @@ test_sohm(void) #ifndef H5_CANNOT_OPEN_TWICE /* On VMS this test fails since it tries to open target file the second time */ test_sohm_extlink(); /* Test SOHMs when external links are used */ - #endif /* H5_CANNOT_OPEN_TWICE */ test_sohm_extend_dset(); /* Test extending shared datasets */ - + test_sohm_external_dtype(); /* Test using datatype in another file */ } /* test_sohm() */