]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/journal/test-compress-benchmark.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / journal / test-compress-benchmark.c
index baed0d82a46befa2ace2cb51a8289d46902fc4f5..409a876054aa644b20d7763f3183c2ea2cc5121f 100644 (file)
@@ -1,5 +1,4 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd
 
@@ -21,6 +20,7 @@
 
 #include "alloc-util.h"
 #include "compress.h"
+#include "env-util.h"
 #include "macro.h"
 #include "parse-util.h"
 #include "random-util.h"
@@ -32,7 +32,9 @@ typedef int (compress_t)(const void *src, uint64_t src_size, void *dst,
 typedef int (decompress_t)(const void *src, uint64_t src_size,
                            void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
 
-static usec_t arg_duration = 2 * USEC_PER_SEC;
+#if HAVE_XZ || HAVE_LZ4
+
+static usec_t arg_duration;
 static size_t arg_start;
 
 #define MAX_SIZE (1024*1024LU)
@@ -107,6 +109,8 @@ static void test_compress_decompress(const char* label, const char* type,
                 int r;
 
                 size = permute(i);
+                if (size == 0)
+                        continue;
 
                 log_debug("%s %zu %zu", type, i, size);
 
@@ -151,9 +155,12 @@ static void test_compress_decompress(const char* label, const char* type,
                  100 - compressed * 100. / total,
                  skipped);
 }
+#endif
 
 int main(int argc, char *argv[]) {
+#if HAVE_XZ || HAVE_LZ4
         const char *i;
+        int r;
 
         log_set_max_level(LOG_INFO);
 
@@ -162,19 +169,30 @@ int main(int argc, char *argv[]) {
 
                 assert_se(safe_atou(argv[1], &x) >= 0);
                 arg_duration = x * USEC_PER_SEC;
+        } else {
+                bool slow;
+
+                r = getenv_bool("SYSTEMD_SLOW_TESTS");
+                slow = r >= 0 ? r : SYSTEMD_SLOW_TESTS_DEFAULT;
+
+                arg_duration = slow ? 2 * USEC_PER_SEC : USEC_PER_SEC / 50;
         }
+
         if (argc == 3)
-                (void) safe_atolu(argv[2], &arg_start);
+                (void) safe_atozu(argv[2], &arg_start);
         else
-                arg_start = getpid();
+                arg_start = getpid_cached();
 
         NULSTR_FOREACH(i, "zeros\0simple\0random\0") {
-#ifdef HAVE_XZ
+#if HAVE_XZ
                 test_compress_decompress("XZ", i, compress_blob_xz, decompress_blob_xz);
 #endif
-#ifdef HAVE_LZ4
+#if HAVE_LZ4
                 test_compress_decompress("LZ4", i, compress_blob_lz4, decompress_blob_lz4);
 #endif
         }
         return 0;
+#else
+        return EXIT_TEST_SKIP;
+#endif
 }