Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test opening unseekable file #4720

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions test/tfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Comment on lines +8114 to +8115

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe fflush(stdout) after this, to know which test that causes a Segmentation Fault.


/* 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():
Expand Down Expand Up @@ -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 */
Comment on lines -8422 to +8469

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to keep the comments aligned, better keep diff size down.

#ifndef H5_NO_DEPRECATED_SYMBOLS
test_file_ishdf5(driver_name); /* Test detecting HDF5 files correctly */
test_deprec(driver_name); /* Test deprecated routines */
Expand Down
Loading