]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
877d54e9 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2012 Lennart Poettering | |
877d54e9 LP |
6 | ***/ |
7 | ||
8 | #include <stddef.h> | |
9 | #include <unistd.h> | |
10 | ||
f97b34a6 | 11 | #include "format-util.h" |
877d54e9 | 12 | #include "log.h" |
dccca82b | 13 | #include "process-util.h" |
de0671ee | 14 | #include "util.h" |
877d54e9 | 15 | |
ff524019 ZJS |
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 | ||
f8e6f4aa ZJS |
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)) | |
877d54e9 | 28 | |
f8e6f4aa | 29 | static void test_log_console(void) { |
877d54e9 | 30 | log_struct(LOG_INFO, |
df0ff127 | 31 | "MESSAGE=Waldo PID="PID_FMT, getpid_cached(), |
877d54e9 LP |
32 | "SERVICE=piepapo", |
33 | NULL); | |
f8e6f4aa | 34 | } |
877d54e9 | 35 | |
f8e6f4aa | 36 | static void test_log_journal(void) { |
877d54e9 | 37 | log_struct(LOG_INFO, |
df0ff127 | 38 | "MESSAGE=Foobar PID="PID_FMT, getpid_cached(), |
877d54e9 LP |
39 | "SERVICE=foobar", |
40 | NULL); | |
41 | ||
963ddb91 | 42 | log_struct(LOG_INFO, |
df0ff127 | 43 | "MESSAGE=Foobar PID="PID_FMT, getpid_cached(), |
963ddb91 LP |
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); | |
f8e6f4aa ZJS |
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 | } | |
963ddb91 | 74 | |
877d54e9 LP |
75 | return 0; |
76 | } |