Replace () with (void) in function prototypes
[platform/core/system/dlog.git] / src / tests / libdlog_prio_filter_pos.c
1 /* Copyright (c) 2020, Samsung Electronics Co., Ltd. All rights reserved.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14
15 // C
16 #include <assert.h>
17 #include <stdarg.h>
18 #include <stdio.h>
19 #include <string.h>
20
21 // DLog
22 #include <dlog.h>
23 #include <libdlog.h>
24 #include <logconfig.h>
25 #include <loglimiter.h>
26
27 int wtl(log_id_t buf_id, log_priority pri, const char *tag, const char *msg, struct timespec *tp_mono) { return 0xABCD; }
28 void __dlog_init_pipe(const struct log_config *conf) { write_to_log = wtl; }
29
30 int __wrap_log_config_read(struct log_config *config)
31 {
32         config->begin = config->last = NULL;
33         log_config_set(config, "backend", "pipe");
34         log_config_set(config, "debugmode", "1");
35         return 0;
36 }
37
38 // lobotomize various mechanisms I don't want to deal with
39 void __log_limiter_update(const struct log_config *config) { }
40 void __log_limiter_destroy(void) { }
41 void __dynamic_config_destroy(void) { }
42 struct pass_log_result __log_limiter_pass_log(const char *tag, int prio) { return (struct pass_log_result) { .decision = DECISION_ALLOWED }; }
43 int __log_limiter_create(const struct log_config *config) { return 1; }
44 bool __dynamic_config_create(struct log_config *config) { return false; }
45 void __dynamic_config_update(void) { }
46 void __dlog_init_android(const struct log_config *conf) { }
47
48
49 int main(void)
50 {
51 #define   VALID_FILTER(x) assert(dlog_set_minimum_priority(x) == DLOG_ERROR_NONE)
52 #define INVALID_FILTER(x) assert(dlog_set_minimum_priority(x) == DLOG_ERROR_INVALID_PARAMETER)
53 #define ALLOW(x) assert(__dlog_print(LOG_ID_MAIN, x, "tag", "msg") == 0xABCD)
54 #define BLOCK(x) assert(__dlog_print(LOG_ID_MAIN, x, "tag", "msg") == 0)
55
56         // Nothing should be filtered if there hasn't been a minimum set
57         for (int p = DLOG_VERBOSE; p < DLOG_PRIO_MAX; ++p)
58                 ALLOW(p);
59
60         // The DEFAULT level should also not filter anything
61         VALID_FILTER(DLOG_DEFAULT);
62         for (int p = DLOG_VERBOSE; p < DLOG_PRIO_MAX; ++p)
63                 ALLOW(p);
64
65         // The MAX filter should filter everything.
66         VALID_FILTER(DLOG_PRIO_MAX);
67         for (int p = DLOG_VERBOSE; p <= DLOG_SILENT; ++p)
68                 BLOCK(p);
69
70         for (int l = DLOG_VERBOSE; l < DLOG_PRIO_MAX; ++l) {
71                 VALID_FILTER(l);
72                 for (int p = DLOG_VERBOSE; p < DLOG_PRIO_MAX; ++p)
73                         if (p < l)
74                                 BLOCK(p);
75                         else
76                                 ALLOW(p);
77         }
78
79         // Named priorities
80         INVALID_FILTER(DLOG_UNKNOWN);
81
82         // Adjacent to the allowed values
83         INVALID_FILTER(DLOG_DEFAULT  - 1);
84         INVALID_FILTER(DLOG_PRIO_MAX + 1);
85
86         // Misc arbitrary values
87         INVALID_FILTER((log_priority) -1);
88         INVALID_FILTER((log_priority)  0);
89         INVALID_FILTER((log_priority) 57);
90
91 #undef BLOCK
92 #undef ALLOW
93 #undef INVALID_FILTER
94 #undef   VALID_FILTER
95 }