]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-log.c
basic/log: add the log_struct terminator to macro
[thirdparty/systemd.git] / src / test / test-log.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2012 Lennart Poettering
6 ***/
7
8 #include <stddef.h>
9 #include <unistd.h>
10
11 #include "format-util.h"
12 #include "log.h"
13 #include "process-util.h"
14 #include "util.h"
15
16 assert_cc(LOG_REALM_REMOVE_LEVEL(LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, LOG_FTP | LOG_DEBUG))
17 == LOG_REALM_SYSTEMD);
18 assert_cc(LOG_REALM_REMOVE_LEVEL(LOG_REALM_PLUS_LEVEL(LOG_REALM_UDEV, LOG_LOCAL7 | LOG_DEBUG))
19 == LOG_REALM_UDEV);
20 assert_cc((LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, LOG_LOCAL3 | LOG_DEBUG) & LOG_FACMASK)
21 == LOG_LOCAL3);
22 assert_cc((LOG_REALM_PLUS_LEVEL(LOG_REALM_UDEV, LOG_USER | LOG_INFO) & LOG_PRIMASK)
23 == LOG_INFO);
24
25 #define X10(x) x x x x x x x x x x
26 #define X100(x) X10(X10(x))
27 #define X1000(x) X100(X10(x))
28
29 static void test_log_console(void) {
30 log_struct(LOG_INFO,
31 "MESSAGE=Waldo PID="PID_FMT, getpid_cached(),
32 "SERVICE=piepapo");
33 }
34
35 static void test_log_journal(void) {
36 log_struct(LOG_INFO,
37 "MESSAGE=Foobar PID="PID_FMT, getpid_cached(),
38 "SERVICE=foobar");
39
40 log_struct(LOG_INFO,
41 "MESSAGE=Foobar PID="PID_FMT, getpid_cached(),
42 "FORMAT_STR_TEST=1=%i A=%c 2=%hi 3=%li 4=%lli 1=%p foo=%s 2.5=%g 3.5=%g 4.5=%Lg",
43 (int) 1, 'A', (short) 2, (long int) 3, (long long int) 4, (void*) 1, "foo", (float) 2.5f, (double) 3.5, (long double) 4.5,
44 "SUFFIX=GOT IT");
45 }
46
47 static void test_long_lines(void) {
48 log_object_internal(LOG_NOTICE,
49 EUCLEAN,
50 X1000("abcd_") ".txt",
51 1000000,
52 X1000("fff") "unc",
53 "OBJECT=",
54 X1000("obj_") "ect",
55 "EXTRA=",
56 X1000("ext_") "tra",
57 "asdfasdf %s asdfasdfa", "foobar");
58 }
59
60 int main(int argc, char* argv[]) {
61 int target;
62
63 for (target = 0; target < _LOG_TARGET_MAX; target++) {
64 log_set_target(target);
65 log_open();
66
67 test_log_console();
68 test_log_journal();
69 test_long_lines();
70 }
71
72 return 0;
73 }