]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-log.c
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / src / test / test-log.c
CommitLineData
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
11assert_cc(LOG_REALM_REMOVE_LEVEL(LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, LOG_FTP | LOG_DEBUG))
12 == LOG_REALM_SYSTEMD);
13assert_cc(LOG_REALM_REMOVE_LEVEL(LOG_REALM_PLUS_LEVEL(LOG_REALM_UDEV, LOG_LOCAL7 | LOG_DEBUG))
14 == LOG_REALM_UDEV);
15assert_cc((LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, LOG_LOCAL3 | LOG_DEBUG) & LOG_FACMASK)
16 == LOG_LOCAL3);
17assert_cc((LOG_REALM_PLUS_LEVEL(LOG_REALM_UDEV, LOG_USER | LOG_INFO) & LOG_PRIMASK)
18 == LOG_INFO);
19
f8e6f4aa
ZJS
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))
877d54e9 23
f8e6f4aa 24static void test_log_console(void) {
877d54e9 25 log_struct(LOG_INFO,
df0ff127 26 "MESSAGE=Waldo PID="PID_FMT, getpid_cached(),
a1230ff9 27 "SERVICE=piepapo");
f8e6f4aa 28}
877d54e9 29
f8e6f4aa 30static void test_log_journal(void) {
877d54e9 31 log_struct(LOG_INFO,
df0ff127 32 "MESSAGE=Foobar PID="PID_FMT, getpid_cached(),
a1230ff9 33 "SERVICE=foobar");
877d54e9 34
963ddb91 35 log_struct(LOG_INFO,
df0ff127 36 "MESSAGE=Foobar PID="PID_FMT, getpid_cached(),
963ddb91
LP
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,
a1230ff9 39 "SUFFIX=GOT IT");
f8e6f4aa
ZJS
40}
41
42static 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
55int 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 }
963ddb91 66
877d54e9
LP
67 return 0;
68}