]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-journal-importer.c
2 This file is part of systemd.
4 Copyright 2016 Zbigniew Jędrzejewski-Szmek
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include <sys/types.h>
25 #include "journal-importer.h"
26 #include "string-util.h"
27 #include "test-helper.h"
29 static void assert_iovec_entry(const struct iovec
*iovec
, const char* content
) {
30 assert_se(strlen(content
) == iovec
->iov_len
);
31 assert_se(memcmp(content
, iovec
->iov_base
, iovec
->iov_len
) == 0);
34 #define COREDUMP_PROC_GROUP \
35 "COREDUMP_PROC_CGROUP=1:name=systemd:/\n" \
36 "0::/user.slice/user-1002.slice/user@1002.service/gnome-terminal-server.service\n"
38 static void test_basic_parsing(void) {
39 _cleanup_(journal_importer_cleanup
) JournalImporter imp
= {};
42 imp
.fd
= open(TEST_DATA_DIR("/journal-data/journal-1.txt"), O_RDONLY
|O_CLOEXEC
);
43 assert_se(imp
.fd
>= 0);
46 r
= journal_importer_process_data(&imp
);
50 /* We read one entry, so we should get EOF on next read, but not yet */
51 assert_se(!journal_importer_eof(&imp
));
53 assert_se(imp
.iovw
.count
== 6);
54 assert_iovec_entry(&imp
.iovw
.iovec
[0], "_BOOT_ID=1531fd22ec84429e85ae888b12fadb91");
55 assert_iovec_entry(&imp
.iovw
.iovec
[1], "_TRANSPORT=journal");
56 assert_iovec_entry(&imp
.iovw
.iovec
[2], COREDUMP_PROC_GROUP
);
57 assert_iovec_entry(&imp
.iovw
.iovec
[3], "COREDUMP_RLIMIT=-1");
58 assert_iovec_entry(&imp
.iovw
.iovec
[4], COREDUMP_PROC_GROUP
);
59 assert_iovec_entry(&imp
.iovw
.iovec
[5], "_SOURCE_REALTIME_TIMESTAMP=1478389147837945");
61 /* Let's check if we get EOF now */
62 r
= journal_importer_process_data(&imp
);
64 assert_se(journal_importer_eof(&imp
));
67 int main(int argc
, char **argv
) {
68 log_set_max_level(LOG_DEBUG
);
69 log_parse_environment();