logging: Move the logging test from OpenBSC into libosmocore

Add a testcase for the logging facility. The test is coming from
the OpenBSC code.
This commit is contained in:
Holger Hans Peter Freyther 2012-09-27 14:18:37 +02:00
parent 0262d3ff9f
commit 4b54cab476
6 changed files with 94 additions and 2 deletions

1
.gitignore vendored
View File

@ -67,6 +67,7 @@ tests/lapd/lapd_test
tests/gsm0808/gsm0808_test
tests/gb/bssgp_fc_test
tests/gsm0408/gsm0408_test
tests/logging/logging_test
utils/osmo-arfcn
utils/osmo-auc-gen

View File

@ -4,7 +4,7 @@ check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test \
smscb/smscb_test bits/bitrev_test a5/a5_test \
conv/conv_test auth/milenage_test lapd/lapd_test \
gsm0808/gsm0808_test gsm0408/gsm0408_test \
gb/bssgp_fc_test
gb/bssgp_fc_test logging/logging_test
if ENABLE_MSGFILE
check_PROGRAMS += msgfile/msgfile_test
endif
@ -48,6 +48,9 @@ ussd_ussd_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gs
gb_bssgp_fc_test_SOURCES = gb/bssgp_fc_test.c
gb_bssgp_fc_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la
logging_logging_test_SOURCES = logging/logging_test.c
logging_logging_test_LDADD = $(top_builddir)/src/libosmocore.la
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
$(srcdir)/package.m4: $(top_srcdir)/configure.ac
:;{ \
@ -73,7 +76,9 @@ EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \
lapd/lapd_test.ok gsm0408/gsm0408_test.ok \
gsm0808/gsm0808_test.ok gb/bssgp_fc_tests.err \
gb/bssgp_fc_tests.ok gb/bssgp_fc_tests.sh \
msgfile/msgfile_test.ok msgfile/msgconfig.cfg
msgfile/msgfile_test.ok msgfile/msgconfig.cfg \
logging/logging_test.ok logging/logging_test.err
TESTSUITE = $(srcdir)/testsuite
check-local: atconfig $(TESTSUITE)

View File

@ -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;
}

View File

@ -0,0 +1,3 @@
You should see this
You should see this


View File

View File

@ -84,3 +84,10 @@ AT_KEYWORDS([gsm0408])
cat $abs_srcdir/gsm0408/gsm0408_test.ok > expout
AT_CHECK([$abs_top_builddir/tests/gsm0408/gsm0408_test], [], [expout], [ignore])
AT_CLEANUP
AT_SETUP([logging])
AT_KEYWORDS([logging])
cat $abs_srcdir/logging/logging_test.ok > expout
cat $abs_srcdir/logging/logging_test.err > experr
AT_CHECK([$abs_top_builddir/tests/logging/logging_test], [], [expout], [experr])
AT_CLEANUP