int test_sphere_point_depth() { int j; dVector3 p,q; dMatrix3 R; dReal r,d; dSimpleSpace space(0); dGeomID sphere = dCreateSphere (0,1); dSpaceAdd (space,sphere); // ********** make a random sphere of radius r at position p r = dRandReal()+0.1; dGeomSphereSetRadius (sphere,r); dMakeRandomVector (p,3,1.0); dGeomSetPosition (sphere,p[0],p[1],p[2]); dRFromAxisAndAngle (R,dRandReal()*2-1,dRandReal()*2-1, dRandReal()*2-1,dRandReal()*10-5); dGeomSetRotation (sphere,R); // ********** test center point has depth r if (dFabs(dGeomSpherePointDepth (sphere,p[0],p[1],p[2]) - r) > tol) FAILED(); // ********** test point on surface has depth 0 for (j=0; j<3; j++) q[j] = dRandReal()-0.5; dNormalize3 (q); for (j=0; j<3; j++) q[j] = q[j]*r + p[j]; if (dFabs(dGeomSpherePointDepth (sphere,q[0],q[1],q[2])) > tol) FAILED(); // ********** test point at random depth d = (dRandReal()*2-1) * r; for (j=0; j<3; j++) q[j] = dRandReal()-0.5; dNormalize3 (q); for (j=0; j<3; j++) q[j] = q[j]*(r-d) + p[j]; if (dFabs(dGeomSpherePointDepth (sphere,q[0],q[1],q[2])-d) > tol) FAILED(); PASSED(); }
/*------------------------------------------------------------------------- * Function: test_create * * Purpose: Test trivial creating & closing memory pool * * Return: Success: 0 * * Failure: 1 * * Programmer: Quincey Koziol * Tuesday, May 3, 2005 * * Modifications: * *------------------------------------------------------------------------- */ static int test_create(void) { H5MP_pool_t *mp; /* Memory pool */ H5MP_page_t *page; /* Memory pool page */ size_t free_size; /* Free size in pool */ /* * Test memory pool creation */ TESTING("memory pool creation"); /* Create a memory pool */ if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) TEST_ERROR /* Check free space */ if(H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR; if(free_size != 0) TEST_ERROR /* Check first page */ if (H5MP_get_pool_first_page(mp, &page) < 0) TEST_ERROR; if(page != NULL) TEST_ERROR /* Close the memory pool */ if (H5MP_close(mp) < 0) TEST_ERROR PASSED(); return 0; error: H5E_BEGIN_TRY { } H5E_END_TRY; return 1; } /* test_create() */
/*------------------------------------------------------------------------- * Purpose: Creates a group with a very long name * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke <*****@*****.**> 2002-03-28 * * Modifications: *------------------------------------------------------------------------- */ static int test_long(hid_t file) { hid_t g1=-1, g2=-1; char *name1=NULL, *name2=NULL; size_t namesize=40960, i; TESTING("long names"); /* Group names */ name1 = malloc(namesize); for (i=0; i<namesize; i++) name1[i] = (char)('A' + i%26); name1[namesize-1] = '\0'; name2 = malloc(2*namesize + 2); sprintf(name2, "%s/%s", name1, name1); /* Create groups */ if ((g1=H5Gcreate(file, name1, 0))<0) goto error; if ((g2=H5Gcreate(g1, name1, 0))<0) goto error; H5Gclose(g1); H5Gclose(g2); /* Open groups */ if ((g1=H5Gopen(file, name1))<0) goto error; if ((g2=H5Gopen(file, name2))<0) goto error; H5Gclose(g1); H5Gclose(g2); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Gclose(g1); H5Gclose(g2); } H5E_END_TRY; return 1; }
/*------------------------------------------------------------------------- * Function: test_1f * * Purpose: Test multiple external files for a dataset. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Monday, November 23, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int test_1f(hid_t file) { hid_t dcpl=-1; /*dataset creation properties */ hid_t space=-1; /*data space */ hid_t dset=-1; /*dataset */ hsize_t cur_size[1]; /*data space current size */ hsize_t max_size[1]; /*data space maximum size */ TESTING("multiple external files"); if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error; cur_size[0] = max_size[0] = 100; if(H5Pset_external(dcpl, "ext1.data", (off_t)0, (hsize_t)(max_size[0]*sizeof(int)/4)) < 0) goto error; if(H5Pset_external(dcpl, "ext2.data", (off_t)0, (hsize_t)(max_size[0]*sizeof(int)/4)) < 0) goto error; if(H5Pset_external(dcpl, "ext3.data", (off_t)0, (hsize_t)(max_size[0]*sizeof(int)/4)) < 0) goto error; if(H5Pset_external(dcpl, "ext4.data", (off_t)0, (hsize_t)(max_size[0]*sizeof(int)/4)) < 0) goto error; if((space = H5Screate_simple(1, cur_size, max_size)) < 0) goto error; if((dset = H5Dcreate2(file, "dset6", H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error; if(H5Dclose(dset) < 0) goto error; if(H5Sclose(space) < 0) goto error; if(H5Pclose(dcpl) < 0) goto error; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Dclose(dset); H5Pclose(dcpl); H5Sclose(space); } H5E_END_TRY; return 1; }
/*------------------------------------------------------------------------- * Function: test_1d * * Purpose: Test a single external file which is large enough for the * current data size but not large enough for the eventual size. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Monday, November 23, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int test_1d(hid_t file) { hid_t dcpl=-1; /*dataset creation properties */ hid_t space=-1; /*data space */ hid_t dset=-1; /*dataset */ hsize_t cur_size[1]; /*current data space size */ hsize_t max_size[1]; /*maximum data space size */ TESTING("extendible dataspace, external storage is too small"); if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error; cur_size[0] = 100; max_size[0] = 200; if(H5Pset_external(dcpl, "ext1.data", (off_t)0, (hsize_t)(max_size[0] * sizeof(int) - 1)) < 0) goto error; if((space = H5Screate_simple(1, cur_size, max_size)) < 0) goto error; H5E_BEGIN_TRY { dset = H5Dcreate2(file, "dset4", H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT); } H5E_END_TRY; if(dset >= 0) { H5_FAILED(); puts(" Small external file succeeded instead of failing."); goto error; } if(H5Sclose(space) < 0) goto error; if(H5Pclose(dcpl) < 0) goto error; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Dclose(dset); H5Pclose(dcpl); H5Sclose(space); } H5E_END_TRY; return 1; }
/* * Test drive for testing the szip compression feature with SD interface */ extern int test_szip_compression () { int num_errs = 0; /* Output message about test being performed */ TESTING("szip compression for datasets (tszip.c)"); #ifdef H4_HAVE_SZIP_ENCODER /* Test creating and writing SZIP compressed data only when szlib encoder is available */ num_errs = num_errs + test_szip_SDS8bit(); num_errs = num_errs + test_szip_SDS16bit(); num_errs = num_errs + test_szip_SDS32bit(); num_errs = num_errs + test_szip_SDSfl32bit(); num_errs = num_errs + test_szip_SDSfl64bit(); num_errs = num_errs + test_szip_chunk(); num_errs = num_errs + test_szip_unlimited(); num_errs = num_errs + test_szip_chunk_3d(); #else /* printf("Test creating and writing SZIP compressed data \tSKIPPED\n"); */ #endif #ifdef H4_HAVE_LIBSZ /* Test reading szipped data when szlib is available, either with encoder or only decoder */ num_errs = num_errs + test_getszipdata(); #else /* printf("Test reading SZIP compressed data \tSKIPPED\n"); */ #endif /* Test reading szip compression information and should pass with or without SZIP library */ num_errs = num_errs + test_getszipinfo(); if (num_errs == 0) PASSED(); return num_errs; }
/*------------------------------------------------------------------------- * * Function: group_version_macros * * Purpose: Test H5G version compatibility macros. * * Return: Success: 0 * Failure: -1 * * Programmer: Neil Fortner * Saturday, October 11, 2008 * *------------------------------------------------------------------------- */ static int group_version_macros(hid_t fapl) { hid_t fid, gid; char filename[NAME_BUF_SIZE]; /* Output message about test being performed */ TESTING("H5G version compatibility macros"); /* Create file */ h5_fixname(FILENAME[1], fapl, filename, sizeof filename); if ((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; /* Create a group (test H5Gcreate1) */ if ((gid = H5Gcreate1(fid, "group", 0)) < 0) TEST_ERROR; /* Close group */ if (H5Gclose(gid) < 0) TEST_ERROR; /* Open group (test H5Gopen1) */ if ((gid = H5Gopen1(fid, "group")) < 0) TEST_ERROR; /* Close group */ if (H5Gclose(gid) < 0) TEST_ERROR; /* Close file */ if (H5Fclose(fid) < 0) TEST_ERROR; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(gid); H5Gclose(fid); } H5E_END_TRY return -1; } /* end group_version_macros() */
/*------------------------------------------------------------------------- * Function: test_filters_for_groups * * Purpose: Tests creating group with dynamically loaded filters * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * 1 April 2013 * *------------------------------------------------------------------------- */ static herr_t test_filters_for_groups(hid_t file) { hid_t gcpl, gid, group; int i; char gname[256]; TESTING("Testing DYNLIB3 filter for group"); if((gcpl = H5Pcreate(H5P_GROUP_CREATE)) < 0) goto error; /* Use DYNLIB3 for creating groups */ if(H5Pset_filter (gcpl, H5Z_FILTER_DYNLIB3, H5Z_FLAG_MANDATORY, (size_t)0, NULL) < 0) goto error; /* Create a group using this filter */ if((gid = H5Gcreate2(file, "group1", H5P_DEFAULT, gcpl, H5P_DEFAULT)) < 0) goto error; /* Create multiple groups under "group1" */ for (i=0; i < GROUP_ITERATION; i++) { sprintf(gname, "group_%d", i); if((group = H5Gcreate2(gid, gname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; if(H5Gclose(group) < 0) goto error; } /* Close the group */ if(H5Gclose(gid) < 0) goto error; /* Clean up objects used for this test */ if(H5Pclose (gcpl) < 0) goto error; PASSED(); return 0; error: return -1; }
/* * Get current value, request timeout for next value, increment counter, check * notified correctly. */ static void test03(void) { uint32_t cur_value; L4_Word_t result; L4_Word_t notifybits = 0x1; L4_MsgTag_t tag; L4_Word_t mask; printf("%s: ", __func__); result = counter_current_value(&cur_value); if (result == 0) { FAILED(); return; } result = counter_request(cur_value + 1, main_tid, notifybits); if (result == 0) { FAILED(); return; } result = counter_increment(1); if (result == 0) { FAILED(); return; } L4_Set_NotifyMask(notifybits); L4_Accept(L4_NotifyMsgAcceptor); tag = L4_WaitNotify(&mask); if (L4_IpcFailed(tag)) { FAILED(); return; } PASSED(); }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Exercise private object header behavior and routines * * Return: Success: 0 * Failure: 1 * * Programmer: Robb Matzke * Tuesday, November 24, 1998 * *------------------------------------------------------------------------- */ int main(void) { hid_t fapl = -1, file = -1; hid_t dset = -1; H5F_t *f = NULL; char filename[1024]; H5O_hdr_info_t hdr_info; /* Object info */ H5O_loc_t oh_loc, oh_loc2; /* Object header locations */ time_t time_new, ro; int chunkno; /* Chunk index for message */ int i; /* Local index variable */ hbool_t b; /* Index for "new format" loop */ herr_t ret; /* Generic return value */ /* Reset library */ h5_reset(); fapl = h5_fileaccess(); h5_fixname(FILENAME[0], fapl, filename, sizeof filename); /* Loop over old & new formats */ for(b = FALSE; b <= TRUE; b++) { /* Display info about testing */ if(b) HDputs("Using new file format:"); else HDputs("Using default file format:"); /* Set the format to use for the file */ if(H5Pset_libver_bounds(fapl, (b ? H5F_LIBVER_LATEST : H5F_LIBVER_EARLIEST), H5F_LIBVER_LATEST) < 0) FAIL_STACK_ERROR /* test on object continuation block */ if(test_cont(filename, fapl) < 0) FAIL_STACK_ERROR /* Create the file to operate on */ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR if(NULL == (f = (H5F_t *)H5I_object(file))) FAIL_STACK_ERROR if (H5AC_ignore_tags(f) < 0) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } /* * Test object header creation * (using default group creation property list only because it's convenient) */ TESTING("object header creation"); HDmemset(&oh_loc, 0, sizeof(oh_loc)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0) FAIL_STACK_ERROR PASSED(); /* create a new message */ TESTING("message creation"); time_new = 11111111; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(ro != time_new) TEST_ERROR PASSED(); /* * Test modification of an existing message. */ TESTING("message modification"); time_new = 33333333; if(H5O_msg_write(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(ro != time_new) TEST_ERROR /* Make certain that chunk #0 in the object header can be encoded with a 1-byte size */ if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.space.total >=256) TEST_ERROR PASSED(); /* * Test creation of a bunch of messages one after another to see * what happens when the object header overflows in core. * (Use 'old' MTIME message here, because it is large enough to be * replaced with a continuation message (the new one is too small) * and the library doesn't understand how to migrate more than one * message from an object header currently - QAK - 10/8/03) */ TESTING("object header overflow in memory"); for(i = 0; i < 40; i++) { time_new = (i + 1) * 1000 + 1000000; if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR } /* end for */ if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR /* Make certain that chunk #0 in the object header will be encoded with a 2-byte size */ if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.space.total < 256) TEST_ERROR PASSED(); /* Close & re-open file & object header */ /* (makes certain that an object header in the new format that transitions * between 1-byte chunk #0 size encoding and 2-byte chunk #0 size encoding * works correctly - QAK) */ TESTING("close & re-open object header"); if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR if(H5Fclose(file) < 0) FAIL_STACK_ERROR if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) FAIL_STACK_ERROR if(NULL == (f = (H5F_t *)H5I_object(file))) FAIL_STACK_ERROR if (H5AC_ignore_tags(f) < 0) FAIL_STACK_ERROR oh_loc.file = f; if(H5O_open(&oh_loc) < 0) FAIL_STACK_ERROR PASSED(); /* * Test creation of a bunch of messages one after another to see * what happens when the object header overflows on disk. */ TESTING("object header overflow on disk"); for(i = 0; i < 10; i++) { time_new = (i + 1) * 1000 + 10; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR } /* end for */ PASSED(); /* * Delete all time messages. */ TESTING("message deletion"); if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_remove(&oh_loc, H5O_MTIME_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(H5O_msg_read(&oh_loc, H5O_MTIME_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR PASSED(); /* * Constant message handling. * (can't write to them, but should be able to remove them) */ TESTING("constant message handling"); time_new = 22222222; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, H5O_MSG_FLAG_CONSTANT, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5AC_expunge_entry(f, H5P_DATASET_XFER_DEFAULT, H5AC_OHDR, oh_loc.addr, H5AC__NO_FLAGS_SET) < 0) FAIL_STACK_ERROR if(NULL == H5O_msg_read(&oh_loc, H5O_MTIME_NEW_ID, &ro, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(ro != time_new) TEST_ERROR time_new = 33333333; H5E_BEGIN_TRY { ret = H5O_msg_write(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT); } H5E_END_TRY; if(ret >= 0) TEST_ERROR if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR PASSED(); /* release resources */ TESTING("object header closing"); if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR PASSED(); /* * Test moving message to first chunk */ TESTING("locking messages"); HDmemset(&oh_loc, 0, sizeof(oh_loc)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR /* Create second object header, to guarantee that first object header uses multiple chunks */ HDmemset(&oh_loc2, 0, sizeof(oh_loc2)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc2/*out*/) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc2, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR /* Fill object header with messages, creating multiple chunks */ for(i = 0; i < 10; i++) { time_new = (i + 1) * 1000 + 10; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR } /* end for */ /* Get # of object header chunks */ if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.nchunks != 2) TEST_ERROR /* Add message to lock to object header */ time_new = 11111111; if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Verify chunk index for message */ if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR if(chunkno != 1) TEST_ERROR /* Lock the message into the chunk */ if(H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Attempt to lock the message twice */ H5E_BEGIN_TRY { ret = H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT); } H5E_END_TRY; if(ret >= 0) TEST_ERROR /* Delete all the other messages, which would move the message into * chunk #0, if it wasn't locked */ if(H5O_msg_remove(&oh_loc, H5O_MTIME_NEW_ID, H5O_ALL, TRUE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Verify chunk index for message */ if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR if(chunkno != 1) TEST_ERROR /* Unlock the message */ if(H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Attempt to unlock the message twice */ H5E_BEGIN_TRY { ret = H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT); } H5E_END_TRY; if(ret >= 0) TEST_ERROR /* Close object headers */ if(H5O_close(&oh_loc2) < 0) FAIL_STACK_ERROR if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR /* Open first object header */ HDmemset(&oh_loc, 0, sizeof(oh_loc)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR /* Create second object header, to guarantee that first object header uses multiple chunks */ HDmemset(&oh_loc2, 0, sizeof(oh_loc2)); if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)64, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_loc2/*out*/) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_loc2, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR /* Add message to move to object header */ time_new = 11111111; if(H5O_msg_create(&oh_loc, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Verify chunk index for message */ if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR if(chunkno != 0) TEST_ERROR /* Lock the message into the chunk */ if(H5O_msg_lock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Fill object header with messages, creating multiple chunks */ /* (would normally move locked message to new chunk) */ for(i = 0; i < 10; i++) { time_new = (i + 1) * 1000 + 10; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR } /* end for */ /* Get # of object header chunks */ if(H5O_get_hdr_info(&oh_loc, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.nchunks != 2) TEST_ERROR /* Verify chunk index for message */ if((chunkno = H5O_msg_get_chunkno(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR if(chunkno != 0) TEST_ERROR /* Unlock the message */ if(H5O_msg_unlock(&oh_loc, H5O_MTIME_ID, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR /* Close object headers */ if(H5O_close(&oh_loc2) < 0) FAIL_STACK_ERROR if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR PASSED(); /* Test reading datasets with undefined object header messages * and the various "fail/mark if unknown" object header message flags */ HDputs("Accessing objects with unknown header messages:"); { hid_t file2; /* File ID for 'bogus' object file */ hid_t sid; /* Dataspace ID */ hid_t aid; /* Attribute ID */ const char *testfile = H5_get_srcdir_filename(FILE_BOGUS); TESTING("object with unknown header message and no flags set"); /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) */ if((file2 = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) TEST_ERROR /* Open the dataset with the unknown header message, but no extra flags */ if((dset = H5Dopen2(file2, "/Dataset1", H5P_DEFAULT)) < 0) TEST_ERROR if(H5Dclose(dset) < 0) TEST_ERROR PASSED(); TESTING("object in r/o file with unknown header message & 'fail if unknown and open for write' flag set"); /* Open the dataset with the unknown header message, and "fail if unknown and open for write" flag */ if((dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT)) < 0) TEST_ERROR if(H5Dclose(dset) < 0) TEST_ERROR PASSED(); TESTING("object in r/o file with unknown header message & 'fail if unknown always' flag set"); /* Attempt to open the dataset with the unknown header message, and "fail if unknown always" flag */ H5E_BEGIN_TRY { dset = H5Dopen2(file2, "/Dataset3", H5P_DEFAULT); } H5E_END_TRY; if(dset >= 0) { H5Dclose(dset); TEST_ERROR } /* end if */ PASSED(); TESTING("object with unknown header message & 'mark if unknown' flag set"); /* Copy object with "mark if unknown" flag on message into file that can be modified */ if(H5Ocopy(file2, "/Dataset4", file, "/Dataset4", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR /* Close the file we created (to flush changes to file) */ if(H5Fclose(file) < 0) TEST_ERROR /* Re-open the file created, with read-only permissions */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR /* Open the dataset with the "mark if unknown" message */ if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0) TEST_ERROR /* Check that the "unknown" message was _NOT_ marked */ if(H5O_check_msg_marked_test(dset, FALSE) < 0) FAIL_STACK_ERROR /* Close the dataset */ if(H5Dclose(dset) < 0) TEST_ERROR /* Close the file we created (to flush change to object header) */ if(H5Fclose(file) < 0) TEST_ERROR /* Re-open the file created */ if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR /* Open the dataset with the "mark if unknown" message */ if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0) TEST_ERROR /* Create data space */ if((sid = H5Screate(H5S_SCALAR)) < 0) FAIL_STACK_ERROR /* Create an attribute, to get the object header into write access */ if((aid = H5Acreate2(dset, "Attr", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR /* Close dataspace */ if(H5Sclose(sid) < 0) FAIL_STACK_ERROR /* Close attribute */ if(H5Aclose(aid) < 0) FAIL_STACK_ERROR /* Close the dataset */ if(H5Dclose(dset) < 0) TEST_ERROR /* Close the file we created (to flush change to object header) */ if(H5Fclose(file) < 0) TEST_ERROR /* Re-open the file created */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR /* Re-open the dataset with the "mark if unknown" message */ if((dset = H5Dopen2(file, "/Dataset4", H5P_DEFAULT)) < 0) TEST_ERROR /* Check that the "unknown" message was marked */ if(H5O_check_msg_marked_test(dset, TRUE) < 0) FAIL_STACK_ERROR /* Close the dataset */ if(H5Dclose(dset) < 0) TEST_ERROR /* Close the file with the bogus objects */ if(H5Fclose(file2) < 0) TEST_ERROR PASSED(); /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) with RW intent this time */ if((file2 = H5Fopen(testfile, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) TEST_ERROR TESTING("object in r/w file with unknown header message & 'fail if unknown and open for write' flag set"); /* Attempt to open the dataset with the unknown header message, and "fail if unknown and open for write" flag */ H5E_BEGIN_TRY { dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT); } H5E_END_TRY; if(dset >= 0) { H5Dclose(dset); TEST_ERROR } /* end if */ PASSED(); TESTING("object in r/w file with unknown header message & 'fail if unknown always' flag set"); /* Attempt to open the dataset with the unknown header message, and "fail if unknown always" flag */ H5E_BEGIN_TRY { dset = H5Dopen2(file2, "/Dataset3", H5P_DEFAULT); } H5E_END_TRY; if(dset >= 0) { H5Dclose(dset); TEST_ERROR } /* end if */
/*------------------------------------------------------------------------- * Function: test_invalid_parameters * * Purpose: Test invalid parameters for H5DOwrite_chunk * * Return: Success: 0 * * Failure: 1 * * Programmer: Raymond Lu * 30 November 2012 * *------------------------------------------------------------------------- */ static int test_invalid_parameters(hid_t file) { hid_t dataspace = -1, dataset = -1; hid_t mem_space = -1; hid_t cparms = -1, dxpl = -1; hsize_t dims[2] = {NX, NY}; hsize_t chunk_dims[2] ={CHUNK_NX, CHUNK_NY}; herr_t status; int i, j, n; unsigned filter_mask = 0; int direct_buf[CHUNK_NX][CHUNK_NY]; hsize_t offset[2] = {0, 0}; size_t buf_size = CHUNK_NX*CHUNK_NY*sizeof(int); int aggression = 9; /* Compression aggression setting */ TESTING("invalid parameters for H5DOwrite_chunk"); /* * Create the data space with unlimited dimensions. */ if((dataspace = H5Screate_simple(RANK, dims, NULL)) < 0) goto error; if((mem_space = H5Screate_simple(RANK, chunk_dims, NULL)) < 0) goto error; /* * Modify dataset creation properties */ if((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error; /* * Create a new contiguous dataset to verify H5DOwrite_chunk doesn't work */ if((dataset = H5Dcreate2(file, DATASETNAME5, H5T_NATIVE_INT, dataspace, H5P_DEFAULT, cparms, H5P_DEFAULT)) < 0) goto error; if((dxpl = H5Pcreate(H5P_DATASET_XFER)) < 0) goto error; /* Initialize data for one chunk */ for(i = n = 0; i < CHUNK_NX; i++) for(j = 0; j < CHUNK_NY; j++) { direct_buf[i][j] = n++; } /* Try to write the chunk data to contiguous dataset. It should fail */ offset[0] = CHUNK_NX; offset[1] = CHUNK_NY; H5E_BEGIN_TRY { if((status = H5DOwrite_chunk(dataset, dxpl, filter_mask, offset, buf_size, direct_buf)) != FAIL) goto error; } H5E_END_TRY; if(H5Dclose(dataset) < 0) goto error; /* Create a chunked dataset with compression filter */ if((status = H5Pset_chunk( cparms, RANK, chunk_dims)) < 0) goto error; if((status = H5Pset_deflate( cparms, (unsigned ) aggression)) < 0) goto error; /* * Create a new dataset within the file using cparms * creation properties. */ if((dataset = H5Dcreate2(file, DATASETNAME6, H5T_NATIVE_INT, dataspace, H5P_DEFAULT, cparms, H5P_DEFAULT)) < 0) goto error; /* Check invalid dataset ID */ H5E_BEGIN_TRY { if((status = H5DOwrite_chunk((hid_t)-1, dxpl, filter_mask, offset, buf_size, direct_buf)) != FAIL) goto error; } H5E_END_TRY; /* Check invalid DXPL ID */ H5E_BEGIN_TRY { if((status = H5DOwrite_chunk(dataset, (hid_t)-1, filter_mask, offset, buf_size, direct_buf)) != FAIL) goto error; } H5E_END_TRY; /* Check invalid OFFSET */ H5E_BEGIN_TRY { if((status = H5DOwrite_chunk(dataset, dxpl, filter_mask, NULL, buf_size, direct_buf)) != FAIL) goto error; } H5E_END_TRY; /* Check when OFFSET is out of dataset range */ offset[0] = NX + 1; offset[1] = NY; H5E_BEGIN_TRY { if((status = H5DOwrite_chunk(dataset, dxpl, filter_mask, offset, buf_size, direct_buf)) != FAIL) goto error; } H5E_END_TRY; /* Check when OFFSET is not on chunk boundary */ offset[0] = CHUNK_NX; offset[1] = CHUNK_NY + 1; H5E_BEGIN_TRY { if((status = H5DOwrite_chunk(dataset, dxpl, filter_mask, offset, buf_size, direct_buf)) != FAIL) goto error; } H5E_END_TRY; /* Check invalid buffer size */ offset[0] = CHUNK_NX; offset[1] = CHUNK_NY; buf_size = 0; H5E_BEGIN_TRY { if((status = H5DOwrite_chunk(dataset, dxpl, filter_mask, offset, buf_size, direct_buf)) != FAIL) goto error; } H5E_END_TRY; /* Check invalid data buffer */ buf_size = CHUNK_NX*CHUNK_NY*sizeof(int); H5E_BEGIN_TRY { if((status = H5DOwrite_chunk(dataset, dxpl, filter_mask, offset, buf_size, NULL)) != FAIL) goto error; } H5E_END_TRY; if(H5Dclose(dataset) < 0) goto error; /* * Close/release resources. */ H5Sclose(mem_space); H5Sclose(dataspace); H5Pclose(cparms); H5Pclose(dxpl); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Dclose(dataset); H5Sclose(mem_space); H5Sclose(dataspace); H5Pclose(cparms); H5Pclose(dxpl); } H5E_END_TRY; return 1; }
/*------------------------------------------------------------------------- * Function: test_data_conv * * Purpose: Test data conversion * * Return: Success: 0 * * Failure: 1 * * Programmer: Raymond Lu * 30 November 2012 * *------------------------------------------------------------------------- */ static int test_data_conv(hid_t file) { typedef struct { int a, b, c[4], d, e; } src_type_t; typedef struct { int a, c[4], e; } dst_type_t; hid_t dataspace = -1, dataset = -1; hid_t mem_space = -1; hid_t cparms = -1, dxpl = -1; hsize_t dims[2] = {NX, NY}; hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; hsize_t chunk_dims[2] ={CHUNK_NX, CHUNK_NY}; herr_t status; int i, j, n; const hsize_t four = 4; hid_t st=-1, dt=-1; hid_t array_dt; unsigned filter_mask = 0; src_type_t direct_buf[CHUNK_NX][CHUNK_NY]; dst_type_t check_chunk[CHUNK_NX][CHUNK_NY]; hsize_t offset[2] = {0, 0}; size_t buf_size = CHUNK_NX*CHUNK_NY*sizeof(src_type_t); hsize_t start[2]; /* Start of hyperslab */ hsize_t stride[2]; /* Stride of hyperslab */ hsize_t count[2]; /* Block count */ hsize_t block[2]; /* Block sizes */ TESTING("data conversion for H5DOwrite_chunk"); /* * Create the data space with unlimited dimensions. */ if((dataspace = H5Screate_simple(RANK, dims, maxdims)) < 0) goto error; if((mem_space = H5Screate_simple(RANK, chunk_dims, NULL)) < 0) goto error; /* * Modify dataset creation properties, i.e. enable chunking */ if((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error; if((status = H5Pset_chunk( cparms, RANK, chunk_dims)) < 0) goto error; /* Build hdf5 datatypes */ array_dt = H5Tarray_create2(H5T_NATIVE_INT, 1, &four); if((st = H5Tcreate(H5T_COMPOUND, sizeof(src_type_t))) < 0 || H5Tinsert(st, "a", HOFFSET(src_type_t, a), H5T_NATIVE_INT) < 0 || H5Tinsert(st, "b", HOFFSET(src_type_t, b), H5T_NATIVE_INT) < 0 || H5Tinsert(st, "c", HOFFSET(src_type_t, c), array_dt) < 0 || H5Tinsert(st, "d", HOFFSET(src_type_t, d), H5T_NATIVE_INT) < 0 || H5Tinsert(st, "e", HOFFSET(src_type_t, e), H5T_NATIVE_INT) < 0) goto error; if(H5Tclose(array_dt) < 0) goto error; array_dt = H5Tarray_create2(H5T_NATIVE_INT, 1, &four); if((dt = H5Tcreate(H5T_COMPOUND, sizeof(dst_type_t))) < 0 || H5Tinsert(dt, "a", HOFFSET(dst_type_t, a), H5T_NATIVE_INT) < 0 || H5Tinsert(dt, "c", HOFFSET(dst_type_t, c), array_dt) < 0 || H5Tinsert(dt, "e", HOFFSET(dst_type_t, e), H5T_NATIVE_INT) < 0) goto error; if(H5Tclose(array_dt) < 0) goto error; /* * Create a new dataset within the file using cparms * creation properties. */ if((dataset = H5Dcreate2(file, DATASETNAME4, st, dataspace, H5P_DEFAULT, cparms, H5P_DEFAULT)) < 0) goto error; if((dxpl = H5Pcreate(H5P_DATASET_XFER)) < 0) goto error; /* Initialize data for one chunk */ for(i = n = 0; i < CHUNK_NX; i++) { for(j = 0; j < CHUNK_NY; j++) { (direct_buf[i][j]).a = i*j+0; (direct_buf[i][j]).b = i*j+1; (direct_buf[i][j]).c[0] = i*j+2; (direct_buf[i][j]).c[1] = i*j+3; (direct_buf[i][j]).c[2] = i*j+4; (direct_buf[i][j]).c[3] = i*j+5; (direct_buf[i][j]).d = i*j+6; (direct_buf[i][j]).e = i*j+7; } } /* write the chunk data to dataset, using the direct writing function. * There should be no data conversion involved. */ offset[0] = CHUNK_NX; offset[1] = CHUNK_NY; if((status = H5DOwrite_chunk(dataset, dxpl, filter_mask, offset, buf_size, direct_buf)) < 0) goto error; if(H5Fflush(dataset, H5F_SCOPE_LOCAL) < 0) goto error; if(H5Dclose(dataset) < 0) goto error; if((dataset = H5Dopen2(file, DATASETNAME4, H5P_DEFAULT)) < 0) goto error; /* * Select hyperslab for the chunk just written in the file */ start[0] = CHUNK_NX; start[1] = CHUNK_NY; stride[0] = 1; stride[1] = 1; count[0] = 1; count[1] = 1; block[0] = CHUNK_NX; block[1] = CHUNK_NY; if((status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, start, stride, count, block)) < 0) goto error; /* Read the chunk back. Data should be converted */ if((status = H5Dread(dataset, dt, mem_space, dataspace, H5P_DEFAULT, check_chunk)) < 0) goto error; /* Check that the values read are the same as the values written */ for(i = 0; i < CHUNK_NX; i++) { for(j = 0; j < CHUNK_NY; j++) { if ((direct_buf[i][j]).a != (check_chunk[i][j]).a || (direct_buf[i][j]).c[0] != (check_chunk[i][j]).c[0] || (direct_buf[i][j]).c[1] != (check_chunk[i][j]).c[1] || (direct_buf[i][j]).c[2] != (check_chunk[i][j]).c[2] || (direct_buf[i][j]).c[3] != (check_chunk[i][j]).c[3] || (direct_buf[i][j]).e != (check_chunk[i][j]).e) { printf(" 1. Read different values than written."); printf(" At index %d,%d\n", i, j); printf(" src={a=%d, b=%d, c=[%d,%d,%d,%d], d=%d, e=%d\n", (direct_buf[i][j]).a, (direct_buf[i][j]).b, (direct_buf[i][j]).c[0], (direct_buf[i][j]).c[1], (direct_buf[i][j]).c[2], (direct_buf[i][j]).c[3], (direct_buf[i][j]).d, (direct_buf[i][j]).e); printf(" dst={a=%d, c=[%d,%d,%d,%d], e=%d\n", (check_chunk[i][j]).a, (check_chunk[i][j]).c[0], (check_chunk[i][j]).c[1], (check_chunk[i][j]).c[2], (check_chunk[i][j]).c[3], (check_chunk[i][j]).e); goto error; } } } /* * Close/release resources. */ H5Dclose(dataset); H5Sclose(mem_space); H5Sclose(dataspace); H5Pclose(cparms); H5Pclose(dxpl); H5Tclose(st); H5Tclose(dt); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Dclose(dataset); H5Sclose(mem_space); H5Sclose(dataspace); H5Pclose(cparms); H5Pclose(dxpl); H5Tclose(st); H5Tclose(dt); } H5E_END_TRY; return 1; }
void done() { ASSERT(MANGLE(failures) == 0); PASSED(); }
/*------------------------------------------------------------------------- * Function: test_family_compat * * Purpose: Tests the backward compatibility for FAMILY driver. * See if we can open files created with v1.6 library. * The source file was created by the test/file_handle.c * of the v1.6 library. Then tools/misc/h5repart.c was * used to concantenated. The command was "h5repart -m 5k * family_file%05d.h5 family_v16_%05d.h5". * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * June 3, 2005 * *------------------------------------------------------------------------- */ static herr_t test_family_compat(void) { hid_t file = (-1), fapl; hid_t dset; char dname[]="dataset"; char filename[1024]; char pathname[1024], pathname_individual[1024]; char newname[1024], newname_individual[1024]; FILE *tmp_fp, *old_fp; /* Pointers to temp & old files */ int counter = 0; TESTING("FAMILY file driver backward compatibility"); /* Set property list and file name for FAMILY driver */ fapl = h5_fileaccess(); if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE2, H5P_DEFAULT) < 0) TEST_ERROR; h5_fixname(COMPAT_BASENAME, fapl, filename, sizeof filename); h5_fixname(FILENAME[3], fapl, newname, sizeof newname); pathname[0] = '\0'; HDstrcat(pathname, filename); /* The following code makes the copies of the family files in the source directory. * Since we're going to open the files with write mode, this protects the original * files. */ sprintf(newname_individual, newname, counter); sprintf(pathname_individual, pathname, counter); while (h5_make_local_copy(pathname_individual, newname_individual) >= 0) { counter++; sprintf(newname_individual, newname, counter); sprintf(pathname_individual, pathname, counter); } if ((NULL != (old_fp = HDfopen(pathname_individual,"rb"))) && (NULL != (tmp_fp = HDfopen(newname_individual,"wb")))) TEST_ERROR; /* Make sure we can open the file. Use the read and write mode to flush the * superblock. */ if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; if((dset = H5Dopen2(file, dname, H5P_DEFAULT)) < 0) TEST_ERROR; if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Open the file again to make sure it isn't corrupted. */ if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; if((dset = H5Dopen2(file, dname, H5P_DEFAULT)) < 0) TEST_ERROR; if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; h5_cleanup(FILENAME, fapl); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(file); H5Pclose(fapl); } H5E_END_TRY; return -1; } /* end test_family_compat() */
/*------------------------------------------------------------------------- * Function: test_core * * Purpose: Tests the file handle interface for CORE driver * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * Tuesday, Sept 24, 2002 * * Modifications: * * Raymond Lu * Wednesday, June 23, 2004 * Added test for H5Fget_filesize. * * Raymond Lu, 2006-11-30 * Enabled the driver to read an existing file depending on * the setting of the backing_store and file open flags. *------------------------------------------------------------------------- */ static herr_t test_core(void) { hid_t file=(-1), fapl, access_fapl = -1; char filename[1024]; void *fhandle=NULL; hsize_t file_size; int *points, *check, *p1, *p2; hid_t dset1=-1, space1=-1; hsize_t dims1[2]; int i, j, n; TESTING("CORE file driver"); /* Set property list and file name for CORE driver */ fapl = h5_fileaccess(); if(H5Pset_fapl_core(fapl, (size_t)CORE_INCREMENT, TRUE) < 0) TEST_ERROR; h5_fixname(FILENAME[1], fapl, filename, sizeof filename); if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; /* Retrieve the access property list... */ if ((access_fapl = H5Fget_access_plist(file)) < 0) TEST_ERROR; /* ...and close the property list */ if (H5Pclose(access_fapl) < 0) TEST_ERROR; if(H5Fget_vfd_handle(file, H5P_DEFAULT, &fhandle) < 0) TEST_ERROR; if(fhandle==NULL) { printf("fhandle==NULL\n"); TEST_ERROR; } /* Check file size API */ if(H5Fget_filesize(file, &file_size) < 0) TEST_ERROR; /* There is no garantee the size of metadata in file is constant. * Just try to check if it's reasonable. Why is this 4KB? */ if(file_size<2*KB || file_size>6*KB) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Open the file with backing store off for read and write. * Changes won't be saved in file. */ if(H5Pset_fapl_core(fapl, (size_t)CORE_INCREMENT, FALSE) < 0) TEST_ERROR; if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; /* Allocate memory for data set. */ points=(int*)malloc(DSET1_DIM1*DSET1_DIM2*sizeof(int)); check=(int*)malloc(DSET1_DIM1*DSET1_DIM2*sizeof(int)); /* Initialize the dset1 */ p1 = points; for(i = n = 0; i < DSET1_DIM1; i++) for(j = 0; j < DSET1_DIM2; j++) *p1++ = n++; /* Create the data space1 */ dims1[0] = DSET1_DIM1; dims1[1] = DSET1_DIM2; if((space1 = H5Screate_simple(2, dims1, NULL)) < 0) TEST_ERROR; /* Create the dset1 */ if((dset1 = H5Dcreate2(file, DSET1_NAME, H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; /* Write the data to the dset1 */ if(H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) TEST_ERROR; if(H5Dclose(dset1) < 0) TEST_ERROR; if((dset1 = H5Dopen2(file, DSET1_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; /* Read the data back from dset1 */ if(H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ p1 = points; p2 = check; for(i = 0; i < DSET1_DIM1; i++) for(j = 0; j < DSET1_DIM2; j++) if(*p1++ != *p2++) { H5_FAILED(); printf(" Read different values than written in data set 1.\n"); printf(" At index %d,%d\n", i, j); TEST_ERROR; } /* end if */ if(H5Dclose(dset1) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Open the file with backing store on for read and write. * Changes will be saved in file. */ if(H5Pset_fapl_core(fapl, (size_t)CORE_INCREMENT, TRUE) < 0) TEST_ERROR; if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; /* Create the dset1 */ if((dset1 = H5Dcreate2(file, DSET1_NAME, H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; /* Write the data to the dset1 */ if(H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) TEST_ERROR; if(H5Dclose(dset1) < 0) TEST_ERROR; if((dset1 = H5Dopen2(file, DSET1_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; /* Reallocate memory for reading buffer. */ if(check) free(check); check = (int*)malloc(DSET1_DIM1 * DSET1_DIM2 * sizeof(int)); /* Read the data back from dset1 */ if(H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ p1 = points; p2 = check; for(i = 0; i < DSET1_DIM1; i++) for(j = 0; j < DSET1_DIM2; j++) if(*p1++ != *p2++) { H5_FAILED(); printf(" Read different values than written in data set 1.\n"); printf(" At index %d,%d\n", i, j); TEST_ERROR; } /* end if */ /* Check file size API */ if(H5Fget_filesize(file, &file_size) < 0) TEST_ERROR; /* There is no garantee the size of metadata in file is constant. * Just try to check if it's reasonable. */ if(file_size<64*KB || file_size>256*KB) TEST_ERROR; if(H5Sclose(space1) < 0) TEST_ERROR; if(H5Dclose(dset1) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; if(points) free(points); if(check) free(check); h5_cleanup(FILENAME, fapl); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Pclose (fapl); H5Fclose(file); } H5E_END_TRY; return -1; }
/*------------------------------------------------------------------------- * Function: test_allocate_random * * Purpose: Tests allocating random sized blocks in pool * * Return: Success: 0 * * Failure: 1 * * Programmer: Quincey Koziol * Friday, May 6, 2005 * * Modifications: * *------------------------------------------------------------------------- */ static int test_allocate_random(void) { H5MP_pool_t *mp; /* Memory pool */ size_t u; /* Local index variable */ time_t curr_time; /* Current time, for seeding random number generator */ size_t *blk_size = NULL; /* Pointer to block sizes */ void **spc = NULL; /* Pointer to space allocated */ size_t swap_idx; /* Location to swap with when shuffling */ void *swap_ptr; /* Pointer to swap when shuffling */ /* * Test memory pool allocation */ TESTING("allocate many random sized blocks"); /* Initialize random number seed */ curr_time=HDtime(NULL); #ifdef QAK curr_time=1115412944; HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); #endif /* QAK */ HDsrandom((unsigned long)curr_time); /* Create a memory pool */ if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) TEST_ERROR /* Allocate space for the block sizes */ if(NULL == (blk_size = HDmalloc(sizeof(size_t) * MPOOL_NUM_RANDOM))) TEST_ERROR /* Allocate space for the block pointers */ if(NULL == (spc = HDmalloc(sizeof(void *) * MPOOL_NUM_RANDOM))) TEST_ERROR /* Initialize the block sizes with random values */ for(u = 0; u < MPOOL_NUM_RANDOM; u++) blk_size[u] = (size_t)(HDrandom() % MPOOL_RANDOM_MAX_SIZE) + 1; /* Allocate space in pool */ for(u = 0; u < MPOOL_NUM_RANDOM; u++) if(NULL == (spc[u] = H5MP_malloc(mp, blk_size[u]))) TEST_ERROR /* Check that free space totals match */ if(H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR; /* Shuffle pointers to free */ for(u = 0; u < MPOOL_NUM_RANDOM; u++) { swap_idx = (size_t)(HDrandom() % (MPOOL_NUM_RANDOM - u)) + u; swap_ptr = spc[u]; spc[u] = spc[swap_idx]; spc[swap_idx] = swap_ptr; } /* end for */ /* Free blocks in pool */ for(u = 0; u < MPOOL_NUM_RANDOM; u++) H5MP_free(mp, spc[u]); /* Check that free space totals match */ if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR; /* Initialize the block sizes with random values */ for(u = 0; u < MPOOL_NUM_RANDOM; u++) blk_size[u] = (size_t)(HDrandom() % MPOOL_RANDOM_MAX_SIZE) + 1; /* Allocate space in pool (again) */ /* (Leave allocated to test closing pool with many blocks still allocated) */ for(u = 0; u < MPOOL_NUM_RANDOM; u++) if(NULL == (spc[u] = H5MP_malloc(mp, blk_size[u]))) TEST_ERROR /* Check that free space totals match */ if(H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR; /* Close the memory pool */ if (H5MP_close(mp) < 0) TEST_ERROR /* Free memory for block sizes & pointers */ HDfree(blk_size); HDfree(spc); PASSED(); return 0; error: if(blk_size) HDfree(blk_size); if(spc) HDfree(spc); H5E_BEGIN_TRY { } H5E_END_TRY; return 1; } /* test_allocate_random() */
/*------------------------------------------------------------------------- * Function: test_direct * * Purpose: Tests the file handle interface for DIRECT I/O driver * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * Wednesday, 20 September 2006 * *------------------------------------------------------------------------- */ static herr_t test_direct(void) { #ifdef H5_HAVE_DIRECT hid_t file=(-1), fapl, access_fapl = -1; hid_t dset1=-1, dset2=-1, space1=-1, space2=-1; char filename[1024]; int *fhandle=NULL; hsize_t file_size; hsize_t dims1[2], dims2[1]; size_t mbound; size_t fbsize; size_t cbsize; int *points, *check, *p1, *p2; int wdata2[DSET2_DIM] = {11,12,13,14}; int rdata2[DSET2_DIM]; int i, j, n; #endif /*H5_HAVE_DIRECT*/ TESTING("Direct I/O file driver"); #ifndef H5_HAVE_DIRECT SKIPPED(); return 0; #else /*H5_HAVE_DIRECT*/ /* Set property list and file name for Direct driver. Set memory alignment boundary * and file block size to 512 which is the minimum for Linux 2.6. */ fapl = h5_fileaccess(); if(H5Pset_fapl_direct(fapl, MBOUNDARY, FBSIZE, CBSIZE) < 0) TEST_ERROR; h5_fixname(FILENAME[5], fapl, filename, sizeof filename); /* Verify the file access properties */ if(H5Pget_fapl_direct(fapl, &mbound, &fbsize, &cbsize) < 0) TEST_ERROR; if(mbound != MBOUNDARY || fbsize != FBSIZE || cbsize != CBSIZE) TEST_ERROR; if(H5Pset_alignment(fapl, (hsize_t)THRESHOLD, (hsize_t)FBSIZE) < 0) TEST_ERROR; H5E_BEGIN_TRY { file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); } H5E_END_TRY; if(file<0) { H5Pclose (fapl); SKIPPED(); printf(" Probably the file system doesn't support Direct I/O\n"); return 0; } /* Retrieve the access property list... */ if ((access_fapl = H5Fget_access_plist(file)) < 0) TEST_ERROR; /* ...and close the property list */ if (H5Pclose(access_fapl) < 0) TEST_ERROR; /* Check file handle API */ if(H5Fget_vfd_handle(file, H5P_DEFAULT, (void **)&fhandle) < 0) TEST_ERROR; if(*fhandle<0) TEST_ERROR; /* Check file size API */ if(H5Fget_filesize(file, &file_size) < 0) TEST_ERROR; /* There is no guarantee of the number of metadata allocations, but it's * 4 currently and the size of the file should be between 3 & 4 file buffer * sizes.. */ if(file_size < (FBSIZE * 3) || file_size >= (FBSIZE * 4)) TEST_ERROR; /* Allocate aligned memory for data set 1. For data set 1, everything is aligned including * memory address, size of data, and file address. */ if(posix_memalign(&points, (size_t)FBSIZE, (size_t)(DSET1_DIM1*DSET1_DIM2*sizeof(int)))!=0) TEST_ERROR; if(posix_memalign(&check, (size_t)FBSIZE, (size_t)(DSET1_DIM1*DSET1_DIM2*sizeof(int)))!=0) TEST_ERROR; /* Initialize the dset1 */ p1 = points; for(i = n = 0; i < DSET1_DIM1; i++) for(j = 0; j < DSET1_DIM2; j++) *p1++ = n++; /* Create the data space1 */ dims1[0] = DSET1_DIM1; dims1[1] = DSET1_DIM2; if((space1 = H5Screate_simple(2, dims1, NULL)) < 0) TEST_ERROR; /* Create the dset1 */ if((dset1 = H5Dcreate2(file, DSET1_NAME, H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; /* Write the data to the dset1 */ if(H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) TEST_ERROR; if(H5Dclose(dset1) < 0) TEST_ERROR; if((dset1 = H5Dopen2(file, DSET1_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; /* Read the data back from dset1 */ if(H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ p1 = points; p2 = check; for(i = 0; i < DSET1_DIM1; i++) for(j = 0; j < DSET1_DIM2; j++) if(*p1++ != *p2++) { H5_FAILED(); printf(" Read different values than written in data set 1.\n"); printf(" At index %d,%d\n", i, j); TEST_ERROR; } /* end if */ /* Create the data space2. For data set 2, memory address and data size are not aligned. */ dims2[0] = DSET2_DIM; if((space2 = H5Screate_simple(1, dims2, NULL)) < 0) TEST_ERROR; /* Create the dset2 */ if((dset2 = H5Dcreate2(file, DSET2_NAME, H5T_NATIVE_INT, space2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; /* Write the data to the dset1 */ if(H5Dwrite(dset2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata2) < 0) TEST_ERROR; if(H5Dclose(dset2) < 0) TEST_ERROR; if((dset2 = H5Dopen2(file, DSET2_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; /* Read the data back from dset1 */ if(H5Dread(dset2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata2) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ for(i = 0; i < DSET2_DIM; i++) if(wdata2[i] != rdata2[i]) { H5_FAILED(); printf(" Read different values than written in data set 2.\n"); printf(" At index %d\n", i); TEST_ERROR; } /* end if */ if(H5Sclose(space1) < 0) TEST_ERROR; if(H5Dclose(dset1) < 0) TEST_ERROR; if(H5Sclose(space2) < 0) TEST_ERROR; if(H5Dclose(dset2) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; if(points) free(points); if(check) free(check); h5_cleanup(FILENAME, fapl); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Pclose (fapl); H5Sclose(space1); H5Dclose(dset1); H5Sclose(space2); H5Dclose(dset2); H5Fclose(file); } H5E_END_TRY; return -1; #endif /*H5_HAVE_DIRECT*/ }
/*------------------------------------------------------------------------- * Function: test_tr2 * * Purpose: Tests conversions that use the O(log N) lookup function. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Tuesday, January 5, 1999 * * Modifications: * *------------------------------------------------------------------------- */ static int test_tr2(hid_t file) { hid_t cwg=-1, m_type=-1, f_type=-1, space=-1, dset=-1; hsize_t ds_size[1]={10}; size_t i; c_e1 val1; int val2; static c_e1 data1[10]={E1_RED, E1_GREEN, E1_BLUE, E1_GREEN, E1_WHITE, E1_WHITE, E1_BLACK, E1_GREEN, E1_BLUE, E1_RED}; c_e1 data2[10]; TESTING("O(log N) converions"); if ((cwg=H5Gcreate(file, "test_tr2", 0))<0) goto error; if ((m_type = H5Tcreate(H5T_ENUM, sizeof(c_e1)))<0) goto error; if (H5Tenum_insert(m_type, "RED", CPTR(val1, E1_RED ))<0) goto error; if (H5Tenum_insert(m_type, "GREEN", CPTR(val1, E1_GREEN))<0) goto error; if (H5Tenum_insert(m_type, "BLUE", CPTR(val1, E1_BLUE ))<0) goto error; if (H5Tenum_insert(m_type, "WHITE", CPTR(val1, E1_WHITE))<0) goto error; if (H5Tenum_insert(m_type, "BLACK", CPTR(val1, E1_BLACK))<0) goto error; if ((f_type = H5Tcreate(H5T_ENUM, sizeof(int)))<0) goto error; if (H5Tenum_insert(f_type, "RED", CPTR(val2, 1050))<0) goto error; if (H5Tenum_insert(f_type, "GREEN", CPTR(val2, 1040))<0) goto error; if (H5Tenum_insert(f_type, "BLUE", CPTR(val2, 1030))<0) goto error; if (H5Tenum_insert(f_type, "WHITE", CPTR(val2, 1020))<0) goto error; if (H5Tenum_insert(f_type, "BLACK", CPTR(val2, 1010))<0) goto error; if ((space=H5Screate_simple(1, ds_size, NULL))<0) goto error; if ((dset=H5Dcreate(cwg, "color_table", f_type, space, H5P_DEFAULT))<0) goto error; if (H5Dwrite(dset, m_type, space, space, H5P_DEFAULT, data1)<0) goto error; if (H5Dread(dset, m_type, space, space, H5P_DEFAULT, data2)<0) goto error; for (i=0; i<ds_size[0]; i++) { if (data1[i]!=data2[i]) { H5_FAILED(); printf(" data1[%lu]=%d, data2[%lu]=%d (should be same)\n", (unsigned long)i, (int)(data1[i]), (unsigned long)i, (int)(data2[i])); goto error; } } if (H5Dclose(dset)<0) goto error; if (H5Sclose(space)<0) goto error; if (H5Tclose(m_type)<0) goto error; if (H5Tclose(f_type)<0) goto error; if (H5Gclose(cwg)<0) goto error; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Dclose(dset); H5Sclose(space); H5Tclose(m_type); H5Tclose(f_type); H5Gclose(cwg); } H5E_END_TRY; return 1; }
/*------------------------------------------------------------------------- * Function: test_family * * Purpose: Tests the file handle interface for FAMILY driver * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * Tuesday, Sept 24, 2002 * * Modifications: * * Raymond Lu * Wednesday, June 23, 2004 * Added test for H5Fget_filesize. * * Raymond Lu * June 2, 2005 * Added a function test_family_opens() to test different * wrong way to reopen family files. * *------------------------------------------------------------------------- */ static herr_t test_family(void) { hid_t file=(-1), fapl, fapl2=(-1), space=(-1), dset=(-1); hid_t access_fapl = -1; char filename[1024]; char dname[]="dataset"; unsigned int i, j; int *fhandle=NULL, *fhandle2=NULL; int buf[FAMILY_NUMBER][FAMILY_SIZE]; hsize_t dims[2]={FAMILY_NUMBER, FAMILY_SIZE}; hsize_t file_size; TESTING("FAMILY file driver"); /* Set property list and file name for FAMILY driver */ fapl = h5_fileaccess(); if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0) TEST_ERROR; h5_fixname(FILENAME[2], fapl, filename, sizeof filename); if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Test different wrong ways to reopen family files where there's only * one member file existing. */ if(test_family_opens(filename, fapl) < 0) TEST_ERROR; /* Reopen the file with default member file size */ if(H5Pset_fapl_family(fapl, (hsize_t)H5F_FAMILY_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR; if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; /* Check file size API */ if(H5Fget_filesize(file, &file_size) < 0) TEST_ERROR; /* The file size is supposed to be about 800 bytes right now. */ if(file_size < (KB / 2) || file_size > KB) TEST_ERROR; /* Create and write dataset */ if((space=H5Screate_simple(2, dims, NULL)) < 0) TEST_ERROR; /* Retrieve the access property list... */ if ((access_fapl = H5Fget_access_plist(file)) < 0) TEST_ERROR; /* ...and close the property list */ if (H5Pclose(access_fapl) < 0) TEST_ERROR; if((dset=H5Dcreate2(file, dname, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; for(i=0; i<FAMILY_NUMBER; i++) for(j=0; j<FAMILY_SIZE; j++) buf[i][j] = i*10000+j; if(H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) TEST_ERROR; /* check file handle API */ if((fapl2=H5Pcreate(H5P_FILE_ACCESS)) < 0) TEST_ERROR; if(H5Pset_family_offset(fapl2, (hsize_t)0) < 0) TEST_ERROR; if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle) < 0) TEST_ERROR; if(*fhandle<0) TEST_ERROR; if(H5Pset_family_offset(fapl2, (hsize_t)(FAMILY_SIZE*2)) < 0) TEST_ERROR; if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle2) < 0) TEST_ERROR; if(*fhandle2<0) TEST_ERROR; /* Check file size API */ if(H5Fget_filesize(file, &file_size) < 0) TEST_ERROR; /* Some data has been written. The file size should be bigger(18KB+976 * bytes if int size is 4 bytes) now. */ if(sizeof(int)<=4) { if(file_size<18*KB || file_size>20*KB) TEST_ERROR; } else if(sizeof(int)>=8) { if(file_size<32*KB || file_size>40*KB) TEST_ERROR; } if(H5Sclose(space) < 0) TEST_ERROR; if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Pclose(fapl2) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Test different wrong ways to reopen family files when there're multiple * member files existing. */ if(test_family_opens(filename, fapl) < 0) TEST_ERROR; /* Reopen the file with correct member file size. */ if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0) TEST_ERROR; if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; h5_cleanup(FILENAME, fapl); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Sclose(space); H5Dclose(dset); H5Pclose (fapl2); H5Fclose(file); } H5E_END_TRY; return -1; }
static int read_data(char *fname) { char pathname[1024]; char *srcdir = getenv("srcdir"); /*where the src code is located*/ hid_t file, dataset; /* handles */ hid_t datatype; hid_t dt; double data_in[NX][NY]; /* input buffer */ double data_out[NX][NY]; /* output buffer */ int i, j; unsigned nerrors = 0; pathname[0] = '\0'; /* Generate correct name for test file by prepending the source path */ if(srcdir && ((strlen(srcdir) + strlen(fname) + 1) < sizeof(pathname))) { strcpy(pathname, srcdir); strcat(pathname, "/"); } strcat(pathname, fname); /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { data_in[j][i] = i + j; data_out[j][i] = 0; } } /* * 0 1 2 3 4 5 * 1 2 3 4 5 6 * 2 3 4 5 6 7 * 3 4 5 6 7 8 * 4 5 6 7 8 9 */ /* * Open the file and the dataset. */ if((file = H5Fopen(pathname, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) TEST_ERROR; if((dataset = H5Dopen2(file, DATASETNAME, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Get datatype and dataspace handles and then query * dataset class, order, size, rank and dimensions. */ if((dt = H5Dget_type(dataset)) < 0) /* datatype handle */ TEST_ERROR; if((datatype = H5Tget_native_type(dt, H5T_DIR_DEFAULT)) < 0) TEST_ERROR; /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<NX; j++) { for (i=0; i<NY; i++) { if (data_out[j][i] != data_in[j][i]) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %g but should have been %g\n", j, i, data_out[j][i], data_in[j][i]); } } } } /* * Close/release resources. */ H5Tclose(dt); H5Tclose(datatype); H5Dclose(dataset); H5Fclose(file); /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(file); } H5E_END_TRY; return 1; }
/*------------------------------------------------------------------------- * Function: test_multi * * Purpose: Tests the file handle interface for MUTLI driver * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * Tuesday, Sept 24, 2002 * * Modifications: * * Raymond Lu * Wednesday, June 23, 2004 * Added test for H5Fget_filesize. * *------------------------------------------------------------------------- */ static herr_t test_multi(void) { hid_t file=(-1), fapl, fapl2=(-1), dset=(-1), space=(-1); hid_t root, attr, aspace, atype; hid_t access_fapl = -1; char filename[1024]; int *fhandle2=NULL, *fhandle=NULL; hsize_t file_size; H5FD_mem_t mt, memb_map[H5FD_MEM_NTYPES]; hid_t memb_fapl[H5FD_MEM_NTYPES]; haddr_t memb_addr[H5FD_MEM_NTYPES]; const char *memb_name[H5FD_MEM_NTYPES]; char sv[H5FD_MEM_NTYPES][32]; hsize_t dims[2]={MULTI_SIZE, MULTI_SIZE}; hsize_t adims[1]={1}; char dname[]="dataset"; char meta[] = "this is some metadata on this file"; int i, j; int buf[MULTI_SIZE][MULTI_SIZE]; TESTING("MULTI file driver"); /* Set file access property list for MULTI driver */ fapl = h5_fileaccess(); HDmemset(memb_map, 0, sizeof memb_map); HDmemset(memb_fapl, 0, sizeof memb_fapl); HDmemset(memb_name, 0, sizeof memb_name); HDmemset(memb_addr, 0, sizeof memb_addr); HDmemset(sv, 0, sizeof sv); for(mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) { memb_fapl[mt] = H5P_DEFAULT; memb_map[mt] = H5FD_MEM_SUPER; } memb_map[H5FD_MEM_DRAW] = H5FD_MEM_DRAW; memb_map[H5FD_MEM_BTREE] = H5FD_MEM_BTREE; memb_map[H5FD_MEM_GHEAP] = H5FD_MEM_GHEAP; sprintf(sv[H5FD_MEM_SUPER], "%%s-%c.h5", 's'); memb_name[H5FD_MEM_SUPER] = sv[H5FD_MEM_SUPER]; memb_addr[H5FD_MEM_SUPER] = 0; sprintf(sv[H5FD_MEM_BTREE], "%%s-%c.h5", 'b'); memb_name[H5FD_MEM_BTREE] = sv[H5FD_MEM_BTREE]; memb_addr[H5FD_MEM_BTREE] = HADDR_MAX/4; sprintf(sv[H5FD_MEM_DRAW], "%%s-%c.h5", 'r'); memb_name[H5FD_MEM_DRAW] = sv[H5FD_MEM_DRAW]; memb_addr[H5FD_MEM_DRAW] = HADDR_MAX/2; sprintf(sv[H5FD_MEM_GHEAP], "%%s-%c.h5", 'g'); memb_name[H5FD_MEM_GHEAP] = sv[H5FD_MEM_GHEAP]; memb_addr[H5FD_MEM_GHEAP] = HADDR_MAX*3/4; if(H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, TRUE) < 0) TEST_ERROR; h5_fixname(FILENAME[4], fapl, filename, sizeof filename); if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Test wrong ways to reopen multi files */ if(test_multi_opens(filename) < 0) TEST_ERROR; /* Reopen the file */ if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; /* Create and write data set */ if((space=H5Screate_simple(2, dims, NULL)) < 0) TEST_ERROR; /* Retrieve the access property list... */ if ((access_fapl = H5Fget_access_plist(file)) < 0) TEST_ERROR; /* ...and close the property list */ if (H5Pclose(access_fapl) < 0) TEST_ERROR; /* Check file size API */ if(H5Fget_filesize(file, &file_size) < 0) TEST_ERROR; /* Before any data is written, the raw data file is empty. So * the file size is only the size of b-tree + HADDR_MAX/4. */ if(file_size < HADDR_MAX/4 || file_size > HADDR_MAX/2) TEST_ERROR; if((dset=H5Dcreate2(file, dname, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; for(i=0; i<MULTI_SIZE; i++) for(j=0; j<MULTI_SIZE; j++) buf[i][j] = i*10000+j; if(H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) TEST_ERROR; if((fapl2=H5Pcreate(H5P_FILE_ACCESS)) < 0) TEST_ERROR; if(H5Pset_multi_type(fapl2, H5FD_MEM_SUPER) < 0) TEST_ERROR; if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle) < 0) TEST_ERROR; if(*fhandle<0) TEST_ERROR; if(H5Pset_multi_type(fapl2, H5FD_MEM_DRAW) < 0) TEST_ERROR; if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle2) < 0) TEST_ERROR; if(*fhandle2<0) TEST_ERROR; /* Check file size API */ if(H5Fget_filesize(file, &file_size) < 0) TEST_ERROR; /* After the data is written, the file size is huge because the * beginning of raw data file is set at HADDR_MAX/2. It's supposed * to be (HADDR_MAX/2 + 128*128*4) */ if(file_size < HADDR_MAX/2 || file_size > HADDR_MAX) TEST_ERROR; if(H5Sclose(space) < 0) TEST_ERROR; if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Pclose(fapl2) < 0) TEST_ERROR; /* Create and write attribute for the root group. */ if((root = H5Gopen2(file, "/", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR /* Attribute string. */ if((atype = H5Tcopy(H5T_C_S1)) < 0) TEST_ERROR; if(H5Tset_size(atype, strlen(meta) + 1) < 0) TEST_ERROR; if(H5Tset_strpad(atype, H5T_STR_NULLTERM) < 0) TEST_ERROR; /* Create and write attribute */ if((aspace = H5Screate_simple(1, adims, NULL)) < 0) TEST_ERROR; if((attr = H5Acreate2(root, "Metadata", atype, aspace, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; if(H5Awrite(attr, atype, meta) < 0) TEST_ERROR; /* Close IDs */ if(H5Tclose(atype) < 0) TEST_ERROR; if(H5Sclose(aspace) < 0) TEST_ERROR; if(H5Aclose(attr) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; h5_cleanup(FILENAME, fapl); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Sclose(space); H5Dclose(dset); H5Pclose(fapl); H5Pclose(fapl2); H5Fclose(file); } H5E_END_TRY; return -1; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Part 1 of a two-part H5Fflush() test. * * Return: Success: 0 * * Failure: 1 * * Programmer: Robb Matzke * Friday, October 23, 1998 * * Modifications: * Leon Arber * Sept. 26, 2006, expand test to check for failure if H5Fflush is not called. * * *------------------------------------------------------------------------- */ int main(int argc, char* argv[]) { hid_t file1, file2, fapl; MPI_File *mpifh_p = NULL; char name[1024]; const char *envval = NULL; int mpi_size, mpi_rank; MPI_Comm comm = MPI_COMM_WORLD; MPI_Info info = MPI_INFO_NULL; MPI_Init(&argc, &argv); MPI_Comm_size(comm, &mpi_size); MPI_Comm_rank(comm, &mpi_rank); fapl = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_mpio(fapl, comm, info); if(mpi_rank == 0) TESTING("H5Fflush (part1)"); envval = HDgetenv("HDF5_DRIVER"); if(envval == NULL) envval = "nomatch"; if(HDstrcmp(envval, "split")) { /* Create the file */ h5_fixname(FILENAME[0], fapl, name, sizeof name); file1 = create_file(name, fapl); /* Flush and exit without closing the library */ if(H5Fflush(file1, H5F_SCOPE_GLOBAL) < 0) goto error; /* Create the other file which will not be flushed */ h5_fixname(FILENAME[1], fapl, name, sizeof name); file2 = create_file(name, fapl); if(mpi_rank == 0) PASSED(); fflush(stdout); fflush(stderr); } /* end if */ else { SKIPPED(); puts(" Test not compatible with current Virtual File Driver"); } /* end else */ /* * Some systems like AIX do not like files not closed when MPI_Finalize * is called. So, we need to get the MPI file handles, close them by hand. * Then the _exit is still needed to stop at_exit from happening in some systems. * Note that MPIO VFD returns the address of the file-handle in the VFD struct * because MPI_File_close wants to modify the file-handle variable. */ /* close file1 */ if(H5Fget_vfd_handle(file1, fapl, (void **)&mpifh_p) < 0) { printf("H5Fget_vfd_handle for file1 failed\n"); goto error; } /* end if */ if(MPI_File_close(mpifh_p) != MPI_SUCCESS) { printf("MPI_File_close for file1 failed\n"); goto error; } /* end if */ /* close file2 */ if(H5Fget_vfd_handle(file2, fapl, (void **)&mpifh_p) < 0) { printf("H5Fget_vfd_handle for file2 failed\n"); goto error; } /* end if */ if(MPI_File_close(mpifh_p) != MPI_SUCCESS) { printf("MPI_File_close for file2 failed\n"); goto error; } /* end if */ fflush(stdout); fflush(stderr); HD_exit(0); error: fflush(stdout); fflush(stderr); HD_exit(1); }
/*------------------------------------------------------------------------- * Function: test_skip_compress_write2 * * Purpose: Test skipping compression filter when there are three filters * for the dataset * * Return: Success: 0 * * Failure: 1 * * Programmer: Raymond Lu * 30 November 2012 * *------------------------------------------------------------------------- */ static int test_skip_compress_write2(hid_t file) { hid_t dataspace = -1, dataset = -1; hid_t mem_space = -1; hid_t cparms = -1, dxpl = -1; hsize_t dims[2] = {NX, NY}; hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; hsize_t chunk_dims[2] ={CHUNK_NX, CHUNK_NY}; herr_t status; int i, j, n; unsigned filter_mask = 0; int origin_direct_buf[CHUNK_NX][CHUNK_NY]; int direct_buf[CHUNK_NX][CHUNK_NY]; int check_chunk[CHUNK_NX][CHUNK_NY]; hsize_t offset[2] = {0, 0}; size_t buf_size = CHUNK_NX*CHUNK_NY*sizeof(int); int aggression = 9; /* Compression aggression setting */ hsize_t start[2]; /* Start of hyperslab */ hsize_t stride[2]; /* Stride of hyperslab */ hsize_t count[2]; /* Block count */ hsize_t block[2]; /* Block sizes */ TESTING("skipping compression filters but keep two other filters"); /* * Create the data space with unlimited dimensions. */ if((dataspace = H5Screate_simple(RANK, dims, maxdims)) < 0) goto error; if((mem_space = H5Screate_simple(RANK, chunk_dims, NULL)) < 0) goto error; /* * Modify dataset creation properties, i.e. enable chunking and compression. * The order of filters is bogus 1 + deflate + bogus 2. */ if((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error; if((status = H5Pset_chunk( cparms, RANK, chunk_dims)) < 0) goto error; /* Register and enable first bogus filter */ if(H5Zregister (H5Z_BOGUS1) < 0) goto error; if(H5Pset_filter(cparms, H5Z_FILTER_BOGUS1, 0, (size_t)0, NULL) < 0) goto error; /* Enable compression filter */ if((status = H5Pset_deflate( cparms, (unsigned) aggression)) < 0) goto error; /* Register and enable second bogus filter */ if(H5Zregister (H5Z_BOGUS2) < 0) goto error; if(H5Pset_filter(cparms, H5Z_FILTER_BOGUS2, 0, (size_t)0, NULL) < 0) goto error; /* * Create a new dataset within the file using cparms * creation properties. */ if((dataset = H5Dcreate2(file, DATASETNAME3, H5T_NATIVE_INT, dataspace, H5P_DEFAULT, cparms, H5P_DEFAULT)) < 0) goto error; if((dxpl = H5Pcreate(H5P_DATASET_XFER)) < 0) goto error; /* Initialize data for one chunk. Apply operations of two bogus filters to the chunk */ for(i = n = 0; i < CHUNK_NX; i++) for(j = 0; j < CHUNK_NY; j++) { origin_direct_buf[i][j] = n++; direct_buf[i][j] = (origin_direct_buf[i][j] + ADD_ON) * FACTOR; } /* write the uncompressed chunk data repeatedly to dataset, using the direct writing function. * Indicate skipping the compression filter but keep the other two bogus filters */ offset[0] = CHUNK_NX; offset[1] = CHUNK_NY; /* compression filter is the middle one to be skipped */ filter_mask = 0x00000002; if((status = H5DOwrite_chunk(dataset, dxpl, filter_mask, offset, buf_size, direct_buf)) < 0) goto error; if(H5Fflush(dataset, H5F_SCOPE_LOCAL) < 0) goto error; if(H5Dclose(dataset) < 0) goto error; if((dataset = H5Dopen2(file, DATASETNAME3, H5P_DEFAULT)) < 0) goto error; /* * Select hyperslab for one chunk in the file */ start[0] = CHUNK_NX; start[1] = CHUNK_NY; stride[0] = 1; stride[1] = 1; count[0] = 1; count[1] = 1; block[0] = CHUNK_NX; block[1] = CHUNK_NY; if((status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, start, stride, count, block)) < 0) goto error; /* Read the chunk back */ if((status = H5Dread(dataset, H5T_NATIVE_INT, mem_space, dataspace, H5P_DEFAULT, check_chunk)) < 0) goto error; /* Check that the values read are the same as the values written */ for(i = 0; i < CHUNK_NX; i++) { for(j = 0; j < CHUNK_NY; j++) { if(origin_direct_buf[i][j] != check_chunk[i][j]) { printf(" 1. Read different values than written."); printf(" At index %d,%d\n", i, j); printf(" origin_direct_buf=%d, check_chunk=%d\n", origin_direct_buf[i][j], check_chunk[i][j]); goto error; } } } /* * Close/release resources. */ H5Dclose(dataset); H5Sclose(mem_space); H5Sclose(dataspace); H5Pclose(cparms); H5Pclose(dxpl); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Dclose(dataset); H5Sclose(mem_space); H5Sclose(dataspace); H5Pclose(cparms); H5Pclose(dxpl); } H5E_END_TRY; return 1; }
/*------------------------------------------------------------------------- * Function: new_links * * Purpose: Build a file with assorted links for different locations. * * Return: Success: 0 * * Failure: -1 * * Programmer: Raymond Lu * Friday, April 19, 2002 * * Modifications: * *------------------------------------------------------------------------- */ static int new_links(hid_t fapl) { hid_t file_a, file_b=(-1); hid_t grp1_a=(-1), grp1_b=(-1), grp2_a=(-1), grp2_b=(-1); hid_t scalar=(-1); hid_t dset1=(-1), dset2=(-1); char filename[NAME_BUF_SIZE]; hsize_t size[1] = {1}; TESTING("H5Glink2 function"); /* Create two files */ h5_fixname(FILENAME[1], fapl, filename, sizeof filename); if ((file_a=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) { goto error; } h5_fixname(FILENAME[2], fapl, filename, sizeof filename); if ((file_b=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) { goto error; } if ((scalar=H5Screate_simple (1, size, size))<0) goto error; /* Create two groups in each file */ if ((grp1_a=H5Gcreate (file_a, "grp1", (size_t)0))<0) goto error; if ((grp2_a=H5Gcreate (file_a, "grp2", (size_t)0))<0) goto error; if ((grp1_b=H5Gcreate (file_b, "grp1", (size_t)0))<0) goto error; if ((grp2_b=H5Gcreate (file_b, "grp2", (size_t)0))<0) goto error; /* Create datasets */ if((dset1=H5Dcreate(file_a, "dataset1", H5T_NATIVE_INT, scalar, H5P_DEFAULT))<0) { goto error; } if((dset2=H5Dcreate(grp1_a, "dataset2", H5T_NATIVE_INT, scalar, H5P_DEFAULT))<0) { goto error; } /* Create links within a file. Both of source and destination use * H5G_SAME_LOC. Both hard and soft links should fail. */ H5E_BEGIN_TRY { if(H5Glink2(H5G_SAME_LOC, "dataset1", H5G_LINK_HARD , H5G_SAME_LOC, "hard")!=FAIL) goto error; } H5E_END_TRY; H5E_BEGIN_TRY { if(H5Glink2(H5G_SAME_LOC, "dataset1", H5G_LINK_SOFT , H5G_SAME_LOC, "soft")!=FAIL) goto error; } H5E_END_TRY; /* Create links across files. Both hard and soft links should fail. */ H5E_BEGIN_TRY { if(H5Glink2(file_a, "dataset1", H5G_LINK_HARD , file_b, "hard")!=FAIL) goto error; } H5E_END_TRY; H5E_BEGIN_TRY { if(H5Glink2(file_a, "dataset1", H5G_LINK_SOFT, file_b, "soft")!=FAIL) goto error; } H5E_END_TRY; /* Create links to test H5G_SAME_LOC, H5G_LINK_HARD, H5G_LINK_SOFT. */ if(H5Glink2(grp1_a, "dataset2", H5G_LINK_HARD , H5G_SAME_LOC, "hard1")<0) { goto error; } if(H5Glink2(H5G_SAME_LOC, "dataset2", H5G_LINK_SOFT , grp1_a, "soft1")<0) { goto error; } /* Create links to test H5G_LINK_HARD, H5G_LINK_SOFT across different * locations. */ if(H5Glink2(grp1_a, "dataset2", H5G_LINK_HARD, grp2_a, "hard2")<0) { goto error; } if(H5Glink2(grp1_a, "/grp1/dataset2", H5G_LINK_SOFT , grp2_a, "soft2")<0) { goto error; } /* Close dataspace and files */ if (H5Sclose (scalar)<0) goto error; if (H5Dclose(dset1)<0) goto error; if (H5Dclose(dset2)<0) goto error; if (H5Gclose (grp1_a)<0) goto error; if (H5Gclose (grp2_a)<0) goto error; if (H5Gclose (grp1_b)<0) goto error; if (H5Gclose (grp2_b)<0) goto error; if (H5Fclose (file_a)<0) goto error; if (H5Fclose (file_b)<0) goto error; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Sclose (scalar); H5Dclose (dset1); H5Dclose (dset2); H5Gclose (grp1_a); H5Gclose (grp2_a); H5Gclose (grp1_b); H5Gclose (grp2_b); H5Fclose (file_a); H5Fclose (file_b); } H5E_END_TRY; return -1; }
static int test_direct_chunk_write (hid_t file) { hid_t dataspace = -1, dataset = -1; hid_t mem_space = -1; hid_t cparms = -1, dxpl = -1; hsize_t dims[2] = {NX, NY}; hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; hsize_t chunk_dims[2] ={CHUNK_NX, CHUNK_NY}; herr_t status; int ret; int data[NX][NY]; int i, j, n; unsigned filter_mask = 0; int direct_buf[CHUNK_NX][CHUNK_NY]; int check_chunk[CHUNK_NX][CHUNK_NY]; hsize_t offset[2] = {0, 0}; size_t buf_size = CHUNK_NX*CHUNK_NY*sizeof(int); const Bytef *z_src = (const Bytef*)(direct_buf); Bytef *z_dst; /*destination buffer */ uLongf z_dst_nbytes = (uLongf)DEFLATE_SIZE_ADJUST(buf_size); uLong z_src_nbytes = (uLong)buf_size; int aggression = 9; /* Compression aggression setting */ void *outbuf = NULL; /* Pointer to new buffer */ hsize_t start[2]; /* Start of hyperslab */ hsize_t stride[2]; /* Stride of hyperslab */ hsize_t count[2]; /* Block count */ hsize_t block[2]; /* Block sizes */ TESTING("basic functionality of H5DOwrite_chunk"); /* * Create the data space with unlimited dimensions. */ if((dataspace = H5Screate_simple(RANK, dims, maxdims)) < 0) goto error; if((mem_space = H5Screate_simple(RANK, chunk_dims, NULL)) < 0) goto error; /* * Modify dataset creation properties, i.e. enable chunking and compression */ if((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error; if((status = H5Pset_chunk( cparms, RANK, chunk_dims)) < 0) goto error; if((status = H5Pset_deflate( cparms, (unsigned) aggression)) < 0) goto error; /* * Create a new dataset within the file using cparms * creation properties. */ if((dataset = H5Dcreate2(file, DATASETNAME1, H5T_NATIVE_INT, dataspace, H5P_DEFAULT, cparms, H5P_DEFAULT)) < 0) goto error; /* Initialize the dataset */ for(i = n = 0; i < NX; i++) for(j = 0; j < NY; j++) data[i][j] = n++; if((dxpl = H5Pcreate(H5P_DATASET_XFER)) < 0) goto error; /* * Write the data for the dataset. It should stay in the chunk cache. * It will be evicted from the cache by the H5DOwrite_chunk calls. */ if((status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, data)) < 0) goto error; /* Initialize data for one chunk */ for(i = n = 0; i < CHUNK_NX; i++) for(j = 0; j < CHUNK_NY; j++) direct_buf[i][j] = n++; /* Allocate output (compressed) buffer */ outbuf = HDmalloc(z_dst_nbytes); z_dst = (Bytef *)outbuf; /* Perform compression from the source to the destination buffer */ ret = compress2(z_dst, &z_dst_nbytes, z_src, z_src_nbytes, aggression); /* Check for various zlib errors */ if(Z_BUF_ERROR == ret) { fprintf(stderr, "overflow"); goto error; } else if(Z_MEM_ERROR == ret) { fprintf(stderr, "deflate memory error"); goto error; } else if(Z_OK != ret) { fprintf(stderr, "other deflate error"); goto error; } /* Write the compressed chunk data repeatedly to cover all the chunks in the * dataset, using the direct writing function. */ for(i=0; i<NX/CHUNK_NX; i++) { for(j=0; j<NY/CHUNK_NY; j++) { status = H5DOwrite_chunk(dataset, dxpl, filter_mask, offset, z_dst_nbytes, outbuf); offset[1] += CHUNK_NY; } offset[0] += CHUNK_NX; offset[1] = 0; } if(outbuf) HDfree(outbuf); if(H5Fflush(dataset, H5F_SCOPE_LOCAL) < 0) goto error; if(H5Dclose(dataset) < 0) goto error; if((dataset = H5Dopen2(file, DATASETNAME1, H5P_DEFAULT)) < 0) goto error; /* * Select hyperslab for one chunk in the file */ start[0] = CHUNK_NX; start[1] = CHUNK_NY; stride[0] = 1; stride[1] = 1; count[0] = 1; count[1] = 1; block[0] = CHUNK_NX; block[1] = CHUNK_NY; if((status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, start, stride, count, block)) < 0) goto error; /* Read the chunk back */ if((status = H5Dread(dataset, H5T_NATIVE_INT, mem_space, dataspace, H5P_DEFAULT, check_chunk)) < 0) goto error; /* Check that the values read are the same as the values written */ for(i = 0; i < CHUNK_NX; i++) { for(j = 0; j < CHUNK_NY; j++) { if(direct_buf[i][j] != check_chunk[i][j]) { printf(" 1. Read different values than written."); printf(" At index %d,%d\n", i, j); printf(" direct_buf=%d, check_chunk=%d\n", direct_buf[i][j], check_chunk[i][j]); goto error; } } } /* Reinitialize different data for one chunk */ for(i = 0; i < CHUNK_NX; i++) for(j = 0; j < CHUNK_NY; j++) direct_buf[i][j] = i + j; /* Allocate output (compressed) buffer */ outbuf = HDmalloc(z_dst_nbytes); z_dst = (Bytef *)outbuf; /* Perform compression from the source to the destination buffer */ ret = compress2(z_dst, &z_dst_nbytes, z_src, z_src_nbytes, aggression); /* Check for various zlib errors */ if(Z_BUF_ERROR == ret) { fprintf(stderr, "overflow"); goto error; } else if(Z_MEM_ERROR == ret) { fprintf(stderr, "deflate memory error"); goto error; } else if(Z_OK != ret) { fprintf(stderr, "other deflate error"); goto error; } /* Rewrite the compressed chunk data repeatedly to cover all the chunks in the * dataset, using the direct writing function. */ offset[0] = offset[1] = 0; for(i=0; i<NX/CHUNK_NX; i++) { for(j=0; j<NY/CHUNK_NY; j++) { status = H5DOwrite_chunk(dataset, dxpl, filter_mask, offset, z_dst_nbytes, outbuf); offset[1] += CHUNK_NY; } offset[0] += CHUNK_NX; offset[1] = 0; } if(outbuf) HDfree(outbuf); if(H5Fflush(dataset, H5F_SCOPE_LOCAL) < 0) goto error; if(H5Dclose(dataset) < 0) goto error; if((dataset = H5Dopen2(file, DATASETNAME1, H5P_DEFAULT)) < 0) goto error; /* Read the chunk back */ if((status = H5Dread(dataset, H5T_NATIVE_INT, mem_space, dataspace, H5P_DEFAULT, check_chunk)) < 0) goto error; /* Check that the values read are the same as the values written */ for(i = 0; i < CHUNK_NX; i++) { for(j = 0; j < CHUNK_NY; j++) { if(direct_buf[i][j] != check_chunk[i][j]) { printf(" 2. Read different values than written."); printf(" At index %d,%d\n", i, j); printf(" direct_buf=%d, check_chunk=%d\n", direct_buf[i][j], check_chunk[i][j]); goto error; } } } /* * Close/release resources. */ H5Dclose(dataset); H5Sclose(mem_space); H5Sclose(dataspace); H5Pclose(cparms); H5Pclose(dxpl); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Dclose(dataset); H5Sclose(mem_space); H5Sclose(dataspace); H5Pclose(cparms); H5Pclose(dxpl); } H5E_END_TRY; if(outbuf) HDfree(outbuf); return 1; }
/*------------------------------------------------------------------------- * Function: cklinks * * Purpose: Open the file created in the first step and check that the * links look correct. * * Return: Success: 0 * * Failure: -1 * * Programmer: Robb Matzke * Friday, August 14, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int cklinks(hid_t fapl) { hid_t file; H5G_stat_t sb1, sb2; char linkval[LINK_BUF_SIZE]; char filename[NAME_BUF_SIZE]; herr_t status; TESTING("link queries"); /* Open the file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if ((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0) { goto error; } /* Hard link */ if (H5Gget_objinfo(file, "d1", TRUE, &sb1)<0) goto error; if (H5Gget_objinfo(file, "grp1/hard", TRUE, &sb2)<0) goto error; if (H5G_DATASET!=sb2.type) { H5_FAILED(); puts(" Unexpected object type should have been a dataset"); goto error; } if (sb1.objno[0]!=sb2.objno[0] || sb1.objno[1]!=sb2.objno[1]) { H5_FAILED(); puts(" Hard link test failed. Link seems not to point to the "); puts(" expected file location."); goto error; } /* Symbolic link */ if (H5Gget_objinfo(file, "grp1/soft", TRUE, &sb2)<0) goto error; if (H5G_DATASET!=sb2.type) { H5_FAILED(); puts(" Unexpected object type should have been a dataset"); goto error; } if (sb1.objno[0]!=sb2.objno[0] || sb1.objno[1]!=sb2.objno[1]) { H5_FAILED(); puts(" Soft link test failed. Link seems not to point to the "); puts(" expected file location."); goto error; } if (H5Gget_linkval(file, "grp1/soft", sizeof linkval, linkval)<0) { goto error; } if (HDstrcmp(linkval, "/d1")) { H5_FAILED(); puts(" Soft link test failed. Wrong link value"); goto error; } /* Dangling link */ H5E_BEGIN_TRY { status = H5Gget_objinfo(file, "grp1/dangle", TRUE, &sb2); } H5E_END_TRY; if (status>=0) { H5_FAILED(); puts(" H5Gget_objinfo() should have failed for a dangling link."); goto error; } if (H5Gget_objinfo(file, "grp1/dangle", FALSE, &sb2)<0) goto error; if (H5G_LINK!=sb2.type) { H5_FAILED(); puts(" Unexpected object type should have been a symbolic link"); goto error; } if (H5Gget_linkval(file, "grp1/dangle", sizeof linkval, linkval)<0) { goto error; } if (HDstrcmp(linkval, "foobar")) { H5_FAILED(); puts(" Dangling link test failed. Wrong link value"); goto error; } /* Recursive link */ H5E_BEGIN_TRY { status = H5Gget_objinfo(file, "grp1/recursive", TRUE, &sb2); } H5E_END_TRY; if (status>=0) { H5_FAILED(); puts(" H5Gget_objinfo() should have failed for a recursive link."); goto error; } if (H5Gget_objinfo(file, "grp1/recursive", FALSE, &sb2)<0) goto error; if (H5G_LINK!=sb2.type) { H5_FAILED(); puts(" Unexpected object type should have been a symbolic link"); goto error; } if (H5Gget_linkval(file, "grp1/recursive", sizeof linkval, linkval)<0) { goto error; } if (HDstrcmp(linkval, "/grp1/recursive")) { H5_FAILED(); puts(" Recursive link test failed. Wrong link value"); goto error; } /* Cleanup */ if (H5Fclose(file)<0) goto error; PASSED(); return 0; error: return -1; }
/* * Verify that object headers are held in the cache until they are linked * to a location in the graph, or assigned an ID. This is done by * creating an object header, then forcing it out of the cache by creating * local heaps until the object header is evicted from the cache, then * modifying the object header. The refcount on the object header is * checked as verifying that the object header has remained in the cache. */ static herr_t test_ohdr_cache(char *filename, hid_t fapl) { hid_t file = -1; /* File ID */ hid_t my_fapl; /* FAPL ID */ hid_t my_dxpl; /* DXPL ID */ H5AC_cache_config_t mdc_config; /* Metadata cache configuration info */ H5F_t *f = NULL; /* File handle */ H5HL_t *lheap, *lheap2, *lheap3; /* Pointer to local heaps */ haddr_t lheap_addr, lheap_addr2, lheap_addr3; /* Local heap addresses */ H5O_loc_t oh_loc; /* Object header location */ time_t time_new; /* Time value for modification time message */ unsigned rc; /* Refcount for object */ TESTING("object header creation in cache"); /* Make a copy of the FAPL */ if((my_fapl = H5Pcopy(fapl)) < 0) FAIL_STACK_ERROR /* Tweak down the size of the metadata cache to only 64K */ mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION; if(H5Pget_mdc_config(my_fapl, &mdc_config) < 0) FAIL_STACK_ERROR mdc_config.set_initial_size = TRUE; mdc_config.initial_size = 32 * 1024; mdc_config.max_size = 64 * 1024; mdc_config.min_size = 8 * 1024; if(H5Pset_mdc_config(my_fapl, &mdc_config) < 0) FAIL_STACK_ERROR /* Make a copy of the default DXPL */ if((my_dxpl = H5Pcopy(H5P_DATASET_XFER_DEFAULT)) < 0) FAIL_STACK_ERROR /* Create the file to operate on */ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) FAIL_STACK_ERROR if(H5Pclose(my_fapl) < 0) FAIL_STACK_ERROR if(NULL == (f = (H5F_t *)H5I_object(file))) FAIL_STACK_ERROR if(H5AC_ignore_tags(f) < 0) FAIL_STACK_ERROR /* Create object (local heap) that occupies most of cache */ if(H5HL_create(f, my_dxpl, (31 * 1024), &lheap_addr) < 0) FAIL_STACK_ERROR /* Protect local heap (which actually pins it in the cache) */ if(NULL == (lheap = H5HL_protect(f, my_dxpl, lheap_addr, H5AC__READ_ONLY_FLAG))) FAIL_STACK_ERROR /* Create an object header */ HDmemset(&oh_loc, 0, sizeof(oh_loc)); if(H5O_create(f, my_dxpl, (size_t)2048, (size_t)1, H5P_GROUP_CREATE_DEFAULT, &oh_loc/*out*/) < 0) FAIL_STACK_ERROR /* Query object header information */ rc = 0; if(H5O_get_rc(&oh_loc, my_dxpl, &rc) < 0) FAIL_STACK_ERROR if(0 != rc) TEST_ERROR /* Create object (local heap) that occupies most of cache */ if(H5HL_create(f, my_dxpl, (31 * 1024), &lheap_addr2) < 0) FAIL_STACK_ERROR /* Protect local heap (which actually pins it in the cache) */ if(NULL == (lheap2 = H5HL_protect(f, my_dxpl, lheap_addr2, H5AC__READ_ONLY_FLAG))) FAIL_STACK_ERROR /* Unprotect local heap (which actually unpins it from the cache) */ if(H5HL_unprotect(lheap2) < 0) FAIL_STACK_ERROR /* Create object header message in new object header */ time_new = 11111111; if(H5O_msg_create(&oh_loc, H5O_MTIME_NEW_ID, 0, 0, &time_new, my_dxpl) < 0) FAIL_STACK_ERROR /* Create object (local heap) that occupies most of cache */ if(H5HL_create(f, my_dxpl, (31 * 1024), &lheap_addr3) < 0) FAIL_STACK_ERROR /* Protect local heap (which actually pins it in the cache) */ if(NULL == (lheap3 = H5HL_protect(f, my_dxpl, lheap_addr3, H5AC__READ_ONLY_FLAG))) FAIL_STACK_ERROR /* Unprotect local heap (which actually unpins it from the cache) */ if(H5HL_unprotect(lheap3) < 0) FAIL_STACK_ERROR /* Query object header information */ /* (Note that this is somewhat of a weak test, since it doesn't actually * verify that the object header was evicted from the cache, but it's * very difficult to verify when an entry is evicted from the cache in * a non-invasive way -QAK) */ rc = 0; if(H5O_get_rc(&oh_loc, my_dxpl, &rc) < 0) FAIL_STACK_ERROR if(0 != rc) TEST_ERROR /* Decrement reference count o object header */ if(H5O_dec_rc_by_loc(&oh_loc, my_dxpl) < 0) FAIL_STACK_ERROR /* Close object header created */ if(H5O_close(&oh_loc) < 0) FAIL_STACK_ERROR /* Unprotect local heap (which actually unpins it from the cache) */ if(H5HL_unprotect(lheap) < 0) FAIL_STACK_ERROR if(H5Pclose(my_dxpl) < 0) FAIL_STACK_ERROR if(H5Fclose(file) < 0) FAIL_STACK_ERROR PASSED(); return 0; error: H5E_BEGIN_TRY { H5Fclose(file); } H5E_END_TRY; return -1; } /* test_ohdr_cache() */
/*------------------------------------------------------------------------- * Function: ck_new_links * * Purpose: Open the file created in the first step and check that the * links look correct. * * Return: Success: 0 * * Failure: -1 * * Programmer: Raymond Lu * Thursday, April 25, 2002 * * Modifications: * *------------------------------------------------------------------------- */ static int ck_new_links(hid_t fapl) { hid_t file; H5G_stat_t sb_dset, sb_hard1, sb_hard2, sb_soft1, sb_soft2; char filename[NAME_BUF_SIZE]; char linkval[LINK_BUF_SIZE]; TESTING("new link queries"); /* Open the file */ h5_fixname(FILENAME[1], fapl, filename, sizeof filename); if ((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0) { goto error; } /* Get hard link info */ if(H5Gget_objinfo(file, "/grp1/dataset2", TRUE, &sb_dset)<0) goto error; if(H5Gget_objinfo(file, "/grp1/hard1", TRUE, &sb_hard1)<0) goto error; if(H5Gget_objinfo(file, "/grp2/hard2", TRUE, &sb_hard2)<0) goto error; /* Check hard links */ if(H5G_DATASET!=sb_hard1.type || H5G_DATASET!=sb_hard2.type) { H5_FAILED(); puts(" Unexpected object type, should have been a dataset"); goto error; } if( sb_dset.objno[0]!=sb_hard1.objno[0] || sb_dset.objno[1]!=sb_hard1.objno[1] || sb_dset.objno[0]!=sb_hard2.objno[0] || sb_dset.objno[1]!=sb_hard2.objno[1] ) { H5_FAILED(); puts(" Hard link test failed. Link seems not to point to the "); puts(" expected file location."); goto error; } /* Get soft link info */ if(H5Gget_objinfo(file, "/grp1/soft1", TRUE, &sb_soft1)<0) goto error; if(H5Gget_objinfo(file, "/grp2/soft2", TRUE, &sb_soft2)<0) goto error; /* Check soft links */ if(H5G_DATASET!=sb_soft1.type || H5G_DATASET!=sb_soft2.type) { H5_FAILED(); puts(" Unexpected object type, should have been a dataset"); goto error; } if( sb_dset.objno[0]!=sb_soft1.objno[0] || sb_dset.objno[1]!=sb_soft1.objno[1] || sb_dset.objno[0]!=sb_soft2.objno[0] || sb_dset.objno[1]!=sb_soft2.objno[1] ) { H5_FAILED(); puts(" Soft link test failed. Link seems not to point to the "); puts(" expected file location."); goto error; } if (H5Gget_linkval(file, "grp2/soft2", sizeof linkval, linkval)<0) { goto error; } if (HDstrcmp(linkval, "/grp1/dataset2")) { H5_FAILED(); puts(" Soft link test failed. Wrong link value"); goto error; } /* Cleanup */ if(H5Fclose(file)<0) goto error; PASSED(); return 0; error: return -1; }
/* * Verify that messages are moved forward into a "continuation message": * Create an object header with several continuation chunks * Remove a message in the last chunk * The remaining message(s) in the last chunk should be moved forward into the continuation message * The process will repeat when the continuation message is big enough to hold all the * messages in the last chunk. * Result: the number of chunks should be reduced */ static herr_t test_cont(char *filename, hid_t fapl) { hid_t file=-1; H5F_t *f = NULL; H5O_hdr_info_t hdr_info; H5O_loc_t oh_locA, oh_locB; time_t time_new; const char *short_name = "T"; const char *long_name = "This is the message"; size_t nchunks; TESTING("object header continuation block"); HDmemset(&oh_locA, 0, sizeof(oh_locA)); HDmemset(&oh_locB, 0, sizeof(oh_locB)); /* Create the file to operate on */ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR if(NULL == (f = (H5F_t *)H5I_object(file))) FAIL_STACK_ERROR if (H5AC_ignore_tags(f) < 0) { H5_FAILED(); H5Eprint2(H5E_DEFAULT, stdout); goto error; } if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)H5O_MIN_SIZE, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_locA/*out*/) < 0) FAIL_STACK_ERROR if(H5O_create(f, H5P_DATASET_XFER_DEFAULT, (size_t)H5O_MIN_SIZE, (size_t)0, H5P_GROUP_CREATE_DEFAULT, &oh_locB/*out*/) < 0) FAIL_STACK_ERROR time_new = 11111111; if(H5O_msg_create(&oh_locA, H5O_NAME_ID, 0, 0, &long_name, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_create(&oh_locB, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_create(&oh_locB, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_create(&oh_locB, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_create(&oh_locA, H5O_MTIME_NEW_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_create(&oh_locB, H5O_MTIME_ID, 0, 0, &time_new, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_msg_create(&oh_locA, H5O_NAME_ID, 0, 0, &short_name, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(1 != H5O_link(&oh_locA, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(1 != H5O_link(&oh_locB, 1, H5P_DATASET_XFER_DEFAULT)) FAIL_STACK_ERROR if(H5AC_flush(f, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_expunge_chunks_test(&oh_locA, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_get_hdr_info(&oh_locA, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR nchunks = hdr_info.nchunks; /* remove the 1st H5O_NAME_ID message */ if(H5O_msg_remove(&oh_locA, H5O_NAME_ID, 0, FALSE, H5P_DATASET_XFER_DEFAULT) < 0) FAIL_STACK_ERROR if(H5O_get_hdr_info(&oh_locA, H5P_DATASET_XFER_DEFAULT, &hdr_info) < 0) FAIL_STACK_ERROR if(hdr_info.nchunks >= nchunks) TEST_ERROR if(H5O_close(&oh_locA) < 0) FAIL_STACK_ERROR if(H5O_close(&oh_locB) < 0) FAIL_STACK_ERROR if(H5Fclose(file) < 0) FAIL_STACK_ERROR PASSED(); return 0; error: H5E_BEGIN_TRY { H5O_close(&oh_locA); H5O_close(&oh_locB); H5Fclose(file); } H5E_END_TRY; return -1; } /* test_cont() */
/*------------------------------------------------------------------------- * Function: toomany * * Purpose: Build a file with too many symbolic links * * Return: Success: 0 * * Failure: -1 * * Programmer: Quincey Koziol * Tuesday, August 9, 2005 * * Modifications: * *------------------------------------------------------------------------- */ static int toomany(hid_t fapl) { hid_t fid = (-1); /* File ID */ hid_t gid = (-1); /* Group ID */ hid_t gid2 = (-1); /* Datatype ID */ char objname[NAME_BUF_SIZE]; /* Object name */ ssize_t name_len; /* Length of object name */ char filename[NAME_BUF_SIZE]; TESTING("too many links"); /* Make certain test is valid */ /* XXX: should probably make a "generic" test that creates the proper * # of links based on this value - QAK */ HDassert(H5G_NLINKS == 16); /* Create files */ h5_fixname(FILENAME[1], fapl, filename, sizeof filename); if((fid=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR; /* Create group with short name in file (used as target for hard links) */ if((gid=H5Gcreate (fid, "final", (size_t)0))<0) TEST_ERROR; /* Create chain of hard links to existing object (no limit on #) */ if(H5Glink2(fid, "final", H5G_LINK_HARD, fid, "hard1") < 0) TEST_ERROR; if(H5Glink2(fid, "hard1", H5G_LINK_HARD, fid, "hard2") < 0) TEST_ERROR; if(H5Glink2(fid, "hard2", H5G_LINK_HARD, fid, "hard3") < 0) TEST_ERROR; if(H5Glink2(fid, "hard3", H5G_LINK_HARD, fid, "hard4") < 0) TEST_ERROR; if(H5Glink2(fid, "hard4", H5G_LINK_HARD, fid, "hard5") < 0) TEST_ERROR; if(H5Glink2(fid, "hard5", H5G_LINK_HARD, fid, "hard6") < 0) TEST_ERROR; if(H5Glink2(fid, "hard6", H5G_LINK_HARD, fid, "hard7") < 0) TEST_ERROR; if(H5Glink2(fid, "hard7", H5G_LINK_HARD, fid, "hard8") < 0) TEST_ERROR; if(H5Glink2(fid, "hard8", H5G_LINK_HARD, fid, "hard9") < 0) TEST_ERROR; if(H5Glink2(fid, "hard9", H5G_LINK_HARD, fid, "hard10") < 0) TEST_ERROR; if(H5Glink2(fid, "hard10", H5G_LINK_HARD, fid, "hard11") < 0) TEST_ERROR; if(H5Glink2(fid, "hard11", H5G_LINK_HARD, fid, "hard12") < 0) TEST_ERROR; if(H5Glink2(fid, "hard12", H5G_LINK_HARD, fid, "hard13") < 0) TEST_ERROR; if(H5Glink2(fid, "hard13", H5G_LINK_HARD, fid, "hard14") < 0) TEST_ERROR; if(H5Glink2(fid, "hard14", H5G_LINK_HARD, fid, "hard15") < 0) TEST_ERROR; if(H5Glink2(fid, "hard15", H5G_LINK_HARD, fid, "hard16") < 0) TEST_ERROR; if(H5Glink2(fid, "hard16", H5G_LINK_HARD, fid, "hard17") < 0) TEST_ERROR; if(H5Glink2(fid, "hard17", H5G_LINK_HARD, fid, "hard18") < 0) TEST_ERROR; if(H5Glink2(fid, "hard18", H5G_LINK_HARD, fid, "hard19") < 0) TEST_ERROR; if(H5Glink2(fid, "hard19", H5G_LINK_HARD, fid, "hard20") < 0) TEST_ERROR; if(H5Glink2(fid, "hard20", H5G_LINK_HARD, fid, "hard21") < 0) TEST_ERROR; /* Create chain of soft links to existing object (limited) */ if(H5Glink2(fid, "final", H5G_LINK_SOFT, fid, "soft1") < 0) TEST_ERROR; if(H5Glink2(fid, "soft1", H5G_LINK_SOFT, fid, "soft2") < 0) TEST_ERROR; if(H5Glink2(fid, "soft2", H5G_LINK_SOFT, fid, "soft3") < 0) TEST_ERROR; if(H5Glink2(fid, "soft3", H5G_LINK_SOFT, fid, "soft4") < 0) TEST_ERROR; if(H5Glink2(fid, "soft4", H5G_LINK_SOFT, fid, "soft5") < 0) TEST_ERROR; if(H5Glink2(fid, "soft5", H5G_LINK_SOFT, fid, "soft6") < 0) TEST_ERROR; if(H5Glink2(fid, "soft6", H5G_LINK_SOFT, fid, "soft7") < 0) TEST_ERROR; if(H5Glink2(fid, "soft7", H5G_LINK_SOFT, fid, "soft8") < 0) TEST_ERROR; if(H5Glink2(fid, "soft8", H5G_LINK_SOFT, fid, "soft9") < 0) TEST_ERROR; if(H5Glink2(fid, "soft9", H5G_LINK_SOFT, fid, "soft10") < 0) TEST_ERROR; if(H5Glink2(fid, "soft10", H5G_LINK_SOFT, fid, "soft11") < 0) TEST_ERROR; if(H5Glink2(fid, "soft11", H5G_LINK_SOFT, fid, "soft12") < 0) TEST_ERROR; if(H5Glink2(fid, "soft12", H5G_LINK_SOFT, fid, "soft13") < 0) TEST_ERROR; if(H5Glink2(fid, "soft13", H5G_LINK_SOFT, fid, "soft14") < 0) TEST_ERROR; if(H5Glink2(fid, "soft14", H5G_LINK_SOFT, fid, "soft15") < 0) TEST_ERROR; if(H5Glink2(fid, "soft15", H5G_LINK_SOFT, fid, "soft16") < 0) TEST_ERROR; if(H5Glink2(fid, "soft16", H5G_LINK_SOFT, fid, "soft17") < 0) TEST_ERROR; /* Close objects */ if(H5Gclose(gid)<0) TEST_ERROR; if(H5Fclose(fid)<0) TEST_ERROR; /* Open file */ if((fid=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0) TEST_ERROR; /* Open object through last hard link */ if((gid = H5Gopen(fid, "hard21")) < 0) TEST_ERROR; /* Check name */ if((name_len = H5Iget_name( gid, objname, (size_t)NAME_BUF_SIZE )) < 0) TEST_ERROR if(HDstrcmp(objname, "/hard21")) TEST_ERROR /* Create object in hard-linked group */ if((gid2 = H5Gcreate(gid, "new_hard", (size_t)0)) < 0) TEST_ERROR /* Close group in hard-linked group */ if(H5Gclose(gid2) < 0) TEST_ERROR /* Close hard-linked object */ if(H5Gclose(gid) < 0) TEST_ERROR; /* Open object through too deep soft link */ H5E_BEGIN_TRY { gid = H5Gopen(fid, "soft17"); } H5E_END_TRY; if (gid >= 0) { H5_FAILED(); puts(" Should have failed for sequence of too many nested links."); goto error; } /* Open object through lesser soft link */ if((gid = H5Gopen(fid, "soft16")) < 0) TEST_ERROR; /* Check name */ if((name_len = H5Iget_name( gid, objname, (size_t)NAME_BUF_SIZE )) < 0) TEST_ERROR if(HDstrcmp(objname, "/soft16")) TEST_ERROR /* Create object in external file */ if((gid2 = H5Gcreate(gid, "new_soft", (size_t)0)) < 0) TEST_ERROR /* Close group in external file */ if(H5Gclose(gid2) < 0) TEST_ERROR /* Close external object */ if(H5Gclose(gid) < 0) TEST_ERROR; /* Close first file */ if(H5Fclose(fid)<0) TEST_ERROR; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Gclose (gid2); H5Gclose (gid); H5Fclose (fid); } H5E_END_TRY; return -1; } /* end toomany() */