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