Skip to content

Commit

Permalink
testing for relay io handle offset, stride and size (#760)
Browse files Browse the repository at this point in the history
* tests for relay io hnd offset, string, size, tweaks to error messages

* bugfix: avoid dup ref path in relay io hdf5 error messages
  • Loading branch information
cyrush committed May 13, 2021
1 parent b781b7c commit b76c5a4
Show file tree
Hide file tree
Showing 5 changed files with 369 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -33,6 +33,9 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s
- Fixed missing implementation of DataType::is_index_t
- Fixed issue with compiling t_h5z_zfp_smoke.cpp against an MPI-enabled HDF5.

#### Blueprint
- Fixed a bug that caused HDF5 reference paths to appear twice in Relay HDF5 Error messages.

#### Blueprint
- `conduit::relay::io::blueprint.read_mesh` now uses read only I/O handles.

Expand Down
3 changes: 1 addition & 2 deletions src/libs/relay/conduit_relay_io_handle.cpp
Expand Up @@ -711,7 +711,6 @@ void
HDF5Handle::write(const Node &node,
const Node &opts)
{
CONDUIT_UNUSED(opts);
// note: wrong mode errors are handled before dispatch to interface

// Options Push / Pop (only needed for write, since hdf5 only supports
Expand All @@ -723,7 +722,7 @@ HDF5Handle::write(const Node &node,
hdf5_set_options(options()["hdf5"]);
}

hdf5_write(node,m_h5_id);
hdf5_write(node,m_h5_id, opts);

if(!prev_options.dtype().is_empty())
{
Expand Down
69 changes: 50 additions & 19 deletions src/libs/relay/conduit_relay_io_hdf5.cpp
Expand Up @@ -38,17 +38,17 @@
//-----------------------------------------------------------------------------
#define CONDUIT_HDF5_ERROR( ref_path, msg ) \
{ \
CONDUIT_ERROR( "HDF5 Error (reference path: \"" << ref_path \
<< ref_path << "\") " << msg); \
CONDUIT_ERROR( "HDF5 Error (reference path: \"" << ref_path << "\") " \
<< msg); \
}

//-----------------------------------------------------------------------------
/// The CONDUIT_HDF5_WARN macro is used for warnings with ref paths.
//-----------------------------------------------------------------------------
#define CONDUIT_HDF5_WARN( ref_path, msg ) \
{ \
CONDUIT_WARN( "HDF5 Warning (reference path: \"" << ref_path \
<< ref_path << "\") " << msg); \
#define CONDUIT_HDF5_WARN( ref_path, msg ) \
{ \
CONDUIT_WARN( "HDF5 Warning (reference path: \"" << ref_path << "\") " \
<< msg); \
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1853,7 +1853,7 @@ setup_hdf5_group_atts_for_conduit_node(const Node &node,

if( has_list_attr && node.dtype().is_object() )
{
std::cout << " remove_conduit_hdf5_list_attribute " << std::endl;
// std::cout << " remove_conduit_hdf5_list_attribute " << std::endl;
remove_conduit_hdf5_list_attribute(hdf5_group_id,
ref_path);
}
Expand Down Expand Up @@ -2256,9 +2256,12 @@ h5l_iterate_traverse_op_func(hid_t hdf5_id,
<< " parent: " << hdf5_id
<< " path:" << hdf5_path) ;

std::string chld_ref_path = h5_od->ref_path +
std::string("/") +
std::string(hdf5_path);
std::string chld_ref_path = h5_od->ref_path;
if(chld_ref_path != std::string("/"))
{
chld_ref_path += std::string("/");
}
chld_ref_path += std::string(hdf5_path);

switch (h5_info_buf.type)
{
Expand Down Expand Up @@ -2507,11 +2510,17 @@ read_hdf5_dataset_into_conduit_node(hid_t hdf5_dset_id,

if (offset < 0)
{
CONDUIT_ERROR("Offset must be non-negative.");
CONDUIT_HDF5_ERROR(ref_path,
"Error reading HDF5 Dataset with options:"
<< opts.to_yaml() <<
"`offset` must be non-negative.");
}
else if (stride < 1)
{
CONDUIT_ERROR("Stride must be greater than zero.");
CONDUIT_HDF5_ERROR(ref_path,
"Error reading HDF5 Dataset with options:"
<< opts.to_yaml() <<
"`stride` must be greater than zero.");
}

// get the number of elements in the dataset given the offset and stride
Expand All @@ -2527,7 +2536,10 @@ read_hdf5_dataset_into_conduit_node(hid_t hdf5_dset_id,
nelems_to_read = opts["size"].to_value();
if (nelems_to_read < 1)
{
CONDUIT_ERROR("Size must be greater than zero.");
CONDUIT_HDF5_ERROR(ref_path,
"Error reading HDF5 Dataset with options:"
<< opts.to_yaml() <<
"`size` must be greater than zero.");
}
}

Expand Down Expand Up @@ -2614,7 +2626,11 @@ read_hdf5_dataset_into_conduit_node(hid_t hdf5_dset_id,
else if( dt.number_of_elements() < 0 )
{
CONDUIT_HDF5_ERROR(ref_path,
"Cannot read dataset with # of elements < 0");
"Error reading HDF5 Dataset with options:"
<< opts.to_yaml()
<< "Cannot read using offset (" << offset << ")"
<< " greater than the number of entries in"
<< " the HDF5 dataset (" << nelems << ")");
}
else if(dest.dtype().is_compact() &&
dest.dtype().compatible(dt) )
Expand Down Expand Up @@ -2651,11 +2667,26 @@ read_hdf5_dataset_into_conduit_node(hid_t hdf5_dset_id,
H5Dclose(dataspace);
}

CONDUIT_CHECK_HDF5_ERROR_WITH_FILE_AND_REF_PATH(h5_status,
hdf5_dset_id,
ref_path,
"Error reading HDF5 Dataset: "
<< hdf5_dset_id);
if(opts.dtype().is_empty())
{
CONDUIT_CHECK_HDF5_ERROR_WITH_FILE_AND_REF_PATH(h5_status,
hdf5_dset_id,
ref_path,
"Error reading HDF5 Dataset: "
<< hdf5_dset_id);
}
else
{
CONDUIT_CHECK_HDF5_ERROR_WITH_FILE_AND_REF_PATH(h5_status,
hdf5_dset_id,
ref_path,
"Error reading HDF5 Dataset: "
<< hdf5_dset_id
<< " with options: "
<< opts.to_yaml()
<< "HDF5 dataset size: "
<< nelems);
}

CONDUIT_CHECK_HDF5_ERROR_WITH_FILE_AND_REF_PATH(H5Tclose(h5_dtype_id),
hdf5_dset_id,
Expand Down

0 comments on commit b76c5a4

Please sign in to comment.