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