summaryrefslogtreecommitdiffstats
path: root/test/filenotclosed.c
diff options
context:
space:
mode:
authorVailin Choi <vchoi@jam.ad.hdfgroup.org>2017-06-29 06:11:44 (GMT)
committerVailin Choi <vchoi@jam.ad.hdfgroup.org>2017-06-29 06:11:44 (GMT)
commit804a88fafdca3d6a76312ab01ac4d6d5b103e9dc (patch)
treebbde4f73361e683af6ff16461e7d4d90d95f13c1 /test/filenotclosed.c
parent3da8951fb3fc3fa850558ba7ea4d44d507fc1664 (diff)
downloadhdf5-804a88fafdca3d6a76312ab01ac4d6d5b103e9dc.zip
hdf5-804a88fafdca3d6a76312ab01ac4d6d5b103e9dc.tar.gz
hdf5-804a88fafdca3d6a76312ab01ac4d6d5b103e9dc.tar.bz2
Fix for HDFFV-10160
Modifications to fix the assertion/abort failure when the application does not close the file.
Diffstat (limited to 'test/filenotclosed.c')
-rw-r--r--test/filenotclosed.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/test/filenotclosed.c b/test/filenotclosed.c
new file mode 100644
index 0000000..f91f4bc
--- /dev/null
+++ b/test/filenotclosed.c
@@ -0,0 +1,128 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 COPYING file, which can be found at the root of the source code *
+ * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Purpose: Test to verify that the assertion/abort failure is fixed when the
+ * application does not close the file. (See HDFFV-10160)
+ */
+
+
+#include "h5test.h"
+
+#define FILENAME "filenotclosed"
+#define DATASET "dset"
+
+/*-------------------------------------------------------------------------
+ * Function: catch_signal
+ *
+ * Purpose: The signal handler to catch the SIGABRT signal.
+ *
+ * Return: No return
+ *
+ * Programmer: Vailin Choi
+ *
+ *-------------------------------------------------------------------------
+ */
+static void catch_signal(int H5_ATTR_UNUSED signo)
+{
+ HDexit(1);
+} /* catch_signal() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ * Purpose: Test to verify the following problem described in HDFFV-10160 is fixed:
+ * "a.out: H5Fint.c:1679: H5F_close: Assertion `f->file_id > 0' failed."
+ *
+ * Return: Success: exit(EXIT_SUCCESS)
+ * Failure: exit(EXIT_FAILURE)
+ *
+ * Programmer: Vailin Choi; June 2017
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+main(void)
+{
+ hid_t fapl = -1; /* File access property lists */
+ hid_t fid = -1; /* File ID */
+ hid_t did = -1; /* Dataset ID */
+ hid_t dcpl = -1; /* Dataset creation property list */
+ hid_t sid = -1; /* Dataspace ID */
+ hsize_t cur_dim[1] = {5}; /* Current dimension sizes */
+ hsize_t max_dim[1] = {H5S_UNLIMITED}; /* Maximum dimension sizes */
+ hsize_t chunk_dim[1] = {10}; /* Chunk dimension sizes */
+ int buf[5] = {1, 2, 3, 4, 5}; /* The data to be written to the dataset */
+ char filename[100]; /* File name */
+ const char *env_h5_drvr; /* File Driver value from environment */
+
+ h5_reset();
+
+ /* To exit from the file for SIGABRT signal */
+ if(HDsignal(SIGABRT, catch_signal) == SIG_ERR)
+ TEST_ERROR
+
+ fapl = h5_fileaccess();
+ h5_fixname(FILENAME, fapl, filename, sizeof(filename));
+
+ /* Set to latest format */
+ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
+ TEST_ERROR
+
+ /* Create the file */
+ if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
+ TEST_ERROR
+
+ /* Create the dcpl and set the chunk size */
+ if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
+ TEST_ERROR
+
+ if(H5Pset_chunk(dcpl, 1, chunk_dim) < 0)
+ TEST_ERROR
+
+ /* Create the dataspace */
+ if((sid = H5Screate_simple(1, cur_dim, max_dim)) < 0)
+ TEST_ERROR
+
+ /* Create the dataset */
+ if((did = H5Dcreate2(fid, "dset", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
+ TEST_ERROR
+
+ /* Write to the dataset */
+ if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
+ TEST_ERROR
+
+ /* Close the dataset */
+ if(H5Dclose(did) < 0)
+ TEST_ERROR
+
+ /* Close the dataspace */
+ if(H5Sclose(sid) < 0)
+ TEST_ERROR
+
+ /* Close the property lists */
+ if(H5Pclose(dcpl) < 0)
+ TEST_ERROR
+ if(H5Pclose(fapl) < 0)
+ TEST_ERROR
+
+ /* The file is not closed. */
+ /* The library will call H5_term_library to shut down the library. */
+
+ HDexit(EXIT_SUCCESS);
+
+error:
+ HDputs("*** TEST FAILED ***");
+ HDexit(EXIT_FAILURE);
+}