Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 51 additions & 8 deletions BITGROOM/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ foreach (example ${dyn_examples})
endif ()
endforeach ()

# h5repack test input generator. Target name is plugin-suffixed because the
# BITROUND and BITGROOM trees share the same CMake project and source file
# basename (issue #240).
add_executable (h5repack_floats_bitgroom ${PROJECT_SOURCE_DIR}/h5repack_floats.c)
TARGET_C_PROPERTIES (h5repack_floats_bitgroom ${LIB_TYPE})
target_link_libraries (h5repack_floats_bitgroom PRIVATE ${H5PL_HDF5_LINK_LIBS})
if (NOT WIN32)
target_link_libraries (h5repack_floats_bitgroom PRIVATE dl)
endif ()

if (H5PL_BUILD_TESTING)
macro (ADD_H5_TEST testname)
add_test (
Expand Down Expand Up @@ -126,6 +136,7 @@ if (H5PL_BUILD_TESTING)
NAME H5BITGROOM_UD-${testname}-clearall-objects
COMMAND ${CMAKE_COMMAND}
-E remove
${resultfile}
out-${testname}.${resultfile}
${testname}.${resultfile}.out
${testname}.${resultfile}.out.err
Expand All @@ -136,6 +147,18 @@ if (H5PL_BUILD_TESTING)
set_tests_properties (H5BITGROOM_UD-${testname}-clearall-objects PROPERTIES DEPENDS ${last_test})
endif ()
set (last_test "H5BITGROOM_UD-${testname}-clearall-objects")
# Generate the float-data input file for h5repack. The BitGroom filter's
# set_local() callback removes the filter from the pipeline on non-float
# datasets, so the input must contain float data for the test to actually
# exercise the filter (issue #240).
add_test (
NAME H5BITGROOM_UD-${testname}-gen-input
COMMAND $<TARGET_FILE:h5repack_floats_bitgroom>
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
set_tests_properties (H5BITGROOM_UD-${testname}-gen-input PROPERTIES
DEPENDS H5BITGROOM_UD-${testname}-clearall-objects)
set (last_test "H5BITGROOM_UD-${testname}-gen-input")
if (WIN32)
set (${TESTLIBDIR} "${HDF5_TOOLS_DIR}")
else ()
Expand All @@ -159,7 +182,7 @@ if (H5PL_BUILD_TESTING)
)
set_tests_properties (H5BITGROOM_UD-${testname} PROPERTIES
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
DEPENDS H5BITGROOM_UD-${testname}-clearall-objects)
DEPENDS H5BITGROOM_UD-${testname}-gen-input)
add_test (
NAME H5BITGROOM_UD-h5dump-${testname}
COMMAND "${CMAKE_COMMAND}"
Expand All @@ -178,23 +201,43 @@ if (H5PL_BUILD_TESTING)
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
DEPENDS H5BITGROOM_UD-${testname})
set (last_test "H5BITGROOM_UD-h5dump-${testname}")
# Verify that the filter actually modifies the dataset values: dump the
# data (no -pH) and compare against a captured reference of the
# quantized output. If the filter were silently removed from the
# pipeline, the values would match the raw input and this would fail.
add_test (
NAME H5BITGROOM_UD-h5dump-data-${testname}
COMMAND "${CMAKE_COMMAND}"
-D "TEST_PROGRAM=${H5PL_HDF5_DUMP_EXECUTABLE}"
-D "TEST_ARGS:STRING=out-${testname}.${resultfile}"
-D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
-D "TEST_OUTPUT=${resultfile}-${testname}-data.out"
-D "TEST_EXPECT=${resultcode}"
-D "TEST_REFERENCE=${resultfile}-${testname}-data.ddl"
-D "TEST_LIBRARY_DIRECTORY=${TESTLIBDIR}"
-D "TEST_ENV_VAR=HDF5_PLUGIN_PATH"
-D "TEST_ENV_VALUE=${CMAKE_BINARY_DIR}/plugins"
-P "${H5BITGROOM_RESOURCES_DIR}/runTest.cmake"
)
set_tests_properties (H5BITGROOM_UD-h5dump-data-${testname} PROPERTIES
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
DEPENDS H5BITGROOM_UD-h5dump-${testname})
set (last_test "H5BITGROOM_UD-h5dump-data-${testname}")
endif ()
endmacro ()

