2 # SPDX-License-Identifier: 0BSD
4 ###############################################################################
8 ###############################################################################
11 # $1 = directory of the xz executable
13 # If both xz and xzdec were not built, skip this test.
15 XZDEC
=${2:-../src/xzdec}/xzdec
17 test -x "$XZDEC" || XZDEC
=
18 if test -z "$XZ$XZDEC"; then
19 echo "xz and xzdec were not built, skipping this test."
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
32 echo "Decompression support is disabled, skipping this test."
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.
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"
53 # If these integrity check types were disabled at build time,
54 # allow the tests to pass still.
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.
65 */good-1-
*delta-lzma2
*.xz
)
66 have_feature DECODER_DELTA
"$I" ||
continue
70 */good-1-empty-bcj-lzma2.xz
)
71 have_feature DECODER_POWERPC
"$I" ||
continue
75 */good-1-sparc-lzma2.xz
)
76 have_feature DECODER_SPARC
"$I" ||
continue
80 */good-1-x86-lzma2.xz
)
81 have_feature DECODER_X86
"$I" ||
continue
85 */good-1-arm64-lzma2-
*.xz
)
86 have_feature DECODER_ARM64
"$I" ||
continue
90 */good-1-riscv-lzma2-
*.xz
)
91 have_feature DECODER_RISCV
"$I" ||
continue
95 if test -z "$XZ" ||
"$XZ" $NO_WARN -dc "$I" > /dev
/null
; then
98 echo "Good file failed: $I"
102 if test -z "$XZDEC" ||
"$XZDEC" $NO_WARN "$I" > /dev
/null
; then
105 echo "Good file failed: $I"
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"
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"
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"
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"
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
149 echo "Unsupported file failed with xz -Q: $I"
153 if test -z "$XZDEC" ||
"$XZDEC" -qQ "$I" > /dev
/null
; then
156 echo "Unsupported file failed with xzdec -Q: $I"
165 for I
in "$srcdir"/files
/good-
*.lzma
167 if test -z "$XZ" ||
"$XZ" -dc "$I" > /dev
/null
; then
170 echo "Good file failed: $I"
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"
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
194 echo "Good file failed: $I"
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"