summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Purcell <me@seanp.xyz>2017-04-20 11:59:10 -0700
committerSean Purcell <iburinoc@gmail.com>2017-05-15 23:06:48 -0400
commit0f6b9d7a7029eaaeb146cb770ec2f90dad3001dd (patch)
tree18a1ccba72cb670c91101c2e4eaba42755a82187
parentd38f66640aae194c3c055cb24774f00464d52b89 (diff)
downloadlibarchive-0f6b9d7a7029eaaeb146cb770ec2f90dad3001dd.tar.gz
Add zstd test suite
-rw-r--r--Makefile.am13
-rw-r--r--cat/test/CMakeLists.txt2
-rw-r--r--cat/test/test_empty.zst.uu4
-rw-r--r--cat/test/test_empty_zstd.c41
-rw-r--r--cat/test/test_expand.zst.uu4
-rw-r--r--cat/test/test_expand_zstd.c41
-rw-r--r--cpio/test/CMakeLists.txt2
-rw-r--r--cpio/test/test_extract.cpio.zst.uu6
-rw-r--r--cpio/test/test_extract_cpio_zstd.c48
-rw-r--r--cpio/test/test_option_zstd.c85
-rw-r--r--libarchive/test/CMakeLists.txt2
-rw-r--r--libarchive/test/test_archive_write_add_filter_by_name.c5
-rw-r--r--libarchive/test/test_compat_zstd.c82
-rw-r--r--libarchive/test/test_compat_zstd_1.tar.zst.uu12
-rw-r--r--libarchive/test/test_fuzz.c9
-rw-r--r--libarchive/test/test_write_filter_zstd.c201
-rw-r--r--tar/test/CMakeLists.txt2
-rw-r--r--tar/test/test_extract.tar.zst.uu6
-rw-r--r--tar/test/test_extract_tar_zstd.c48
-rw-r--r--tar/test/test_option_zstd.c85
-rw-r--r--test_utils/test_common.h3
-rw-r--r--test_utils/test_main.c15
22 files changed, 716 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index a3762e64..687f9d67 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -389,6 +389,7 @@ libarchive_test_SOURCES= \
libarchive/test/test_compat_gtar.c \
libarchive/test/test_compat_gzip.c \
libarchive/test/test_compat_lz4.c \
+ libarchive/test/test_compat_zstd.c \
libarchive/test/test_compat_lzip.c \
libarchive/test/test_compat_lzma.c \
libarchive/test/test_compat_lzop.c \
@@ -555,6 +556,7 @@ libarchive_test_SOURCES= \
libarchive/test/test_write_filter_gzip_timestamp.c \
libarchive/test/test_write_filter_lrzip.c \
libarchive/test/test_write_filter_lz4.c \
+ libarchive/test/test_write_filter_zstd.c \
libarchive/test/test_write_filter_lzip.c \
libarchive/test/test_write_filter_lzma.c \
libarchive/test/test_write_filter_lzop.c \
@@ -651,6 +653,7 @@ libarchive_test_EXTRA_DIST=\
libarchive/test/test_compat_lz4_B6BD.tar.lz4.uu \
libarchive/test/test_compat_lz4_B7.tar.lz4.uu \
libarchive/test/test_compat_lz4_B7BD.tar.lz4.uu \
+ libarchive/test/test_compat_zstd_1.tar.zst.uu \
libarchive/test/test_compat_lzip_1.tlz.uu \
libarchive/test/test_compat_lzip_2.tlz.uu \
libarchive/test/test_compat_lzma_1.tlz.uu \
@@ -959,6 +962,7 @@ bsdtar_test_SOURCES= \
tar/test/test_extract_tar_lrz.c \
tar/test/test_extract_tar_lz.c \
tar/test/test_extract_tar_lz4.c \
+ tar/test/test_extract_tar_zstd.c \
tar/test/test_extract_tar_lzma.c \
tar/test/test_extract_tar_lzo.c \
tar/test/test_extract_tar_xz.c \
@@ -986,6 +990,7 @@ bsdtar_test_SOURCES= \
tar/test/test_option_keep_newer_files.c \
tar/test/test_option_lrzip.c \
tar/test/test_option_lz4.c \
+ tar/test/test_option_zstd.c \
tar/test/test_option_lzma.c \
tar/test/test_option_lzop.c \
tar/test/test_option_n.c \
@@ -1037,6 +1042,7 @@ bsdtar_test_EXTRA_DIST= \
tar/test/test_extract.tar.lrz.uu \
tar/test/test_extract.tar.lz.uu \
tar/test/test_extract.tar.lz4.uu \
+ tar/test/test_extract.tar.zst.uu \
tar/test/test_extract.tar.lzma.uu \
tar/test/test_extract.tar.lzo.uu \
tar/test/test_extract.tar.xz.uu \
@@ -1119,6 +1125,7 @@ bsdcpio_test_SOURCES= \
cpio/test/test_extract_cpio_lrz.c \
cpio/test/test_extract_cpio_lz.c \
cpio/test/test_extract_cpio_lz4.c \
+ cpio/test/test_extract_cpio_zstd.c \
cpio/test/test_extract_cpio_lzma.c \
cpio/test/test_extract_cpio_lzo.c \
cpio/test/test_extract_cpio_xz.c \
@@ -1141,6 +1148,7 @@ bsdcpio_test_SOURCES= \
cpio/test/test_option_l.c \
cpio/test/test_option_lrzip.c \
cpio/test/test_option_lz4.c \
+ cpio/test/test_option_zstd.c \
cpio/test/test_option_lzma.c \
cpio/test/test_option_lzop.c \
cpio/test/test_option_m.c \
@@ -1185,6 +1193,7 @@ bsdcpio_test_EXTRA_DIST= \
cpio/test/test_extract.cpio.lrz.uu \
cpio/test/test_extract.cpio.lz.uu \
cpio/test/test_extract.cpio.lz4.uu \
+ cpio/test/test_extract.cpio.zst.uu \
cpio/test/test_extract.cpio.lzma.uu \
cpio/test/test_extract.cpio.lzo.uu \
cpio/test/test_extract.cpio.xz.uu \
@@ -1259,6 +1268,7 @@ bsdcat_test_SOURCES= \
cat/test/test_0.c \
cat/test/test_empty_gz.c \
cat/test/test_empty_lz4.c \
+ cat/test/test_empty_zstd.c \
cat/test/test_empty_xz.c \
cat/test/test_error.c \
cat/test/test_error_mixed.c \
@@ -1266,6 +1276,7 @@ bsdcat_test_SOURCES= \
cat/test/test_expand_bz2.c \
cat/test/test_expand_gz.c \
cat/test/test_expand_lz4.c \
+ cat/test/test_expand_zstd.c \
cat/test/test_expand_mixed.c \
cat/test/test_expand_plain.c \
cat/test/test_expand_xz.c \
@@ -1295,11 +1306,13 @@ bsdcat_test_EXTRA_DIST= \
cat/test/list.h \
cat/test/test_empty.gz.uu \
cat/test/test_empty.lz4.uu \
+ cat/test/test_empty.zst.uu \
cat/test/test_empty.xz.uu \
cat/test/test_expand.Z.uu \
cat/test/test_expand.bz2.uu \
cat/test/test_expand.gz.uu \
cat/test/test_expand.lz4.uu \
+ cat/test/test_expand.zst.uu \
cat/test/test_expand.plain.uu \
cat/test/test_expand.xz.uu \
cat/test/CMakeLists.txt
diff --git a/cat/test/CMakeLists.txt b/cat/test/CMakeLists.txt
index 0cd3aad8..e76e92e6 100644
--- a/cat/test/CMakeLists.txt
+++ b/cat/test/CMakeLists.txt
@@ -11,6 +11,7 @@ IF(ENABLE_CAT AND ENABLE_TEST)
test_0.c
test_empty_gz.c
test_empty_lz4.c
+ test_empty_zstd.c
test_empty_xz.c
test_error.c
test_error_mixed.c
@@ -18,6 +19,7 @@ IF(ENABLE_CAT AND ENABLE_TEST)
test_expand_bz2.c
test_expand_gz.c
test_expand_lz4.c
+ test_expand_zstd.c
test_expand_mixed.c
test_expand_plain.c
test_expand_xz.c
diff --git a/cat/test/test_empty.zst.uu b/cat/test/test_empty.zst.uu
new file mode 100644
index 00000000..44ae9a96
--- /dev/null
+++ b/cat/test/test_empty.zst.uu
@@ -0,0 +1,4 @@
+begin 644 test_empty.zst
+-*+4O_010`0``F>G840``
+`
+end
diff --git a/cat/test/test_empty_zstd.c b/cat/test/test_empty_zstd.c
new file mode 100644
index 00000000..c2d5ea10
--- /dev/null
+++ b/cat/test/test_empty_zstd.c
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 2017 Sean Purcell
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_empty_zstd)
+{
+ const char *reffile = "test_empty.zst";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canZstd()) {
+ assertEqualInt(0, f);
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ } else {
+ skipping("It seems zstd is not supported on this platform");
+ }
+}
diff --git a/cat/test/test_expand.zst.uu b/cat/test/test_expand.zst.uu
new file mode 100644
index 00000000..89c28b1b
--- /dev/null
+++ b/cat/test/test_expand.zst.uu
@@ -0,0 +1,4 @@
+begin 644 test_expand.zst
+J*+4O_010Z0``8V]N=&5N=',@;V8@=&5S=%]E>'!A;F0N>G-T+@J;23#F
+`
+end
diff --git a/cat/test/test_expand_zstd.c b/cat/test/test_expand_zstd.c
new file mode 100644
index 00000000..23d91825
--- /dev/null
+++ b/cat/test/test_expand_zstd.c
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 2017 Sean Purcell
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_expand_zstd)
+{
+ const char *reffile = "test_expand.zst";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canZstd()) {
+ assertEqualInt(0, f);
+ assertTextFileContents("contents of test_expand.zst.\n", "test.out");
+ assertEmptyFile("test.err");
+ } else {
+ skipping("It seems zstd is not supported on this platform");
+ }
+}
diff --git a/cpio/test/CMakeLists.txt b/cpio/test/CMakeLists.txt
index 4c3fb88a..3c0e661e 100644
--- a/cpio/test/CMakeLists.txt
+++ b/cpio/test/CMakeLists.txt
@@ -20,6 +20,7 @@ IF(ENABLE_CPIO AND ENABLE_TEST)
test_extract_cpio_lrz
test_extract_cpio_lz
test_extract_cpio_lz4
+ test_extract_cpio_zstd
test_extract_cpio_lzma
test_extract_cpio_lzo
test_extract_cpio_xz
@@ -42,6 +43,7 @@ IF(ENABLE_CPIO AND ENABLE_TEST)
test_option_l.c
test_option_lrzip.c
test_option_lz4.c
+ test_option_zstd.c
test_option_lzma.c
test_option_lzop.c
test_option_m.c
diff --git a/cpio/test/test_extract.cpio.zst.uu b/cpio/test/test_extract.cpio.zst.uu
new file mode 100644
index 00000000..5ec854b8
--- /dev/null
+++ b/cpio/test/test_extract.cpio.zst.uu
@@ -0,0 +1,6 @@
+begin 644 test_extract.cpio.zst
+M*+4O_01090,`,@41%X")&@#'G6T\K16_MR)#=DK)5:.1,2J0HY2"!(1!`!7R
+M$(UB`2"*D41;J2UF&)<0!Y7X'TU<%W.\W^R]GO-WW^OO^QX0`%P<]30-!#U`
+?!KD!`#XP,_`U4`HT3+RF:#!7Y\V@R)5"7P"^;WEUK@``
+`
+end
diff --git a/cpio/test/test_extract_cpio_zstd.c b/cpio/test/test_extract_cpio_zstd.c
new file mode 100644
index 00000000..289f33d0
--- /dev/null
+++ b/cpio/test/test_extract_cpio_zstd.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2017 Sean Purcell
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_extract_cpio_zstd)
+{
+ const char *reffile = "test_extract.cpio.zst";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -it < %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canZstd()) {
+ assertEqualInt(0, systemf("%s -i < %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertTextFileContents("1 block\n", "test.err");
+ } else {
+ skipping("It seems zstd is not supported on this platform");
+ }
+}
diff --git a/cpio/test/test_option_zstd.c b/cpio/test/test_option_zstd.c
new file mode 100644
index 00000000..228356a7
--- /dev/null
+++ b/cpio/test/test_option_zstd.c
@@ -0,0 +1,85 @@
+/*-
+ * Copyright (c) 2017 Sean Purcell
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_zstd)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with lz4 compression. */
+ r = systemf("echo f | %s -o --zstd >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "Unsupported compression") != NULL) {
+ skipping("This version of bsdcpio was compiled "
+ "without zstd support");
+ goto done;
+ }
+ /* POSIX permits different handling of the spawnp
+ * system call used to launch the subsidiary
+ * program: */
+ /* Some systems fail immediately to spawn the new process. */
+ if (strstr(p, "Can't launch") != NULL && !canZstd()) {
+ skipping("This version of bsdcpio uses an external zstd program "
+ "but no such program is available on this system.");
+ goto done;
+ }
+ /* Some systems successfully spawn the new process,
+ * but fail to exec a program within that process.
+ * This results in failure at the first attempt to
+ * write. */
+ if (strstr(p, "Can't write") != NULL && !canZstd()) {
+ skipping("This version of bsdcpio uses an external zstd program "
+ "but no such program is available on this system.");
+ goto done;
+ }
+ /* On some systems the error won't be detected until closing
+ time, by a 127 exit error returned by waitpid. */
+ if (strstr(p, "Error closing") != NULL && !canZstd()) {
+ skipping("This version of bsdcpio uses an external zstd program "
+ "but no such program is available on this system.");
+ return;
+ }
+ failure("--zstd option is broken: %s", p);
+ assertEqualInt(r, 0);
+ goto done;
+ }
+ free(p);
+ /* Check that the archive file has an lz4 signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\x28\xb5\x2f\xfd", 4);
+
+done:
+ free(p);
+}
diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt
index ee8686ba..93bab3f0 100644
--- a/libarchive/test/CMakeLists.txt
+++ b/libarchive/test/CMakeLists.txt
@@ -54,6 +54,7 @@ IF(ENABLE_TEST)
test_compat_gtar.c
test_compat_gzip.c
test_compat_lz4.c
+ test_compat_zstd.c
test_compat_lzip.c
test_compat_lzma.c
test_compat_lzop.c
@@ -220,6 +221,7 @@ IF(ENABLE_TEST)
test_write_filter_gzip_timestamp.c
test_write_filter_lrzip.c
test_write_filter_lz4.c
+ test_write_filter_zstd.c
test_write_filter_lzip.c
test_write_filter_lzma.c
test_write_filter_lzop.c
diff --git a/libarchive/test/test_archive_write_add_filter_by_name.c b/libarchive/test/test_archive_write_add_filter_by_name.c
index 38b606b9..f2ec2e7b 100644
--- a/libarchive/test/test_archive_write_add_filter_by_name.c
+++ b/libarchive/test/test_archive_write_add_filter_by_name.c
@@ -183,6 +183,11 @@ DEFINE_TEST(test_archive_write_add_filter_by_name_lz4)
test_filter_by_name("lz4", ARCHIVE_FILTER_LZ4, canLz4);
}
+DEFINE_TEST(test_archive_write_add_filter_by_name_zstd)
+{
+ test_filter_by_name("zstd", ARCHIVE_FILTER_ZSTD, canZstd);
+}
+
DEFINE_TEST(test_archive_write_add_filter_by_name_lzip)
{
test_filter_by_name("lzip", ARCHIVE_FILTER_LZIP, cannot);
diff --git a/libarchive/test/test_compat_zstd.c b/libarchive/test/test_compat_zstd.c
new file mode 100644
index 00000000..1d63a284
--- /dev/null
+++ b/libarchive/test/test_compat_zstd.c
@@ -0,0 +1,82 @@
+/*-
+ * Copyright (c) 2017 Sean Purcell
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+/*
+ * Verify our ability to read sample files compatibly with 'zstd -d'.
+ *
+ * In particular:
+ * * zstd -d will read multiple zstd streams, concatenating the output
+ * * zstd -d will skip over zstd skippable frames
+ */
+
+static void
+compat_zstd(const char *name)
+{
+ const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL };
+ struct archive_entry *ae;
+ struct archive *a;
+ int i, r;
+
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+ r = archive_read_support_filter_zstd(a);
+ if (r == ARCHIVE_WARN) {
+ skipping("zstd reading not fully supported on this platform");
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ return;
+ }
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+ extract_reference_file(name);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2));
+
+ /* Read entries, match up names with list above. */
+ for (i = 0; i < 6; ++i) {
+ failure("Could not read file %d (%s) from %s", i, n[i], name);
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_next_header(a, &ae));
+ assertEqualString(n[i], archive_entry_pathname(ae));
+ }
+
+ /* Verify the end-of-archive. */
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+
+ /* Verify that the format detection worked. */
+ assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_ZSTD);
+ assertEqualString(archive_filter_name(a, 0), "zstd");
+ assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
+
+ assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
+
+
+DEFINE_TEST(test_compat_zstd)
+{
+ /* This sample was compressed as 3 separate streams with a zstd skippable
+ * frame placed in the middle */
+ compat_zstd("test_compat_zstd_1.tar.zst");
+}
diff --git a/libarchive/test/test_compat_zstd_1.tar.zst.uu b/libarchive/test/test_compat_zstd_1.tar.zst.uu
new file mode 100644
index 00000000..4b0b9844
--- /dev/null
+++ b/libarchive/test/test_compat_zstd_1.tar.zst.uu
@@ -0,0 +1,12 @@
+begin 644 test_compat_zstd_1.tar.zst
+M*+4O_010)0,`HL0.%;`Q&>>\/$2[#IQF[<1+Z3T<0CX]!77&0@R.6+/F,0+I
+M.$1A$QE2`J!+*_6[_YT9_W_M1KC-EG*V>10.`,M`%3*@#F#\`-FT#J:1#U1"
+M`H1!&R#<!.<"@#3@M58XY1,8`DMMD\@HM2_]!%!=`P`B!1`5H#D!0!.SELJ"
+M5#509I*T/YQ^]?H/3T1D>A5\*'"JYIJ;C&4=B2CL(L)*E-IJT/RV?.:A_]_N
+MB&[7SDG;/=4&#P";0!5D0`=8T0&R&19,)1^HA`0(@S9`N`G.!0!IP&NM<,K!
+M-#8!%A]U]K10*DT8!`````$"`P0HM2_]!%!]`P`B11`6H+$)"%]@,Z6OH`"L
+MM$R2MAN&*MSG`W?OJ7+4P*B::VXR`NM(1&$7&58"J*U'_&V^S$/_O]U1N%T[
+M)VW7J'+4!A``_4$%^T`],J`8P.0!L@D63"4?J(0$"(,V0+@)S@4`:<!KK7!J
+)P51V`E@!9CD#
+`
+end
diff --git a/libarchive/test/test_fuzz.c b/libarchive/test/test_fuzz.c
index ce7b8663..42351450 100644
--- a/libarchive/test/test_fuzz.c
+++ b/libarchive/test/test_fuzz.c
@@ -413,6 +413,12 @@ DEFINE_TEST(test_fuzz_tar)
NULL
};
#endif
+#if HAVE_ZSTD_H && HAVE_LIBZSTD
+ static const char *fileset10[] = {
+ "test_compat_zstd_1.tar.zst",
+ NULL
+ };
+#endif
static const struct files filesets[] = {
{0, fileset1}, /* Exercise bzip2 decompressor. */
{1, fileset1},
@@ -426,6 +432,9 @@ DEFINE_TEST(test_fuzz_tar)
#if HAVE_LIBLZO2 && HAVE_LZO_LZO1X_H && HAVE_LZO_LZOCONF_H
{0, fileset9}, /* Exercise lzo decompressor. */
#endif
+#if HAVE_ZSTD_H && HAVE_LIBZSTD
+ {0, fileset10}, /* Excercise zstd decompressor. */
+#endif
{1, NULL}
};
test_fuzz(filesets);
diff --git a/libarchive/test/test_write_filter_zstd.c b/libarchive/test/test_write_filter_zstd.c
new file mode 100644
index 00000000..b9823906
--- /dev/null
+++ b/libarchive/test/test_write_filter_zstd.c
@@ -0,0 +1,201 @@
+/*-
+ * Copyright (c) 2017 Sean Purcell
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_write_filter_zstd)
+{
+ struct archive_entry *ae;
+ struct archive *a;
+ char *buff, *data;
+ size_t buffsize, datasize;
+ char path[16];
+ size_t used1, used2;
+ int i, r;
+
+ buffsize = 2000000;
+ assert(NULL != (buff = (char *)malloc(buffsize)));
+ if (buff == NULL)
+ return;
+
+ datasize = 10000;
+ assert(NULL != (data = (char *)malloc(datasize)));
+ if (data == NULL) {
+ free(buff);
+ return;
+ }
+ memset(data, 0, datasize);
+
+ /*
+ * Write a 100 files and read them all back.
+ */
+ assert((a = archive_write_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
+ r = archive_write_add_filter_zstd(a);
+ if (r == ARCHIVE_FATAL) {
+ skipping("zstd writing not supported on this platform");
+ assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+ free(buff);
+ free(data);
+ return;
+ }
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_write_set_bytes_per_block(a, 10));
+ assertEqualInt(ARCHIVE_FILTER_ZSTD, archive_filter_code(a, 0));
+ assertEqualString("zstd", archive_filter_name(a, 0));
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used1));
+ assertEqualInt(ARCHIVE_FILTER_ZSTD, archive_filter_code(a, 0));
+ assertEqualString("zstd", archive_filter_name(a, 0));
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_set_filetype(ae, AE_IFREG);
+ archive_entry_set_size(ae, datasize);
+ for (i = 0; i < 100; i++) {
+ sprintf(path, "file%03d", i);
+ archive_entry_copy_pathname(ae, path);
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
+ assertA(datasize
+ == (size_t)archive_write_data(a, data, datasize));
+ }
+ archive_entry_free(ae);
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+ r = archive_read_support_filter_zstd(a);
+ if (r == ARCHIVE_WARN) {
+ skipping("Can't verify zstd writing by reading back;"
+ " zstd reading not fully supported on this platform");
+ } else {
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_support_filter_all(a));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_open_memory(a, buff, used1));
+ for (i = 0; i < 100; i++) {
+ sprintf(path, "file%03d", i);
+ if (!assertEqualInt(ARCHIVE_OK,
+ archive_read_next_header(a, &ae)))
+ break;
+ assertEqualString(path, archive_entry_pathname(ae));
+ assertEqualInt((int)datasize, archive_entry_size(ae));
+ }
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ }
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+ /*
+ * Repeat the cycle again, this time setting some compression
+ * options.
+ */
+ assert((a = archive_write_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_write_set_bytes_per_block(a, 10));
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_zstd(a));
+ assertEqualIntA(a, ARCHIVE_FAILED,
+ archive_write_set_filter_option(a, NULL, "nonexistent-option", "0"));
+ assertEqualIntA(a, ARCHIVE_FAILED,
+ archive_write_set_filter_option(a, NULL, "compression-level", "abc"));
+ assertEqualIntA(a, ARCHIVE_FAILED,
+ archive_write_set_filter_option(a, NULL, "compression-level", "25")); /* too big */
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_write_set_filter_option(a, NULL, "compression-level", "9"));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_write_set_filter_option(a, NULL, "compression-level", "15"));
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
+ for (i = 0; i < 100; i++) {
+ sprintf(path, "file%03d", i);
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, path);
+ archive_entry_set_size(ae, datasize);
+ archive_entry_set_filetype(ae, AE_IFREG);
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
+ assertA(datasize == (size_t)archive_write_data(a, data, datasize));
+ archive_entry_free(ae);
+ }
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+ failure("compression-level=15 wrote %d bytes, default wrote %d bytes",
+ (int)used2, (int)used1);
+ assert(used2 < used1);
+
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+ r = archive_read_support_filter_zstd(a);
+ if (r == ARCHIVE_WARN) {
+ skipping("zstd reading not fully supported on this platform");
+ } else {
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_support_filter_all(a));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_open_memory(a, buff, used2));
+ for (i = 0; i < 100; i++) {
+ sprintf(path, "file%03d", i);
+ failure("Trying to read %s", path);
+ if (!assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_next_header(a, &ae)))
+ break;
+ assertEqualString(path, archive_entry_pathname(ae));
+ assertEqualInt((int)datasize, archive_entry_size(ae));
+ }
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ }
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+ /*
+ * Test various premature shutdown scenarios to make sure we
+ * don't crash or leak memory.
+ */
+ assert((a = archive_write_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_zstd(a));
+ assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+ assert((a = archive_write_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_zstd(a));
+ assertEqualInt(ARCHIVE_OK, archive_write_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+ assert((a = archive_write_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_zstd(a));
+ assertEqualInt(ARCHIVE_OK, archive_write_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+ assert((a = archive_write_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_zstd(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
+ assertEqualInt(ARCHIVE_OK, archive_write_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+ /*
+ * Clean up.
+ */
+ free(data);
+ free(buff);
+}
diff --git a/tar/test/CMakeLists.txt b/tar/test/CMakeLists.txt
index abd43b0f..fb9dfee7 100644
--- a/tar/test/CMakeLists.txt
+++ b/tar/test/CMakeLists.txt
@@ -19,6 +19,7 @@ IF(ENABLE_TAR AND ENABLE_TEST)
test_extract_tar_lrz.c
test_extract_tar_lz.c
test_extract_tar_lz4.c
+ test_extract_tar_zstd.c
test_extract_tar_lzma.c
test_extract_tar_lzo.c
test_extract_tar_xz.c
@@ -46,6 +47,7 @@ IF(ENABLE_TAR AND ENABLE_TEST)
test_option_keep_newer_files.c
test_option_lrzip.c
test_option_lz4.c
+ test_option_zstd.c
test_option_lzma.c
test_option_lzop.c
test_option_n.c
diff --git a/tar/test/test_extract.tar.zst.uu b/tar/test/test_extract.tar.zst.uu
new file mode 100644
index 00000000..3df0caf5
--- /dev/null
+++ b/tar/test/test_extract.tar.zst.uu
@@ -0,0 +1,6 @@
+begin 644 test_extract.tar.zst
+M*+4O_010S0,`<L40$Z`5.(2U_RNV_[]L4V;Z_/R@1:7Y$3;9E`8$D$WI:W1)
+M'58'D3->Y+>!0*5E/PM"$7^K^1VI3SS-AX&_W0KQWY!-Z1(`_4$%[$"]<T!A
+L(*`#I!DXC4[J!6J8$!DJ$D"9$T*L]#G-$$/A`#`I`-(`UUKAU$Z@"`UXII``
+`
+end
diff --git a/tar/test/test_extract_tar_zstd.c b/tar/test/test_extract_tar_zstd.c
new file mode 100644
index 00000000..d67170ce
--- /dev/null
+++ b/tar/test/test_extract_tar_zstd.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2017 Sean Purcell
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_extract_tar_zstd)
+{
+ const char *reffile = "test_extract.tar.zst";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canZstd()) {
+ assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ } else {
+ skipping("It seems zstd is not supported on this platform");
+ }
+}
diff --git a/tar/test/test_option_zstd.c b/tar/test/test_option_zstd.c
new file mode 100644
index 00000000..73965e33
--- /dev/null
+++ b/tar/test/test_option_zstd.c
@@ -0,0 +1,85 @@
+/*-
+ * Copyright (c) 2017 Sean Purcell
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_zstd)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with lz4 compression. */
+ r = systemf("%s -cf - --zstd f >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "Unsupported compression") != NULL) {
+ skipping("This version of bsdtar was compiled "
+ "without zstd support");
+ goto done;
+ }
+ /* POSIX permits different handling of the spawnp
+ * system call used to launch the subsidiary
+ * program: */
+ /* Some systems fail immediately to spawn the new process. */
+ if (strstr(p, "Can't launch") != NULL && !canZstd()) {
+ skipping("This version of bsdtar uses an external zstd program "
+ "but no such program is available on this system.");
+ goto done;
+ }
+ /* Some systems successfully spawn the new process,
+ * but fail to exec a program within that process.
+ * This results in failure at the first attempt to
+ * write. */
+ if (strstr(p, "Can't write") != NULL && !canZstd()) {
+ skipping("This version of bsdtar uses an external zstd program "
+ "but no such program is available on this system.");
+ goto done;
+ }
+ /* On some systems the error won't be detected until closing
+ time, by a 127 exit error returned by waitpid. */
+ if (strstr(p, "Error closing") != NULL && !canZstd()) {
+ skipping("This version of bsdcpio uses an external zstd program "
+ "but no such program is available on this system.");
+ return;
+ }
+ failure("--zstd option is broken: %s", p);
+ assertEqualInt(r, 0);
+ goto done;
+ }
+ free(p);
+ /* Check that the archive file has an lz4 signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\x28\xb5\x2f\xfd", 4);
+
+done:
+ free(p);
+}
diff --git a/test_utils/test_common.h b/test_utils/test_common.h
index 1425dd84..dd7e4101 100644
--- a/test_utils/test_common.h
+++ b/test_utils/test_common.h
@@ -329,6 +329,9 @@ int canLrzip(void);
/* Return true if this platform can run the "lz4" program. */
int canLz4(void);
+/* Return true if this platform can run the "zstd" program. */
+int canZstd(void);
+
/* Return true if this platform can run the "lzip" program. */
int canLzip(void);
diff --git a/test_utils/test_main.c b/test_utils/test_main.c
index 0e141369..0e8cc9fc 100644
--- a/test_utils/test_main.c
+++ b/test_utils/test_main.c
@@ -2319,6 +2319,21 @@ canLz4(void)
}
/*
+ * Can this platform run the zstd program?
+ */
+int
+canZstd(void)
+{
+ static int tested = 0, value = 0;
+ if (!tested) {
+ tested = 1;
+ if (systemf("zstd -V %s", redirectArgs) == 0)
+ value = 1;
+ }
+ return (value);
+}
+
+/*
* Can this platform run the lzip program?
*/
int