|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From c552d602ae784c0261ceeb46ace30e6189f38bb2 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Date: Sat, 30 Aug 2014 14:47:36 -0400
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Subject: [PATCH] test-compress: also test with incompressible inputs
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/journal/test-compress.c | 91 ++++++++++++++++++++++++++++++++-------------
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
1 file changed, 65 insertions(+), 26 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/journal/test-compress.c b/src/journal/test-compress.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 026d630ac2..78b3203bef 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/journal/test-compress.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/journal/test-compress.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -48,25 +48,31 @@ typedef int (decompress_stream_t)(int fdf, int fdt, off_t max_size);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
static void test_compress_decompress(int compression,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
compress_blob_t compress,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- decompress_blob_t decompress) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- char text[] = "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF"
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF";
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ decompress_blob_t decompress,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ const char *data,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ size_t data_len,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ bool may_fail) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
char compressed[512];
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
size_t csize = 512;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
size_t usize = 0;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
_cleanup_free_ char *decompressed = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- log_info("/* testing %s blob compression/decompression */",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- object_compressed_to_string(compression));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- r = compress(text, sizeof(text), compressed, &csize);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- assert(r == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- r = decompress(compressed, csize,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- (void **) &decompressed, &usize, &csize, 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- assert(r == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- assert_se(decompressed);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- assert_se(streq(decompressed, text));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ log_info("/* testing %s %s blob compression/decompression */",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ object_compressed_to_string(compression), data);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = compress(data, data_len, compressed, &csize);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r == -ENOBUFS) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ log_info("compression failed: %s", strerror(-r));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(may_fail);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ } else {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(r == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = decompress(compressed, csize,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ (void **) &decompressed, &usize, &csize, 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(r == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert_se(decompressed);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert_se(memcmp(decompressed, data, data_len) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = decompress("garbage", 7,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
(void **) &decompressed, &usize, &csize, 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -86,29 +92,38 @@ static void test_compress_decompress(int compression,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
static void test_decompress_startswith(int compression,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
compress_blob_t compress,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- decompress_sw_t decompress_sw) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ decompress_sw_t decompress_sw,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ const char *data,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ size_t data_len,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ bool may_fail) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- char text[] = "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF"
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF";
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
char compressed[512];
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
size_t csize = 512;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
size_t usize = 0;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
_cleanup_free_ char *decompressed = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ int r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- log_info("/* testing decompress_startswith with %s */",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- object_compressed_to_string(compression));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ log_info("/* testing decompress_startswith with %s on %s text*/",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ object_compressed_to_string(compression), data);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = compress(data, data_len, compressed, &csize);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r == -ENOBUFS) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ log_info("compression failed: %s", strerror(-r));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(may_fail);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(r == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- assert_se(compress(text, sizeof(text), compressed, &csize) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
assert_se(decompress_sw(compressed,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
csize,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
(void **) &decompressed,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
&usize,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- "foofoofoofoo", 12, ' ') > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ data, strlen(data), '\0') > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
assert_se(decompress_sw(compressed,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
csize,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
(void **) &decompressed,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
&usize,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- "foofoofoofoo", 12, 'w') == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ data, strlen(data), 'w') == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
assert_se(decompress_sw(compressed,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
csize,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
(void **) &decompressed,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -118,7 +133,7 @@ static void test_decompress_startswith(int compression,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
csize,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
(void **) &decompressed,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
&usize,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- "foofoofoofoo", 12, ' ') > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ data, strlen(data), '\0') > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
static void test_compress_stream(int compression,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -181,20 +196,44 @@ static void test_compress_stream(int compression,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int main(int argc, char *argv[]) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ const char text[] =
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ "text\0foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF"
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF";
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ char data[512] = "random\0";
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
log_set_max_level(LOG_DEBUG);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ random_bytes(data + 7, sizeof(data) - 7);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
#ifdef HAVE_XZ
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- test_compress_decompress(OBJECT_COMPRESSED_XZ, compress_blob_xz, decompress_blob_xz);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- test_decompress_startswith(OBJECT_COMPRESSED_XZ, compress_blob_xz, decompress_startswith_xz);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ test_compress_decompress(OBJECT_COMPRESSED_XZ, compress_blob_xz, decompress_blob_xz,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ text, sizeof(text), false);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ test_compress_decompress(OBJECT_COMPRESSED_XZ, compress_blob_xz, decompress_blob_xz,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ data, sizeof(data), true);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ test_decompress_startswith(OBJECT_COMPRESSED_XZ,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ compress_blob_xz, decompress_startswith_xz,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ text, sizeof(text), false);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ test_decompress_startswith(OBJECT_COMPRESSED_XZ,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ compress_blob_xz, decompress_startswith_xz,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ data, sizeof(data), true);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
test_compress_stream(OBJECT_COMPRESSED_XZ, "xzcat",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
compress_stream_xz, decompress_stream_xz, argv[0]);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
#else
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
log_info("/* XZ test skipped */");
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
#endif
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
#ifdef HAVE_LZ4
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- test_compress_decompress(OBJECT_COMPRESSED_LZ4, compress_blob_lz4, decompress_blob_lz4);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- test_decompress_startswith(OBJECT_COMPRESSED_LZ4, compress_blob_lz4, decompress_startswith_lz4);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ test_compress_decompress(OBJECT_COMPRESSED_LZ4, compress_blob_lz4, decompress_blob_lz4,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ text, sizeof(text), false);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ test_compress_decompress(OBJECT_COMPRESSED_LZ4, compress_blob_lz4, decompress_blob_lz4,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ data, sizeof(data), true);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ test_decompress_startswith(OBJECT_COMPRESSED_LZ4,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ compress_blob_lz4, decompress_startswith_lz4,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ text, sizeof(text), false);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ test_decompress_startswith(OBJECT_COMPRESSED_LZ4,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ compress_blob_lz4, decompress_startswith_lz4,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ data, sizeof(data), true);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
/* Produced stream is not compatible with lz4 binary, skip lz4cat check. */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
test_compress_stream(OBJECT_COMPRESSED_LZ4, NULL,
|