summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1998-04-03 21:11:05 (GMT)
committerRobb Matzke <matzke@llnl.gov>1998-04-03 21:11:05 (GMT)
commit92571bbe1d77c74ddefeeba6ac0b2097593c058d (patch)
tree610c3a65c2d3fa5dabfda39635770029bb734646 /test
parenta780cdd178f849afbc8cbb24e416eef733cbc9f2 (diff)
downloadhdf5-92571bbe1d77c74ddefeeba6ac0b2097593c058d.zip
hdf5-92571bbe1d77c74ddefeeba6ac0b2097593c058d.tar.gz
hdf5-92571bbe1d77c74ddefeeba6ac0b2097593c058d.tar.bz2
[svn-r336] Changes since 19980402
---------------------- ./MANIFEST ./test/Makefile.in ./test/shtype.c [NEW] Added some tests for shared data types. ./configure.in Removed MF and HL from the default debug list since. MF because it hasn't been implemented yet and HL because it produces lots of annoying messages about adjusting the size of local heaps. ./src/H5F.c ./src/H5T.c ./src/H5Tprivate.h Fixed a bug with opening the same file twice. The first close on the file_id incorrectly closed shared data structs. Closing a file now correctly unshares data types that might be pointing into that file. ./src/H5T.c ./src/H5Tpublic.h Added an H5Tis_shared(). The caller supplies a file and a data type and the function returns true if the data type is currently marked for sharing in that file. ./src/H5AC.c ./src/H5F.c ./src/H5HL.c ./src/H5HG.c ./src/H5MF.c ./src/H5O.c We now detect errors sooner when writing to a read-only file. In the past, the error might not show up until the cached item was flushed, and it was sometimes possible to not even get an error! ./src/H5I.c ./src/H5Iprivate.h If the search function fails then H5I_search() returns failure. Also, the first argument for the search function isn't const anymore because we might want the search to have side effects (like calling H5T_unshare() for all shared data types whose file just closed).
Diffstat (limited to 'test')
-rw-r--r--test/.distdep16
-rw-r--r--test/Makefile.in16
-rw-r--r--test/shtype.c288
3 files changed, 316 insertions, 4 deletions
diff --git a/test/.distdep b/test/.distdep
index 895c967..5cbdc57 100644
--- a/test/.distdep
+++ b/test/.distdep
@@ -287,3 +287,19 @@ gheap.o: \
../src/H5Bpublic.h \
../src/H5HGprivate.h \
../src/H5HGpublic.h
+shtype.o: \
+ shtype.c \
+ ../src/hdf5.h \
+ ../src/H5public.h \
+ ../src/H5config.h \
+ ../src/H5ACpublic.h \
+ ../src/H5Bpublic.h \
+ ../src/H5Dpublic.h \
+ ../src/H5Ipublic.h \
+ ../src/H5Epublic.h \
+ ../src/H5Fpublic.h \
+ ../src/H5Gpublic.h \
+ ../src/H5HLpublic.h \
+ ../src/H5MFpublic.h \
+ ../src/H5MMpublic.h \
+ ../src/H5Opublic.h
diff --git a/test/Makefile.in b/test/Makefile.in
index 7017e9d..10e9135 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -12,8 +12,9 @@ CPPFLAGS=-I. -I../src @CPPFLAGS@
# These are our main targets. They should be listed in the order to be
# executed, generally most specific tests to least specific tests.
PROGS=testhdf5 gheap hyperslab istore dtypes dsets cmpd_dset extend external \
- iopipe
-TESTS=testhdf5 gheap hyperslab istore dtypes dsets cmpd_dset extend external
+ shtype iopipe
+TESTS=testhdf5 gheap hyperslab istore dtypes dsets cmpd_dset extend external \
+ shtype
TIMINGS=iopipe
# Temporary files
@@ -22,7 +23,8 @@ MOSTLYCLEAN=cmpd_dset.h5 dataset.h5 extend.h5 istore.h5 tfile1.h5 tfile2.h5 \
extern_1.h5 extern_2.h5 extern_3.h5 extern_1.raw extern_1b.raw \
extern_2.raw extern_2b.raw extern_3.raw extern_3b.raw \
extern_4.raw extern_4b.raw iopipe.raw iopipe.h5 gheap0.h5 \
- gheap1.h5 gheap2.h5 gheap3.h5 gheap4.h5
+ gheap1.h5 gheap2.h5 gheap3.h5 gheap4.h5 shtype0.h5 shtype1.h5 \
+ shtype2a.h5 shtype2b.h5 shtype3.h5
# Source and object files for programs... The PROG_SRC list contains all the
# source files and is used for things like dependencies, archiving, etc. The
@@ -30,7 +32,7 @@ MOSTLYCLEAN=cmpd_dset.h5 dataset.h5 extend.h5 istore.h5 tfile1.h5 tfile2.h5 \
# overlap with other tests.
PROG_SRC=testhdf5.c tfile.c theap.c tmeta.c tohdr.c tstab.c th5s.c dtypes.c \
hyperslab.c istore.c dsets.c cmpd_dset.c extend.c external.c \
- iopipe.c gheap.c
+ iopipe.c gheap.c shtype.c
PROG_OBJ=$(PROG_SRC:.c=.o)
TESTHDF5_SRC=testhdf5.c tfile.c theap.c tmeta.c tohdr.c tstab.c th5s.c
@@ -63,6 +65,9 @@ EXTERNAL_OBJ=$(EXTERNAL_SRC:.c=.o)
GRPTIME_SRC=grptime.c
GRPTIME_OBJ=$(GRPTIME_SRC:.c=.o)
+SHTYPE_SRC=shtype.c
+SHTYPE_OBJ=$(SHTYPE_SRC:.c=.o)
+
IOPIPE_SRC=iopipe.c
IOPIPE_OBJ=$(IOPIPE_SRC:.c=.o)
@@ -107,6 +112,9 @@ extend: $(EXTEND_OBJ) ../src/libhdf5.a
external: $(EXTERNAL_OBJ) ../src/libhdf5.a
$(CC) $(CFLAGS) -o $@ $(EXTERNAL_OBJ) ../src/libhdf5.a $(LIBS)
+shtype: $(SHTYPE_OBJ) ../src/libhdf5.a
+ $(CC) $(CFLAGS) -o $@ $(SHTYPE_OBJ) ../src/libhdf5.a $(LIBS)
+
iopipe: $(IOPIPE_OBJ) ../src/libhdf5.a
$(CC) $(CFLAGS) -o $@ $(IOPIPE_OBJ) ../src/libhdf5.a $(LIBS)
diff --git a/test/shtype.c b/test/shtype.c
new file mode 100644
index 0000000..e1b1aa9
--- /dev/null
+++ b/test/shtype.c
@@ -0,0 +1,288 @@
+/*
+ * Copyright (C) 1998 NCSA
+ * All rights reserved.
+ *
+ * Programmer: Robb Matzke <matzke@llnl.gov>
+ * Thursday, April 2, 1998
+ *
+ * Purpose: Tests datasets with shared data types.
+ */
+#include <assert.h>
+#include <hdf5.h>
+
+
+/*-------------------------------------------------------------------------
+ * Function: display_error_cb
+ *
+ * Purpose: Displays the error stack after printing "*FAILED*".
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Wednesday, March 4, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+display_error_cb (void *client_data)
+{
+ puts ("*FAILED*");
+ H5Eprint (stdout);
+ return 0;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_1
+ *
+ * Purpose: Create a shared data type and use it to create a dataset.
+ * Then query that dataset's type and use it to create a second
+ * dataset. Both datasets should share a single data type.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Thursday, April 2, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_1 (void)
+{
+ hid_t f, d1, d2, s1, t1, t2;
+ size_t size[1] = {1};
+
+ printf ("%-70s", "...creating/quering datasets with shared type");
+ fflush (stdout);
+
+ f = H5Fcreate ("shtype1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ if (f<0) goto error;
+ if ((s1 = H5Screate_simple (1, size, size))<0) goto error;
+ if ((t1 = H5Tcopy (H5T_NATIVE_INT))<0) goto error;
+ if (H5Tshare (f, t1)<0) goto error;
+
+ /* Create the first dataset */
+ if ((d1 = H5Dcreate (f, "d1", t1, s1, H5P_DEFAULT))<0) goto error;
+ if (H5Dclose (d1)<0) goto error;
+
+ /* Get the type of the first dataset to use for the second */
+ if ((d1 = H5Dopen (f, "d1"))<0) goto error;
+ if ((t2 = H5Dget_type (d1))<0) goto error;
+ if (H5Dclose (d1)<0) goto error;
+
+ /* Create the second datatype */
+ if ((d2 = H5Dcreate (f, "d2", t2, s1, H5P_DEFAULT))<0) goto error;
+ if (H5Dclose (d2)<0) goto error;
+
+ if (H5Sclose (s1)<0) goto error;
+ if (H5Fclose (f)<0) goto error;
+
+ puts (" PASSED");
+ return 0;
+
+ error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_2
+ *
+ * Purpose: Create lots of datasets that have their own types, then
+ * create another file with lots of datasets that share a type
+ * and compare the file sizes.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Thursday, April 2, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_2 (void)
+{
+ hid_t f1, f2, t1, t2, s1, d1, d2;
+ size_t size[1] = {1};
+ char buf[32];
+ int i;
+
+ printf ("%-70s", "...compare shared and unshared types");
+ fflush (stdout);
+
+ f1 = H5Fcreate ("shtype2a.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ if (f1<0) goto error;
+ f2 = H5Fcreate ("shtype2b.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ if (f2<0) goto error;
+ s1 = H5Screate_simple (1, size, size);
+ if (s1<0) goto error;
+
+ /* Create a large compound type */
+ if ((t1 = H5Tcreate (H5T_COMPOUND, 100))<0) goto error;
+ for (i=0; i<10; i++) {
+ sprintf (buf, "member-%d", i);
+ if (H5Tinsert (t1, buf, i*sizeof(int), H5T_NATIVE_INT)<0) goto error;
+ }
+
+ /* Create a shared version of that type for file #2 */
+ if ((t2 = H5Tcopy (t1))<0) goto error;
+ if (H5Tshare (f2, t2)<0) goto error;
+
+ /* Create the datasets */
+ for (i=0; i<1000; i++) {
+ sprintf (buf, "dset%04d", i);
+ d1 = H5Dcreate (f1, buf, t1, s1, H5P_DEFAULT);
+ if (d1<0) goto error;
+ if (H5Dclose (d1)<0) goto error;
+ d2 = H5Dcreate (f2, buf, t2, s1, H5P_DEFAULT);
+ if (d2<0) goto error;
+ if (H5Dclose (d2)<0) goto error;
+ }
+
+ /* Close things */
+ if (H5Sclose (s1)<0) goto error;
+ if (H5Tclose (t1)<0) goto error;
+ if (H5Tclose (t2)<0) goto error;
+ if (H5Fclose (f1)<0) goto error;
+ if (H5Fclose (f2)<0) goto error;
+
+ puts (" PASSED");
+ return 0;
+
+ error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_3
+ *
+ * Purpose: Tries to create a shared type in a read-only file.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Friday, April 3, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_3 (void)
+{
+ hid_t f1, s1, t1, d1;
+ size_t size[1] = {1};
+ herr_t status, (*ef)(void*)=NULL;
+ void *ed = NULL;
+
+ printf ("%-70s", "...shared types and read-only files");
+ fflush (stdout);
+
+ /*
+ * Create the file first since we can't create a file for read-only
+ * access. Add a dataset with a shared type. Then close it and open it
+ * for read-only. The shared type causes a global heap to be allocated.
+ */
+ f1 = H5Fcreate ("shtype3.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ if (f1<0) goto error;
+ if ((s1 = H5Screate_simple (1, size, size))<0) goto error;
+ if ((t1 = H5Tcopy (H5T_NATIVE_INT))<0) goto error;
+ if (H5Tshare (f1, t1)<0) goto error;
+ if ((d1 = H5Dcreate (f1, "d1", t1, s1, H5P_DEFAULT))<0) goto error;
+ if (H5Sclose (s1)<0) goto error;
+ if (H5Dclose (d1)<0) goto error;
+ if (H5Fclose (f1)<0) goto error;
+ f1 = H5Fopen ("shtype3.h5", H5F_ACC_RDONLY, H5P_DEFAULT);
+ if (f1<0) goto error;
+ assert (0==H5Tis_shared (f1, t1));
+
+ /*
+ * Create a shared data type. We know that H5MF_alloc() will fail on a
+ * read-only file so there's not much point in trying to create a global
+ * heap. But what happens if we modify a global heap in the cache? So
+ * lets try to get a collection loaded into memory by reading the shared
+ * type. Then creating another shared type will just upate memory unless
+ * an error is correctly detected.
+ */
+ if ((d1 = H5Dopen (f1, "d1"))<0) goto error;
+ if (H5Dclose (d1)<0) goto error;
+ if (H5Eget_auto (&ef, &ed)<0) goto error;
+ if (H5Eset_auto (NULL, NULL)<0) goto error;
+ status = H5Tshare (f1, t1);
+ if (H5Eset_auto (ef, ed)<0) goto error;
+ if (status>=0) {
+ puts ("*FAILED*");
+ puts (" H5Tshare() should have failed but didn't.");
+ goto error;
+ }
+
+ /* Close the file */
+ if (H5Fclose (f1)<0) goto error;
+
+ puts (" PASSED");
+ return 0;
+
+ error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ * Purpose:
+ *
+ * Return: Success:
+ *
+ * Failure:
+ *
+ * Programmer: Robb Matzke
+ * Thursday, April 2, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+main (void)
+{
+ int nerrors = 0;
+ hid_t f1, g1;
+
+ /* Make sure diagnostics get emitted before we start doing real stuff */
+ f1 = H5Fcreate ("shtype0.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ g1 = H5Gcreate (f1, "howdy", 0);
+ H5Gclose (g1);
+ H5Fclose (f1);
+
+ /* Set the error handler */
+ H5Eset_auto (display_error_cb, NULL);
+
+ /* Run the tests */
+ nerrors += test_1()<0 ? 1 : 0;
+ nerrors += test_2()<0 ? 1 : 0;
+ nerrors += test_3()<0 ? 1 : 0;
+
+ /* Report results */
+ if (nerrors) {
+ puts ("*** Shared data type test(s) failed ***");
+ } else {
+ puts ("All shared data type tests passed.");
+ }
+ return nerrors ? 1 : 0;
+}