summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVailin Choi <vchoi@hdfgroup.org>2013-10-21 21:48:48 (GMT)
committerVailin Choi <vchoi@hdfgroup.org>2013-10-21 21:48:48 (GMT)
commitf09d3e86b3753ea6c6b2c855248481b0b3581ac4 (patch)
tree72581aae0e194e991e8281bf315afdf7ae401122 /test
parent2b18e934c6812fd1b487ebfebf9240b009c3e4ae (diff)
downloadhdf5-f09d3e86b3753ea6c6b2c855248481b0b3581ac4.zip
hdf5-f09d3e86b3753ea6c6b2c855248481b0b3581ac4.tar.gz
hdf5-f09d3e86b3753ea6c6b2c855248481b0b3581ac4.tar.bz2
[svn-r24337] Bring revisions #24200 - #24333 from trunk.
Diffstat (limited to 'test')
-rw-r--r--test/big.c6
-rw-r--r--test/file_image.c2
-rw-r--r--test/tfile.c97
-rw-r--r--test/ttsafe.c80
4 files changed, 143 insertions, 42 deletions
diff --git a/test/big.c b/test/big.c
index 5a70c26..7465e47 100644
--- a/test/big.c
+++ b/test/big.c
@@ -395,7 +395,8 @@ writer (char* filename, hid_t fapl, fsizes_t testsize, int wrt_n)
break;
default:
- HDassert(0 && "Invalid test size.");
+ HDfprintf(stdout, "Unexpected file size(%d)\n", testsize);
+ goto error;
break;
}
@@ -435,7 +436,8 @@ writer (char* filename, hid_t fapl, fsizes_t testsize, int wrt_n)
hs_size[0] = WRT_SIZE;
if ((mem_space = H5Screate_simple (1, hs_size, hs_size)) < 0) goto error;
for (i=0; i<wrt_n; i++) {
- hs_start[0] = randll (size2[0], i);
+ /* start position must be at least hs_size from the end */
+ hs_start[0] = randll (size2[0]-hs_size[0], i);
HDfprintf (out, "#%03d 0x%016Hx\n", i, hs_start[0]);
if (H5Sselect_hyperslab (space2, H5S_SELECT_SET, hs_start, NULL,
hs_size, NULL) < 0) goto error;
diff --git a/test/file_image.c b/test/file_image.c
index d4056a7..b1b9d47 100644
--- a/test/file_image.c
+++ b/test/file_image.c
@@ -557,7 +557,7 @@ test_core(void)
/* Append ".copy" to the filename from the source directory */
VERIFY(HDstrlen(filename) < (1023 - 5), "file name too long.");
- HDstrncpy(copied_filename, filename, 1023);
+ HDstrncpy(copied_filename, filename, (size_t)1023);
copied_filename[1023] = '\0';
HDstrcat(copied_filename, ".copy");
diff --git a/test/tfile.c b/test/tfile.c
index 07e6ab1..26a94cb 100644
--- a/test/tfile.c
+++ b/test/tfile.c
@@ -112,6 +112,11 @@
/* Declaration for test_libver_macros2() */
#define FILE6 "tfile6.h5" /* Test file */
+/* Declaration for test_get_obj_ids() */
+#define FILE7 "tfile7.h5" /* Test file */
+#define NGROUPS 2
+#define NDSETS 4
+
const char *OLD_FILENAME[] = { /* Files created under 1.6 branch and 1.8 branch */
"filespace_1_6.h5", /* 1.6 HDF5 file */
"filespace_1_8.h5" /* 1.8 HDF5 file */
@@ -952,6 +957,97 @@ create_objects(hid_t fid1, hid_t fid2, hid_t *ret_did, hid_t *ret_gid1,
/****************************************************************
**
+** test_get_obj_ids(): Test the bug and the fix for Jira 8528.
+** H5Fget_obj_ids overfilled the list of
+** object IDs by one. This is an enhancement
+** for test_obj_count_and_id().
+**
+****************************************************************/
+static void
+test_get_obj_ids(void)
+{
+ hid_t fid, gid[NGROUPS], dset[NDSETS];
+ hid_t filespace;
+ hsize_t file_dims[F2_RANK] = {F2_DIM0, F2_DIM1};
+ ssize_t oid_count, ret_count;
+ hid_t *oid_list = NULL;
+ herr_t ret;
+ int i, m, n;
+ ssize_t oid_list_size = NDSETS;
+ char gname[64], dname[64];
+
+ /* Create a new file */
+ fid = H5Fcreate(FILE7, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(fid, FAIL, "H5Fcreate");
+
+ filespace = H5Screate_simple(F2_RANK, file_dims, NULL);
+ CHECK(filespace, FAIL, "H5Screate_simple");
+
+ /* creates NGROUPS groups under the root group */
+ for(m = 0; m < NGROUPS; m++) {
+ sprintf(gname, "group%d", m);
+ gid[m] = H5Gcreate2(fid, gname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(gid[m], FAIL, "H5Gcreate2");
+ }
+
+ /* create NDSETS datasets under the root group */
+ for(n = 0; n < NDSETS; n++) {
+ sprintf(dname, "dataset%d", n);
+ dset[n] = H5Dcreate2(fid, dname, H5T_NATIVE_INT, filespace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(dset[n], FAIL, "H5Dcreate2");
+ }
+
+ /* The number of opened objects should be NGROUPS + NDSETS + 1. One is opened file. */
+ oid_count = H5Fget_obj_count(fid, H5F_OBJ_ALL);
+ CHECK(oid_count, FAIL, "H5Fget_obj_count");
+ VERIFY(oid_count, (NGROUPS + NDSETS + 1), "H5Fget_obj_count");
+
+ oid_list = (hid_t *)HDcalloc((size_t)oid_list_size, sizeof(hid_t));
+ CHECK(oid_list, NULL, "HDcalloc");
+
+ /* Call the public function H5F_get_obj_ids to use H5F_get_objects. User reported having problem here.
+ * that the returned size (ret_count) from H5Fget_obj_ids is one greater than the size passed in
+ * (oid_list_size) */
+ ret_count = H5Fget_obj_ids(fid, H5F_OBJ_ALL, (size_t)oid_list_size, oid_list);
+ CHECK(ret_count, FAIL, "H5Fget_obj_ids");
+ VERIFY(ret_count, oid_list_size, "H5Fget_obj_count");
+
+ /* Close all object IDs on the list except the file ID. The first ID is supposed to be file ID according
+ * to the library design */
+ for(i = 0; i< ret_count; i++) {
+ if(fid != oid_list[i]) {
+ ret = H5Oclose(oid_list[i]);
+ CHECK(ret, FAIL, "H5Oclose");
+ }
+ }
+
+ /* The number of opened objects should be NGROUPS + 1 + 1. The first one is opened file. The second one
+ * is the dataset ID left open from the previous around of H5Fget_obj_ids */
+ oid_count = H5Fget_obj_count(fid, H5F_OBJ_ALL);
+ CHECK(oid_count, FAIL, "H5Fget_obj_count");
+ VERIFY(oid_count, NGROUPS + 2, "H5Fget_obj_count");
+
+ /* Get the IDs of the left opend objects */
+ ret_count = H5Fget_obj_ids(fid, H5F_OBJ_ALL, (size_t)oid_list_size, oid_list);
+ CHECK(ret_count, FAIL, "H5Fget_obj_ids");
+ VERIFY(ret_count, oid_list_size, "H5Fget_obj_count");
+
+ /* Close all object IDs on the list except the file ID. The first ID is still the file ID */
+ for(i = 0; i< ret_count; i++) {
+ if(fid != oid_list[i]) {
+ ret = H5Oclose(oid_list[i]);
+ CHECK(ret, FAIL, "H5Oclose");
+ }
+ }
+
+ H5Sclose(filespace);
+ H5Fclose(fid);
+
+ HDfree(oid_list);
+}
+
+/****************************************************************
+**
** test_get_file_id(): Test H5Iget_file_id()
**
*****************************************************************/
@@ -3722,6 +3818,7 @@ test_file(void)
test_file_close(); /* Test file close behavior */
#endif /* H5_NO_SHARED_WRITING */
test_get_file_id(); /* Test H5Iget_file_id */
+ test_get_obj_ids(); /* Test H5Fget_obj_ids for Jira Issue 8528 */
test_file_perm(); /* Test file access permissions */
test_file_perm2(); /* Test file access permission again */
test_file_freespace(); /* Test file free space information */
diff --git a/test/ttsafe.c b/test/ttsafe.c
index 253470b..d0ab81a 100644
--- a/test/ttsafe.c
+++ b/test/ttsafe.c
@@ -52,69 +52,71 @@ int main(void)
#define NAME_OFFSET 6 /* offset for "name<num>" */
/* pre-condition: num must be a non-negative number */
-static int num_digits(int num)
+static unsigned
+num_digits(int num)
{
- int i;
+ unsigned u;
- if (num == 0)
- return 1;
+ if(num == 0)
+ return 1;
- for (i = 0; num > 0; i++)
- num = num / 10;
+ for(u = 0; num > 0; u++)
+ num = num / 10;
- return i;
+ return u;
}
/* Routine to generate attribute names for numeric values */
char *gen_name(int value)
{
- char *temp;
- int i, length;
+ char *temp;
+ unsigned length;
+ int i;
- length = num_digits(MAX_NUM_NAME - 1);
- temp = (char *)HDmalloc((NAME_OFFSET + length + 1) * sizeof(char));
- temp = HDstrcpy(temp, "attrib");
- temp[NAME_OFFSET + length] = '\0';
+ length = num_digits(MAX_NUM_NAME - 1);
+ temp = (char *)HDmalloc(NAME_OFFSET + length + 1);
+ temp = HDstrcpy(temp, "attrib");
+ temp[NAME_OFFSET + length] = '\0';
- for (i = length - 1; i >= 0; i--) {
- temp[NAME_OFFSET + i] = (char)((int)'0' + value % 10);
- value = value / 10;
- }
+ for (i = (int)(length - 1); i >= 0; i--) {
+ temp[NAME_OFFSET + i] = (char)((int)'0' + value % 10);
+ value = value / 10;
+ }
- return temp;
+ return temp;
}
int main(int argc, char *argv[])
{
- /* Initialize testing framework */
- TestInit(argv[0], NULL, NULL);
+ /* Initialize testing framework */
+ TestInit(argv[0], NULL, NULL);
- /* Tests are generally arranged from least to most complexity... */
- AddTest("dcreate", tts_dcreate, cleanup_dcreate, "multi-dataset creation", NULL);
- AddTest("error", tts_error, cleanup_error, "per-thread error stacks", NULL);
+ /* Tests are generally arranged from least to most complexity... */
+ AddTest("dcreate", tts_dcreate, cleanup_dcreate, "multi-dataset creation", NULL);
+ AddTest("error", tts_error, cleanup_error, "per-thread error stacks", NULL);
#ifdef H5_HAVE_PTHREAD_H
- /* Thread cancellability only supported with pthreads ... */
- AddTest("cancel", tts_cancel, cleanup_cancel, "thread cancellation safety test", NULL);
+ /* Thread cancellability only supported with pthreads ... */
+ AddTest("cancel", tts_cancel, cleanup_cancel, "thread cancellation safety test", NULL);
#endif /* H5_HAVE_PTHREAD_H */
- AddTest("acreate", tts_acreate, cleanup_acreate, "multi-attribute creation", NULL);
+ AddTest("acreate", tts_acreate, cleanup_acreate, "multi-attribute creation", NULL);
- /* Display testing information */
- TestInfo(argv[0]);
+ /* Display testing information */
+ TestInfo(argv[0]);
- /* Parse command line arguments */
- TestParseCmdLine(argc,argv);
+ /* Parse command line arguments */
+ TestParseCmdLine(argc,argv);
- /* Perform requested testing */
- PerformTests();
+ /* Perform requested testing */
+ PerformTests();
- /* Display test summary, if requested */
- if (GetTestSummary())
- TestSummary();
+ /* Display test summary, if requested */
+ if (GetTestSummary())
+ TestSummary();
- /* Clean up test files, if allowed */
- if (GetTestCleanup() && !getenv("HDF5_NOCLEANUP"))
- TestCleanup();
+ /* Clean up test files, if allowed */
+ if (GetTestCleanup() && !getenv("HDF5_NOCLEANUP"))
+ TestCleanup();
- return GetTestNumErrs();
+ return GetTestNumErrs();
} /* end main() */
#endif /*H5_HAVE_THREADSAFE*/