]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add zstd test suite
authorSean Purcell <me@seanp.xyz>
Thu, 20 Apr 2017 18:59:10 +0000 (11:59 -0700)
committerSean Purcell <iburinoc@gmail.com>
Tue, 16 May 2017 03:06:48 +0000 (23:06 -0400)
22 files changed:
Makefile.am
cat/test/CMakeLists.txt
cat/test/test_empty.zst.uu [new file with mode: 0644]
cat/test/test_empty_zstd.c [new file with mode: 0644]
cat/test/test_expand.zst.uu [new file with mode: 0644]
cat/test/test_expand_zstd.c [new file with mode: 0644]
cpio/test/CMakeLists.txt
cpio/test/test_extract.cpio.zst.uu [new file with mode: 0644]
cpio/test/test_extract_cpio_zstd.c [new file with mode: 0644]
cpio/test/test_option_zstd.c [new file with mode: 0644]
libarchive/test/CMakeLists.txt
libarchive/test/test_archive_write_add_filter_by_name.c
libarchive/test/test_compat_zstd.c [new file with mode: 0644]
libarchive/test/test_compat_zstd_1.tar.zst.uu [new file with mode: 0644]
libarchive/test/test_fuzz.c
libarchive/test/test_write_filter_zstd.c [new file with mode: 0644]
tar/test/CMakeLists.txt
tar/test/test_extract.tar.zst.uu [new file with mode: 0644]
tar/test/test_extract_tar_zstd.c [new file with mode: 0644]
tar/test/test_option_zstd.c [new file with mode: 0644]
test_utils/test_common.h
test_utils/test_main.c

index a3762e640da9f8473296a47b420b47a77da8393c..687f9d6707fe160afc7e99d605e1931f9397e72d 100644 (file)
@@ -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
index 0cd3aad84f49584ae57307f578eefe3f1bb9eb3e..e76e92e6be72a522d01a792f01d3bf08427f99ea 100644 (file)
@@ -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 (file)
index 0000000..44ae9a9
--- /dev/null
@@ -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 (file)
index 0000000..c2d5ea1
--- /dev/null
@@ -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 (file)
index 0000000..89c28b1
--- /dev/null
@@ -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 (file)
index 0000000..23d9182
--- /dev/null
@@ -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");
+       }
+}
index 4c3fb88a61fd67fd7420f91bc17172169ef86e7a..3c0e661eb04f7b30f536f1d9f579268089652f38 100644 (file)
@@ -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 (file)
index 0000000..5ec854b
--- /dev/null
@@ -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 (file)
index 0000000..289f33d
--- /dev/null
@@ -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 (file)
index 0000000..228356a
--- /dev/null
@@ -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);
+}
index ee8686bae98482d47fda8952ffdd614e23178d1f..93bab3f0ab42bf389f293f2aff16272d64c5ee5c 100644 (file)
@@ -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
index 38b606b9d165464173844ac5ae42f0eb870ae521..f2ec2e7b035a89348207f0aa69e2fd139793f7b6 100644 (file)
@@ -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 (file)
index 0000000..1d63a28
--- /dev/null
@@ -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 (file)
index 0000000..4b0b984
--- /dev/null
@@ -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
index ce7b8663faea122747108116a7c217ea7d3e97de..42351450b26530ed2f43310b679de83480204415 100644 (file)
@@ -412,6 +412,12 @@ DEFINE_TEST(test_fuzz_tar)
                "test_compat_lzop_1.tar.lzo",
                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. */
@@ -425,6 +431,9 @@ DEFINE_TEST(test_fuzz_tar)
                {0, fileset8},
 #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}
        };
diff --git a/libarchive/test/test_write_filter_zstd.c b/libarchive/test/test_write_filter_zstd.c
new file mode 100644 (file)
index 0000000..b982390
--- /dev/null
@@ -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);
+}
index abd43b0f4b25ed46cd80ac096d99028dd800176a..fb9dfee748e2bfb08d30df9137a4169f855461d1 100644 (file)
@@ -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 (file)
index 0000000..3df0caf
--- /dev/null
@@ -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 (file)
index 0000000..d67170c
--- /dev/null
@@ -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 (file)
index 0000000..73965e3
--- /dev/null
@@ -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);
+}
index 1425dd84b7df6a1071971c1422fe2bc56f13ecf9..dd7e41016d52acc683fdbadf825d29375a9c799b 100644 (file)
@@ -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);
 
index 0e1413693f4a86807e35d97aeef079cae3500a21..0e8cc9fc56a29b7ca3bbbf9a6fcd0b1d9e152851 100644 (file)
@@ -2318,6 +2318,21 @@ canLz4(void)
        return (value);
 }
 
+/*
+ * 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?
  */