Skip to content

Commit 0d14ea0

Browse files
authored
Test BitGroom/BitRound h5repack with float data (#245)
* Test BitGroom/BitRound h5repack with float data (#240) * Replace log10()/floor() in BitRound filter with deterministic table ccr_gbr() called log10()+floor() per value to decide how many mantissa bits to zero, but log10() differences (~1 ULP, allowed by the C standard) at floor() integer boundaries produce 1-bit-different stored output on different platforms (as indicated by tests using macOS BSD libm and Linux glibc). * Fix Windows DLL load error for h5repack_floats gen-input fixtures The h5repack_floats_bit{groom,round} helpers were invoked directly with add_test(COMMAND $<TARGET_FILE:...>); on Windows the loader could not find the HDF5 DLL and reported STATUS_DLL_NOT_FOUND, cascading into gen-input/ud_convert/h5dump test failures. Route the fixture through runTest.cmake so PATH/DYLD_LIBRARY_PATH/LD_LIBRARY_PATH are set up consistently across platforms. * Mirror example/ testfile changes into binex trees Create equivalent of the test files under BITGROOM/example/ and BITROUND/example/ in three "binex" mirror trees that test the plugins as if installed from a binary distribution.
1 parent c74b1e4 commit 0d14ea0

34 files changed

Lines changed: 2051 additions & 799 deletions

BITGROOM/config/cmake/binex/example/CMakeLists.txt

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ foreach (example ${dyn_examples})
3434
endforeach ()
3535

3636
if (H5PL_BUILD_TESTING)
37+
# h5repack test input generator. Target name is plugin-suffixed because the
38+
# BITROUND and BITGROOM trees share the same CMake project and source file
39+
# basename (issue #240).
40+
add_executable (h5repack_floats_bitgroom ${PROJECT_SOURCE_DIR}/h5repack_floats.c)
41+
target_include_directories(h5repack_floats_bitgroom PRIVATE ${H5PL_HDF5_INCLUDE_DIRS})
42+
TARGET_C_PROPERTIES (h5repack_floats_bitgroom ${LIB_TYPE})
43+
target_link_libraries (h5repack_floats_bitgroom PRIVATE ${H5PL_HDF5_LINK_LIBS})
44+
if (NOT WIN32)
45+
target_link_libraries (h5repack_floats_bitgroom PRIVATE ${CMAKE_DL_LIBS})
46+
endif ()
47+
3748
macro (ADD_H5_TEST testname)
3849
add_test (
3950
NAME ${testname}-clearall
@@ -121,21 +132,47 @@ if (H5PL_BUILD_TESTING)
121132
NAME H5BITGROOM_UD-${testname}-clearall-objects
122133
COMMAND ${CMAKE_COMMAND}
123134
-E remove
135+
${resultfile}
124136
out-${testname}.${resultfile}
125137
${testname}.${resultfile}.out
126138
${testname}.${resultfile}.out.err
127139
${resultfile}-${testname}.out
128140
${resultfile}-${testname}.out.err
141+
${resultfile}-${testname}-data.out
142+
${resultfile}-${testname}-data.out.err
129143
)
130144
if (NOT "${last_test}" STREQUAL "")
131145
set_tests_properties (H5BITGROOM_UD-${testname}-clearall-objects PROPERTIES DEPENDS ${last_test})
132146
endif ()
133147
set (last_test "H5BITGROOM_UD-${testname}-clearall-objects")
134148
if (WIN32)
135-
set (${TESTLIBDIR} "${HDF5_TOOLS_DIR}")
149+
set (TESTLIBDIR "${HDF5_TOOLS_DIR}")
136150
else ()
137-
set (${TESTLIBDIR} "${HDF5_LIBRARY_PATH}")
151+
set (TESTLIBDIR "${HDF5_LIBRARY_PATH}")
138152
endif ()
153+
# Generate the float-data input file for h5repack. The BitGroom filter's
154+
# set_local() callback removes the filter from the pipeline on non-float
155+
# datasets, so the input must contain float data for the test to actually
156+
# exercise the filter (issue #240). Routed through runTest.cmake so
157+
# PATH/DYLD_LIBRARY_PATH/LD_LIBRARY_PATH are set up for the helper to find
158+
# the HDF5 runtime library on every platform (Windows in particular has
159+
# no rpath equivalent and reports STATUS_DLL_NOT_FOUND if the HDF5 DLL is
160+
# not on PATH).
161+
add_test (
162+
NAME H5BITGROOM_UD-${testname}-gen-input
163+
COMMAND "${CMAKE_COMMAND}"
164+
-D "TEST_PROGRAM=$<TARGET_FILE:h5repack_floats_bitgroom>"
165+
-D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
166+
-D "TEST_EXPECT=0"
167+
-D "TEST_OUTPUT=h5repack_floats_bitgroom.out"
168+
-D "TEST_SKIP_COMPARE=1"
169+
-D "TEST_LIBRARY_DIRECTORY=${TESTLIBDIR}"
170+
-P "${H5PL_RESOURCES_DIR}/runTest.cmake"
171+
)
172+
set_tests_properties (H5BITGROOM_UD-${testname}-gen-input PROPERTIES
173+
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
174+
DEPENDS H5BITGROOM_UD-${testname}-clearall-objects)
175+
set (last_test "H5BITGROOM_UD-${testname}-gen-input")
139176
if (HDF5_BUILD_TOOLS OR HDF5_PROVIDES_TOOLS)
140177
add_test (
141178
NAME H5BITGROOM_UD-${testname}
@@ -150,7 +187,7 @@ if (H5PL_BUILD_TESTING)
150187
-D "TEST_LIBRARY_DIRECTORY=${TESTLIBDIR}"
151188
-P "${H5PL_RESOURCES_DIR}/runTest.cmake"
152189
)
153-
set_tests_properties (H5BITGROOM_UD-${testname} PROPERTIES DEPENDS H5BITGROOM_UD-${testname}-clearall-objects)
190+
set_tests_properties (H5BITGROOM_UD-${testname} PROPERTIES DEPENDS H5BITGROOM_UD-${testname}-gen-input)
154191
add_test (
155192
NAME H5BITGROOM_UD-h5dump-${testname}
156193
COMMAND "${CMAKE_COMMAND}"
@@ -167,23 +204,43 @@ if (H5PL_BUILD_TESTING)
167204
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
168205
DEPENDS H5BITGROOM_UD-${testname})
169206
set (last_test "H5BITGROOM_UD-h5dump-${testname}")
207+
# Verify that the filter actually modifies the dataset values: dump the
208+
# data (no -pH) and compare against a captured reference of the
209+
# quantized output. BitGroom's encoding is bit-deterministic across
210+
# platforms (its inner loop is pure integer bit ops, with the bit-zero
211+
# count derived once per call from NSD via ceil() of a constant
212+
# expression), so the captured reference is portable.
213+
add_test (
214+
NAME H5BITGROOM_UD-h5dump-data-${testname}
215+
COMMAND "${CMAKE_COMMAND}"
216+
-D "TEST_PROGRAM=${H5PL_HDF5_DUMP_EXECUTABLE}"
217+
-D "TEST_ARGS:STRING=out-${testname}.${resultfile}"
218+
-D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
219+
-D "TEST_OUTPUT=${resultfile}-${testname}-data.out"
220+
-D "TEST_EXPECT=${resultcode}"
221+
-D "TEST_REFERENCE=${resultfile}-${testname}-data.ddl"
222+
-D "TEST_LIBRARY_DIRECTORY=${TESTLIBDIR}"
223+
-P "${H5PL_RESOURCES_DIR}/runTest.cmake"
224+
)
225+
set_tests_properties (H5BITGROOM_UD-h5dump-data-${testname} PROPERTIES
226+
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
227+
DEPENDS H5BITGROOM_UD-h5dump-${testname})
228+
set (last_test "H5BITGROOM_UD-h5dump-data-${testname}")
170229
endif ()
171230
endmacro ()
172231

173232
# --------------------------------------------------------------------
174233
# Copy all the HDF5 files from the source directory into the test directory
175234
# --------------------------------------------------------------------
176-
set (LIST_HDF5_TEST_FILES
177-
h5repack_layout.h5
178-
)
179235
set (LIST_OTHER_TEST_FILES
180236
h5ex_d_bitgroom.ddl
181237
h5ex_d_bitgroom.tst
182-
h5repack_layout.h5-ud_convert.ddl
183-
ud_convert.h5repack_layout.h5.tst
238+
h5repack_floats.h5-ud_convert.ddl
239+
h5repack_floats.h5-ud_convert-data.ddl
240+
ud_convert.h5repack_floats.h5.tst
184241
)
185242

186-
foreach (h5_file ${LIST_HDF5_TEST_FILES} ${LIST_OTHER_TEST_FILES})
243+
foreach (h5_file ${LIST_OTHER_TEST_FILES})
187244
HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/testfiles/${h5_file}" "${PROJECT_BINARY_DIR}/${h5_file}" "example_files")
188245
endforeach ()
189246
add_custom_target(example_files ALL COMMENT "Copying files needed by example tests" DEPENDS ${example_files_list})
@@ -192,7 +249,7 @@ if (H5PL_BUILD_TESTING)
192249

193250
if (NOT DISABLE_H5PL_ENCODER)
194251
#UD BITGROOM
195-
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)
252+
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)
196253
endif ()
197254

