a045a5640649f9b4e9c0d850a209ea79d652d00a
[platform/core/system/dlog.git] / src / tests / libdlog_base_pos.c
1 /*
2  * Copyright (c) 2018-2020, Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "libdlog_base_wrap.c"
18
19 int main()
20 {
21         log_config_set(&CONFIG, "backend", "pipe");
22         log_config_set(&CONFIG, "limiter", "0");
23         __configure();
24         assert(dlog_print(DLOG_ERROR, "tag", "msg") == 0xDECC16);
25         assert(!dynamic_config_called);
26         assert(write_to_log == wtl_pipe);
27         assert(!limiter_created);
28         __dlog_fini();
29
30         log_config_set(&CONFIG, "backend", "logger");
31         log_config_set(&CONFIG, "limiter", "1");
32         log_config_set(&CONFIG, "debugmode", "0");
33         use_dynamic_conf = true;
34         limiter_ret = (struct pass_log_result) { .decision = DECISION_ALLOWED };
35         __configure();
36         assert(dlog_print(DLOG_ERROR, "tag", "msg") == 45835705);
37         assert(__dlog_print(LOG_ID_MAIN, DLOG_ERROR, "tag", "msg") == 45835705);
38         assert(write_to_log != wtl_pipe); // ceci n'est pas une pipe
39         assert(write_to_log == wtl_android);
40         assert(limiter_created);
41         assert(dynamic_config_called);
42
43         limiter_ret = (struct pass_log_result) { .decision = DECISION_DENIED };
44         assert(dlog_print(DLOG_ERROR, "tag", "msg") == 45835705);
45         assert(__dlog_print(LOG_ID_MAIN, DLOG_ERROR, "tag", "msg") == DLOG_ERROR_NONE);
46         limiter_ret = (struct pass_log_result) { .decision = DECISION_TAG_LIMIT_EXCEEDED_MESSAGE };
47         assert(dlog_print(DLOG_ERROR, "tag", "msg") == 45835705);
48         assert(__dlog_print(LOG_ID_MAIN, DLOG_ERROR, "tag", "msg") == DLOG_ERROR_NONE);
49
50         assert(__dlog_print(LOG_ID_MAIN, DLOG_DEBUG, "tag", "msg") == DLOG_ERROR_NONE); // limited
51
52         assert(__dlog_sec_print(LOG_ID_MAIN, DLOG_DEBUG, "tag", "msg") == DLOG_ERROR_NONE); // limited
53
54         __dlog_fini();
55         log_config_set(&CONFIG, "enable_secure_logs", "0");
56         assert(__dlog_sec_print(LOG_ID_MAIN, DLOG_DEBUG, "tag", "msg") == 0);
57         assert(__dlog_sec_print(LOG_ID_MAIN, DLOG_DEBUG, "tag", "msg") == 0);
58
59         limiter_ret = (struct pass_log_result) { .decision = DECISION_ALLOWED };
60         __dlog_fini();
61         log_config_set(&CONFIG, "enable_system", "0");
62         __configure();
63         assert(__dlog_print(LOG_ID_SYSTEM, DLOG_ERROR, "tag", "msg") == DLOG_ERROR_NONE);
64         __dlog_fini();
65
66         __configure();
67         tct_tests();
68         destroyed = false;
69         __dlog_fini();
70         assert(destroyed);
71
72         return 0;
73 }