tuklib_integer.h: Fix a recent copypaste error in Clang detection.
[xz/debian.git] / tests / test_compress.sh
blob61d20ce965f3339be92a42868f455eebca0b5b47
1 #!/bin/sh
3 ###############################################################################
5 # Author: Lasse Collin
7 # This file has been put into the public domain.
8 # You can do whatever you want with this file.
10 ###############################################################################
12 # If xz wasn't built, this test is skipped.
13 if test -x ../src/xz/xz ; then
15 else
16 exit 77
19 # If compression or decompression support is missing, this test is skipped.
20 # This isn't perfect as if only some compressors or decompressors are disabled
21 # then this script can still fail because for now this doesn't check the
22 # availability of each filter.
23 if grep 'define HAVE_ENCODERS' ../config.h > /dev/null \
24 && grep 'define HAVE_DECODERS' ../config.h > /dev/null ; then
26 else
27 echo "Compression or decompression support is disabled, skipping this test."
28 exit 77
31 # Find out if our shell supports functions.
32 eval 'unset foo ; foo() { return 42; } ; foo'
33 if test $? != 42 ; then
34 echo "/bin/sh doesn't support functions, skipping this test."
35 exit 77
38 test_xz() {
39 if $XZ -c "$@" "$FILE" > "$TMP_COMP"; then
41 else
42 echo "Compressing failed: $* $FILE"
43 exit 1
46 if $XZ -cd "$TMP_COMP" > "$TMP_UNCOMP" ; then
48 else
49 echo "Decompressing failed: $* $FILE"
50 exit 1
53 if cmp "$TMP_UNCOMP" "$FILE" ; then
55 else
56 echo "Decompressed file does not match" \
57 "the original: $* $FILE"
58 exit 1
61 if test -n "$XZDEC" ; then
62 if $XZDEC "$TMP_COMP" > "$TMP_UNCOMP" ; then
64 else
65 echo "Decompressing failed: $* $FILE"
66 exit 1
69 if cmp "$TMP_UNCOMP" "$FILE" ; then
71 else
72 echo "Decompressed file does not match" \
73 "the original: $* $FILE"
74 exit 1
79 XZ="../src/xz/xz --memlimit-compress=48MiB --memlimit-decompress=5MiB \
80 --no-adjust --threads=1 --check=crc32"
81 grep "define HAVE_CHECK_CRC64" ../config.h > /dev/null \
82 && XZ="$XZ --check=crc64"
83 XZDEC="../src/xzdec/xzdec" # No memory usage limiter available
84 test -x ../src/xzdec/xzdec || XZDEC=
86 # Create the required input file if needed.
88 # Derive temporary filenames for compressed and uncompressed outputs
89 # from the input filename. This is needed when multiple tests are
90 # run in parallel.
91 FILE=$1
92 TMP_COMP="tmp_comp_$FILE"
93 TMP_UNCOMP="tmp_uncomp_$FILE"
95 case $FILE in
96 # compress_generated files will be created in the build directory
97 # in the /tests/ sub-directory.
98 compress_generated_*)
99 if ./create_compress_files "$FILE" ; then
101 else
102 rm -f "$FILE"
103 echo "Failed to create the file '$FILE'."
104 exit 1
107 # compress_prepared files exist in the source directory since they
108 # do not need to be copied or regenerated.
109 compress_prepared_*)
110 FILE="$srcdir/$FILE"
113 echo "No test file was specified."
114 exit 1
116 esac
118 # Remove temporary now (in case they are something weird), and on exit.
119 rm -f "$TMP_COMP" "$TMP_UNCOMP"
120 trap 'rm -f "$TMP_COMP" "$TMP_UNCOMP"' 0
122 # Compress and decompress the file with various filter configurations.
124 # Don't test with empty arguments; it breaks some ancient
125 # proprietary /bin/sh versions due to $@ used in test_xz().
126 test_xz -1
127 test_xz -2
128 test_xz -3
129 test_xz -4
131 test_filter()
133 grep "define HAVE_ENCODER_$1" ../config.h > /dev/null || return
134 grep "define HAVE_DECODER_$1" ../config.h > /dev/null || return
135 shift
136 test_xz "$@" --lzma2=dict=64KiB,nice=32,mode=fast
139 test_filter DELTA --delta=dist=1
140 test_filter DELTA --delta=dist=4
141 test_filter DELTA --delta=dist=256
142 test_filter X86 --x86
143 test_filter POWERPC --power
144 test_filter IA64 --ia64
145 test_filter ARM --arm
146 test_filter ARMTHUMB --armthumb
147 test_filter SPARC --sparc
149 exit 0