mirror of
https://git.tukaani.org/xz.git
synced 2025-02-22 16:38:11 +00:00
Now the test scripts detect both #define HAVE_DECODER_ARM #define HAVE_DECODER_ARM 1 as support for the ARM filter without confusing it with these: #define HAVE_DECODER_ARM64 #define HAVE_DECODER_ARM64 1 Previously only the ones ending with " 1" were accepted for the macros where this kind of confusion was possible. This should help with Meson support because Meson's built-in features produce config.h entries that are either #define FOO 1 #define FOO 0 or: #define FOO #undef FOO The former method has a benefit that one can use "#if FOO" and -Wundef will catch if a #define is missing (for example, it helps catching typos). But XZ Utils has to use the latter since it has been convenient with Autoconf's default behavior.[*] While it's easy to emulate the Autoconf style (#define FOO 1 vs. no #define at all) in Meson, it results in clumsy code. Thus it's better to change the few places in the tests where this difference matters. [*] While most checks in Autoconf default to the second style above, a few things use the first style (like AC_CHECK_DECLS). The mix of both styles is the most confusing as one has to remember which macro needs #ifdef and which #if. Currently HAVE_VISIBILITY is only such config.h entry that is 1 or 0. It comes unmodified from Gnulib's visibility.m4.
167 lines
3.9 KiB
Bash
Executable File
167 lines
3.9 KiB
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: 0BSD
|
|
|
|
###############################################################################
|
|
#
|
|
# Author: Lasse Collin
|
|
#
|
|
###############################################################################
|
|
|
|
# Mandatory argument:
|
|
# $1 = test filename: compress_generated_<foo> or compress_prepared_<foo>
|
|
#
|
|
# Optional argument:
|
|
# $2 = directory of the xz and xzdec executables
|
|
|
|
XZ=${2:-../src/xz}/xz
|
|
XZDEC=${2:-../src/xzdec}/xzdec
|
|
|
|
# If xz wasn't built, this test is skipped.
|
|
if test ! -x "$XZ"; then
|
|
echo "xz was not built, skipping this test."
|
|
exit 77
|
|
fi
|
|
|
|
# xzdec isn't mandatory for this script.
|
|
test -x "$XZDEC" || XZDEC=
|
|
|
|
# If compression or decompression support is missing, this test is skipped.
|
|
# This isn't perfect as if only some compressors or decompressors are disabled
|
|
# then this script can still fail because for now this doesn't check the
|
|
# availability of each filter.
|
|
if test ! -f ../config.h ; then
|
|
:
|
|
elif grep 'define HAVE_ENCODERS' ../config.h > /dev/null \
|
|
&& grep 'define HAVE_DECODERS' ../config.h > /dev/null ; then
|
|
:
|
|
else
|
|
echo "Compression or decompression support is disabled, skipping this test."
|
|
exit 77
|
|
fi
|
|
|
|
# Find out if our shell supports functions.
|
|
eval 'unset foo ; foo() { return 42; } ; foo'
|
|
if test $? != 42 ; then
|
|
echo "/bin/sh doesn't support functions, skipping this test."
|
|
exit 77
|
|
fi
|
|
|
|
test_xz() {
|
|
if $XZ -c "$@" "$FILE" > "$TMP_COMP"; then
|
|
:
|
|
else
|
|
echo "Compressing failed: $* $FILE"
|
|
exit 1
|
|
fi
|
|
|
|
if $XZ -cd "$TMP_COMP" > "$TMP_UNCOMP" ; then
|
|
:
|
|
else
|
|
echo "Decompressing failed: $* $FILE"
|
|
exit 1
|
|
fi
|
|
|
|
if cmp "$TMP_UNCOMP" "$FILE" ; then
|
|
:
|
|
else
|
|
echo "Decompressed file does not match" \
|
|
"the original: $* $FILE"
|
|
exit 1
|
|
fi
|
|
|
|
if test -n "$XZDEC" ; then
|
|
if $XZDEC "$TMP_COMP" > "$TMP_UNCOMP" ; then
|
|
:
|
|
else
|
|
echo "Decompressing failed: $* $FILE"
|
|
exit 1
|
|
fi
|
|
|
|
if cmp "$TMP_UNCOMP" "$FILE" ; then
|
|
:
|
|
else
|
|
echo "Decompressed file does not match" \
|
|
"the original: $* $FILE"
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Set memory usage limit for xz. xzdec has no memory usage limiter.
|
|
# Force single-threaded mode as the test files are small
|
|
# (so more than one thread wouldn't be used anyway) and
|
|
# the tests are usually run in parallel.
|
|
XZ="$XZ --memlimit-compress=48MiB --memlimit-decompress=5MiB \
|
|
--no-adjust --threads=1"
|
|
|
|
# Create the required input file if needed.
|
|
#
|
|
# Derive temporary filenames for compressed and uncompressed outputs
|
|
# from the input filename. This is needed when multiple tests are
|
|
# run in parallel.
|
|
FILE=$1
|
|
TMP_COMP="tmp_comp_$FILE"
|
|
TMP_UNCOMP="tmp_uncomp_$FILE"
|
|
|
|
case $FILE in
|
|
# compress_generated files will be created in the build directory
|
|
# in the /tests/ sub-directory.
|
|
compress_generated_*)
|
|
if ./create_compress_files "$FILE" ; then
|
|
:
|
|
else
|
|
rm -f "$FILE"
|
|
echo "Failed to create the file '$FILE'."
|
|
exit 1
|
|
fi
|
|
;;
|
|
# compress_prepared files exist in the source directory since they
|
|
# do not need to be copied or regenerated.
|
|
compress_prepared_*)
|
|
FILE="$srcdir/$FILE"
|
|
;;
|
|
'')
|
|
echo "No test file was specified."
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Remove temporary now (in case they are something weird), and on exit.
|
|
rm -f "$TMP_COMP" "$TMP_UNCOMP"
|
|
trap 'rm -f "$TMP_COMP" "$TMP_UNCOMP"' 0
|
|
|
|
# Compress and decompress the file with various filter configurations.
|
|
#
|
|
# Don't test with empty arguments; it breaks some ancient
|
|
# proprietary /bin/sh versions due to $@ used in test_xz().
|
|
test_xz -1
|
|
test_xz -2
|
|
test_xz -3
|
|
test_xz -4
|
|
|
|
test_filter()
|
|
{
|
|
if test -f ../config.h ; then
|
|
grep "define HAVE_ENCODER_$1[ 1]*\$" ../config.h > /dev/null \
|
|
|| return
|
|
grep "define HAVE_DECODER_$1[ 1]*\$" ../config.h > /dev/null \
|
|
|| return
|
|
fi
|
|
shift
|
|
test_xz --filters="$* lzma2:dict=64KiB,nice=32,mode=fast"
|
|
}
|
|
|
|
test_filter DELTA delta:dist=1
|
|
test_filter DELTA delta:dist=4
|
|
test_filter DELTA delta:dist=256
|
|
test_filter X86 x86
|
|
test_filter POWERPC powerpc
|
|
test_filter IA64 ia64
|
|
test_filter ARM arm
|
|
test_filter ARMTHUMB armthumb
|
|
test_filter ARM64 arm64
|
|
test_filter SPARC sparc
|
|
test_filter RISCV riscv
|
|
|
|
exit 0
|