hdf5/test/accum_swmr_reader.c

120 lines
4.2 KiB
C
Raw Normal View History

2016-12-18 16:42:15 +08:00
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
2016-12-18 16:42:15 +08:00
* 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://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
2016-12-18 16:42:15 +08:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "h5test.h"
2020-09-30 22:27:10 +08:00
#define H5F_FRIEND /*suppress error about including H5Fpkg */
#define H5FD_FRIEND /*suppress error about including H5FDpkg */
2016-12-18 16:42:15 +08:00
#define H5FD_TESTING
#include "H5Fpkg.h"
#include "H5FDpkg.h"
2020-09-30 22:27:10 +08:00
#include "H5CXprivate.h" /* API Contexts */
2016-12-18 16:42:15 +08:00
#include "H5Iprivate.h"
2020-09-30 22:27:10 +08:00
#include "H5VLprivate.h" /* Virtual Object Layer */
2016-12-18 16:42:15 +08:00
/* Filename: this is the same as the define in accum.c used by test_swmr_write_big() */
static const char *FILENAME[] = {"accum", "accum_swmr_big", NULL};
2016-12-18 16:42:15 +08:00
/*-------------------------------------------------------------------------
* Function: main
2020-04-21 07:12:00 +08:00
*
* Purpose: This is the reader forked/execved by "test_swmr_write_big()"
2016-12-18 16:42:15 +08:00
* test in accum.c. The reader reads at address 1024 from the file
* and verifies that the metadata in the accumulator at address
* 1024 does get written to disk.
2020-04-21 07:12:00 +08:00
*
2016-12-18 16:42:15 +08:00
* Return: Success: EXIT_SUCCESS
* Failure: EXIT_FAILURE
*-------------------------------------------------------------------------
*/
int
main(void)
{
const char *driver_name = NULL; /* VFD string (from env variable) */
hid_t fid = H5I_INVALID_HID; /* File ID */
hid_t fapl = H5I_INVALID_HID; /* file access property list ID */
H5F_t *f = NULL; /* File pointer */
char filename[1024];
unsigned u; /* Local index variable */
uint8_t rbuf[1024]; /* Buffer for reading */
uint8_t buf[1024]; /* Buffer for holding the expected data */
bool api_ctx_pushed = false; /* Whether API context pushed */
2016-12-18 16:42:15 +08:00
/* Testing setup */
h5_reset();
2016-12-18 16:42:15 +08:00
/* Skip this test if SWMR I/O is not supported for the VFD specified
* by the environment variable.
*/
driver_name = h5_get_test_driver_name();
if (!H5FD__supports_swmr_test(driver_name))
2016-12-18 16:42:15 +08:00
return EXIT_SUCCESS;
/* Initialize buffers */
2020-09-30 22:27:10 +08:00
for (u = 0; u < 1024; u++) {
rbuf[u] = 0; /* The buffer for reading */
buf[u] = 1; /* The expected data should be all 1s */
2016-12-18 16:42:15 +08:00
}
2020-09-30 22:27:10 +08:00
if ((fapl = h5_fileaccess()) < 0)
FAIL_STACK_ERROR;
h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
2016-12-18 16:42:15 +08:00
/* Open the file with SWMR_READ */
2020-09-30 22:27:10 +08:00
if ((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
FAIL_STACK_ERROR;
2018-03-19 11:51:19 +08:00
/* Push API context */
2020-09-30 22:27:10 +08:00
if (H5CX_push() < 0)
FAIL_STACK_ERROR;
api_ctx_pushed = true;
2016-12-18 16:42:15 +08:00
/* Get H5F_t * to internal file structure */
2020-09-30 22:27:10 +08:00
if (NULL == (f = (H5F_t *)H5VL_object(fid)))
FAIL_STACK_ERROR;
2016-12-18 16:42:15 +08:00
/* Should read in [1024, 2024] with buf data */
2020-09-30 22:27:10 +08:00
if (H5F_block_read(f, H5FD_MEM_DEFAULT, (haddr_t)1024, (size_t)1024, rbuf) < 0)
FAIL_STACK_ERROR;
2016-12-18 16:42:15 +08:00
/* Verify the data read is correct */
2023-06-30 03:33:46 +08:00
if (memcmp(buf, rbuf, (size_t)1024) != 0)
TEST_ERROR;
2016-12-18 16:42:15 +08:00
/* CLose the file */
2020-09-30 22:27:10 +08:00
if (H5Pclose(fapl) < 0)
FAIL_STACK_ERROR;
2020-09-30 22:27:10 +08:00
if (H5Fclose(fid) < 0)
FAIL_STACK_ERROR;
2018-03-19 11:51:19 +08:00
/* Pop API context */
if (api_ctx_pushed && H5CX_pop(false) < 0)
FAIL_STACK_ERROR;
api_ctx_pushed = false;
2016-12-18 16:42:15 +08:00
return EXIT_SUCCESS;
error:
2020-09-30 22:27:10 +08:00
H5E_BEGIN_TRY
{
H5Pclose(fapl);
H5Fclose(fid);
2020-09-30 22:27:10 +08:00
}
H5E_END_TRY
2018-03-19 11:51:19 +08:00
2020-09-30 22:27:10 +08:00
if (api_ctx_pushed)
H5CX_pop(false);
2018-03-19 11:51:19 +08:00
2016-12-18 16:42:15 +08:00
return EXIT_FAILURE;
} /* end main() */