# --------------------------------------------------------------------
# Copy all the HDF5 files from the source directory into the test directory
# --------------------------------------------------------------------
set (LIST_HDF5_TEST_FILES
h5repack_layout.h5
)
set (LIST_OTHER_TEST_FILES
h5ex_d_bitgroom.ddl
h5ex_d_bitgroom.tst
h5repack_layout.h5-ud_convert.ddl
ud_convert.h5repack_layout.h5.tst
h5repack_floats.h5-ud_convert.ddl
h5repack_floats.h5-ud_convert-data.ddl
ud_convert.h5repack_floats.h5.tst
)

foreach (h5_file ${LIST_HDF5_TEST_FILES} ${LIST_OTHER_TEST_FILES})
foreach (h5_file ${LIST_OTHER_TEST_FILES})
HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/testfiles/${h5_file}" "${PROJECT_BINARY_DIR}/${h5_file}" "bitgroom_files")
endforeach ()
add_custom_target(bitgroom_files ALL COMMENT "Copying files needed by bitgroom tests" DEPENDS ${bitgroom_files_list})
Expand All @@ -203,7 +246,7 @@ if (H5PL_BUILD_TESTING)

if (NOT DISABLE_H5BITGROOM_ENCODER)
#UD BITGROOM
ADD_H5_UD_TEST (ud_convert 0 h5repack_layout.h5 --enable-error-stack -v -f UD=32022,0,5,3,4,0,0,0 -l CHUNK=4x8)
ADD_H5_UD_TEST (ud_convert 0 h5repack_floats.h5 --enable-error-stack -v -f UD=32022,0,5,3,4,0,0,0 -l CHUNK=4x8)
endif ()

endif ()
87 changes: 87 additions & 0 deletions BITGROOM/example/h5repack_floats.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of the HDF5 BitGroom filter plugin source. The full *
* copyright notice, including terms governing use, modification, and *
* redistribution, is contained in the file COPYING, which can be found at *
* the root of the source code distribution tree. If you do not have access *
* to this file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
* Generates an HDF5 file with a chunked dataset of IEEE 32-bit floats and no
* filters applied. Used as input for the h5repack BitGroom test so the
* filter's set_local() callback retains the filter in the pipeline (the
* callback removes itself on non-float data). See issue #240.
*/

#include "hdf5.h"
#include <stdio.h>

#define FILENAME "h5repack_floats.h5"
#define DATASET "data"
#define DIM0 32
#define DIM1 64
#define CHUNK0 4
#define CHUNK1 8

int
main(void)
{
hid_t file_id = H5I_INVALID_HID;
hid_t space_id = H5I_INVALID_HID;
hid_t dcpl_id = H5I_INVALID_HID;
hid_t dset_id = H5I_INVALID_HID;
hsize_t dims[2] = {DIM0, DIM1};
hsize_t chunk[2] = {CHUNK0, CHUNK1};
float wdata[DIM0][DIM1];
int i, j;
int ret_value = 1;

/* Non-integer floats: the 0.137f multiplier ensures every value carries
* non-trivial mantissa bits, so quantization by BitGroom is visible
* across the entire dataset rather than only on values that exceed the
* retained mantissa width. */
for (i = 0; i < DIM0; i++)
for (j = 0; j < DIM1; j++)
wdata[i][j] = ((float)(i * j) - (float)j) * 0.137f;

file_id = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
if (file_id < 0)
goto done;

space_id = H5Screate_simple(2, dims, NULL);
if (space_id < 0)
goto done;

dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
if (dcpl_id < 0)
goto done;
if (H5Pset_chunk(dcpl_id, 2, chunk) < 0)
goto done;

dset_id = H5Dcreate(file_id, DATASET, H5T_IEEE_F32LE, space_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
if (dset_id < 0)
goto done;

if (H5Dwrite(dset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, (void *)wdata) < 0)
goto done;

ret_value = 0;

done:
if (dset_id >= 0)
H5Dclose(dset_id);
if (dcpl_id >= 0)
H5Pclose(dcpl_id);
if (space_id >= 0)
H5Sclose(space_id);
if (file_id >= 0)
H5Fclose(file_id);

if (ret_value != 0)
fprintf(stderr, "h5repack_floats: failed to create %s\n", FILENAME);

return ret_value;
}
Loading
Loading