Blame SOURCES/libarchive-3.3.3-fixed-zstd_test.patch

fd59e7
From 1bb2ec24b433bf87fed40e207c61c6aa8790e793 Mon Sep 17 00:00:00 2001
fd59e7
From: Ondrej Dubaj <odubaj@redhat.com>
fd59e7
Date: Mon, 18 Nov 2019 12:41:07 +0100
fd59e7
Subject: [PATCH] test_write_filter_zstd: size @ lvl=20 < default < lvl=1
fd59e7
fd59e7
Raise compression on the second test to level=20, and perform a
fd59e7
third at level=1. Expect the output archive sizes to line up
fd59e7
based on compression level. Reduces test susceptibility to small
fd59e7
output size variations from different libzstd releases.
fd59e7
---
fd59e7
 libarchive/test/test_write_filter_zstd.c      | 66 +++++++++++++++++--
fd59e7
 1 file changed, 60 insertions(+), 6 deletions(-)
fd59e7
fd59e7
diff --git a/libarchive/test/test_write_filter_zstd.c b/libarchive/test/test_write_filter_zstd.c
fd59e7
index da3c806..13de134 100644
fd59e7
--- a/libarchive/test/test_write_filter_zstd.c
fd59e7
+++ b/libarchive/test/test_write_filter_zstd.c
fd59e7
@@ -34,7 +34,7 @@ DEFINE_TEST(test_write_filter_zstd)
fd59e7
 	char *buff, *data;
fd59e7
 	size_t buffsize, datasize;
fd59e7
 	char path[16];
fd59e7
-	size_t used1, used2;
fd59e7
+	size_t used1, used2, used3;
fd59e7
 	int i, r;
fd59e7
 
fd59e7
 	buffsize = 2000000;
fd59e7
@@ -125,7 +125,7 @@ DEFINE_TEST(test_write_filter_zstd)
fd59e7
 	assertEqualIntA(a, ARCHIVE_OK,
fd59e7
 	    archive_write_set_filter_option(a, NULL, "compression-level", "9"));
fd59e7
 	assertEqualIntA(a, ARCHIVE_OK,
fd59e7
-	    archive_write_set_filter_option(a, NULL, "compression-level", "6"));
fd59e7
+	    archive_write_set_filter_option(a, NULL, "compression-level", "20"));
fd59e7
 	assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2));
fd59e7
 	for (i = 0; i < 100; i++) {
fd59e7
 		sprintf(path, "file%03d", i);
fd59e7
@@ -140,10 +140,6 @@ DEFINE_TEST(test_write_filter_zstd)
fd59e7
 	assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
fd59e7
 	assertEqualInt(ARCHIVE_OK, archive_write_free(a));
fd59e7
 
fd59e7
-	failure("compression-level=6 wrote %d bytes, default wrote %d bytes",
fd59e7
-	    (int)used2, (int)used1);
fd59e7
-	assert(used2 < used1);
fd59e7
-
fd59e7
 	assert((a = archive_read_new()) != NULL);
fd59e7
 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
fd59e7
 	r = archive_read_support_filter_zstd(a);
fd59e7
@@ -167,6 +163,64 @@ DEFINE_TEST(test_write_filter_zstd)
fd59e7
 	}
fd59e7
 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
fd59e7
 
fd59e7
+	/*
fd59e7
+	 * One more time at level 1
fd59e7
+	 */
fd59e7
+	assert((a = archive_write_new()) != NULL);
fd59e7
+	assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
fd59e7
+	assertEqualIntA(a, ARCHIVE_OK,
fd59e7
+	    archive_write_set_bytes_per_block(a, 10));
fd59e7
+	assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_zstd(a));
fd59e7
+	assertEqualIntA(a, ARCHIVE_OK,
fd59e7
+	    archive_write_set_filter_option(a, NULL, "compression-level", "1"));
fd59e7
+	assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used3));
fd59e7
+	assert((ae = archive_entry_new()) != NULL);
fd59e7
+	archive_entry_set_filetype(ae, AE_IFREG);
fd59e7
+	archive_entry_set_size(ae, datasize);
fd59e7
+	for (i = 0; i < 100; i++) {
fd59e7
+		sprintf(path, "file%03d", i);
fd59e7
+		archive_entry_copy_pathname(ae, path);
fd59e7
+		assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
fd59e7
+		assertA(datasize == (size_t)archive_write_data(a, data, datasize));
fd59e7
+	}
fd59e7
+	archive_entry_free(ae);
fd59e7
+	assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
fd59e7
+	assertEqualInt(ARCHIVE_OK, archive_write_free(a));
fd59e7
+
fd59e7
+	assert((a = archive_read_new()) != NULL);
fd59e7
+	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
fd59e7
+	r = archive_read_support_filter_zstd(a);
fd59e7
+	if (r == ARCHIVE_WARN) {
fd59e7
+		skipping("zstd reading not fully supported on this platform");
fd59e7
+	} else {
fd59e7
+		assertEqualIntA(a, ARCHIVE_OK,
fd59e7
+		    archive_read_support_filter_all(a));
fd59e7
+		assertEqualIntA(a, ARCHIVE_OK,
fd59e7
+		    archive_read_open_memory(a, buff, used3));
fd59e7
+		for (i = 0; i < 100; i++) {
fd59e7
+			sprintf(path, "file%03d", i);
fd59e7
+			failure("Trying to read %s", path);
fd59e7
+			if (!assertEqualIntA(a, ARCHIVE_OK,
fd59e7
+				archive_read_next_header(a, &ae)))
fd59e7
+				break;
fd59e7
+			assertEqualString(path, archive_entry_pathname(ae));
fd59e7
+			assertEqualInt((int)datasize, archive_entry_size(ae));
fd59e7
+		}
fd59e7
+		assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
fd59e7
+	}
fd59e7
+	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
fd59e7
+
fd59e7
+	/*
fd59e7
+	 * Check output sizes for various compression levels, expectation
fd59e7
+	 * is that archive size for level=20 < default < level=1
fd59e7
+	 */
fd59e7
+	failure("compression-level=20 wrote %d bytes, default wrote %d bytes",
fd59e7
+	    (int)used2, (int)used1);
fd59e7
+	assert(used2 < used1);
fd59e7
+	failure("compression-level=1 wrote %d bytes, default wrote %d bytes",
fd59e7
+	    (int)used3, (int)used1);
fd59e7
+	assert(used1 < used3);
fd59e7
+
fd59e7
 	/*
fd59e7
 	 * Test various premature shutdown scenarios to make sure we
fd59e7
 	 * don't crash or leak memory.
fd59e7
-- 
fd59e7
2.19.1
fd59e7