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 *
|
2021-02-17 22:52:04 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* 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
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2020-03-14 06:13:17 +08:00
|
|
|
* Use Case 1.7 Appending a single chunk
|
2017-01-27 03:34:12 +08:00
|
|
|
* Description:
|
|
|
|
* Appending a single chunk of raw data to a dataset along an unlimited
|
|
|
|
* dimension 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 one chunk (for example,
|
|
|
|
* appending 2-dim planes along the slowest changing dimension in the
|
|
|
|
* 3-dim dataset).
|
|
|
|
* Level:
|
|
|
|
* User Level
|
|
|
|
* Guarantees:
|
2020-03-14 06:13:17 +08:00
|
|
|
* 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.
|
|
|
|
*
|
2017-01-27 03:34:12 +08:00
|
|
|
* Preconditions:
|
2020-03-14 06:13:17 +08:00
|
|
|
* 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.
|
|
|
|
* o Data is written by a hyperslab contained in one chunk.
|
|
|
|
*
|
2017-01-27 03:34:12 +08:00
|
|
|
* Main Success Scenario:
|
2020-03-14 06:13:17 +08:00
|
|
|
* 1. An application creates a file with required objects (groups,
|
|
|
|
* datasets, and attributes).
|
|
|
|
* 2. The Writer application opens the file and datasets in the file
|
|
|
|
* and starts adding data along the unlimited dimension using a hyperslab
|
|
|
|
* selection that corresponds to an HDF5 chunk.
|
|
|
|
* 3. A Reader opens the file and a dataset in a file, and queries
|
|
|
|
* the sizes of the dataset; if the extent of the dataset has changed,
|
|
|
|
* reads the appended data back.
|
|
|
|
*
|
2017-01-27 03:34:12 +08:00
|
|
|
* Discussion points:
|
2020-03-14 06:13:17 +08:00
|
|
|
* 1. Since the new data is written to the file, and metadata update
|
|
|
|
* operation of adding pointer to the newly written chunk is atomic and
|
|
|
|
* happens after the chunk is on the disk, only two things may happen
|
|
|
|
* to the Reader:
|
|
|
|
* o The Reader will not see new data.
|
|
|
|
* o The Reader will see all new data written by Writer.
|
2017-01-27 03:34:12 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
/* Created: Albert Cheng, 2013/5/28 */
|
|
|
|
|
|
|
|
#include "h5test.h"
|
|
|
|
|
|
|
|
/* This test uses many POSIX things that are not available on
|
2021-03-12 05:34:55 +08:00
|
|
|
* Windows.
|
2017-01-27 03:34:12 +08:00
|
|
|
*/
|
2022-01-08 12:29:25 +08:00
|
|
|
#if defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID)
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
#include "use.h"
|
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
#define USE_APPEND_CHUNK_PROGNAME "use_append_chunk"
|
|
|
|
|
|
|
|
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 = TRUE; /* 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_CHUNK_PROGNAME;
|
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);
|
2020-03-14 06:13:17 +08:00
|
|
|
|
|
|
|
opts->chunkdims[0] = opts->chunkplanes;
|
|
|
|
opts->chunkdims[1] = opts->chunkdims[2] = 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] = opts->chunksize;
|
|
|
|
|
|
|
|
if (opts->nplanes == 0)
|
|
|
|
opts->nplanes = (hsize_t)opts->chunksize;
|
|
|
|
|
|
|
|
show_parameters(opts);
|
2020-09-30 22:27:10 +08:00
|
|
|
return (0);
|
2020-03-14 06:13:17 +08:00
|
|
|
} /* 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-02-20 10:28:52 +08:00
|
|
|
hbool_t send_wait = FALSE;
|
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);
|
2017-02-20 10:28:52 +08:00
|
|
|
send_wait = TRUE;
|
2017-01-27 03:34:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ==============================================================*/
|
|
|
|
/* 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);
|
2020-04-21 07:12:00 +08:00
|
|
|
}
|
2020-03-14 06:13:17 +08:00
|
|
|
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) {
|
2018-11-02 01:03:34 +08:00
|
|
|
HDfprintf(stderr, "***encounter error\n");
|
|
|
|
Hgoto_error(1);
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
else {
|
2018-11-02 01:03:34 +08:00
|
|
|
HDprintf("File created.\n");
|
2020-03-14 06:13:17 +08:00
|
|
|
}
|
2020-04-21 07:12:00 +08:00
|
|
|
/* Close FAPL to prevent issues with forking later */
|
2020-03-14 06:13:17 +08:00
|
|
|
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 */
|
|
|
|
/* ============ */
|
|
|
|
if (UC_opts.launch == UC_READWRITE) {
|
|
|
|
if ((childpid = HDfork()) < 0) {
|
2018-11-02 01:03:34 +08:00
|
|
|
HDperror("fork");
|
|
|
|
Hgoto_error(1);
|
2020-03-14 06:13:17 +08:00
|
|
|
}
|
|
|
|
}
|
2017-02-20 10:28:52 +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
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
if ((fapl = h5_fileaccess()) < 0) {
|
|
|
|
HDfprintf(stderr, "can't create 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 write\n");
|
|
|
|
Hgoto_error(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (H5Pclose(fapl) < 0) {
|
|
|
|
HDfprintf(stderr, "can't close write FAPL\n");
|
|
|
|
Hgoto_error(1);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
if ((tmppid = HDwaitpid(childpid, &child_status, child_wait_option)) < 0) {
|
2018-10-31 05:53:09 +08:00
|
|
|
HDperror("waitpid");
|
|
|
|
Hgoto_error(1);
|
|
|
|
}
|
|
|
|
|
2020-03-14 06:13:17 +08:00
|
|
|
if (WIFEXITED(child_status)) {
|
|
|
|
if ((child_ret_value = WEXITSTATUS(child_status)) != 0) {
|
2020-09-30 22:27:10 +08:00
|
|
|
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(2);
|
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
else {
|
2020-03-14 06:13:17 +08:00
|
|
|
HDprintf("%d: child process terminated abnormally\n", mypid);
|
|
|
|
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);
|
2017-01-27 03:34:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-08 12:29:25 +08:00
|
|
|
#else /* defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID) */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
HDfprintf(stderr, "Non-POSIX platform. Skipping.\n");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
} /* end main() */
|
|
|
|
|
2022-01-08 12:29:25 +08:00
|
|
|
#endif /* defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID) */
|