blob: b263f9053d193f624c8e5649c2950100b8b3f567 [file] [log] [blame]
Holger Hans Peter Freyther4b54cab2012-09-27 14:18:37 +02001/* simple test for the debug interface */
2/*
3 * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#include <osmocom/core/logging.h>
22#include <osmocom/core/utils.h>
23
Holger Hans Peter Freytherb7d0f462013-12-29 19:38:01 +010024#include <stdlib.h>
25
Holger Hans Peter Freyther4b54cab2012-09-27 14:18:37 +020026enum {
27 DRLL,
28 DCC,
29 DMM,
30};
31
Holger Hans Peter Freytherb7d0f462013-12-29 19:38:01 +010032static int filter_called = 0;
33
Holger Hans Peter Freyther4b54cab2012-09-27 14:18:37 +020034static const struct log_info_cat default_categories[] = {
35 [DRLL] = {
36 .name = "DRLL",
37 .description = "A-bis Radio Link Layer (RLL)",
38 .color = "\033[1;31m",
39 .enabled = 1, .loglevel = LOGL_NOTICE,
40 },
41 [DCC] = {
42 .name = "DCC",
43 .description = "Layer3 Call Control (CC)",
44 .color = "\033[1;32m",
45 .enabled = 1, .loglevel = LOGL_NOTICE,
46 },
47 [DMM] = {
Holger Hans Peter Freyther779d2f42012-09-27 16:31:29 +020048 .name = NULL,
Holger Hans Peter Freyther4b54cab2012-09-27 14:18:37 +020049 .description = "Layer3 Mobility Management (MM)",
50 .color = "\033[1;33m",
51 .enabled = 1, .loglevel = LOGL_NOTICE,
52 },
53};
54
Holger Hans Peter Freytherb7d0f462013-12-29 19:38:01 +010055static int test_filter(const struct log_context *ctx, struct log_target *target)
56{
57 filter_called += 1;
58 /* omit everything */
59 return 0;
60}
61
Holger Hans Peter Freyther4b54cab2012-09-27 14:18:37 +020062const struct log_info log_info = {
63 .cat = default_categories,
64 .num_cat = ARRAY_SIZE(default_categories),
Holger Hans Peter Freytherb7d0f462013-12-29 19:38:01 +010065 .filter_fn = test_filter,
Holger Hans Peter Freyther4b54cab2012-09-27 14:18:37 +020066};
67
68int main(int argc, char **argv)
69{
70 struct log_target *stderr_target;
71
72 log_init(&log_info, NULL);
73 stderr_target = log_target_create_stderr();
74 log_add_target(stderr_target);
75 log_set_all_filter(stderr_target, 1);
76 log_set_print_filename(stderr_target, 0);
77
78 log_parse_category_mask(stderr_target, "DRLL:DCC");
79 log_parse_category_mask(stderr_target, "DRLL");
80 DEBUGP(DCC, "You should not see this\n");
81
82 log_parse_category_mask(stderr_target, "DRLL:DCC");
83 DEBUGP(DRLL, "You should see this\n");
84 DEBUGP(DCC, "You should see this\n");
85 DEBUGP(DMM, "You should not see this\n");
Holger Hans Peter Freytherb7d0f462013-12-29 19:38:01 +010086 OSMO_ASSERT(filter_called == 0);
87
88 log_set_all_filter(stderr_target, 0);
89 DEBUGP(DRLL, "You should not see this and filter is called\n");
90 OSMO_ASSERT(filter_called == 1);
Holger Hans Peter Freyther4b54cab2012-09-27 14:18:37 +020091
92 return 0;
93}