]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-verify.c
journal: split up journal-file.c
[thirdparty/systemd.git] / src / journal / test-journal-verify.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2012 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <stdio.h>
23 #include <unistd.h>
24 #include <fcntl.h>
25
26 #include "util.h"
27 #include "log.h"
28 #include "journal-file.h"
29 #include "journal-verify.h"
30
31 #define N_ENTRIES 6000
32 #define RANDOM_RANGE 77
33
34 int main(int argc, char *argv[]) {
35 char t[] = "/tmp/journal-XXXXXX";
36 unsigned n;
37 JournalFile *f;
38
39 log_set_max_level(LOG_DEBUG);
40
41 assert_se(mkdtemp(t));
42 assert_se(chdir(t) >= 0);
43
44 log_info("Generating...");
45
46 assert_se(journal_file_open("test.journal", O_RDWR|O_CREAT, 0666, true, true, NULL, NULL, NULL, &f) == 0);
47
48 for (n = 0; n < N_ENTRIES; n++) {
49 struct iovec iovec;
50 struct dual_timestamp ts;
51 char *test;
52
53 dual_timestamp_get(&ts);
54
55 assert_se(asprintf(&test, "RANDOM=%lu", random() % RANDOM_RANGE));
56
57 iovec.iov_base = (void*) test;
58 iovec.iov_len = strlen(test);
59
60 assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
61
62 free(test);
63 }
64
65 journal_file_close(f);
66
67 log_info("Verifying...");
68
69 assert_se(journal_file_open("test.journal", O_RDONLY, 0666, false, false, NULL, NULL, NULL, &f) == 0);
70 assert_se(journal_file_verify(f, NULL) >= 0);
71 journal_file_close(f);
72
73 log_info("Exiting...");
74
75 assert_se(rm_rf_dangerous(t, false, true, false) >= 0);
76
77 return 0;
78 }