blob: 2e2c717b8b6bf1d0b510e61fe72b7ba301c9cd70 [file] [log] [blame]
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +00001/* simple test for the debug interface */
2/*
3 * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * (C) 2012-2013 by Katerina Barone-Adesi <kat.obsc@gmail.com>
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000021
22#include <osmocom/core/logging.h>
23#include <osmocom/core/utils.h>
Michael McTernan4e0543f2015-03-30 13:22:14 +010024#include <osmocom/core/loggingrb.h>
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000025
26enum {
27 DRLL,
28 DCC,
29 DMM,
30};
31
32static const struct log_info_cat default_categories[] = {
33 [DRLL] = {
34 .name = "DRLL",
35 .description = "A-bis Radio Link Layer (RLL)",
36 .color = "\033[1;31m",
37 .enabled = 1, .loglevel = LOGL_NOTICE,
38 },
39 [DCC] = {
40 .name = "DCC",
41 .description = "Layer3 Call Control (CC)",
42 .color = "\033[1;32m",
43 .enabled = 1, .loglevel = LOGL_NOTICE,
44 },
45 [DMM] = {
46 .name = NULL,
47 .description = "Layer3 Mobility Management (MM)",
48 .color = "\033[1;33m",
49 .enabled = 1, .loglevel = LOGL_NOTICE,
50 },
51};
52
53const struct log_info log_info = {
54 .cat = default_categories,
55 .num_cat = ARRAY_SIZE(default_categories),
56};
57
58int main(int argc, char **argv)
59{
60 struct log_target *ringbuf_target;
61
62 log_init(&log_info, NULL);
Michael McTernan4e0543f2015-03-30 13:22:14 +010063 ringbuf_target = log_target_create_rb(0x1000);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000064 log_add_target(ringbuf_target);
65 log_set_all_filter(ringbuf_target, 1);
66 log_set_print_filename(ringbuf_target, 0);
67
68 log_parse_category_mask(ringbuf_target, "DRLL:DCC");
69 log_parse_category_mask(ringbuf_target, "DRLL");
70 DEBUGP(DCC, "You should not see this\n");
71
72 log_parse_category_mask(ringbuf_target, "DRLL:DCC");
73 DEBUGP(DRLL, "You should see this\n");
74 DEBUGP(DCC, "You should see this\n");
75 DEBUGP(DMM, "You should not see this\n");
Holger Hans Peter Freyther6b1faf72015-04-11 19:33:10 +020076 fprintf(stderr, "%s", log_target_rb_get(ringbuf_target, 0));
77 fprintf(stderr, "%s", log_target_rb_get(ringbuf_target, 1));
Michael McTernan4e0543f2015-03-30 13:22:14 +010078 OSMO_ASSERT(!log_target_rb_get(ringbuf_target, 2));
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000079
80 return 0;
81}