Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change compression tests reference files to use masking for compression ratios #4083

Merged
merged 11 commits into from
Mar 10, 2024
Merged
9 changes: 8 additions & 1 deletion HDF5Examples/config/cmake/runTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ if (TEST_FIND_RESULT GREATER -1)
endif ()

# if the output file needs Storage text removed
if (TEST_MASK)
if (TEST_MASK_STORE)
file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM)
string (REGEX REPLACE "Storage:[^\n]+\n" "Storage: <details removed for portability>\n" TEST_STREAM "${TEST_STREAM}")
file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}")
Expand Down Expand Up @@ -205,6 +205,13 @@ if (TEST_MASK_ERROR)
endif ()

# remove text from the output file
if (TEST_MASK)
file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM)
string (REGEX REPLACE "${TEST_MASK}" "" TEST_STREAM "${TEST_STREAM}")
file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}")
endif ()

# replace text from the output file
if (TEST_FILTER)
file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM)
string (REGEX REPLACE "${TEST_FILTER}" "${TEST_FILTER_REPLACE}" TEST_STREAM "${TEST_STREAM}")
Expand Down
10 changes: 9 additions & 1 deletion config/cmake/runTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ if (TEST_FIND_RESULT GREATER -1)
endif ()

# if the output file needs Storage text removed
if (TEST_MASK)
if (TEST_MASK_STORE)
file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM)
string (REGEX REPLACE "Storage:[^\n]+\n" "Storage: <details removed for portability>\n" TEST_STREAM "${TEST_STREAM}")
file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}")
Expand Down Expand Up @@ -205,8 +205,16 @@ if (TEST_MASK_ERROR)
endif ()

# remove text from the output file
if (TEST_MASK)
file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM)
string (REGEX REPLACE "${TEST_MASK}" "" TEST_STREAM "${TEST_STREAM}")
file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}")
endif ()

# replace text from the output file
if (TEST_FILTER)
file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM)
message (STATUS "TEST_FILTER: ${TEST_FILTER} TEST_FILTER_REPLACE: ${TEST_FILTER_REPLACE}")
string (REGEX REPLACE "${TEST_FILTER}" "${TEST_FILTER_REPLACE}" TEST_STREAM "${TEST_STREAM}")
file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}")
endif ()
Expand Down
1 change: 0 additions & 1 deletion release_docs/USING_HDF5_CMake.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ set (LINK_LIBS ${LINK_LIBS} ${HDF5_C_${LIB_TYPE}_LIBRARY})
set (example hdf_example)

add_executable (${example} ${PROJECT_SOURCE_DIR}/${example}.c)
TARGET_C_PROPERTIES (${example} PRIVATE ${LIB_TYPE})
target_link_libraries (${example} ${LINK_LIBS})

enable_testing ()
Expand Down
2 changes: 1 addition & 1 deletion tools/test/h5copy/CMakeTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
-D "TEST_EXPECT=${resultcode}"
-D "TEST_REFERENCE=./testfiles/${testname}.out"
-D "TEST_ERRREF=${result_errcheck}"
-D "TEST_MASK=true"
-D "TEST_MASK_STORE=true"
-P "${HDF_RESOURCES_DIR}/grepTest.cmake"
)
endif ()
Expand Down
46 changes: 40 additions & 6 deletions tools/test/h5dump/CMakeTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,40 @@
endif ()
endmacro ()

