]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/journal/test-journal-send.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / journal / test-journal-send.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
b070e7f3
LP
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
5430f7f2
LP
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
b070e7f3
LP
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
5430f7f2 15 Lesser General Public License for more details.
b070e7f3 16
5430f7f2 17 You should have received a copy of the GNU Lesser General Public License
b070e7f3
LP
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
d94819c8 21#include <errno.h>
7fb4d896
LP
22#include <stdlib.h>
23#include <unistd.h>
b070e7f3 24
3ffd4af2
LP
25#include "sd-journal.h"
26
d94819c8 27#include "macro.h"
cbdca852 28
b070e7f3 29int main(int argc, char *argv[]) {
1dfa7e79
LP
30 char huge[4096*1024];
31
85049096
ZJS
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);
b070e7f3 51
18c7ed18 52 errno = ENOENT;
85049096 53 assert_se(sd_journal_perror("Foobar") == 0);
18c7ed18 54
85049096 55 assert_se(sd_journal_perror("") == 0);
18c7ed18 56
1dfa7e79
LP
57 memset(huge, 'x', sizeof(huge));
58 memcpy(huge, "HUGE=", 5);
59 char_array_0(huge);
60
85049096
ZJS
61 assert_se(sd_journal_send("MESSAGE=Huge field attached",
62 huge,
63 NULL) == 0);
1dfa7e79 64
85049096
ZJS
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);
d99ae53a 74
7fb4d896
LP
75 syslog(LOG_NOTICE, "Hello World!");
76
85049096
ZJS
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);
7fb4d896 99
037ee337 100 sleep(1);
7fb4d896 101
b070e7f3
LP
102 return 0;
103}