]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/journal/test-journal-verify.c
journal: reword verification messages a bit
[thirdparty/systemd.git] / src / journal / test-journal-verify.c
CommitLineData
0284adc6
LP
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
34int main(int argc, char *argv[]) {
35 char t[] = "/tmp/journal-XXXXXX";
36 unsigned n;
37 JournalFile *f;
14d10188 38 const char *verification_key = argv[1];
0284adc6
LP
39
40 log_set_max_level(LOG_DEBUG);
41
42 assert_se(mkdtemp(t));
43 assert_se(chdir(t) >= 0);
44
45 log_info("Generating...");
46
14d10188 47 assert_se(journal_file_open("test.journal", O_RDWR|O_CREAT, 0666, true, !!verification_key, NULL, NULL, NULL, &f) == 0);
0284adc6
LP
48
49 for (n = 0; n < N_ENTRIES; n++) {
50 struct iovec iovec;
51 struct dual_timestamp ts;
52 char *test;
53
54 dual_timestamp_get(&ts);
55
56 assert_se(asprintf(&test, "RANDOM=%lu", random() % RANDOM_RANGE));
57
58 iovec.iov_base = (void*) test;
59 iovec.iov_len = strlen(test);
60
61 assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
62
63 free(test);
64 }
65
66 journal_file_close(f);
67
68 log_info("Verifying...");
69
70 assert_se(journal_file_open("test.journal", O_RDONLY, 0666, false, false, NULL, NULL, NULL, &f) == 0);
3223f44f
LP
71
72 journal_file_print_header(f);
73
14d10188 74 assert_se(journal_file_verify(f, verification_key) >= 0);
0284adc6
LP
75 journal_file_close(f);
76
77 log_info("Exiting...");
78
79 assert_se(rm_rf_dangerous(t, false, true, false) >= 0);
80
81 return 0;
82}