summaryrefslogtreecommitdiff
path: root/src/journal/test-compress.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-06-24 21:24:46 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-06-26 01:41:04 -0400
commit355b59e252c9910e44a1ad95c045ba8db58a4f6a (patch)
tree7428dd29c3fb1488b3b04a0bd7c4cb1fd6b5c597 /src/journal/test-compress.c
parent76cc0bf682b944d4cb611f1b37c71fce140f8fe7 (diff)
journal/compress: add stream compression/decompression functions
Diffstat (limited to 'src/journal/test-compress.c')
-rw-r--r--src/journal/test-compress.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/journal/test-compress.c b/src/journal/test-compress.c
index 15b3f9aa00..b098ef93a8 100644
--- a/src/journal/test-compress.c
+++ b/src/journal/test-compress.c
@@ -68,9 +68,63 @@ static void test_uncompress_startswith(void) {
"barbarbar", 9, ' '));
}
+static void test_compress_stream(const char *srcfile) {
+ _cleanup_close_ int src = -1, dst = -1, dst2 = -1;
+ char pattern[] = "/tmp/systemd-test.xz.XXXXXX",
+ pattern2[] = "/tmp/systemd-test.xz.XXXXXX";
+ int r;
+ _cleanup_free_ char *cmd, *cmd2;
+ struct stat st = {};
+
+ log_debug("/* create source from %s */", srcfile);
+
+ assert_se((src = open(srcfile, O_RDONLY|O_CLOEXEC)) >= 0);
+
+ log_debug("/* test compression */");
+
+ assert_se((dst = mkostemp_safe(pattern, O_RDWR|O_CLOEXEC)) >= 0);
+
+ r = compress_stream(src, dst, -1);
+ assert(r == 0);
+
+ assert_se(asprintf(&cmd, "xzcat %s | diff %s -", pattern, srcfile) > 0);
+ assert_se(system(cmd) == 0);
+
+ log_debug("/* test decompression */");
+
+ assert_se((dst2 = mkostemp_safe(pattern2, O_RDWR|O_CLOEXEC)) >= 0);
+
+ assert_se(stat(srcfile, &st) == 0);
+
+ assert_se(lseek(dst, 0, SEEK_SET) == 0);
+ r = decompress_stream(dst, dst2, st.st_size);
+ assert(r == 0);
+
+ assert_se(asprintf(&cmd2, "diff %s %s", srcfile, pattern2) > 0);
+ assert_se(system(cmd2) == 0);
+
+ log_debug("/* test faulty decompression */");
+
+ assert_se(lseek(dst, 1, SEEK_SET) == 1);
+ r = decompress_stream(dst, dst2, st.st_size);
+ assert(r == -EBADMSG);
+
+ assert_se(lseek(dst, 0, SEEK_SET) == 0);
+ assert_se(lseek(dst2, 0, SEEK_SET) == 0);
+ r = decompress_stream(dst, dst2, st.st_size - 1);
+ assert(r == -E2BIG);
+
+ assert_se(unlink(pattern) == 0);
+ assert_se(unlink(pattern2) == 0);
+}
+
int main(int argc, char *argv[]) {
+
+ log_set_max_level(LOG_DEBUG);
+
test_compress_uncompress();
test_uncompress_startswith();
+ test_compress_stream(argv[0]);
return 0;
}