macro (ADD_H5_COMP_TEST resultfile resultcode resultvalue)
# If using memchecker add tests without using scripts
if (HDF5_USING_ANALYSIS_TOOL)
add_test (NAME H5DUMP-${resultfile} COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:h5dump> ${ARGN})
if (${resultcode})
set_tests_properties (H5DUMP-${resultfile} PROPERTIES WILL_FAIL "true")
endif ()
set_tests_properties (H5DUMP-${resultfile} PROPERTIES
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles/std"
)
else ()
add_test (
NAME H5DUMP-${resultfile}
COMMAND "${CMAKE_COMMAND}"
-D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
-D "TEST_PROGRAM=$<TARGET_FILE:h5dump>"
-D "TEST_ARGS:STRING=${ARGN}"
-D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles/std"
-D "TEST_OUTPUT=${resultfile}.out"
-D "TEST_EXPECT=${resultcode}"
-D "TEST_REFERENCE=${resultfile}.ddl"
-D "TEST_FILTER:STRING=SIZE [0-9]* \\(${resultvalue}\\\.[0-9][0-9][0-9]:1 COMPRESSION\\)"
-D "TEST_FILTER_REPLACE:STRING=SIZE XXXX (${resultvalue}.XXX:1 COMPRESSION)"
-P "${HDF_RESOURCES_DIR}/runTest.cmake"
)
endif ()
set_tests_properties (H5DUMP-${resultfile} PROPERTIES
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles/std"
)
if ("H5DUMP-${resultfile}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
set_tests_properties (H5DUMP-${resultfile} PROPERTIES DISABLED true)
endif ()
endmacro ()

macro (ADD_H5_TEST_N resultfile resultcode)
add_test (
NAME H5DUMP-N-${resultfile}-clear-objects
Expand Down Expand Up @@ -1235,25 +1269,25 @@

# tests for filters
# SZIP
ADD_H5_TEST (tszip 0 --enable-error-stack -H -p -d szip tfilters.h5)
ADD_H5_COMP_TEST (tszip 0 2 --enable-error-stack -H -p -d szip tfilters.h5)

# deflate
ADD_H5_TEST (tdeflate 0 --enable-error-stack -H -p -d deflate tfilters.h5)
ADD_H5_COMP_TEST (tdeflate 0 2 --enable-error-stack -H -p -d deflate tfilters.h5)

# shuffle
ADD_H5_TEST (tshuffle 0 --enable-error-stack -H -p -d shuffle tfilters.h5)

# fletcher32
ADD_H5_TEST (tfletcher32 0 --enable-error-stack -H -p -d fletcher32 tfilters.h5)
ADD_H5_COMP_TEST (tfletcher32 0 0 --enable-error-stack -H -p -d fletcher32 tfilters.h5)

# nbit
ADD_H5_TEST (tnbit 0 --enable-error-stack -H -p -d nbit tfilters.h5)
ADD_H5_COMP_TEST (tnbit 0 10 --enable-error-stack -H -p -d nbit tfilters.h5)

# scaleoffset
ADD_H5_TEST (tscaleoffset 0 --enable-error-stack -H -p -d scaleoffset tfilters.h5)
ADD_H5_COMP_TEST (tscaleoffset 0 4 --enable-error-stack -H -p -d scaleoffset tfilters.h5)

# all
ADD_H5_TEST (tallfilters 0 --enable-error-stack -H -p -d all tfilters.h5)
ADD_H5_COMP_TEST (tallfilters 0 1 --enable-error-stack -H -p -d all tfilters.h5)

# user defined
ADD_H5_TEST (tuserfilter 0 --enable-error-stack -H -p -d myfilter tfilters.h5)
Expand Down
2 changes: 1 addition & 1 deletion tools/test/h5dump/expected/tallfilters.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DATASET "all" {
DATASPACE SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
STORAGE_LAYOUT {
CHUNKED ( 10, 5 )
SIZE 458 (1.747:1 COMPRESSION)
SIZE XXXX (1.XXX:1 COMPRESSION)
}
FILTERS {
PREPROCESSING SHUFFLE
Expand Down
2 changes: 1 addition & 1 deletion tools/test/h5dump/expected/tdeflate.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DATASET "deflate" {
DATASPACE SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
STORAGE_LAYOUT {
CHUNKED ( 10, 5 )
SIZE 385 (2.078:1 COMPRESSION)
SIZE XXXX (2.XXX:1 COMPRESSION)
}
FILTERS {
COMPRESSION DEFLATE { LEVEL 9 }
Expand Down
2 changes: 1 addition & 1 deletion tools/test/h5dump/expected/tfletcher32.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DATASET "fletcher32" {
DATASPACE SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
STORAGE_LAYOUT {
CHUNKED ( 10, 5 )
SIZE 816 (0.980:1 COMPRESSION)
SIZE XXXX (0.XXX:1 COMPRESSION)
}
FILTERS {
CHECKSUM FLETCHER32
Expand Down
2 changes: 1 addition & 1 deletion tools/test/h5dump/expected/tnbit.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DATASET "nbit" {
DATASPACE SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
STORAGE_LAYOUT {
CHUNKED ( 10, 5 )
SIZE 76 (10.526:1 COMPRESSION)
SIZE XXXX (10.XXX:1 COMPRESSION)
}
FILTERS {
COMPRESSION NBIT
Expand Down
2 changes: 1 addition & 1 deletion tools/test/h5dump/expected/tscaleoffset.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DATASET "scaleoffset" {
DATASPACE SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
STORAGE_LAYOUT {
CHUNKED ( 10, 5 )
SIZE 188 (4.255:1 COMPRESSION)
SIZE XXXX (4.XXX:1 COMPRESSION)
}
FILTERS {
COMPRESSION SCALEOFFSET { MIN BITS 2 }
Expand Down
2 changes: 1 addition & 1 deletion tools/test/h5dump/expected/tszip.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DATASET "szip" {
DATASPACE SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
STORAGE_LAYOUT {
CHUNKED ( 10, 5 )
SIZE 372 (2.151:1 COMPRESSION)
SIZE XXXX (2.XXX:1 COMPRESSION)
}
FILTERS {
COMPRESSION SZIP {
Expand Down
75 changes: 69 additions & 6 deletions tools/test/h5dump/testh5dump.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,69 @@ TOOLTEST() {

}

# same as TOOLTEST but masks out the compression values
TOOLTESTC() {
# check if caseless compare and diff requested
if [ "$1" = ignorecase ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this whole block isn't needed since the $1 argument is supposed to be the leading number in the compression ratio to not mask out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a weird way to add an optional parameter, which controls whether diff adds a "-i".
I left it as is.

Copy link
Collaborator

@jhendersonHDF jhendersonHDF Mar 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably remove this block because the script doesn't account for this being $1 and the mask part to ignore possibly being $2, it's just checking $1 for both of them which may be confusing to some and ignorecase will never be passed for $1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No look athe the if/else if it matches it shifts otherwise continues

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, missed the shift. I guess that's fine then, even though nothing's using it currently.

caseless="-i"
# replace cmp with diff which runs much longer.
xCMP="$DIFF -i"
shift
else
caseless=""
# stick with faster cmp if ignorecase is not requested.
xCMP="$CMP"
fi

txttype=$1
expect="$TESTDIR/$2"
actual="$TESTDIR/`basename $2 .ddl`.out"
actual_err="$TESTDIR/`basename $2 .ddl`.err"
actual_sav=${actual}-sav
actual_err_sav=${actual_err}-sav
shift
shift

# Run test.
TESTING $DUMPER $@
(
cd $TESTDIR
$RUNSERIAL $DUMPER_BIN "$@"
) >$actual 2>$actual_err

# save actual and actual_err in case they are needed later.
cp $actual $actual_sav
STDOUT_FILTER $actual
cp $actual_err $actual_err_sav
STDERR_FILTER $actual_err

tmp_file=/tmp/h5test_tmp_$$
cp $actual $tmp_file
sed -e 's/SIZE [0-9]* ('"$txttype"'\.[0-9][0-9][0-9]:1 COMPRESSION)/SIZE XXXX ('"$txttype"'.XXX:1 COMPRESSION)/' \
< $tmp_file > $actual
rm -f $tmp_file

if [ ! -f $expect ]; then
# Create the expect file if it doesn't yet exist.
echo " CREATED"
cp $actual $expect
echo " Expected result (*.ddl) missing"
nerrors="`expr $nerrors + 1`"
elif $xCMP $expect $actual > /dev/null 2>&1 ; then
echo " PASSED"
else
echo "*FAILED*"
echo " Expected result (*.ddl) differs from actual result (*.out)"
nerrors="`expr $nerrors + 1`"
test yes = "$verbose" && $DIFF $caseless $expect $actual |sed 's/^/ /'
fi

# Clean up output file
if test -z "$HDF5_NOCLEANUP"; then
rm -f $actual $actual_err $actual_sav $actual_err_sav $actual_ext
fi

}

# same as TOOLTEST1 but compares generated file to expected output
# and compares the generated data file to the expected data file
Expand Down Expand Up @@ -1355,19 +1418,19 @@ TOOLTEST texceedsubblock.ddl --enable-error-stack -d 1d -k 1,3 taindices.h5

# tests for filters
# SZIP
TOOLTEST tszip.ddl --enable-error-stack -H -p -d szip tfilters.h5
TOOLTESTC 2 tszip.ddl --enable-error-stack -H -p -d szip tfilters.h5
# deflate
TOOLTEST tdeflate.ddl --enable-error-stack -H -p -d deflate tfilters.h5
TOOLTESTC 2 tdeflate.ddl --enable-error-stack -H -p -d deflate tfilters.h5
# shuffle
TOOLTEST tshuffle.ddl --enable-error-stack -H -p -d shuffle tfilters.h5
# fletcher32
TOOLTEST tfletcher32.ddl --enable-error-stack -H -p -d fletcher32 tfilters.h5
TOOLTESTC 0 tfletcher32.ddl --enable-error-stack -H -p -d fletcher32 tfilters.h5
# nbit
TOOLTEST tnbit.ddl --enable-error-stack -H -p -d nbit tfilters.h5
TOOLTESTC 10 tnbit.ddl --enable-error-stack -H -p -d nbit tfilters.h5
# scaleoffset
TOOLTEST tscaleoffset.ddl --enable-error-stack -H -p -d scaleoffset tfilters.h5
TOOLTESTC 4 tscaleoffset.ddl --enable-error-stack -H -p -d scaleoffset tfilters.h5
# all
TOOLTEST tallfilters.ddl --enable-error-stack -H -p -d all tfilters.h5
TOOLTESTC 1 tallfilters.ddl --enable-error-stack -H -p -d all tfilters.h5
# user defined
TOOLTEST tuserfilter.ddl --enable-error-stack -H -p -d myfilter tfilters.h5

Expand Down
Loading
Loading