]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/journal/test-journal-interleaving.c
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / src / journal / test-journal-interleaving.c
index 8067cd38ee3bf22240b36c0cd5df0b9350ad5d0a..69f83b808e115b68312079484239e9c6b2b0d737 100644 (file)
@@ -1,45 +1,30 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
-  This file is part of systemd.
-
   Copyright 2013 Marius Vollmer
   Copyright 2013 Zbigniew JÄ™drzejewski-Szmek
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <unistd.h>
 #include <fcntl.h>
+#include <unistd.h>
 
-#include "systemd/sd-journal.h"
+#include "sd-journal.h"
 
+#include "alloc-util.h"
 #include "journal-file.h"
-#include "journal-internal.h"
 #include "journal-vacuum.h"
-#include "util.h"
 #include "log.h"
+#include "parse-util.h"
+#include "rm-rf.h"
+#include "util.h"
 
 /* This program tests skipping around in a multi-file journal.
  */
 
 static bool arg_keep = false;
 
-noreturn static void log_assert_errno(const char *text, int eno, const char *file, int line, const char *func) {
-        log_meta(LOG_CRIT, file, line, func,
-                 "'%s' failed at %s:%u (%s): %s.",
-                 text, file, line, func, strerror(eno));
+_noreturn_ static void log_assert_errno(const char *text, int error, const char *file, int line, const char *func) {
+        log_internal(LOG_CRIT, error, file, line, func,
+                     "'%s' failed at %s:%u (%s): %m", text, file, line, func);
         abort();
 }
 
@@ -52,25 +37,34 @@ noreturn static void log_assert_errno(const char *text, int eno, const char *fil
 
 static JournalFile *test_open(const char *name) {
         JournalFile *f;
-        assert_ret(journal_file_open(name, O_RDWR|O_CREAT, 0644, true, false, NULL, NULL, NULL, &f));
+        assert_ret(journal_file_open(-1, name, O_RDWR|O_CREAT, 0644, true, (uint64_t) -1, false, NULL, NULL, NULL, NULL, &f));
         return f;
 }
 
 static void test_close(JournalFile *f) {
-        journal_file_close (f);
+        (void) journal_file_close (f);
 }
 
 static void append_number(JournalFile *f, int n, uint64_t *seqnum) {
         char *p;
         dual_timestamp ts;
+        static dual_timestamp previous_ts = {};
         struct iovec iovec[1];
 
         dual_timestamp_get(&ts);
 
+        if (ts.monotonic <= previous_ts.monotonic)
+                ts.monotonic = previous_ts.monotonic + 1;
+
+        if (ts.realtime <= previous_ts.realtime)
+                ts.realtime = previous_ts.realtime + 1;
+
+        previous_ts = ts;
+
         assert_se(asprintf(&p, "NUMBER=%d", n) >= 0);
         iovec[0].iov_base = p;
         iovec[0].iov_len = strlen(p);
-        assert_ret(journal_file_append_entry(f, &ts, iovec, 1, seqnum, NULL, NULL));
+        assert_ret(journal_file_append_entry(f, &ts, NULL, iovec, 1, seqnum, NULL, NULL));
         free(p);
 }
 
@@ -189,9 +183,9 @@ static void test_skip(void (*setup)(void)) {
         if (arg_keep)
                 log_info("Not removing %s", t);
         else {
-                journal_directory_vacuum(".", 3000000, 0, NULL, true);
+                journal_directory_vacuum(".", 3000000, 0, 0, NULL, true);
 
-                assert_se(rm_rf_dangerous(t, false, true, false) >= 0);
+                assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
         }
 
         puts("------------------------------------------------------------");
@@ -207,62 +201,62 @@ static void test_sequence_numbers(void) {
         assert_se(mkdtemp(t));
         assert_se(chdir(t) >= 0);
 
-        assert_se(journal_file_open("one.journal", O_RDWR|O_CREAT, 0644,
-                                    true, false, NULL, NULL, NULL, &one) == 0);
+        assert_se(journal_file_open(-1, "one.journal", O_RDWR|O_CREAT, 0644,
+                                    true, (uint64_t) -1, false, NULL, NULL, NULL, NULL, &one) == 0);
 
         append_number(one, 1, &seqnum);
         printf("seqnum=%"PRIu64"\n", seqnum);
-        assert(seqnum == 1);
+        assert_se(seqnum == 1);
         append_number(one, 2, &seqnum);
         printf("seqnum=%"PRIu64"\n", seqnum);
-        assert(seqnum == 2);
+        assert_se(seqnum == 2);
 
-        assert(one->header->state == STATE_ONLINE);
-        assert(!sd_id128_equal(one->header->file_id, one->header->machine_id));
-        assert(!sd_id128_equal(one->header->file_id, one->header->boot_id));
-        assert(sd_id128_equal(one->header->file_id, one->header->seqnum_id));
+        assert_se(one->header->state == STATE_ONLINE);
+        assert_se(!sd_id128_equal(one->header->file_id, one->header->machine_id));
+        assert_se(!sd_id128_equal(one->header->file_id, one->header->boot_id));
+        assert_se(sd_id128_equal(one->header->file_id, one->header->seqnum_id));
 
         memcpy(&seqnum_id, &one->header->seqnum_id, sizeof(sd_id128_t));
 
-        assert_se(journal_file_open("two.journal", O_RDWR|O_CREAT, 0644,
-                                    true, false, NULL, NULL, one, &two) == 0);
+        assert_se(journal_file_open(-1, "two.journal", O_RDWR|O_CREAT, 0644,
+                                    true, (uint64_t) -1, false, NULL, NULL, NULL, one, &two) == 0);
 
-        assert(two->header->state == STATE_ONLINE);
-        assert(!sd_id128_equal(two->header->file_id, one->header->file_id));
-        assert(sd_id128_equal(one->header->machine_id, one->header->machine_id));
-        assert(sd_id128_equal(one->header->boot_id, one->header->boot_id));
-        assert(sd_id128_equal(one->header->seqnum_id, one->header->seqnum_id));
+        assert_se(two->header->state == STATE_ONLINE);
+        assert_se(!sd_id128_equal(two->header->file_id, one->header->file_id));
+        assert_se(sd_id128_equal(one->header->machine_id, one->header->machine_id));
+        assert_se(sd_id128_equal(one->header->boot_id, one->header->boot_id));
+        assert_se(sd_id128_equal(one->header->seqnum_id, one->header->seqnum_id));
 
         append_number(two, 3, &seqnum);
         printf("seqnum=%"PRIu64"\n", seqnum);
-        assert(seqnum == 3);
+        assert_se(seqnum == 3);
         append_number(two, 4, &seqnum);
         printf("seqnum=%"PRIu64"\n", seqnum);
-        assert(seqnum == 4);
+        assert_se(seqnum == 4);
 
         test_close(two);
 
         append_number(one, 5, &seqnum);
         printf("seqnum=%"PRIu64"\n", seqnum);
-        assert(seqnum == 5);
+        assert_se(seqnum == 5);
 
         append_number(one, 6, &seqnum);
         printf("seqnum=%"PRIu64"\n", seqnum);
-        assert(seqnum == 6);
+        assert_se(seqnum == 6);
 
         test_close(one);
 
         /* restart server */
         seqnum = 0;
 
-        assert_se(journal_file_open("two.journal", O_RDWR, 0,
-                                    true, false, NULL, NULL, NULL, &two) == 0);
+        assert_se(journal_file_open(-1, "two.journal", O_RDWR, 0,
+                                    true, (uint64_t) -1, false, NULL, NULL, NULL, NULL, &two) == 0);
 
-        assert(sd_id128_equal(two->header->seqnum_id, seqnum_id));
+        assert_se(sd_id128_equal(two->header->seqnum_id, seqnum_id));
 
         append_number(two, 7, &seqnum);
         printf("seqnum=%"PRIu64"\n", seqnum);
-        assert(seqnum == 5);
+        assert_se(seqnum == 5);
 
         /* So..., here we have the same seqnum in two files with the
          * same seqnum_id. */
@@ -274,9 +268,9 @@ static void test_sequence_numbers(void) {
         if (arg_keep)
                 log_info("Not removing %s", t);
         else {
-                journal_directory_vacuum(".", 3000000, 0, NULL, true);
+                journal_directory_vacuum(".", 3000000, 0, 0, NULL, true);
 
-                assert_se(rm_rf_dangerous(t, false, true, false) >= 0);
+                assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
         }
 }