Tests: Make test_compress.sh more flexible

Add a new optional second argument: directory of the xz and xzdec
executables. This is need with the CMake build where the binaries
end up in the top-level build directory.

If ../config.h doesn't exist, assume that all encoders and decoders
are available. This will make this script usable from CMake in the
most common build configuration.

NOTE: Since the existence of ../config.h is checked, the working
directory of the test script must be a subdir in the build tree!
Otherwise ../config.h would look outside the build tree.

Use the default check type instead of forcing CRC32 or CRC64.
Now the script doesn't need to check if CRC64 is available.
This commit is contained in:
Lasse Collin 2024-05-20 16:55:00 +03:00
parent 006040b29c
commit ac3222d2cb
1 changed files with 29 additions and 12 deletions

View File

@ -7,18 +7,31 @@
# #
############################################################################### ###############################################################################
# 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 xz wasn't built, this test is skipped.
if test -x ../src/xz/xz ; then if test ! -x "$XZ"; then
: echo "xz was not built, skipping this test."
else
exit 77 exit 77
fi fi
# xzdec isn't mandatory for this script.
test -x "$XZDEC" || XZDEC=
# If compression or decompression support is missing, this test is skipped. # If compression or decompression support is missing, this test is skipped.
# This isn't perfect as if only some compressors or decompressors are disabled # 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 # then this script can still fail because for now this doesn't check the
# availability of each filter. # availability of each filter.
if grep 'define HAVE_ENCODERS' ../config.h > /dev/null \ if test ! -f ../config.h ; then
:
elif grep 'define HAVE_ENCODERS' ../config.h > /dev/null \
&& grep 'define HAVE_DECODERS' ../config.h > /dev/null ; then && grep 'define HAVE_DECODERS' ../config.h > /dev/null ; then
: :
else else
@ -74,12 +87,12 @@ test_xz() {
fi fi
} }
XZ="../src/xz/xz --memlimit-compress=48MiB --memlimit-decompress=5MiB \ # Set memory usage limit for xz. xzdec has no memory usage limiter.
--no-adjust --threads=1 --check=crc32" # Force single-threaded mode as the test files are small
grep "define HAVE_CHECK_CRC64" ../config.h > /dev/null \ # (so more than one thread wouldn't be used anyway) and
&& XZ="$XZ --check=crc64" # the tests are usually run in parallel.
XZDEC="../src/xzdec/xzdec" # No memory usage limiter available XZ="$XZ --memlimit-compress=48MiB --memlimit-decompress=5MiB \
test -x ../src/xzdec/xzdec || XZDEC= --no-adjust --threads=1"
# Create the required input file if needed. # Create the required input file if needed.
# #
@ -128,8 +141,12 @@ test_xz -4
test_filter() test_filter()
{ {
grep "define HAVE_ENCODER_$1 1" ../config.h > /dev/null || return if test -f ../config.h ; then
grep "define HAVE_DECODER_$1 1" ../config.h > /dev/null || return grep "define HAVE_ENCODER_$1 1" ../config.h > /dev/null \
|| return
grep "define HAVE_DECODER_$1 1" ../config.h > /dev/null \
|| return
fi
shift shift
test_xz --filters="$* lzma2:dict=64KiB,nice=32,mode=fast" test_xz --filters="$* lzma2:dict=64KiB,nice=32,mode=fast"
} }