From 6d44f9f3404fd44c5c9796181d85b2fd7e8d75a2 Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Thu, 15 Aug 2024 10:18:03 -0500 Subject: [PATCH] Test creating unseekable file --- test/tfile.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/test/tfile.c b/test/tfile.c index 62881264441..a93b7be6857 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -8100,6 +8100,49 @@ test_min_dset_ohdr(void) CHECK(ret, FAIL, "H5Fclose"); } /* end test_min_dset_ohdr() */ +/**************************************************************** +** +** test_unseekable_file(): +** Test that attempting to open an unseekable file fails gracefully +** without a segfault (see hdf5#1498) +****************************************************************/ +static void +test_unseekable_file(void) +{ + hid_t file_id = H5I_INVALID_HID; /* File ID */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing creating/opening an unseekable file\n")); + + /* Creation */ +#ifdef H5_HAVE_WIN32_API + file_id = H5Fcreate("NUL", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); +#else + file_id = H5Fcreate("/dev/null", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); +#endif + + H5Fclose(file_id); + + /* Open, truncate */ +#ifdef H5_HAVE_WIN32_API + file_id = H5Fopen("NUL", H5F_ACC_TRUNC, H5P_DEFAULT); +#else + file_id = H5Fopen("/dev/null", H5F_ACC_TRUNC, H5P_DEFAULT); +#endif + + H5Fclose(file_id); + + /* Open, RDWR */ +#ifdef H5_HAVE_WIN32_API + file_id = H5Fopen("NUL", H5F_ACC_RDWR, H5P_DEFAULT); +#else + file_id = H5Fopen("/dev/null", H5F_ACC_RDWR, H5P_DEFAULT); +#endif + + H5Fclose(file_id); + + exit(EXIT_SUCCESS); +} /**************************************************************** ** ** test_deprec(): @@ -8419,10 +8462,11 @@ test_file(void) test_libver_bounds(); /* Test compatibility for file space management */ test_libver_bounds_low_high(driver_name); - test_libver_macros(); /* Test the macros for library version comparison */ - test_libver_macros2(); /* Test the macros for library version comparison */ - test_incr_filesize(); /* Test H5Fincrement_filesize() and H5Fget_eoa() */ - test_min_dset_ohdr(); /* Test dataset object header minimization */ + test_libver_macros(); /* Test the macros for library version comparison */ + test_libver_macros2(); /* Test the macros for library version comparison */ + test_incr_filesize(); /* Test H5Fincrement_filesize() and H5Fget_eoa() */ + test_min_dset_ohdr(); /* Test dataset object header minimization */ + test_unseekable_file(); /* Test attempting to open/create an unseekable file */ #ifndef H5_NO_DEPRECATED_SYMBOLS test_file_ishdf5(driver_name); /* Test detecting HDF5 files correctly */ test_deprec(driver_name); /* Test deprecated routines */