]>
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(), |
a1230ff9 | 32 | "SERVICE=piepapo"); |
f8e6f4aa | 33 | } |
877d54e9 | 34 | |
f8e6f4aa | 35 | static void test_log_journal(void) { |
877d54e9 | 36 | log_struct(LOG_INFO, |
df0ff127 | 37 | "MESSAGE=Foobar PID="PID_FMT, getpid_cached(), |
a1230ff9 | 38 | "SERVICE=foobar"); |
877d54e9 | 39 | |
963ddb91 | 40 | log_struct(LOG_INFO, |
df0ff127 | 41 | "MESSAGE=Foobar PID="PID_FMT, getpid_cached(), |
963ddb91 LP |
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, | |
a1230ff9 | 44 | "SUFFIX=GOT IT"); |
f8e6f4aa ZJS |
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 | } | |
963ddb91 | 71 | |
877d54e9 LP |
72 | return 0; |
73 | } |