]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-send.c
core: when booting up, initialize hostname to compile-time fallback hostname
[thirdparty/systemd.git] / src / journal / test-journal-send.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2011 Lennart Poettering
5
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.
10
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.
15
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/>.
18 ***/
19
20 #include <errno.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23
24 #include "sd-journal.h"
25
26 #include "macro.h"
27
28 int main(int argc, char *argv[]) {
29 char huge[4096*1024];
30
31 /* utf-8 and non-utf-8, message-less and message-ful iovecs */
32 struct iovec graph1[] = {
33 {(char*) "GRAPH=graph", strlen("GRAPH=graph")}
34 };
35 struct iovec graph2[] = {
36 {(char*) "GRAPH=graph\n", strlen("GRAPH=graph\n")}
37 };
38 struct iovec message1[] = {
39 {(char*) "MESSAGE=graph", strlen("MESSAGE=graph")}
40 };
41 struct iovec message2[] = {
42 {(char*) "MESSAGE=graph\n", strlen("MESSAGE=graph\n")}
43 };
44
45 assert_se(sd_journal_print(LOG_INFO, "piepapo") == 0);
46
47 assert_se(sd_journal_send("MESSAGE=foobar",
48 "VALUE=%i", 7,
49 NULL) == 0);
50
51 errno = ENOENT;
52 assert_se(sd_journal_perror("Foobar") == 0);
53
54 assert_se(sd_journal_perror("") == 0);
55
56 memset(huge, 'x', sizeof(huge));
57 memcpy(huge, "HUGE=", 5);
58 char_array_0(huge);
59
60 assert_se(sd_journal_send("MESSAGE=Huge field attached",
61 huge,
62 NULL) == 0);
63
64 assert_se(sd_journal_send("MESSAGE=uiui",
65 "VALUE=A",
66 "VALUE=B",
67 "VALUE=C",
68 "SINGLETON=1",
69 "OTHERVALUE=X",
70 "OTHERVALUE=Y",
71 "WITH_BINARY=this is a binary value \a",
72 NULL) == 0);
73
74 syslog(LOG_NOTICE, "Hello World!");
75
76 assert_se(sd_journal_print(LOG_NOTICE, "Hello World") == 0);
77
78 assert_se(sd_journal_send("MESSAGE=Hello World!",
79 "MESSAGE_ID=52fb62f99e2c49d89cfbf9d6de5e3555",
80 "PRIORITY=5",
81 "HOME=%s", getenv("HOME"),
82 "TERM=%s", getenv("TERM"),
83 "PAGE_SIZE=%li", sysconf(_SC_PAGESIZE),
84 "N_CPUS=%li", sysconf(_SC_NPROCESSORS_ONLN),
85 NULL) == 0);
86
87 assert_se(sd_journal_sendv(graph1, 1) == 0);
88 assert_se(sd_journal_sendv(graph2, 1) == 0);
89 assert_se(sd_journal_sendv(message1, 1) == 0);
90 assert_se(sd_journal_sendv(message2, 1) == 0);
91
92 /* test without location fields */
93 #undef sd_journal_sendv
94 assert_se(sd_journal_sendv(graph1, 1) == 0);
95 assert_se(sd_journal_sendv(graph2, 1) == 0);
96 assert_se(sd_journal_sendv(message1, 1) == 0);
97 assert_se(sd_journal_sendv(message2, 1) == 0);
98
99 sleep(1);
100
101 return 0;
102 }