]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-send.c
docs: add a simple, auto-generated index.md
[thirdparty/systemd.git] / src / journal / test-journal-send.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <errno.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6
7 #include "sd-journal.h"
8
9 #include "macro.h"
10
11 int main(int argc, char *argv[]) {
12 char huge[4096*1024];
13
14 /* utf-8 and non-utf-8, message-less and message-ful iovecs */
15 struct iovec graph1[] = {
16 {(char*) "GRAPH=graph", STRLEN("GRAPH=graph")}
17 };
18 struct iovec graph2[] = {
19 {(char*) "GRAPH=graph\n", STRLEN("GRAPH=graph\n")}
20 };
21 struct iovec message1[] = {
22 {(char*) "MESSAGE=graph", STRLEN("MESSAGE=graph")}
23 };
24 struct iovec message2[] = {
25 {(char*) "MESSAGE=graph\n", STRLEN("MESSAGE=graph\n")}
26 };
27
28 assert_se(sd_journal_print(LOG_INFO, "piepapo") == 0);
29
30 assert_se(sd_journal_send("MESSAGE=foobar",
31 "VALUE=%i", 7,
32 NULL) == 0);
33
34 errno = ENOENT;
35 assert_se(sd_journal_perror("Foobar") == 0);
36
37 assert_se(sd_journal_perror("") == 0);
38
39 memset(huge, 'x', sizeof(huge));
40 memcpy(huge, "HUGE=", 5);
41 char_array_0(huge);
42
43 assert_se(sd_journal_send("MESSAGE=Huge field attached",
44 huge,
45 NULL) == 0);
46
47 assert_se(sd_journal_send("MESSAGE=uiui",
48 "VALUE=A",
49 "VALUE=B",
50 "VALUE=C",
51 "SINGLETON=1",
52 "OTHERVALUE=X",
53 "OTHERVALUE=Y",
54 "WITH_BINARY=this is a binary value \a",
55 NULL) == 0);
56
57 syslog(LOG_NOTICE, "Hello World!");
58
59 assert_se(sd_journal_print(LOG_NOTICE, "Hello World") == 0);
60
61 assert_se(sd_journal_send("MESSAGE=Hello World!",
62 "MESSAGE_ID=52fb62f99e2c49d89cfbf9d6de5e3555",
63 "PRIORITY=5",
64 "HOME=%s", getenv("HOME"),
65 "TERM=%s", getenv("TERM"),
66 "PAGE_SIZE=%li", sysconf(_SC_PAGESIZE),
67 "N_CPUS=%li", sysconf(_SC_NPROCESSORS_ONLN),
68 NULL) == 0);
69
70 assert_se(sd_journal_sendv(graph1, 1) == 0);
71 assert_se(sd_journal_sendv(graph2, 1) == 0);
72 assert_se(sd_journal_sendv(message1, 1) == 0);
73 assert_se(sd_journal_sendv(message2, 1) == 0);
74
75 /* test without location fields */
76 #undef sd_journal_sendv
77 assert_se(sd_journal_sendv(graph1, 1) == 0);
78 assert_se(sd_journal_sendv(graph2, 1) == 0);
79 assert_se(sd_journal_sendv(message1, 1) == 0);
80 assert_se(sd_journal_sendv(message2, 1) == 0);
81
82 sleep(1);
83
84 return 0;
85 }