aboutsummaryrefslogtreecommitdiff
path: root/src/zlib-ng/cmake/test-compress.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'src/zlib-ng/cmake/test-compress.cmake')
-rw-r--r--src/zlib-ng/cmake/test-compress.cmake96
1 files changed, 72 insertions, 24 deletions
diff --git a/src/zlib-ng/cmake/test-compress.cmake b/src/zlib-ng/cmake/test-compress.cmake
index e5b1f3b..cfc7613 100644
--- a/src/zlib-ng/cmake/test-compress.cmake
+++ b/src/zlib-ng/cmake/test-compress.cmake
@@ -58,17 +58,47 @@ endif()
# Generate unique output path so multiple tests can be executed at the same time
string(RANDOM LENGTH 6 UNIQUE_ID)
string(REPLACE "." "-" TEST_NAME "${TEST_NAME}")
-set(OUTPUT_BASE "${CMAKE_CURRENT_BINARY_DIR}/test/${TEST_NAME}-${UNIQUE_ID}")
+set(OUTPUT_BASE "${CMAKE_CURRENT_BINARY_DIR}/Testing/Temporary/${TEST_NAME}-${UNIQUE_ID}")
# Ensure directory exists for output files
get_filename_component(OUTPUT_DIR "${OUTPUT_BASE}" DIRECTORY)
file(MAKE_DIRECTORY "${OUTPUT_DIR}")
+# Cleanup temporary files
+macro(cleanup_always)
+ file(GLOB TEMP_FILES ${OUTPUT_BASE}*)
+ file(REMOVE ${TEMP_FILES})
+endmacro()
+# Clean up temporary files if not on CI
macro(cleanup)
- # Cleanup temporary mingizip files
- file(REMOVE ${OUTPUT_BASE}.gz ${OUTPUT_BASE}.out)
- # Cleanup temporary gzip files
- file(REMOVE ${OUTPUT_BASE}.gzip.gz ${OUTPUT_BASE}.gzip.out)
+ if(NOT DEFINED ENV{CI})
+ cleanup_always()
+ endif()
+endmacro()
+
+# Show differences between two files
+macro(diff src1 src2)
+ find_program(XXD xxd)
+ if(XXD)
+ find_program(DIFF diff)
+ if(DIFF)
+ set(XXD_COMMAND ${XXD} ${src1} ${src1}.hex)
+ execute_process(COMMAND ${XXD_COMMAND})
+ set(XXD_COMMAND ${XXD} ${src2} ${src2}.hex)
+ execute_process(COMMAND ${XXD_COMMAND})
+
+ set(DIFF_COMMAND ${DIFF} -u ${src1}.hex ${src2}.hex)
+ execute_process(COMMAND ${DIFF_COMMAND}
+ OUTPUT_FILE ${src2}.diff)
+
+ file(READ ${src2}.diff DIFF_OUTPUT)
+ message(STATUS "Diff:\n${DIFF_OUTPUT}")
+
+ if(NOT DEFINED ENV{CI})
+ file(REMOVE ${src1}.hex ${src2}.hex ${src2}.diff)
+ endif()
+ endif()
+ endif()
endmacro()
# Compress input file
@@ -78,6 +108,10 @@ endif()
set(COMPRESS_COMMAND ${COMPRESS_TARGET} ${COMPRESS_ARGS})
+message(STATUS "Compress ${COMPRESS_COMMAND}")
+message(STATUS " Input: ${INPUT}")
+message(STATUS " Output: ${OUTPUT_BASE}.gz")
+
execute_process(COMMAND ${CMAKE_COMMAND}
"-DCOMMAND=${COMPRESS_COMMAND}"
-DINPUT=${INPUT}
@@ -99,10 +133,14 @@ endif()
set(DECOMPRESS_COMMAND ${DECOMPRESS_TARGET} ${DECOMPRESS_ARGS})
+message(STATUS "Decompress ${DECOMPRESS_COMMAND}")
+message(STATUS " Input: ${OUTPUT_BASE}.gz")
+message(STATUS " Output: ${OUTPUT_BASE}")
+
execute_process(COMMAND ${CMAKE_COMMAND}
"-DCOMMAND=${DECOMPRESS_COMMAND}"
-DINPUT=${OUTPUT_BASE}.gz
- -DOUTPUT=${OUTPUT_BASE}.out
+ -DOUTPUT=${OUTPUT_BASE}
"-DSUCCESS_EXIT=${SUCCESS_EXIT}"
-P ${CMAKE_CURRENT_LIST_DIR}/run-and-redirect.cmake
RESULT_VARIABLE CMD_RESULT)
@@ -115,12 +153,13 @@ endif()
if(COMPARE)
# Compare decompressed output with original input file
execute_process(COMMAND ${CMAKE_COMMAND}
- -E compare_files ${INPUT} ${OUTPUT_BASE}.out
+ -E compare_files ${INPUT} ${OUTPUT_BASE}
RESULT_VARIABLE CMD_RESULT)
if(CMD_RESULT)
+ diff(${INPUT} ${OUTPUT_BASE})
cleanup()
- message(FATAL_ERROR "Compare minigzip decompress failed: ${CMD_RESULT}")
+ message(FATAL_ERROR "Compare decompress failed: ${CMD_RESULT}")
endif()
endif()
@@ -136,10 +175,14 @@ if(GZIP_VERIFY AND NOT "${COMPRESS_ARGS}" MATCHES "-T")
# Check gzip can decompress our compressed output
set(GZ_DECOMPRESS_COMMAND ${GZIP} --decompress)
+ message(STATUS "Gzip decompress ${GZ_DECOMPRESS_COMMAND}")
+ message(STATUS " Input: ${OUTPUT_BASE}.gz")
+ message(STATUS " Output: ${OUTPUT_BASE}-ungzip")
+
execute_process(COMMAND ${CMAKE_COMMAND}
"-DCOMMAND=${GZ_DECOMPRESS_COMMAND}"
-DINPUT=${OUTPUT_BASE}.gz
- -DOUTPUT=${OUTPUT_BASE}.gzip.out
+ -DOUTPUT=${OUTPUT_BASE}-ungzip
"-DSUCCESS_EXIT=${SUCCESS_EXIT}"
-P ${CMAKE_CURRENT_LIST_DIR}/run-and-redirect.cmake
RESULT_VARIABLE CMD_RESULT)
@@ -151,26 +194,26 @@ if(GZIP_VERIFY AND NOT "${COMPRESS_ARGS}" MATCHES "-T")
# Compare gzip output with original input file
execute_process(COMMAND ${CMAKE_COMMAND}
- -E compare_files ${INPUT} ${OUTPUT_BASE}.gzip.out
+ -E compare_files ${INPUT} ${OUTPUT_BASE}-ungzip
RESULT_VARIABLE CMD_RESULT)
if(CMD_RESULT)
+ diff(${INPUT} ${OUTPUT_BASE}-ungzip)
cleanup()
message(FATAL_ERROR "Compare gzip decompress failed: ${CMD_RESULT}")
endif()
- if(NOT EXISTS ${OUTPUT_BASE}.gz)
- cleanup()
- message(FATAL_ERROR "Cannot find gzip compress input: ${INPUT}")
- endif()
-
# Compress input file with gzip
set(GZ_COMPRESS_COMMAND ${GZIP} --stdout)
+ message(STATUS "Gzip compress ${GZ_COMPRESS_COMMAND}")
+ message(STATUS " Input: ${INPUT}")
+ message(STATUS " Output: ${OUTPUT_BASE}-gzip.gz")
+
execute_process(COMMAND ${CMAKE_COMMAND}
"-DCOMMAND=${GZ_COMPRESS_COMMAND}"
-DINPUT=${INPUT}
- -DOUTPUT=${OUTPUT_BASE}.gzip.gz
+ -DOUTPUT=${OUTPUT_BASE}-gzip.gz
"-DSUCCESS_EXIT=${SUCCESS_EXIT}"
-P ${CMAKE_CURRENT_LIST_DIR}/run-and-redirect.cmake
RESULT_VARIABLE CMD_RESULT)
@@ -180,37 +223,42 @@ if(GZIP_VERIFY AND NOT "${COMPRESS_ARGS}" MATCHES "-T")
message(FATAL_ERROR "Gzip compress failed: ${CMD_RESULT}")
endif()
- if(NOT EXISTS ${OUTPUT_BASE}.gz)
+ if(NOT EXISTS ${OUTPUT_BASE}-gzip.gz)
cleanup()
- message(FATAL_ERROR "Cannot find minigzip decompress input: ${OUTPUT_BASE}.gzip.gz")
+ message(FATAL_ERROR "Cannot find decompress gzip input: ${OUTPUT_BASE}-gzip.gz")
endif()
+ message(STATUS "Decompress gzip ${DECOMPRESS_COMMAND}")
+ message(STATUS " Input: ${OUTPUT_BASE}-gzip.gz")
+ message(STATUS " Output: ${OUTPUT_BASE}-gzip")
+
# Check decompress target can handle gzip compressed output
execute_process(COMMAND ${CMAKE_COMMAND}
"-DCOMMAND=${DECOMPRESS_COMMAND}"
- -DINPUT=${OUTPUT_BASE}.gzip.gz
- -DOUTPUT=${OUTPUT_BASE}.gzip.out
+ -DINPUT=${OUTPUT_BASE}-gzip.gz
+ -DOUTPUT=${OUTPUT_BASE}-gzip
"-DSUCCESS_EXIT=${SUCCESS_EXIT}"
-P ${CMAKE_CURRENT_LIST_DIR}/run-and-redirect.cmake
RESULT_VARIABLE CMD_RESULT)
if(CMD_RESULT)
cleanup()
- message(FATAL_ERROR "Minigzip decompress gzip failed: ${CMD_RESULT}")
+ message(FATAL_ERROR "Decompress gzip failed: ${CMD_RESULT}")
endif()
if(COMPARE)
# Compare original input file with gzip decompressed output
execute_process(COMMAND ${CMAKE_COMMAND}
- -E compare_files ${INPUT} ${OUTPUT_BASE}.gzip.out
+ -E compare_files ${INPUT} ${OUTPUT_BASE}-gzip
RESULT_VARIABLE CMD_RESULT)
if(CMD_RESULT)
+ diff(${INPUT} ${OUTPUT_BASE}-gzip)
cleanup()
- message(FATAL_ERROR "Compare minigzip decompress gzip failed: ${CMD_RESULT}")
+ message(FATAL_ERROR "Compare decompress gzip failed: ${CMD_RESULT}")
endif()
endif()
endif()
endif()
-cleanup() \ No newline at end of file
+cleanup_always()