blob: fd11896ac88e7cd4c22b864528308ab4842ce573 [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
Holger Hans Peter Freyther53aa0f52017-12-09 13:03:29 +00008 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000010 * (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 *
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000017 */
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000018
19#include <osmocom/core/logging.h>
20#include <osmocom/core/utils.h>
Michael McTernan4e0543f2015-03-30 13:22:14 +010021#include <osmocom/core/loggingrb.h>
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000022
23enum {
24 DRLL,
25 DCC,
26 DMM,
27};
28
29static const struct log_info_cat default_categories[] = {
30 [DRLL] = {
31 .name = "DRLL",
32 .description = "A-bis Radio Link Layer (RLL)",
Neels Hofmeyrf2644ae2019-11-20 04:00:29 +010033 .color = OSMO_LOGCOLOR_RED,
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000034 .enabled = 1, .loglevel = LOGL_NOTICE,
35 },
36 [DCC] = {
37 .name = "DCC",
38 .description = "Layer3 Call Control (CC)",
Neels Hofmeyrf2644ae2019-11-20 04:00:29 +010039 .color = OSMO_LOGCOLOR_GREEN,
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000040 .enabled = 1, .loglevel = LOGL_NOTICE,
41 },
42 [DMM] = {
43 .name = NULL,
44 .description = "Layer3 Mobility Management (MM)",
Neels Hofmeyrf2644ae2019-11-20 04:00:29 +010045 .color = OSMO_LOGCOLOR_BLUE,
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000046 .enabled = 1, .loglevel = LOGL_NOTICE,
47 },
48};
49
50const struct log_info log_info = {
51 .cat = default_categories,
52 .num_cat = ARRAY_SIZE(default_categories),
53};
54
55int main(int argc, char **argv)
56{
57 struct log_target *ringbuf_target;
58
59 log_init(&log_info, NULL);
Michael McTernan4e0543f2015-03-30 13:22:14 +010060 ringbuf_target = log_target_create_rb(0x1000);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000061 log_add_target(ringbuf_target);
62 log_set_all_filter(ringbuf_target, 1);
Pau Espin Pedrol01e0d3e2021-02-18 19:25:44 +010063 log_set_print_filename2(ringbuf_target, LOG_FILENAME_NONE);
Pau Espin Pedrol690b6612021-02-18 19:10:28 +010064 log_set_print_category(ringbuf_target, 0);
65 log_set_print_category_hex(ringbuf_target, 0);
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000066
67 log_parse_category_mask(ringbuf_target, "DRLL:DCC");
68 log_parse_category_mask(ringbuf_target, "DRLL");
69 DEBUGP(DCC, "You should not see this\n");
70
71 log_parse_category_mask(ringbuf_target, "DRLL:DCC");
72 DEBUGP(DRLL, "You should see this\n");
73 DEBUGP(DCC, "You should see this\n");
74 DEBUGP(DMM, "You should not see this\n");
Holger Hans Peter Freyther6b1faf72015-04-11 19:33:10 +020075 fprintf(stderr, "%s", log_target_rb_get(ringbuf_target, 0));
76 fprintf(stderr, "%s", log_target_rb_get(ringbuf_target, 1));
Michael McTernan4e0543f2015-03-30 13:22:14 +010077 OSMO_ASSERT(!log_target_rb_get(ringbuf_target, 2));
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +000078
79 return 0;
80}