summaryrefslogtreecommitdiffstats
path: root/src/test/test-compress.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:45 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:45 +0000
commitefeb864cb547a2cbf96dc0053a8bdb4d9190b364 (patch)
treec0b83368f18be983fcc763200c4c24d633244588 /src/test/test-compress.c
parentReleasing progress-linux version 255.5-1~progress7.99u1. (diff)
downloadsystemd-efeb864cb547a2cbf96dc0053a8bdb4d9190b364.tar.xz
systemd-efeb864cb547a2cbf96dc0053a8bdb4d9190b364.zip
Merging upstream version 256.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/test/test-compress.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/test/test-compress.c b/src/test/test-compress.c
index 2f20d00..868b862 100644
--- a/src/test/test-compress.c
+++ b/src/test/test-compress.c
@@ -6,6 +6,7 @@
#include <lz4.h>
#endif
+#include "dlfcn-util.h"
#include "alloc-util.h"
#include "compress.h"
#include "fd-util.h"
@@ -187,13 +188,13 @@ _unused_ static void test_compress_stream(const char *compression,
log_debug("/* create source from %s */", srcfile);
- assert_se((src = open(srcfile, O_RDONLY|O_CLOEXEC)) >= 0);
+ ASSERT_OK((src = open(srcfile, O_RDONLY|O_CLOEXEC)));
log_debug("/* test compression */");
assert_se((dst = mkostemp_safe(pattern)) >= 0);
- assert_se(compress(src, dst, -1, &uncompressed_size) >= 0);
+ ASSERT_OK(compress(src, dst, -1, &uncompressed_size));
if (cat) {
assert_se(asprintf(&cmd, "%s %s | diff %s -", cat, pattern, srcfile) > 0);
@@ -241,16 +242,16 @@ static void test_lz4_decompress_partial(void) {
memset(&huge[STRLEN("HUGE=")], 'x', HUGE_SIZE - STRLEN("HUGE=") - 1);
huge[HUGE_SIZE - 1] = '\0';
- r = LZ4_compress_default(huge, buf, HUGE_SIZE, buf_size);
+ r = sym_LZ4_compress_default(huge, buf, HUGE_SIZE, buf_size);
assert_se(r >= 0);
compressed = r;
log_info("Compressed %i → %zu", HUGE_SIZE, compressed);
- r = LZ4_decompress_safe(buf, huge, r, HUGE_SIZE);
+ r = sym_LZ4_decompress_safe(buf, huge, r, HUGE_SIZE);
assert_se(r >= 0);
log_info("Decompressed → %i", r);
- r = LZ4_decompress_safe_partial(buf, huge,
+ r = sym_LZ4_decompress_safe_partial(buf, huge,
compressed,
12, HUGE_SIZE);
assert_se(r >= 0);
@@ -258,10 +259,10 @@ static void test_lz4_decompress_partial(void) {
for (size_t size = 1; size < sizeof(buf2); size++) {
/* This failed in older lz4s but works in newer ones. */
- r = LZ4_decompress_safe_partial(buf, buf2, compressed, size, size);
+ r = sym_LZ4_decompress_safe_partial(buf, buf2, compressed, size, size);
log_info("Decompressed partial %zu/%zu → %i (%s)", size, size, r,
r < 0 ? "bad" : "good");
- if (r >= 0 && LZ4_versionNumber() >= 10803)
+ if (r >= 0 && sym_LZ4_versionNumber() >= 10803)
/* lz4 <= 1.8.2 should fail that test, let's only check for newer ones */
assert_se(memcmp(buf2, huge, r) == 0);
}
@@ -316,28 +317,30 @@ int main(int argc, char *argv[]) {
#endif
#if HAVE_LZ4
- test_compress_decompress("LZ4", compress_blob_lz4, decompress_blob_lz4,
- text, sizeof(text), false);
- test_compress_decompress("LZ4", compress_blob_lz4, decompress_blob_lz4,
- data, sizeof(data), true);
-
- test_decompress_startswith("LZ4",
- compress_blob_lz4, decompress_startswith_lz4,
- text, sizeof(text), false);
- test_decompress_startswith("LZ4",
- compress_blob_lz4, decompress_startswith_lz4,
- data, sizeof(data), true);
- test_decompress_startswith("LZ4",
- compress_blob_lz4, decompress_startswith_lz4,
- huge, HUGE_SIZE, true);
-
- test_compress_stream("LZ4", "lz4cat",
- compress_stream_lz4, decompress_stream_lz4, srcfile);
-
- test_lz4_decompress_partial();
-
- test_decompress_startswith_short("LZ4", compress_blob_lz4, decompress_startswith_lz4);
-
+ if (dlopen_lz4() >= 0) {
+ test_compress_decompress("LZ4", compress_blob_lz4, decompress_blob_lz4,
+ text, sizeof(text), false);
+ test_compress_decompress("LZ4", compress_blob_lz4, decompress_blob_lz4,
+ data, sizeof(data), true);
+
+ test_decompress_startswith("LZ4",
+ compress_blob_lz4, decompress_startswith_lz4,
+ text, sizeof(text), false);
+ test_decompress_startswith("LZ4",
+ compress_blob_lz4, decompress_startswith_lz4,
+ data, sizeof(data), true);
+ test_decompress_startswith("LZ4",
+ compress_blob_lz4, decompress_startswith_lz4,
+ huge, HUGE_SIZE, true);
+
+ test_compress_stream("LZ4", "lz4cat",
+ compress_stream_lz4, decompress_stream_lz4, srcfile);
+
+ test_lz4_decompress_partial();
+
+ test_decompress_startswith_short("LZ4", compress_blob_lz4, decompress_startswith_lz4);
+ } else
+ log_error("/* Can't load liblz4 */");
#else
log_info("/* LZ4 test skipped */");
#endif