]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
877d54e9 LP |
2 | |
3 | #include <stddef.h> | |
4 | #include <unistd.h> | |
5 | ||
f97b34a6 | 6 | #include "format-util.h" |
877d54e9 | 7 | #include "log.h" |
dccca82b | 8 | #include "process-util.h" |
de0671ee | 9 | #include "util.h" |
877d54e9 | 10 | |
ff524019 ZJS |
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 | ||
52d86690 ZJS |
20 | assert_cc(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(EINVAL))); |
21 | assert_cc(!IS_SYNTHETIC_ERRNO(EINVAL)); | |
22 | assert_cc(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(0))); | |
23 | assert_cc(!IS_SYNTHETIC_ERRNO(0)); | |
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 | |
52d86690 | 29 | static void test_log_struct(void) { |
877d54e9 | 30 | log_struct(LOG_INFO, |
52d86690 | 31 | "MESSAGE=Waldo PID="PID_FMT" (no errno)", getpid_cached(), |
a1230ff9 | 32 | "SERVICE=piepapo"); |
877d54e9 | 33 | |
52d86690 ZJS |
34 | log_struct_errno(LOG_INFO, EILSEQ, |
35 | "MESSAGE=Waldo PID="PID_FMT": %m (normal)", getpid_cached(), | |
36 | "SERVICE=piepapo"); | |
37 | ||
38 | log_struct_errno(LOG_INFO, SYNTHETIC_ERRNO(EILSEQ), | |
39 | "MESSAGE=Waldo PID="PID_FMT": %m (synthetic)", getpid_cached(), | |
40 | "SERVICE=piepapo"); | |
877d54e9 | 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, | |
a1230ff9 | 46 | "SUFFIX=GOT IT"); |
f8e6f4aa ZJS |
47 | } |
48 | ||
49 | static void test_long_lines(void) { | |
50 | log_object_internal(LOG_NOTICE, | |
51 | EUCLEAN, | |
52 | X1000("abcd_") ".txt", | |
53 | 1000000, | |
54 | X1000("fff") "unc", | |
55 | "OBJECT=", | |
56 | X1000("obj_") "ect", | |
57 | "EXTRA=", | |
58 | X1000("ext_") "tra", | |
59 | "asdfasdf %s asdfasdfa", "foobar"); | |
60 | } | |
61 | ||
59c1546b YW |
62 | static void test_log_syntax(void) { |
63 | assert_se(log_syntax("unit", LOG_ERR, "filename", 10, EINVAL, "EINVAL: %s: %m", "hogehoge") == -EINVAL); | |
64 | assert_se(log_syntax("unit", LOG_ERR, "filename", 10, -ENOENT, "ENOENT: %s: %m", "hogehoge") == -ENOENT); | |
65 | assert_se(log_syntax("unit", LOG_ERR, "filename", 10, SYNTHETIC_ERRNO(ENOTTY), "ENOTTY: %s: %m", "hogehoge") == -ENOTTY); | |
66 | } | |
67 | ||
f8e6f4aa ZJS |
68 | int main(int argc, char* argv[]) { |
69 | int target; | |
70 | ||
59c1546b | 71 | for (target = 0; target < _LOG_TARGET_MAX; target++) { |
f8e6f4aa ZJS |
72 | log_set_target(target); |
73 | log_open(); | |
74 | ||
52d86690 | 75 | test_log_struct(); |
f8e6f4aa | 76 | test_long_lines(); |
59c1546b | 77 | test_log_syntax(); |
f8e6f4aa | 78 | } |
963ddb91 | 79 | |
52d86690 ZJS |
80 | assert_se(log_info_errno(SYNTHETIC_ERRNO(EUCLEAN), "foo") == -EUCLEAN); |
81 | ||
877d54e9 LP |
82 | return 0; |
83 | } |