198255
endif ()
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2+
* Copyright by The HDF Group. *
3+
* All rights reserved. *
4+
* *
5+
* This file is part of the HDF5 BitGroom filter plugin source. The full *
6+
* copyright notice, including terms governing use, modification, and *
7+
* redistribution, is contained in the file COPYING, which can be found at *
8+
* the root of the source code distribution tree. If you do not have access *
9+
* to this file, you may request a copy from help@hdfgroup.org. *
10+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
11+
12+
/*
13+
* Generates an HDF5 file with a chunked dataset of IEEE 32-bit floats and no
14+
* filters applied. Used as input for the h5repack BitGroom test so the
15+
* filter's set_local() callback retains the filter in the pipeline (the
16+
* callback removes itself on non-float data). See issue #240.
17+
*/
18+
19+
#include "hdf5.h"
20+
#include <stdio.h>
21+
22+
#define FILENAME "h5repack_floats.h5"
23+
#define DATASET "data"
24+
#define DIM0 32
25+
#define DIM1 64
26+
#define CHUNK0 4
27+
#define CHUNK1 8
28+
29+
int
30+
main(void)
31+
{
32+
hid_t file_id = H5I_INVALID_HID;
33+
hid_t space_id = H5I_INVALID_HID;
34+
hid_t dcpl_id = H5I_INVALID_HID;
35+
hid_t dset_id = H5I_INVALID_HID;
36+
hsize_t dims[2] = {DIM0, DIM1};
37+
hsize_t chunk[2] = {CHUNK0, CHUNK1};
38+
float wdata[DIM0][DIM1];
39+
int i, j;
40+
int ret_value = 1;
41+
42+
/* Non-integer floats: the 0.137f multiplier ensures every value carries
43+
* non-trivial mantissa bits, so quantization by BitGroom is visible
44+
* across the entire dataset rather than only on values that exceed the
45+
* retained mantissa width. */
46+
for (i = 0; i < DIM0; i++)
47+
for (j = 0; j < DIM1; j++)
48+
wdata[i][j] = ((float)(i * j) - (float)j) * 0.137f;
49+
50+
file_id = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
51+
if (file_id < 0)
52+
goto done;
53+
54+
space_id = H5Screate_simple(2, dims, NULL);
55+
if (space_id < 0)
56+
goto done;
57+
58+
dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
59+
if (dcpl_id < 0)
60+
goto done;
61+
if (H5Pset_chunk(dcpl_id, 2, chunk) < 0)
62+
goto done;
63+
64+
dset_id = H5Dcreate(file_id, DATASET, H5T_IEEE_F32LE, space_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
65+
if (dset_id < 0)
66+
goto done;
67+
68+
if (H5Dwrite(dset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, (void *)wdata) < 0)
69+
goto done;
70+
71+
ret_value = 0;
72+
73+
done:
74+
if (dset_id >= 0)
75+
H5Dclose(dset_id);
76+
if (dcpl_id >= 0)
77+
H5Pclose(dcpl_id);
78+
if (space_id >= 0)
79+
H5Sclose(space_id);
80+
if (file_id >= 0)
81+
H5Fclose(file_id);
82+
83+
if (ret_value != 0)
84+
fprintf(stderr, "h5repack_floats: failed to create %s\n", FILENAME);
85+
86+
return ret_value;
87+
}

0 commit comments

Comments
 (0)