2018-05-05 00:01:54 +08:00
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2018-05-05 05:16:56 +08:00
|
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
|
* All rights reserved. *
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2018-05-05 00:01:54 +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. *
|
2018-05-05 05:16:56 +08:00
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
|
|
|
|
#include "h5hltest.h"
|
|
|
|
|
#include "H5DOpublic.h"
|
|
|
|
|
|
2018-05-05 05:16:56 +08:00
|
|
|
|
/* This test is a minimal test to ensure that the H5DO compatibility wrappers
|
|
|
|
|
* work correctly.
|
2018-05-05 00:01:54 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2018-05-05 07:43:06 +08:00
|
|
|
|
#ifndef H5_NO_DEPRECATED_SYMBOLS
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
#define FILE_NAME "h5do_compat.h5"
|
|
|
|
|
#define DATASET_NAME "direct_chunk_io"
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
#define NX 8
|
|
|
|
|
#define CHUNK_NX 4
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
|
2018-05-05 00:01:54 +08:00
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_direct_chunk_write
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Test the basic functionality of H5DOwrite_chunk
|
|
|
|
|
*
|
2018-05-05 05:13:56 +08:00
|
|
|
|
* Return: Success: An identifer for the dataset used in the tests
|
|
|
|
|
* Failure: H5I_INVALID_HID
|
2018-05-05 00:01:54 +08:00
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2018-05-05 05:13:56 +08:00
|
|
|
|
static hid_t
|
|
|
|
|
create_dataset(hid_t fid)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
{
|
2018-05-05 05:13:56 +08:00
|
|
|
|
hid_t did = H5I_INVALID_HID;
|
|
|
|
|
hid_t sid = H5I_INVALID_HID;
|
|
|
|
|
hid_t dcpl_id = H5I_INVALID_HID;
|
|
|
|
|
hsize_t dims[1] = {NX};
|
|
|
|
|
hsize_t maxdims[1] = {H5S_UNLIMITED};
|
|
|
|
|
hsize_t chunk_dims[1] = {CHUNK_NX};
|
|
|
|
|
int data[NX];
|
|
|
|
|
int i;
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
/* Create a dataspace for the new dataset */
|
|
|
|
|
if ((sid = H5Screate_simple(1, dims, maxdims)) < 0)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
goto error;
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
/* Set up dataset creation parameters */
|
|
|
|
|
if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
goto error;
|
2018-05-05 05:13:56 +08:00
|
|
|
|
if (H5Pset_chunk(dcpl_id, 1, chunk_dims) < 0)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
goto error;
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
/* Create a new dataset */
|
|
|
|
|
if ((did = H5Dcreate2(fid, DATASET_NAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
goto error;
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
/* Initialize the data */
|
|
|
|
|
for (i = 0; i < NX; i++)
|
|
|
|
|
data[i] = i;
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
/* Write the initialized data */
|
|
|
|
|
if (H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
goto error;
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
/* Close everything */
|
|
|
|
|
if (H5Sclose(sid) < 0)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
goto error;
|
2018-05-05 05:13:56 +08:00
|
|
|
|
if (H5Pclose(dcpl_id) < 0)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
goto error;
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
return did;
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
error:
|
2018-05-05 00:01:54 +08:00
|
|
|
|
H5E_BEGIN_TRY {
|
2018-05-05 05:13:56 +08:00
|
|
|
|
H5Dclose(did);
|
|
|
|
|
H5Sclose(sid);
|
|
|
|
|
H5Pclose(dcpl_id);
|
2018-05-05 00:01:54 +08:00
|
|
|
|
} H5E_END_TRY;
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
return H5I_INVALID_HID;
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
} /* end create_dataset() */
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
|
2018-05-05 00:01:54 +08:00
|
|
|
|
/*-------------------------------------------------------------------------
|
2018-05-05 05:13:56 +08:00
|
|
|
|
* Function: test_direct_chunk_write
|
2018-05-05 00:01:54 +08:00
|
|
|
|
*
|
2018-05-05 05:13:56 +08:00
|
|
|
|
* Purpose: Test the basic functionality of H5DOwrite_chunk
|
2018-05-05 00:01:54 +08:00
|
|
|
|
*
|
2018-05-05 05:13:56 +08:00
|
|
|
|
* Return: Success: 0
|
|
|
|
|
* Failure: 1
|
2018-05-05 00:01:54 +08:00
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2018-05-05 05:13:56 +08:00
|
|
|
|
test_direct_chunk_write(hid_t did)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned filter_mask = 0;
|
2018-05-05 05:13:56 +08:00
|
|
|
|
int chunk_data[CHUNK_NX];
|
|
|
|
|
hsize_t offset[1];
|
|
|
|
|
size_t data_size;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
TESTING("H5DOwrite_chunk wrapper");
|
|
|
|
|
|
|
|
|
|
/* Set the size of the chunk data */
|
|
|
|
|
data_size = CHUNK_NX * sizeof(int);
|
|
|
|
|
|
|
|
|
|
/* Initialize the chunk data */
|
|
|
|
|
for (i = 0; i < CHUNK_NX; i++)
|
|
|
|
|
chunk_data[i] = (i * 10) + i;
|
|
|
|
|
|
|
|
|
|
/* Write the direct chunk data repeatedly to cover all the chunks in the
|
|
|
|
|
* dataset, using the direct writing function.
|
|
|
|
|
*/
|
|
|
|
|
offset[0] = 0;
|
|
|
|
|
for (i = 0; i < NX/CHUNK_NX; i++) {
|
|
|
|
|
if (H5DOwrite_chunk(did, H5P_DEFAULT, filter_mask, offset, data_size, chunk_data) < 0)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
offset[0] += CHUNK_NX;
|
2018-05-05 00:01:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PASSED();
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
H5_FAILED();
|
|
|
|
|
return 1;
|
2018-05-05 05:13:56 +08:00
|
|
|
|
} /* test_direct_chunk_write() */
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
|
2018-05-05 00:01:54 +08:00
|
|
|
|
/*-------------------------------------------------------------------------
|
2018-05-05 05:13:56 +08:00
|
|
|
|
* Function: test_direct_chunk_read
|
2018-05-05 00:01:54 +08:00
|
|
|
|
*
|
2018-05-05 05:13:56 +08:00
|
|
|
|
* Purpose: Test the basic functionality of H5DOread_chunk
|
2018-05-05 00:01:54 +08:00
|
|
|
|
*
|
2018-05-05 05:13:56 +08:00
|
|
|
|
* Return: Success: 0
|
|
|
|
|
* Failure: 1
|
2018-05-05 00:01:54 +08:00
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2018-05-05 05:13:56 +08:00
|
|
|
|
test_direct_chunk_read(hid_t did)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
{
|
2018-05-05 05:13:56 +08:00
|
|
|
|
hid_t mem_sid = H5I_INVALID_HID;
|
|
|
|
|
hid_t file_sid = H5I_INVALID_HID;
|
|
|
|
|
hsize_t dims[1] = {NX};
|
|
|
|
|
hsize_t chunk_dims[1] = {CHUNK_NX};
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
unsigned filter_mask;
|
|
|
|
|
int chunk_data[CHUNK_NX]; /* Chunk read with H5DOread_chunk */
|
|
|
|
|
int check[CHUNK_NX]; /* Chunk read with H5Dread */
|
|
|
|
|
hsize_t offset[1];
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
hsize_t start[1]; /* Start of hyperslab */
|
|
|
|
|
hsize_t stride[1]; /* Stride of hyperslab */
|
|
|
|
|
hsize_t count[1]; /* Block count */
|
|
|
|
|
hsize_t block[1]; /* Block sizes */
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
int i,j;
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
TESTING("H5DOread_chunk wrapper");
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
/* Create dataspaces for reading */
|
|
|
|
|
if ((mem_sid = H5Screate_simple(1, chunk_dims, NULL)) < 0)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
if ((file_sid = H5Screate_simple(1, dims, NULL)) < 0)
|
|
|
|
|
TEST_ERROR
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
/* For each chunk in the dataset, compare the result of H5Dread and H5DOread_chunk. */
|
|
|
|
|
for (i = 0; i < NX/CHUNK_NX; i++) {
|
|
|
|
|
|
|
|
|
|
/* Select hyperslab for one chunk in the file */
|
|
|
|
|
start[0] = (hsize_t)i * CHUNK_NX;
|
|
|
|
|
stride[0] = 1;
|
|
|
|
|
count[0] = 1;
|
|
|
|
|
block[0] = CHUNK_NX;
|
|
|
|
|
|
|
|
|
|
/* Hyperslab selection equals single chunk */
|
|
|
|
|
if (H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, stride, count, block) < 0)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Read the chunk back */
|
|
|
|
|
if (H5Dread(did, H5T_NATIVE_INT, mem_sid, file_sid, H5P_DEFAULT, check) < 0)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Read the raw chunk back */
|
|
|
|
|
HDmemset(chunk_data, 0, CHUNK_NX * sizeof(int));
|
|
|
|
|
filter_mask = UINT_MAX;
|
|
|
|
|
offset[0] = (hsize_t)i * CHUNK_NX;
|
|
|
|
|
if (H5DOread_chunk(did, H5P_DEFAULT, offset, &filter_mask, chunk_data) < 0)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check filter mask return value */
|
|
|
|
|
if (filter_mask != 0)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check that the values are correct */
|
|
|
|
|
for (j = 0; j < CHUNK_NX; j++)
|
|
|
|
|
if (chunk_data[i] != check[i])
|
|
|
|
|
TEST_ERROR
|
2018-05-05 00:01:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
/* Close */
|
|
|
|
|
if (H5Sclose(mem_sid) < 0)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
if (H5Sclose(file_sid) < 0)
|
|
|
|
|
TEST_ERROR
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
|
|
|
|
PASSED();
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
2018-05-05 05:13:56 +08:00
|
|
|
|
H5Sclose(mem_sid);
|
|
|
|
|
H5Sclose(file_sid);
|
2018-05-05 00:01:54 +08:00
|
|
|
|
} H5E_END_TRY;
|
|
|
|
|
|
|
|
|
|
H5_FAILED();
|
|
|
|
|
return 1;
|
2018-05-05 05:13:56 +08:00
|
|
|
|
} /* test_direct_chunk_read() */
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 07:43:06 +08:00
|
|
|
|
#endif /* H5_NO_DEPRECATED_SYMBOLS */
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
|
2018-05-05 00:01:54 +08:00
|
|
|
|
/*-------------------------------------------------------------------------
|
2018-05-05 07:43:06 +08:00
|
|
|
|
* Function: main
|
2018-05-05 00:01:54 +08:00
|
|
|
|
*
|
2018-05-05 05:13:56 +08:00
|
|
|
|
* Purpose: Test direct chunk write function H5DOwrite_chunk and
|
|
|
|
|
* chunk direct read function H5DOread_chunk
|
2018-05-05 00:01:54 +08:00
|
|
|
|
*
|
2018-05-05 05:13:56 +08:00
|
|
|
|
* Return: Success: 0
|
|
|
|
|
* Failure: 1
|
2018-05-05 00:01:54 +08:00
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2018-05-05 05:13:56 +08:00
|
|
|
|
int main( void )
|
2018-05-05 00:01:54 +08:00
|
|
|
|
{
|
2018-05-05 07:43:06 +08:00
|
|
|
|
#ifdef H5_NO_DEPRECATED_SYMBOLS
|
|
|
|
|
|
|
|
|
|
HDputs("Direct chunk read/write wrapper tests SKIPPED.");
|
|
|
|
|
HDputs("(Backward compatibility not configured)");
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
hid_t fid = H5I_INVALID_HID;
|
|
|
|
|
hid_t did = H5I_INVALID_HID;
|
|
|
|
|
int nerrors = 0;
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
if ((fid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
goto error;
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
if ((did = create_dataset(fid)) < 0)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
goto error;
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
nerrors += test_direct_chunk_write(did);
|
|
|
|
|
nerrors += test_direct_chunk_read(did);
|
2018-05-05 00:01:54 +08:00
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
if (H5Dclose(did) < 0)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
goto error;
|
2018-05-05 05:13:56 +08:00
|
|
|
|
if (H5Fclose(fid) < 0)
|
2018-05-05 00:01:54 +08:00
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
/* check for errors */
|
|
|
|
|
if (nerrors)
|
|
|
|
|
goto error;
|
|
|
|
|
|
2018-05-05 05:13:56 +08:00
|
|
|
|
HDputs("All direct chunk read/write wrapper tests passed.");
|
2018-05-05 00:01:54 +08:00
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
HDputs("*** TESTS FAILED ***");
|
|
|
|
|
return EXIT_FAILURE;
|
2018-05-05 07:43:06 +08:00
|
|
|
|
#endif /* H5_NO_DEPRECATED_SYMBOLS */
|
2018-05-05 05:13:56 +08:00
|
|
|
|
} /* end main() */
|