[svn-r15852] 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 with h5committest.
This commit is contained in:
Raymond Lu 2008-10-13 13:25:34 -05:00
parent ffef670c90
commit 63d0b37133

View File

@ -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; x<TEST_NUM_INDEXES; ++x)
{
ret = H5Pset_shared_mesg_index(fcpl, x, test_type_flags[x], test_minsizes[x]);
CHECK_I(ret, "H5Pset_shared_mesg_index");
}
ret = H5Pset_shared_mesg_phase_change(fcpl, TEST_L2B, TEST_B2L);
CHECK_I(ret, "H5Pset_shared_mesg_phase_change");
/* Create the data space */
space = H5Screate_simple(2, dims, NULL);
CHECK_I(space, "H5Screate_simple");
/* Create a data type for s1_t */
s1_tid = H5Tcreate(H5T_COMPOUND, sizeof(s1_t));
CHECK_I(s1_tid, "H5Tcreate");
ret = H5Tinsert(s1_tid, "a", HOFFSET(s1_t,a), H5T_NATIVE_INT);
CHECK_I(ret, "H5Tinsert");
ret = H5Tinsert (s1_tid, "b", HOFFSET(s1_t,b), H5T_NATIVE_INT);
CHECK_I(ret, "H5Tinsert");
/* Create the first file for this test */
file1 = H5Fcreate(FILENAME_SRC, H5F_ACC_TRUNC, fcpl, H5P_DEFAULT);
CHECK_I(file1, "H5Fcreate");
/* Check on datatype storage status. It should be zero now. */
ret = H5F_get_sohm_mesg_count_test(file1, 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 data set */
dataset1 = H5Dcreate2(file1, "dataset_1", s1_tid, space, H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT);
CHECK_I(dataset1, "H5Dcreate2");
/* Check on datatype storage status. It should be 1 now. */
ret = H5F_get_sohm_mesg_count_test(file1, H5O_DTYPE_ID, &dmsg_count);
CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
VERIFY(dmsg_count, 1, "H5F_get_sohm_mesg_count_test");
/* Retieve the dataset's datatype */
dset1_tid = H5Dget_type(dataset1);
CHECK_I(dset1_tid, "H5Dget_type");
/* Allocate space and initialize data */
orig = (s1_t*)malloc(NX * NY * sizeof(s1_t));
for(i=0; i<NX*NY; i++) {
s_ptr = (s1_t*)orig + i;
s_ptr->a = 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() */