2017-01-27 03:34:12 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* 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. *
|
2017-01-27 03:34:12 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Use Case 1.8 Appending a hyperslab of multiple chunks.
|
|
|
|
* Description:
|
|
|
|
* Appending a hyperslab that spans several chunks of a dataset with
|
|
|
|
* unlimited dimensions within a pre-created file and reading the new
|
|
|
|
* data back.
|
|
|
|
* Goal:
|
|
|
|
* Read data appended by the Writer to a pre-existing dataset in a
|
|
|
|
* file. The dataset has one or more unlimited dimensions. The data
|
|
|
|
* is appended by a hyperslab that is contained in several chunks (for
|
|
|
|
* example, appending 2-dim planes along the slowest changing dimension
|
|
|
|
* in the 3-dim dataset and each plane is covered by 4 chunks).
|
|
|
|
* Level:
|
|
|
|
* User Level
|
|
|
|
* Guarantees:
|
|
|
|
* o Readers will see the modified dimension sizes after the Writer
|
|
|
|
* finishes HDF5 metadata updates and issues H5Fflush or H5Oflush calls.
|
|
|
|
* o Readers will see newly appended data after the Writer finishes
|
|
|
|
* the flush operation.
|
2020-03-14 06:13:17 +08:00
|
|
|
*
|
2017-01-27 03:34:12 +08:00
|
|
|
* Preconditions:
|
|
|
|
* o Readers are not allowed to modify the file.
|
|
|
|
* o All datasets that are modified by the Writer exist when the
|
|
|
|
* Writer opens the file.
|
|
|
|
* o All datasets that are modified by the Writer exist when a Reader
|
|
|
|
* opens the file.
|
2020-03-14 06:13:17 +08:00
|
|
|
*
|
2017-01-27 03:34:12 +08:00
|
|
|
* Main Success Scenario:
|
|
|
|
* 1. An application creates a file with required objects (groups,
|
|
|
|
* datasets, and attributes).
|
|
|
|
* 2. The Writer opens the file and datasets in the file and starts
|
|
|
|
* adding data using H5Dwrite call with a hyperslab selection that
|
|
|
|
* spans several chunks.
|
|
|
|
* 3. A Reader opens the file and a dataset in a file; if the size of
|
|
|
|
* the unlimited dimension has changed, reads the appended data back.
|
2020-03-14 06:13:17 +08:00
|
|
|
*
|
2017-01-27 03:34:12 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
/* Created: Albert Cheng, 2013/6/1 */
|
|
|
|
|
|
|
|
#include "h5test.h"
|
|
|
|
|
|
|
|
/* This test uses many POSIX things that are not available on
|
|
|
|
* Windows. We're using a check for fork(2) here as a proxy for
|
|
|
|
* all POSIX/Unix/Linux things until this test can be made
|
|
|
|
* more platform-independent.
|
|
|
|
*/
|
|
|
|
#ifdef H5_HAVE_FORK
|
|
|
|
|
|
|
|
#include "use.h"
|
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
#define USE_APPEND_MCHUNKS_PROGNAME "use_append_mchunks"
|
|
|
|
|
|
|
|
static options_t UC_opts; /* Use Case Options */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Setup parameters for the use case.
|
|
|
|
* Return: 0 succeed; -1 fail.
|
|
|
|
*/
|
2020-03-14 06:13:17 +08:00
|
|
|
int
|
2020-09-30 22:27:10 +08:00
|
|
|
setup_parameters(int argc, char *const argv[], options_t *opts)
|
2017-01-27 03:34:12 +08:00
|
|
|
{
|
|
|
|
/* use case defaults */
|
2020-03-14 06:13:17 +08:00
|
|
|
HDmemset(opts, 0, sizeof(options_t));
|
2020-09-30 22:27:10 +08:00
|
|
|
opts->chunksize = Chunksize_DFT;
|
|
|
|
opts->use_swmr = 1; /* use swmr open */
|
|
|
|
opts->iterations = 1;
|
2020-03-14 06:13:17 +08:00
|
|
|
opts->chunkplanes = 1;
|
2020-09-30 22:27:10 +08:00
|
|
|
opts->progname = USE_APPEND_MCHUNKS_PROGNAME;
|
|
|
|
opts->fapl_id = H5I_INVALID_HID;
|
2020-03-14 06:13:17 +08:00
|
|
|
|
|
|
|
if (parse_option(argc, argv, opts) < 0) {
|
2020-09-30 22:27:10 +08:00
|
|
|
return (-1);
|
2017-01-27 03:34:12 +08:00
|
|
|
}
|
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
opts->chunkdims[0] = (hsize_t)opts->chunkplanes;
|
|
|
|
opts->chunkdims[1] = opts->chunkdims[2] = (hsize_t)opts->chunksize;
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
opts->dims[0] = 0;
|
2020-03-14 06:13:17 +08:00
|
|
|
opts->max_dims[0] = H5S_UNLIMITED;
|
|
|
|
opts->dims[1] = opts->dims[2] = opts->max_dims[1] = opts->max_dims[2] = 2 * (hsize_t)opts->chunksize;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
if (opts->nplanes == 0)
|
|
|
|
opts->nplanes = 2 * (hsize_t)opts->chunksize;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
show_parameters(opts);
|
2020-09-30 22:27:10 +08:00
|
|
|
return (0);
|
2020-03-14 06:13:17 +08:00
|
|
|
} /* end setup_parameters() */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
/* Overall Algorithm:
|
2017-01-27 03:34:12 +08:00
|
|
|
* Parse options from user;
|
|
|
|
* Generate/pre-created test files needed and close it;
|
|
|
|
* fork: child process becomes the reader process;
|
|
|
|
* while parent process continues as the writer process;
|
|
|
|
* both run till ending conditions are met.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
pid_t childpid = 0;
|
|
|
|
pid_t mypid, tmppid;
|
|
|
|
int child_status;
|
|
|
|
int child_wait_option = 0;
|
|
|
|
int ret_value = 0;
|
|
|
|
int child_ret_value;
|
2017-01-27 03:34:12 +08:00
|
|
|
hbool_t send_wait = 0;
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t fapl = -1; /* File access property list */
|
|
|
|
hid_t fid = -1; /* File ID */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
if (setup_parameters(argc, argv, &UC_opts) < 0) {
|
2018-11-02 01:03:34 +08:00
|
|
|
Hgoto_error(1);
|
2017-01-27 03:34:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the need to send/wait message file*/
|
2020-03-14 06:13:17 +08:00
|
|
|
if (UC_opts.launch == UC_READWRITE) {
|
2017-01-27 03:34:12 +08:00
|
|
|
HDunlink(WRITER_MESSAGE);
|
|
|
|
send_wait = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ==============================================================*/
|
|
|
|
/* UC_READWRITE: create datafile, launch both reader and writer. */
|
|
|
|
/* UC_WRITER: create datafile, skip reader, launch writer. */
|
|
|
|
/* UC_READER: skip create, launch reader, exit. */
|
|
|
|
/* ==============================================================*/
|
2020-03-14 06:13:17 +08:00
|
|
|
/* =========== */
|
2017-01-27 03:34:12 +08:00
|
|
|
/* Create file */
|
2020-03-14 06:13:17 +08:00
|
|
|
/* =========== */
|
|
|
|
if (UC_opts.launch != UC_READER) {
|
2018-11-02 01:03:34 +08:00
|
|
|
HDprintf("Creating skeleton data file for test...\n");
|
2020-03-14 06:13:17 +08:00
|
|
|
if ((UC_opts.fapl_id = h5_fileaccess()) < 0) {
|
|
|
|
HDfprintf(stderr, "can't create creation FAPL\n");
|
|
|
|
Hgoto_error(1);
|
|
|
|
}
|
|
|
|
if (H5Pset_libver_bounds(UC_opts.fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) {
|
|
|
|
HDfprintf(stderr, "can't set creation FAPL libver bounds\n");
|
|
|
|
Hgoto_error(1);
|
|
|
|
}
|
|
|
|
if (create_uc_file(&UC_opts) < 0) {
|
|
|
|
HDfprintf(stderr, "***encounter error\n");
|
|
|
|
Hgoto_error(1);
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
else {
|
2020-03-14 06:13:17 +08:00
|
|
|
HDprintf("File created.\n");
|
|
|
|
}
|
|
|
|
/* Close FAPL to prevent issues with forking later */
|
|
|
|
if (H5Pclose(UC_opts.fapl_id) < 0) {
|
|
|
|
HDfprintf(stderr, "can't close creation FAPL\n");
|
|
|
|
Hgoto_error(1);
|
|
|
|
}
|
|
|
|
UC_opts.fapl_id = H5I_INVALID_HID;
|
2017-01-27 03:34:12 +08:00
|
|
|
}
|
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
/* ============ */
|
|
|
|
/* Fork process */
|
|
|
|
/* ============ */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (UC_opts.launch == UC_READWRITE) {
|
2020-10-24 08:13:05 +08:00
|
|
|
if ((childpid = HDfork()) < 0) {
|
|
|
|
HDperror("fork");
|
2018-11-02 01:03:34 +08:00
|
|
|
Hgoto_error(1);
|
2020-03-14 06:13:17 +08:00
|
|
|
}
|
|
|
|
}
|
2020-10-24 08:13:05 +08:00
|
|
|
mypid = HDgetpid();
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* ============= */
|
|
|
|
/* launch reader */
|
|
|
|
/* ============= */
|
2020-03-14 06:13:17 +08:00
|
|
|
if (UC_opts.launch != UC_WRITER) {
|
2018-11-02 01:03:34 +08:00
|
|
|
/* child process launch the reader */
|
2020-03-14 06:13:17 +08:00
|
|
|
if (0 == childpid) {
|
2018-11-02 01:03:34 +08:00
|
|
|
HDprintf("%d: launch reader process\n", mypid);
|
2020-03-14 06:13:17 +08:00
|
|
|
if ((UC_opts.fapl_id = h5_fileaccess()) < 0) {
|
|
|
|
HDfprintf(stderr, "can't create read FAPL\n");
|
|
|
|
HDexit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if (read_uc_file(send_wait, &UC_opts) < 0) {
|
2018-11-02 01:03:34 +08:00
|
|
|
HDfprintf(stderr, "read_uc_file encountered error\n");
|
2019-09-07 09:06:26 +08:00
|
|
|
HDexit(EXIT_FAILURE);
|
2018-11-02 01:03:34 +08:00
|
|
|
}
|
2020-03-14 06:13:17 +08:00
|
|
|
if (H5Pclose(UC_opts.fapl_id) < 0) {
|
|
|
|
HDfprintf(stderr, "can't close read FAPL\n");
|
|
|
|
HDexit(EXIT_FAILURE);
|
|
|
|
}
|
2019-09-07 09:06:26 +08:00
|
|
|
HDexit(EXIT_SUCCESS);
|
2018-11-02 01:03:34 +08:00
|
|
|
}
|
2017-01-27 03:34:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ============= */
|
|
|
|
/* launch writer */
|
|
|
|
/* ============= */
|
|
|
|
/* this process continues to launch the writer */
|
2018-11-02 01:03:34 +08:00
|
|
|
HDprintf("%d: continue as the writer process\n", mypid);
|
2018-10-31 05:53:09 +08:00
|
|
|
|
|
|
|
/* Set the file access property list */
|
2020-03-14 06:13:17 +08:00
|
|
|
if ((fapl = h5_fileaccess()) < 0) {
|
|
|
|
HDfprintf(stderr, "can't get write FAPL\n");
|
2018-10-31 05:53:09 +08:00
|
|
|
Hgoto_error(1);
|
2020-03-14 06:13:17 +08:00
|
|
|
}
|
2018-10-31 05:53:09 +08:00
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
if (UC_opts.use_swmr) {
|
|
|
|
if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) {
|
|
|
|
HDfprintf(stderr, "can't set write FAPL libver bounds\n");
|
2018-10-31 05:53:09 +08:00
|
|
|
Hgoto_error(1);
|
2020-03-14 06:13:17 +08:00
|
|
|
}
|
|
|
|
}
|
2018-10-31 05:53:09 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fid = H5Fopen(UC_opts.filename, H5F_ACC_RDWR | (UC_opts.use_swmr ? H5F_ACC_SWMR_WRITE : 0), fapl)) <
|
|
|
|
0) {
|
2018-11-02 01:03:34 +08:00
|
|
|
HDfprintf(stderr, "H5Fopen failed\n");
|
2018-10-31 05:53:09 +08:00
|
|
|
Hgoto_error(1);
|
|
|
|
}
|
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
if (write_uc_file(send_wait, fid, &UC_opts) < 0) {
|
2018-11-02 01:03:34 +08:00
|
|
|
HDfprintf(stderr, "write_uc_file encountered error\n");
|
2018-10-31 05:53:09 +08:00
|
|
|
Hgoto_error(1);
|
2017-01-27 03:34:12 +08:00
|
|
|
}
|
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
if (H5Fclose(fid) < 0) {
|
|
|
|
HDfprintf(stderr, "Failed to close file id\n");
|
|
|
|
Hgoto_error(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (H5Pclose(fapl) < 0) {
|
|
|
|
HDfprintf(stderr, "can't close write FAPL\n");
|
|
|
|
Hgoto_error(1);
|
|
|
|
}
|
2018-10-31 05:53:09 +08:00
|
|
|
|
2017-01-27 03:34:12 +08:00
|
|
|
/* ================================================ */
|
|
|
|
/* If readwrite, collect exit code of child process */
|
|
|
|
/* ================================================ */
|
2020-03-14 06:13:17 +08:00
|
|
|
if (UC_opts.launch == UC_READWRITE) {
|
2020-10-24 08:13:05 +08:00
|
|
|
if ((tmppid = HDwaitpid(childpid, &child_status, child_wait_option)) < 0) {
|
|
|
|
HDperror("waitpid");
|
2018-10-31 05:53:09 +08:00
|
|
|
Hgoto_error(1);
|
|
|
|
}
|
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
if (WIFEXITED(child_status)) {
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((child_ret_value = WEXITSTATUS(child_status)) != 0) {
|
|
|
|
HDprintf("%d: child process exited with non-zero code (%d)\n", mypid, child_ret_value);
|
2018-10-31 05:53:09 +08:00
|
|
|
Hgoto_error(1);
|
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
else {
|
2018-11-02 01:03:34 +08:00
|
|
|
HDprintf("%d: child process terminated abnormally\n", mypid);
|
2018-10-31 05:53:09 +08:00
|
|
|
Hgoto_error(2);
|
|
|
|
}
|
2017-01-27 03:34:12 +08:00
|
|
|
}
|
2020-03-14 06:13:17 +08:00
|
|
|
|
2017-01-27 03:34:12 +08:00
|
|
|
done:
|
2020-03-14 06:13:17 +08:00
|
|
|
if (ret_value != 0) {
|
2018-11-02 01:03:34 +08:00
|
|
|
HDprintf("Error(s) encountered\n");
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
else {
|
2018-11-02 01:03:34 +08:00
|
|
|
HDprintf("All passed\n");
|
2017-01-27 03:34:12 +08:00
|
|
|
}
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
return (ret_value);
|
2020-03-14 06:13:17 +08:00
|
|
|
} /* end main() */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
#else /* H5_HAVE_FORK */
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
HDfprintf(stderr, "Non-POSIX platform. Skipping.\n");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
} /* end main() */
|
|
|
|
|
|
|
|
#endif /* H5_HAVE_FORK */
|