2 # SPDX-License-Identifier: 0BSD
4 ###############################################################################
8 ###############################################################################
11 # $1 = test filename: compress_generated_<foo> or compress_prepared_<foo>
14 # $2 = directory of the xz and xzdec executables
17 XZDEC
=${2:-../src/xzdec}/xzdec
19 # If xz wasn't built, this test is skipped.
20 if test ! -x "$XZ"; then
21 echo "xz was not built, skipping this test."
25 # xzdec isn't mandatory for this script.
26 test -x "$XZDEC" || XZDEC
=
28 # If compression or decompression support is missing, this test is skipped.
29 # This isn't perfect as if only some compressors or decompressors are disabled
30 # then this script can still fail because for now this doesn't check the
31 # availability of each filter.
32 if test ! -f ..
/config.h
; then
34 elif grep 'define HAVE_ENCODERS' ..
/config.h
> /dev
/null \
35 && grep 'define HAVE_DECODERS' ..
/config.h
> /dev
/null
; then
38 echo "Compression or decompression support is disabled, skipping this test."
42 # Find out if our shell supports functions.
43 eval 'unset foo ; foo() { return 42; } ; foo'
44 if test $?
!= 42 ; then
45 echo "/bin/sh doesn't support functions, skipping this test."
50 if $XZ -c "$@" "$FILE" > "$TMP_COMP"; then
53 echo "Compressing failed: $* $FILE"
57 if $XZ -cd "$TMP_COMP" > "$TMP_UNCOMP" ; then
60 echo "Decompressing failed: $* $FILE"
64 if cmp "$TMP_UNCOMP" "$FILE" ; then
67 echo "Decompressed file does not match" \
68 "the original: $* $FILE"
72 if test -n "$XZDEC" ; then
73 if $XZDEC "$TMP_COMP" > "$TMP_UNCOMP" ; then
76 echo "Decompressing failed: $* $FILE"
80 if cmp "$TMP_UNCOMP" "$FILE" ; then
83 echo "Decompressed file does not match" \
84 "the original: $* $FILE"
90 # Set memory usage limit for xz. xzdec has no memory usage limiter.
91 # Force single-threaded mode as the test files are small
92 # (so more than one thread wouldn't be used anyway) and
93 # the tests are usually run in parallel.
94 XZ
="$XZ --memlimit-compress=48MiB --memlimit-decompress=5MiB \
95 --no-adjust --threads=1"
97 # Create the required input file if needed.
99 # Derive temporary filenames for compressed and uncompressed outputs
100 # from the input filename. This is needed when multiple tests are
103 TMP_COMP
="tmp_comp_$FILE"
104 TMP_UNCOMP
="tmp_uncomp_$FILE"
107 # compress_generated files will be created in the build directory
108 # in the /tests/ sub-directory.
109 compress_generated_
*)
110 if .
/create_compress_files
"$FILE" ; then
114 echo "Failed to create the file '$FILE'."
118 # compress_prepared files exist in the source directory since they
119 # do not need to be copied or regenerated.
124 echo "No test file was specified."
129 # Remove temporary now (in case they are something weird), and on exit.
130 rm -f "$TMP_COMP" "$TMP_UNCOMP"
131 trap 'rm -f "$TMP_COMP" "$TMP_UNCOMP"' 0
133 # Compress and decompress the file with various filter configurations.
135 # Don't test with empty arguments; it breaks some ancient
136 # proprietary /bin/sh versions due to $@ used in test_xz().
144 if test -f ..
/config.h
; then
145 grep "define HAVE_ENCODER_$1 1" ..
/config.h
> /dev
/null \
147 grep "define HAVE_DECODER_$1 1" ..
/config.h
> /dev
/null \
151 test_xz
--filters="$* lzma2:dict=64KiB,nice=32,mode=fast"
154 test_filter DELTA delta
:dist
=1
155 test_filter DELTA delta
:dist
=4
156 test_filter DELTA delta
:dist
=256
158 test_filter POWERPC powerpc
159 test_filter IA64 ia64
161 test_filter ARMTHUMB armthumb
162 test_filter ARM64 arm64
163 test_filter SPARC sparc
164 test_filter RISCV riscv