summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2008-08-19 16:35:16 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2008-08-19 16:35:16 (GMT)
commita59d91d19251163b0e9cfeb351f8a069d6e6fd64 (patch)
treef70ca52185d816ce92ac89414d4fa331ba600b68 /test
parent936e52b581b3f4739e12c331d93ba6259a2cb5e0 (diff)
downloadhdf5-a59d91d19251163b0e9cfeb351f8a069d6e6fd64.zip
hdf5-a59d91d19251163b0e9cfeb351f8a069d6e6fd64.tar.gz
hdf5-a59d91d19251163b0e9cfeb351f8a069d6e6fd64.tar.bz2
[svn-r15485] Purpose: Allow library to shut down properly when objects have reference count
> 1. Description: Added a new field 'app_count' to H5I_id_info_t struct, to track the reference count on an id due to the application. the old 'count' field tracks the total. Generally any id visible to the application gets placed in app_count. Added app_ref boolean parameter to H5I_inc_ref, H5I_dec_ref, H5I_register, H5I_clear_type, and a few other functions, to specify whether the operation(s) being performed on the id(s) are due to the application (TRUE) or not (FALSE). Test added for this case. Tested: kagiso, smirom, linew (h5committest)
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am6
-rw-r--r--test/Makefile.in33
-rw-r--r--test/app_ref.c197
3 files changed, 221 insertions, 15 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index a3f8660..5b7edef 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -39,7 +39,7 @@ SCRIPT_DEPEND = error_test$(EXEEXT) err_compat$(EXEEXT)
TEST_PROG=testhdf5 lheap ohdr stab gheap cache cache_api \
pool hyperslab istore bittests dt_arith \
dtypes dsets cmpd_dset extend external objcopy links unlink big mtime \
- fillval mount flush1 flush2 enum \
+ fillval mount flush1 flush2 app_ref enum \
set_extent ttsafe \
getname vfd ntypes dangle dtransform reserved cross_read \
btree2 fheap
@@ -119,8 +119,8 @@ CHECK_CLEANFILES+=cmpd_dset.h5 compact_dataset.h5 dataset.h5 dset_offset.h5 \
family_file000[0-3][0-9].h5 multi_file-[rs].h5 core_file \
new_move_[ab].h5 ntypes.h5 dangle.h5 error_test.h5 err_compat.h5 \
dtransform.h5 test_filters.h5 get_file_name.h5 tstint[1-2].h5 \
- unlink_chunked.h5 btree2.h5 \
- objcopy_src.h5 objcopy_dst.h5 objcopy_ext.dat trefer1.h5 trefer2.h5
+ unlink_chunked.h5 btree2.h5 objcopy_src.h5 objcopy_dst.h5 \
+ objcopy_ext.dat trefer1.h5 trefer2.h5 app_ref.h5
# Sources for testhdf5 executable
testhdf5_SOURCES=testhdf5.c tarray.c tattr.c tchecksum.c tconfig.c tfile.c \
diff --git a/test/Makefile.in b/test/Makefile.in
index f9e36cc..91008ad 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -76,11 +76,11 @@ am__EXEEXT_1 = testhdf5$(EXEEXT) lheap$(EXEEXT) ohdr$(EXEEXT) \
dsets$(EXEEXT) cmpd_dset$(EXEEXT) extend$(EXEEXT) \
external$(EXEEXT) objcopy$(EXEEXT) links$(EXEEXT) \
unlink$(EXEEXT) big$(EXEEXT) mtime$(EXEEXT) fillval$(EXEEXT) \
- mount$(EXEEXT) flush1$(EXEEXT) flush2$(EXEEXT) enum$(EXEEXT) \
- set_extent$(EXEEXT) ttsafe$(EXEEXT) getname$(EXEEXT) \
- vfd$(EXEEXT) ntypes$(EXEEXT) dangle$(EXEEXT) \
- dtransform$(EXEEXT) reserved$(EXEEXT) cross_read$(EXEEXT) \
- btree2$(EXEEXT) fheap$(EXEEXT)
+ mount$(EXEEXT) flush1$(EXEEXT) flush2$(EXEEXT) \
+ app_ref$(EXEEXT) enum$(EXEEXT) set_extent$(EXEEXT) \
+ ttsafe$(EXEEXT) getname$(EXEEXT) vfd$(EXEEXT) ntypes$(EXEEXT) \
+ dangle$(EXEEXT) dtransform$(EXEEXT) reserved$(EXEEXT) \
+ cross_read$(EXEEXT) btree2$(EXEEXT) fheap$(EXEEXT)
am__EXEEXT_2 = gen_bad_ohdr$(EXEEXT) gen_bogus$(EXEEXT) \
gen_cross$(EXEEXT) gen_deflate$(EXEEXT) gen_filters$(EXEEXT) \
gen_new_array$(EXEEXT) gen_new_fill$(EXEEXT) \
@@ -89,6 +89,10 @@ am__EXEEXT_2 = gen_bad_ohdr$(EXEEXT) gen_bogus$(EXEEXT) \
gen_nullspace$(EXEEXT) gen_udlinks$(EXEEXT) \
space_overflow$(EXEEXT)
PROGRAMS = $(noinst_PROGRAMS)
+app_ref_SOURCES = app_ref.c
+app_ref_OBJECTS = app_ref.$(OBJEXT)
+app_ref_LDADD = $(LDADD)
+app_ref_DEPENDENCIES = libh5test.la $(LIBHDF5)
big_SOURCES = big.c
big_OBJECTS = big.$(OBJEXT)
big_LDADD = $(LDADD)
@@ -331,8 +335,8 @@ CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
-SOURCES = $(libh5test_la_SOURCES) big.c bittests.c btree2.c cache.c \
- cache_api.c cmpd_dset.c cross_read.c dangle.c dsets.c \
+SOURCES = $(libh5test_la_SOURCES) app_ref.c big.c bittests.c btree2.c \
+ cache.c cache_api.c cmpd_dset.c cross_read.c dangle.c dsets.c \
dt_arith.c dtransform.c dtypes.c enum.c err_compat.c \
error_test.c extend.c external.c fheap.c fillval.c flush1.c \
flush2.c gen_bad_ohdr.c gen_bogus.c gen_cross.c gen_deflate.c \
@@ -343,9 +347,9 @@ SOURCES = $(libh5test_la_SOURCES) big.c bittests.c btree2.c cache.c \
ohdr.c pool.c reserved.c set_extent.c space_overflow.c stab.c \
$(testhdf5_SOURCES) testmeta.c $(ttsafe_SOURCES) unlink.c \
vfd.c
-DIST_SOURCES = $(libh5test_la_SOURCES) big.c bittests.c btree2.c \
- cache.c cache_api.c cmpd_dset.c cross_read.c dangle.c dsets.c \
- dt_arith.c dtransform.c dtypes.c enum.c err_compat.c \
+DIST_SOURCES = $(libh5test_la_SOURCES) app_ref.c big.c bittests.c \
+ btree2.c cache.c cache_api.c cmpd_dset.c cross_read.c dangle.c \
+ dsets.c dt_arith.c dtransform.c dtypes.c enum.c err_compat.c \
error_test.c extend.c external.c fheap.c fillval.c flush1.c \
flush2.c gen_bad_ohdr.c gen_bogus.c gen_cross.c gen_deflate.c \
gen_filters.c gen_new_array.c gen_new_fill.c gen_new_group.c \
@@ -628,7 +632,8 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog cmpd_dset.h5 \
core_file new_move_[ab].h5 ntypes.h5 dangle.h5 error_test.h5 \
err_compat.h5 dtransform.h5 test_filters.h5 get_file_name.h5 \
tstint[1-2].h5 unlink_chunked.h5 btree2.h5 objcopy_src.h5 \
- objcopy_dst.h5 objcopy_ext.dat trefer1.h5 trefer2.h5
+ objcopy_dst.h5 objcopy_ext.dat trefer1.h5 trefer2.h5 \
+ app_ref.h5
INCLUDES = -I$(top_srcdir)/src -I$(top_builddir)/src
# Test script for error_test and err_compat
@@ -646,7 +651,7 @@ SCRIPT_DEPEND = error_test$(EXEEXT) err_compat$(EXEEXT)
TEST_PROG = testhdf5 lheap ohdr stab gheap cache cache_api \
pool hyperslab istore bittests dt_arith \
dtypes dsets cmpd_dset extend external objcopy links unlink big mtime \
- fillval mount flush1 flush2 enum \
+ fillval mount flush1 flush2 app_ref enum \
set_extent ttsafe \
getname vfd ntypes dangle dtransform reserved cross_read \
btree2 fheap
@@ -763,6 +768,9 @@ clean-noinstPROGRAMS:
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
+app_ref$(EXEEXT): $(app_ref_OBJECTS) $(app_ref_DEPENDENCIES)
+ @rm -f app_ref$(EXEEXT)
+ $(LINK) $(app_ref_OBJECTS) $(app_ref_LDADD) $(LIBS)
big$(EXEEXT): $(big_OBJECTS) $(big_DEPENDENCIES)
@rm -f big$(EXEEXT)
$(LINK) $(big_OBJECTS) $(big_LDADD) $(LIBS)
@@ -935,6 +943,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/app_ref.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/big.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bittests.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/btree2.Po@am__quote@
diff --git a/test/app_ref.c b/test/app_ref.c
new file mode 100644
index 0000000..0cacad8
--- /dev/null
+++ b/test/app_ref.c
@@ -0,0 +1,197 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Programmer: Neil Fortner <nfortne2@hdfgroup.org>
+ * Thursday, August 14, 2008
+ *
+ * Purpose: Tests closing the library after reference counts have been
+ * manipulated.
+ */
+#include "h5test.h"
+
+#define DSET_NAME "test_dset"
+#define ATTR_NAME "test_attr"
+#define GROUP_NAME "test_grp"
+
+#define ERR_WIDTH 40 /* Width of output for the SIGABRT handler */
+#define MAX_NINC 16 /* Maximum increments of a reference count */
+
+/* Macro to increment the reference count on id a random number of times (from
+ * 1 to MAX_NINC). Assumes integers i and ninc are in scope. */
+#define RAND_INC(id) \
+ ninc = (HDrand() % MAX_NINC) + 1; \
+ \
+ for (i=0; i<ninc; i++) \
+ if (H5Iinc_ref(ids[id]) != i + 2) \
+ TEST_ERROR \
+ \
+ rc[id] = ninc + 1;
+
+typedef enum {
+ T_FILE,
+ T_PLIST,
+ T_PCLASS,
+ T_TYPE,
+ T_SPACE,
+ T_DSET,
+ T_ATTR,
+ T_GROUP,
+ T_ECLASS,
+ T_EMSG,
+ T_ESTACK,
+ T_NUMCLASSES
+} id_class_t;
+
+const char *FILENAME[] = {
+ "app_ref",
+ NULL
+};
+
+const char *IDNAME[T_NUMCLASSES] = {
+ "File",
+ "Property List",
+ "Property Class",
+ "Datatype",
+ "Dataspace",
+ "Dataset",
+ "Attribute",
+ "Group",
+ "Error Class",
+ "Error Message",
+ "Error Stack"
+};
+
+int rc[T_NUMCLASSES];
+
+/* Handler for SIGABRT - prints the reference count on each id */
+void
+Abrt_Handler (int UNUSED sig)
+{
+ int i, n;
+
+ for (i=0; i<T_NUMCLASSES; i++) {
+ fprintf (stderr, "%s ID reference count: %n", IDNAME[i], &n);
+ fprintf (stderr, "%*d\n", (n < ERR_WIDTH) ? (ERR_WIDTH - n) : 0, rc[i]);
+ }
+}
+
+/* Main test routine */
+int
+main (void)
+{
+ hid_t ids[T_NUMCLASSES];
+ hid_t fapl; /* File Access Property List */
+ int ninc;
+ int i;
+ char filename[1024];
+
+ h5_reset();
+ h5_fixname (FILENAME[0], H5P_DEFAULT, filename, sizeof filename);
+
+ HDsrand ((unsigned) HDtime (NULL));
+
+ TESTING ("library shutdown with reference count > 1");
+
+ /* Create the file */
+ if ((ids[T_FILE] = H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT,
+ H5P_DEFAULT)) < 0)
+ TEST_ERROR
+
+ RAND_INC (T_FILE)
+
+ /* Create the property list */
+ if ((ids[T_PLIST] = H5Pcreate(H5P_DATASET_CREATE)) < 0)
+ TEST_ERROR
+
+ RAND_INC (T_PLIST)
+
+ /* Create a property class */
+ if ((ids[T_PCLASS] = H5Pcreate_class (H5P_DATASET_CREATE, "foo", NULL, NULL,
+ NULL, NULL, NULL, NULL)) < 0)
+ TEST_ERROR
+
+ RAND_INC (T_PCLASS)
+
+ /* Create a datatype */
+ if ((ids[T_TYPE] = H5Tcreate (H5T_OPAQUE, (size_t) 16)) < 0)
+ TEST_ERROR
+
+ RAND_INC (T_TYPE)
+
+ /* Create a dataspace */
+ if ((ids[T_SPACE] = H5Screate (H5S_SCALAR)) < 0)
+ TEST_ERROR
+
+ RAND_INC (T_SPACE)
+
+ /* Create a dataset */
+ if ((ids[T_DSET] = H5Dcreate2 (ids[T_FILE], DSET_NAME, H5T_NATIVE_INT,
+ ids[T_SPACE], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR
+
+ RAND_INC (T_DSET)
+
+ /* Create an attribute */
+ if ((ids[T_ATTR] = H5Acreate2 (ids[T_DSET], ATTR_NAME, H5T_NATIVE_INT,
+ ids[T_SPACE], H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR
+
+ RAND_INC (T_ATTR)
+
+ /* Create a group */
+ if ((ids[T_GROUP] = H5Gcreate2 (ids[T_FILE], GROUP_NAME, H5P_DEFAULT,
+ H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ TEST_ERROR
+
+ RAND_INC (T_GROUP)
+
+ /* Create an error class */
+ if ((ids[T_ECLASS] = H5Eregister_class("foo","bar","baz")) < 0)
+ TEST_ERROR
+
+ RAND_INC (T_ECLASS)
+
+ /* Create an error message */
+ if ((ids[T_EMSG] = H5Ecreate_msg(ids[T_ECLASS],H5E_MAJOR,"mumble")) < 0)
+ TEST_ERROR
+
+ RAND_INC (T_EMSG)
+
+ /* Create an error stack */
+ if ((ids[T_ESTACK] = H5Eget_current_stack()) < 0)
+ TEST_ERROR
+
+ RAND_INC (T_ESTACK)
+
+ HDsignal (SIGABRT, &Abrt_Handler);
+
+ if (H5close() < 0)
+ TEST_ERROR
+
+ PASSED();
+
+ h5_reset();
+ fapl = H5Pcreate (H5P_FILE_ACCESS);
+ h5_cleanup (FILENAME, fapl);
+
+ return 0;
+
+error:
+
+ puts("***** APPLICATION REFERENCE COUNT TESTS FAILED *****");
+
+ return 1;
+}