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