summaryrefslogtreecommitdiffstats
path: root/tests/logging
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2012-09-27 14:18:37 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2012-09-27 16:29:54 +0200
commit4b54cab4763777c7741cf401ac02ec7bb4d023c4 (patch)
tree3669c7e9e369273eac590abff8a7dde1e0f66e59 /tests/logging
parent0262d3ff9fadbc6300e4146101539b4f07fcf4b8 (diff)
logging: Move the logging test from OpenBSC into libosmocore
Add a testcase for the logging facility. The test is coming from the OpenBSC code.
Diffstat (limited to 'tests/logging')
-rw-r--r--tests/logging/logging_test.c76
-rw-r--r--tests/logging/logging_test.err3
-rw-r--r--tests/logging/logging_test.ok0
3 files changed, 79 insertions, 0 deletions
diff --git a/tests/logging/logging_test.c b/tests/logging/logging_test.c
new file mode 100644
index 00000000..5f29499d
--- /dev/null
+++ b/tests/logging/logging_test.c
@@ -0,0 +1,76 @@
+/* simple test for the debug interface */
+/*
+ * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <osmocom/core/logging.h>
+#include <osmocom/core/utils.h>
+
+enum {
+ DRLL,
+ DCC,
+ DMM,
+};
+
+static const struct log_info_cat default_categories[] = {
+ [DRLL] = {
+ .name = "DRLL",
+ .description = "A-bis Radio Link Layer (RLL)",
+ .color = "\033[1;31m",
+ .enabled = 1, .loglevel = LOGL_NOTICE,
+ },
+ [DCC] = {
+ .name = "DCC",
+ .description = "Layer3 Call Control (CC)",
+ .color = "\033[1;32m",
+ .enabled = 1, .loglevel = LOGL_NOTICE,
+ },
+ [DMM] = {
+ .name = "DMM",
+ .description = "Layer3 Mobility Management (MM)",
+ .color = "\033[1;33m",
+ .enabled = 1, .loglevel = LOGL_NOTICE,
+ },
+};
+
+const struct log_info log_info = {
+ .cat = default_categories,
+ .num_cat = ARRAY_SIZE(default_categories),
+};
+
+int main(int argc, char **argv)
+{
+ struct log_target *stderr_target;
+
+ log_init(&log_info, NULL);
+ stderr_target = log_target_create_stderr();
+ log_add_target(stderr_target);
+ log_set_all_filter(stderr_target, 1);
+ log_set_print_filename(stderr_target, 0);
+
+ log_parse_category_mask(stderr_target, "DRLL:DCC");
+ log_parse_category_mask(stderr_target, "DRLL");
+ DEBUGP(DCC, "You should not see this\n");
+
+ log_parse_category_mask(stderr_target, "DRLL:DCC");
+ DEBUGP(DRLL, "You should see this\n");
+ DEBUGP(DCC, "You should see this\n");
+ DEBUGP(DMM, "You should not see this\n");
+
+ return 0;
+}
diff --git a/tests/logging/logging_test.err b/tests/logging/logging_test.err
new file mode 100644
index 00000000..b59d2e83
--- /dev/null
+++ b/tests/logging/logging_test.err
@@ -0,0 +1,3 @@
+You should see this
+You should see this
+ \ No newline at end of file
diff --git a/tests/logging/logging_test.ok b/tests/logging/logging_test.ok
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/logging/logging_test.ok