]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-journal-importer.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 #include "alloc-util.h"
9 #include "journal-importer.h"
10 #include "path-util.h"
11 #include "string-util.h"
14 static void assert_iovec_entry(const struct iovec
*iovec
, const char* content
) {
15 assert_se(strlen(content
) == iovec
->iov_len
);
16 assert_se(memcmp(content
, iovec
->iov_base
, iovec
->iov_len
) == 0);
19 #define COREDUMP_PROC_GROUP \
20 "COREDUMP_PROC_CGROUP=1:name=systemd:/\n" \
21 "0::/user.slice/user-1002.slice/user@1002.service/gnome-terminal-server.service\n"
23 static void test_basic_parsing(void) {
24 _cleanup_(journal_importer_cleanup
) JournalImporter imp
= {};
25 _cleanup_free_
char *journal_data_path
= NULL
;
28 journal_data_path
= path_join(get_testdata_dir(), "journal-data/journal-1.txt");
29 imp
.fd
= open(journal_data_path
, O_RDONLY
|O_CLOEXEC
);
30 assert_se(imp
.fd
>= 0);
33 r
= journal_importer_process_data(&imp
);
34 while (r
== 0 && !journal_importer_eof(&imp
));
37 /* We read one entry, so we should get EOF on next read, but not yet */
38 assert_se(!journal_importer_eof(&imp
));
40 assert_se(imp
.iovw
.count
== 6);
41 assert_iovec_entry(&imp
.iovw
.iovec
[0], "_BOOT_ID=1531fd22ec84429e85ae888b12fadb91");
42 assert_iovec_entry(&imp
.iovw
.iovec
[1], "_TRANSPORT=journal");
43 assert_iovec_entry(&imp
.iovw
.iovec
[2], COREDUMP_PROC_GROUP
);
44 assert_iovec_entry(&imp
.iovw
.iovec
[3], "COREDUMP_RLIMIT=-1");
45 assert_iovec_entry(&imp
.iovw
.iovec
[4], COREDUMP_PROC_GROUP
);
46 assert_iovec_entry(&imp
.iovw
.iovec
[5], "_SOURCE_REALTIME_TIMESTAMP=1478389147837945");
48 /* Let's check if we get EOF now */
49 r
= journal_importer_process_data(&imp
);
51 assert_se(journal_importer_eof(&imp
));
54 static void test_bad_input(void) {
55 _cleanup_(journal_importer_cleanup
) JournalImporter imp
= {};
56 _cleanup_free_
char *journal_data_path
= NULL
;
59 journal_data_path
= path_join(get_testdata_dir(), "journal-data/journal-2.txt");
60 imp
.fd
= open(journal_data_path
, O_RDONLY
|O_CLOEXEC
);
61 assert_se(imp
.fd
>= 0);
64 r
= journal_importer_process_data(&imp
);
65 while (!journal_importer_eof(&imp
));
66 assert_se(r
== 0); /* If we don't have enough input, 0 is returned */
68 assert_se(journal_importer_eof(&imp
));
71 int main(int argc
, char **argv
) {
72 test_setup_logging(LOG_DEBUG
);