tests: zlogger nominally runs the daemon
[platform/core/system/dlog.git] / tests / test_capi_coverage.c
1 /*  MIT License
2  *
3  * Copyright (c) 2023 Samsung Electronics Co., Ltd
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is furnished
10  * to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE. */
22
23 // dlog public API
24 #include <dlog.h>
25 #include <dlog-redirect-stdout.h>
26
27 // dlog secret API
28 #include <extra_sinks.h>
29
30 #include <fcntl.h>
31 #include <unistd.h>
32
33 #include <limits.h>
34
35 int dlog_vprint_native(log_priority prio, const char *tag, const char *fmt, va_list ap);
36 int  dlog_print_native(log_priority prio, const char *tag, const char *fmt, ...);
37 int dlog_vprint_dotnet(log_priority prio, const char *tag, const char *fmt, va_list ap);
38 int  dlog_print_dotnet(log_priority prio, const char *tag, const char *fmt, ...);
39
40 void va_stuff(log_priority prio, const char *tag, const char *fmt, ...)
41 {
42         va_list va;
43         va_start(va, fmt);
44
45         va_list va_dotnet, va_native, va_vprint, va_iprint;
46         va_copy(va_native, va);
47         va_copy(va_dotnet, va);
48         va_copy(va_vprint, va);
49         va_copy(va_iprint, va);
50
51         dlog_vprint_native(prio, tag, fmt, va_native);
52         dlog_vprint_dotnet(prio, tag, fmt, va_dotnet);
53         dlog_vprint(prio, tag, fmt, va_vprint);
54         __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt, va_iprint);
55
56         va_end(va);
57         va_end(va_native);
58         va_end(va_dotnet);
59         va_end(va_vprint);
60         va_end(va_iprint);
61 }
62
63 int main()
64 {
65         dlog_connect_fd(LOG_ID_INVALID,             1,   "x", DLOG_INFO);
66         dlog_connect_fd(SINK_DOTNET   ,             1,   "x", DLOG_INFO);
67         dlog_connect_fd(LOG_ID_MAIN   ,            -1,   "x", DLOG_INFO);
68         dlog_connect_fd(LOG_ID_MAIN   ,             1,  NULL, DLOG_INFO);
69         dlog_connect_fd(LOG_ID_MAIN   ,             1,    "", DLOG_INFO);
70         dlog_connect_fd(LOG_ID_MAIN   ,             1,   "x",      -999);
71         dlog_connect_fd(LOG_ID_MAIN   ,             1,   "x",      +999);
72         dlog_connect_fd(LOG_ID_MAIN   ,           999,   "x", DLOG_INFO);
73         dlog_connect_fd(LOG_ID_MAIN   ,       INT_MAX,   "x", DLOG_INFO);
74
75         dlog_connect_fd(LOG_ID_MAIN   , STDOUT_FILENO,   "x", DLOG_INFO);
76         dlog_connect_fd(LOG_ID_RADIO  , STDOUT_FILENO,   "x", DLOG_INFO);
77         dlog_connect_fd(LOG_ID_SYSTEM , STDOUT_FILENO,   "x", DLOG_INFO);
78         dlog_connect_fd(LOG_ID_APPS   , STDOUT_FILENO,   "x", DLOG_INFO);
79         dlog_connect_fd(SINK_DOTNET   , STDOUT_FILENO,   "x", DLOG_INFO);
80         dlog_connect_fd(SINK_NATIVE   , STDOUT_FILENO,   "x", DLOG_INFO);
81         dlog_connect_fd(LOG_ID_MAIN   , STDERR_FILENO,   "x", DLOG_INFO);
82
83
84         int const fd_null = open("/dev/null"    , O_RDONLY);
85         int const fd_logs = open("/dev/log_main", O_RDONLY);
86         int const fd_else = open("/dev/kmsg"    , O_RDONLY);
87
88         dlog_is_log_fd(     -1);
89         dlog_is_log_fd(    999);
90         dlog_is_log_fd(fd_null);
91         dlog_is_log_fd(fd_logs);
92         dlog_is_log_fd(fd_else);
93
94         close(fd_null);
95         close(fd_logs);
96         close(fd_else);
97
98
99         dlog_set_minimum_priority(         -99);
100         dlog_set_minimum_priority(         +99);
101         dlog_set_minimum_priority(DLOG_VERBOSE);
102
103         va_stuff(DLOG_ERROR, "x", "x");
104
105         dlog_print_native(DLOG_ERROR, "x", "x");
106         dlog_print_dotnet(DLOG_ERROR, "x", "x");
107
108                  __dlog_print(LOG_ID_MAIN, DLOG_ERROR, "x", "x");
109              __dlog_sec_print(LOG_ID_MAIN, DLOG_ERROR, "x", "x");
110         __dlog_critical_print(LOG_ID_MAIN, DLOG_ERROR, "x", "x");
111                  __dlog_print(LOG_ID_MAIN, DLOG_ERROR, "x", "x");
112 }