2 * Copyright (c) 2018-2020, Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "limiter_wrap.c"
21 __log_limiter_destroy(); // check whether it explodes if called before init
23 struct log_config conf = {NULL, NULL};
24 assert(!__log_limiter_create(&conf));
26 struct rule *r = NULL;
28 assert(!__log_limiter_dump_rule(&r, buffer, sizeof buffer));
31 log_config_set(&conf, "limiter|*|*" , "allow");
32 log_config_set(&conf, "limiter|FOO|*", "deny");
33 log_config_set(&conf, "limiter|*|E" , "deny");
34 log_config_set(&conf, "limiter|FOO|E", "7");
35 assert(__log_limiter_create(&conf));
38 __log_limiter_update(&conf);
39 for (int i = 0; i < 100; ++i) {
40 assert(__log_limiter_pass_log("FOO", 'F').decision == DECISION_ALLOWED);
41 assert(__log_limiter_pass_log("BAR", 'F').decision == DECISION_ALLOWED);
42 assert(__log_limiter_pass_log("BAR", 'E').decision == DECISION_ALLOWED);
46 __log_limiter_update(&conf);
47 for (int i = 0; i < 100; ++i) {
48 assert(__log_limiter_pass_log("FOO", 'F').decision == DECISION_ALLOWED);
49 assert(__log_limiter_pass_log("BAR", 'F').decision == DECISION_ALLOWED);
50 assert(__log_limiter_pass_log("BAR", 'E').decision == DECISION_ALLOWED);
54 __log_limiter_destroy();
55 assert(__log_limiter_create(&conf));
58 assert(__log_limiter_pass_log("FOO", 'E').decision == DECISION_ALLOWED);
61 int rule_count = get_rulecount();
62 log_config_set(&conf, "irrelevant", "entry");
63 assert(rule_count == get_rulecount());
64 __log_limiter_update(&conf);
66 for (int i = 1; i <= 2; ++i) {
67 struct rule *r = NULL;
70 assert(__log_limiter_dump_rule(&r, buf, sizeof buf) == -1);
74 assert(0 == util_hash_key(NULL, 0));
75 assert(0 == util_hash_key("", 0));