Update THANKS
[xz/debian.git] / tests / test_files.sh
blob99c9f2fac7ee6785f756954e7b042d11725de37f
1 #!/bin/sh
2 # SPDX-License-Identifier: 0BSD
4 ###############################################################################
6 # Author: Lasse Collin
8 ###############################################################################
10 # Optional argument:
11 # $1 = directory of the xz executable
13 # If both xz and xzdec were not built, skip this test.
14 XZ=${1:-../src/xz}/xz
15 XZDEC=${2:-../src/xzdec}/xzdec
16 test -x "$XZ" || XZ=
17 test -x "$XZDEC" || XZDEC=
18 if test -z "$XZ$XZDEC"; then
19 echo "xz and xzdec were not built, skipping this test."
20 exit 77
23 # If decompression support is missing, this test is skipped.
24 # This isn't perfect as if only some decompressors are disabled
25 # then some good files might not decompress and the test fails
26 # for a (kind of) wrong reason.
27 if test ! -f ../config.h ; then
29 elif grep 'define HAVE_DECODERS' ../config.h > /dev/null ; then
31 else
32 echo "Decompression support is disabled, skipping this test."
33 exit 77
36 # If a feature was disabled at build time, make it possible to skip
37 # some of the test files. Use exit status 77 if any files were skipped.
38 EXIT_STATUS=0
39 have_feature()
41 test -f ../config.h || return 0
42 grep "define HAVE_$1 1" ../config.h > /dev/null && return 0
43 printf '%s: Skipping because HAVE_%s is not enabled\n' "$2" "$1"
44 EXIT_STATUS=77
45 return 1
49 #######
50 # .xz #
51 #######
53 # If these integrity check types were disabled at build time,
54 # allow the tests to pass still.
55 NO_WARN=
56 if test -f ../config.h ; then
57 grep 'define HAVE_CHECK_CRC64' ../config.h > /dev/null || NO_WARN=-qQ
58 grep 'define HAVE_CHECK_SHA256' ../config.h > /dev/null || NO_WARN=-qQ
61 for I in "$srcdir"/files/good-*.xz
63 # If features were disabled at build time, keep this still working.
64 case $I in
65 */good-1-*delta-lzma2*.xz)
66 have_feature DECODER_DELTA "$I" || continue
68 esac
69 case $I in
70 */good-1-empty-bcj-lzma2.xz)
71 have_feature DECODER_POWERPC "$I" || continue
73 esac
74 case $I in
75 */good-1-sparc-lzma2.xz)
76 have_feature DECODER_SPARC "$I" || continue
78 esac
79 case $I in
80 */good-1-x86-lzma2.xz)
81 have_feature DECODER_X86 "$I" || continue
83 esac
84 case $I in
85 */good-1-arm64-lzma2-*.xz)
86 have_feature DECODER_ARM64 "$I" || continue
88 esac
89 case $I in
90 */good-1-riscv-lzma2-*.xz)
91 have_feature DECODER_RISCV "$I" || continue
93 esac
95 if test -z "$XZ" || "$XZ" $NO_WARN -dc "$I" > /dev/null; then
97 else
98 echo "Good file failed: $I"
99 exit 1
102 if test -z "$XZDEC" || "$XZDEC" $NO_WARN "$I" > /dev/null; then
104 else
105 echo "Good file failed: $I"
106 exit 1
108 done
110 for I in "$srcdir"/files/bad-*.xz
112 if test -n "$XZ" && "$XZ" -dc "$I" > /dev/null 2>&1; then
113 echo "Bad file succeeded: $I"
114 exit 1
117 # xzdec doesn't warn about unsupported check so skip this if any of
118 # the check types were disabled at built time (NO_WARN isn't empty).
119 if test -n "$XZDEC" && test -z "$NO_WARN" \
120 && "$XZDEC" "$I" > /dev/null 2>&1; then
121 echo "Bad file succeeded: $I"
122 exit 1
124 done
126 # Testing for the lzma_index_append() bug in <= 5.2.6 needs "xz -l":
127 I="$srcdir/files/bad-3-index-uncomp-overflow.xz"
128 if test -n "$XZ" && "$XZ" -l "$I" > /dev/null 2>&1; then
129 echo "Bad file succeeded with xz -l: $I"
130 exit 1
133 for I in "$srcdir"/files/unsupported-*.xz
135 # Test these only with xz as unsupported-check.xz will exit
136 # successfully with xzdec because it doesn't warn about
137 # unsupported check type.
138 if test -n "$XZ" && "$XZ" -dc "$I" > /dev/null 2>&1; then
139 echo "Unsupported file succeeded: $I"
140 exit 1
142 done
144 # Test that this passes with --no-warn (-Q).
145 I="$srcdir/files/unsupported-check.xz"
146 if test -z "$XZ" || "$XZ" -dcqQ "$I" > /dev/null; then
148 else
149 echo "Unsupported file failed with xz -Q: $I"
150 exit 1
153 if test -z "$XZDEC" || "$XZDEC" -qQ "$I" > /dev/null; then
155 else
156 echo "Unsupported file failed with xzdec -Q: $I"
157 exit 1
161 #########
162 # .lzma #
163 #########
165 for I in "$srcdir"/files/good-*.lzma
167 if test -z "$XZ" || "$XZ" -dc "$I" > /dev/null; then
169 else
170 echo "Good file failed: $I"
171 exit 1
173 done
175 for I in "$srcdir"/files/bad-*.lzma
177 if test -n "$XZ" && "$XZ" -dc "$I" > /dev/null 2>&1; then
178 echo "Bad file succeeded: $I"
179 exit 1
181 done
184 #######
185 # .lz #
186 #######
188 if have_feature LZIP_DECODER ".lz files" ; then
189 for I in "$srcdir"/files/good-*.lz
191 if test -z "$XZ" || "$XZ" -dc "$I" > /dev/null; then
193 else
194 echo "Good file failed: $I"
195 exit 1
197 done
199 for I in "$srcdir"/files/bad-*.lz "$srcdir"/files/unsupported-*.lz
201 if test -n "$XZ" && "$XZ" -dc "$I" > /dev/null 2>&1; then
202 echo "Bad file succeeded: $I"
203 exit 1
205 done
208 exit "$EXIT_STATUS"