]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-send.c
tree-wide: make use of new STRLEN() macro everywhere (#7639)
[thirdparty/systemd.git] / src / journal / test-journal-send.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2011 Lennart Poettering
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24
25 #include "sd-journal.h"
26
27 #include "macro.h"
28
29 int main(int argc, char *argv[]) {
30 char huge[4096*1024];
31
32 /* utf-8 and non-utf-8, message-less and message-ful iovecs */
33 struct iovec graph1[] = {
34 {(char*) "GRAPH=graph", STRLEN("GRAPH=graph")}
35 };
36 struct iovec graph2[] = {
37 {(char*) "GRAPH=graph\n", STRLEN("GRAPH=graph\n")}
38 };
39 struct iovec message1[] = {
40 {(char*) "MESSAGE=graph", STRLEN("MESSAGE=graph")}
41 };
42 struct iovec message2[] = {
43 {(char*) "MESSAGE=graph\n", STRLEN("MESSAGE=graph\n")}
44 };
45
46 assert_se(sd_journal_print(LOG_INFO, "piepapo") == 0);
47
48 assert_se(sd_journal_send("MESSAGE=foobar",
49 "VALUE=%i", 7,
50 NULL) == 0);
51
52 errno = ENOENT;
53 assert_se(sd_journal_perror("Foobar") == 0);
54
55 assert_se(sd_journal_perror("") == 0);
56
57 memset(huge, 'x', sizeof(huge));
58 memcpy(huge, "HUGE=", 5);
59 char_array_0(huge);
60
61 assert_se(sd_journal_send("MESSAGE=Huge field attached",
62 huge,
63 NULL) == 0);
64
65 assert_se(sd_journal_send("MESSAGE=uiui",
66 "VALUE=A",
67 "VALUE=B",
68 "VALUE=C",
69 "SINGLETON=1",
70 "OTHERVALUE=X",
71 "OTHERVALUE=Y",
72 "WITH_BINARY=this is a binary value \a",
73 NULL) == 0);
74
75 syslog(LOG_NOTICE, "Hello World!");
76
77 assert_se(sd_journal_print(LOG_NOTICE, "Hello World") == 0);
78
79 assert_se(sd_journal_send("MESSAGE=Hello World!",
80 "MESSAGE_ID=52fb62f99e2c49d89cfbf9d6de5e3555",
81 "PRIORITY=5",
82 "HOME=%s", getenv("HOME"),
83 "TERM=%s", getenv("TERM"),
84 "PAGE_SIZE=%li", sysconf(_SC_PAGESIZE),
85 "N_CPUS=%li", sysconf(_SC_NPROCESSORS_ONLN),
86 NULL) == 0);
87
88 assert_se(sd_journal_sendv(graph1, 1) == 0);
89 assert_se(sd_journal_sendv(graph2, 1) == 0);
90 assert_se(sd_journal_sendv(message1, 1) == 0);
91 assert_se(sd_journal_sendv(message2, 1) == 0);
92
93 /* test without location fields */
94 #undef sd_journal_sendv
95 assert_se(sd_journal_sendv(graph1, 1) == 0);
96 assert_se(sd_journal_sendv(graph2, 1) == 0);
97 assert_se(sd_journal_sendv(message1, 1) == 0);
98 assert_se(sd_journal_sendv(message2, 1) == 0);
99
100 sleep(1);
101
102 return 0;
103 }