• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1if(TARGET)
2    set(COMPRESS_TARGET ${TARGET})
3    set(DECOMPRESS_TARGET ${TARGET})
4endif()
5
6if(NOT INPUT OR NOT COMPRESS_TARGET OR NOT DECOMPRESS_TARGET)
7    message(FATAL_ERROR "Compress test arguments missing")
8endif()
9
10# Set default values
11if(NOT COMPRESS_ARGS)
12    set(COMPRESS_ARGS -c -k)
13endif()
14if(NOT DECOMPRESS_ARGS)
15    set(DECOMPRESS_ARGS -d -c)
16endif()
17if(NOT GZIP_VERIFY)
18    set(GZIP_VERIFY ON)
19endif()
20if(NOT SUCCESS_EXIT)
21    set(SUCCESS_EXIT 0)
22endif()
23
24# Generate unique output path so multiple tests can be executed at the same time
25if(NOT OUTPUT)
26    string(RANDOM UNIQUE_ID)
27    set(OUTPUT ${INPUT}-${UNIQUE_ID})
28endif()
29string(REPLACE ".gz" "" OUTPUT "${OUTPUT}")
30
31# Compress input file
32set(COMPRESS_COMMAND ${COMPRESS_TARGET} ${COMPRESS_ARGS})
33
34execute_process(COMMAND ${CMAKE_COMMAND}
35    "-DCOMMAND=${COMPRESS_COMMAND}"
36    -DINPUT=${INPUT}
37    -DOUTPUT=${OUTPUT}.gz
38    "-DSUCCESS_EXIT=${SUCCESS_EXIT}"
39    -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/run-and-redirect.cmake)
40
41# Decompress output
42set(DECOMPRESS_COMMAND ${DECOMPRESS_TARGET} ${DECOMPRESS_ARGS})
43
44execute_process(COMMAND ${CMAKE_COMMAND}
45    "-DCOMMAND=${DECOMPRESS_COMMAND}"
46    -DINPUT=${OUTPUT}.gz
47    -DOUTPUT=${OUTPUT}.out
48    "-DSUCCESS_EXIT=${SUCCESS_EXIT}"
49    -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/run-and-redirect.cmake)
50
51# Compare decompressed output with original input file
52execute_process(COMMAND ${CMAKE_COMMAND}
53    -E compare_files ${INPUT} ${OUTPUT}.out)
54
55if(GZIP_VERIFY AND NOT "${COMPRESS_ARGS}" MATCHES "-T")
56    # Transparent writing does not use gzip format
57    find_program(GZIP gzip)
58    if(GZIP)
59        # Check gzip can decompress our compressed output
60        set(GZ_DECOMPRESS_COMMAND ${GZIP} --decompress)
61
62        execute_process(COMMAND ${CMAKE_COMMAND}
63            "-DCOMMAND=${GZ_DECOMPRESS_COMMAND}"
64            -DINPUT=${OUTPUT}.gz
65            -DOUTPUT=${OUTPUT}.gzip.out
66            "-DSUCCESS_EXIT=${SUCCESS_EXIT}"
67            -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/run-and-redirect.cmake)
68
69        # Compare gzip output with original input file
70        execute_process(COMMAND ${CMAKE_COMMAND}
71            -E compare_files ${INPUT} ${OUTPUT}.gzip.out)
72
73        # Compress input file with gzip
74        set(GZ_COMPRESS_COMMAND ${GZIP} --stdout)
75
76        execute_process(COMMAND ${CMAKE_COMMAND}
77            "-DCOMMAND=${GZ_COMPRESS_COMMAND}"
78            -DINPUT=${INPUT}
79            -DOUTPUT=${OUTPUT}.gzip.gz
80            "-DSUCCESS_EXIT=${SUCCESS_EXIT}"
81            -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/run-and-redirect.cmake)
82
83        # Check minigzip can decompress gzip compressed output
84        execute_process(COMMAND ${CMAKE_COMMAND}
85            "-DCOMMAND=${DECOMPRESS_COMMAND}"
86            -DINPUT=${OUTPUT}.gzip.gz
87            -DOUTPUT=${OUTPUT}.gzip.out
88            "-DSUCCESS_EXIT=${SUCCESS_EXIT}"
89            -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/run-and-redirect.cmake)
90
91        # Compare original input file with gzip decompressed output
92        execute_process(COMMAND ${CMAKE_COMMAND}
93            -E compare_files ${INPUT} ${OUTPUT}.gzip.out)
94
95        # Cleanup temporary files
96        file(REMOVE ${OUTPUT}.gzip.gz ${OUTPUT}.gzip.out)
97    endif()
98endif()
99
100# Cleanup temporary files
101file(REMOVE ${OUTPUT}.gz ${OUTPUT}.out)
102