]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-log.c
Merge pull request #8676 from keszybz/drop-license-boilerplate
[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 NULL);
34 }
35
36 static void test_log_journal(void) {
37 log_struct(LOG_INFO,
38 "MESSAGE=Foobar PID="PID_FMT, getpid_cached(),
39 "SERVICE=foobar",
40 NULL);
41
42 log_struct(LOG_INFO,
43 "MESSAGE=Foobar PID="PID_FMT, getpid_cached(),
44 "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",
45 (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,
46 "SUFFIX=GOT IT",
47 NULL);
48 }
49
50 static void test_long_lines(void) {
51 log_object_internal(LOG_NOTICE,
52 EUCLEAN,
53 X1000("abcd_") ".txt",
54 1000000,
55 X1000("fff") "unc",
56 "OBJECT=",
57 X1000("obj_") "ect",
58 "EXTRA=",
59 X1000("ext_") "tra",
60 "asdfasdf %s asdfasdfa", "foobar");
61 }
62
63 int main(int argc, char* argv[]) {
64 int target;
65
66 for (target = 0; target < _LOG_TARGET_MAX; target++) {
67 log_set_target(target);
68 log_open();
69
70 test_log_console();
71 test_log_journal();
72 test_long_lines();
73 }
74
75 return 0;
76 }