From 1562225332d7ad30f315bab124d3f23f9ed2908f Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Tue, 4 Jan 2022 17:23:47 +0100 Subject: [PATCH] Introduce dynamic log category for libosmo-rua/hnbap Same as already done for libosmo-ranap. This allows applications setting the cateogy dynamically, and will allow untangling library tests using hnbgw log categories in this repo. Change-Id: I5d09b67b115ad8938e5162a23accfcbafab139d4 --- include/osmocom/hnbap/hnbap_common.h | 5 ++++- include/osmocom/ranap/ranap_common.h | 2 +- include/osmocom/rua/rua_common.h | 5 ++++- src/hnbap_common.c | 9 ++++++++- src/ranap_common_cn.c | 2 +- src/rua_common.c | 9 ++++++++- src/rua_msg_factory.c | 12 +++++++----- src/tests/Makefile.am | 2 +- src/tests/hnb-test.h | 5 +---- src/tests/test-helpers.c | 1 + src/tests/test-hnbap.c | 2 ++ src/tests/test-ranap.c | 3 +-- src/tests/test_common.c | 8 +++----- src/tests/test_common.h | 7 +++++++ 14 files changed, 49 insertions(+), 23 deletions(-) diff --git a/include/osmocom/hnbap/hnbap_common.h b/include/osmocom/hnbap/hnbap_common.h index 69a5383f..af619e27 100644 --- a/include/osmocom/hnbap/hnbap_common.h +++ b/include/osmocom/hnbap/hnbap_common.h @@ -124,7 +124,8 @@ #include -#define HNBAP_DEBUG(x, args ...) DEBUGP(1, x, ## args) +extern int _hnbap_DHNBAP; +#define HNBAP_DEBUG(x, args ...) DEBUGP(_hnbap_DHNBAP, x, ## args) extern int asn1_xer_print; @@ -149,3 +150,5 @@ HNBAP_IE_t *hnbap_new_ie(HNBAP_ProtocolIE_ID_t id, HNBAP_Criticality_t criticali asn_TYPE_descriptor_t *type, void *sptr); char *hnbap_cause_str(HNBAP_Cause_t *cause); + +void hnbap_set_log_area(int log_area); diff --git a/include/osmocom/ranap/ranap_common.h b/include/osmocom/ranap/ranap_common.h index 8899bd51..23359e1b 100644 --- a/include/osmocom/ranap/ranap_common.h +++ b/include/osmocom/ranap/ranap_common.h @@ -593,8 +593,8 @@ struct gprs_ra_id; -#define RANAP_DEBUG(x, args ...) DEBUGP(_ranap_DRANAP, x, ## args) extern int _ranap_DRANAP; +#define RANAP_DEBUG(x, args ...) DEBUGP(_ranap_DRANAP, x, ## args) extern int asn1_xer_print; diff --git a/include/osmocom/rua/rua_common.h b/include/osmocom/rua/rua_common.h index 9b3a65c5..7967c91b 100644 --- a/include/osmocom/rua/rua_common.h +++ b/include/osmocom/rua/rua_common.h @@ -44,7 +44,8 @@ #include -#define RUA_DEBUG(x, args ...) DEBUGP(0, x, ## args) +extern int _rua_DRUA; +#define RUA_DEBUG(x, args ...) DEBUGP(_rua_DRUA, x, ## args) extern int asn1_xer_print; @@ -69,3 +70,5 @@ RUA_IE_t *rua_new_ie(RUA_ProtocolIE_ID_t id, RUA_Criticality_t criticality, asn_TYPE_descriptor_t *type, void *sptr); char *rua_cause_str(RUA_Cause_t *cause); + +void rua_set_log_area(int log_area); diff --git a/src/hnbap_common.c b/src/hnbap_common.c index ac42959d..be7d5702 100644 --- a/src/hnbap_common.c +++ b/src/hnbap_common.c @@ -24,7 +24,9 @@ #include #include -#include + +int _hnbap_DHNBAP = 0; +#define DHNBAP _hnbap_DHNBAP static const struct value_string hnbap_cause_radio_vals[] = { { HNBAP_CauseRadioNetwork_overload, "overload" }, @@ -242,3 +244,8 @@ HNBAP_IE_t *hnbap_new_ie(HNBAP_ProtocolIE_ID_t id, return buff; } + +void hnbap_set_log_area(int log_area) +{ + _hnbap_DHNBAP = log_area; +} diff --git a/src/ranap_common_cn.c b/src/ranap_common_cn.c index d2c875eb..03ce9ead 100644 --- a/src/ranap_common_cn.c +++ b/src/ranap_common_cn.c @@ -29,7 +29,7 @@ #include #include -#include +#define DRANAP _ranap_DRANAP static int cn_ranap_rx_initiating_msg_co(void *ctx, RANAP_InitiatingMessage_t *imsg, ranap_message *message) diff --git a/src/rua_common.c b/src/rua_common.c index 77ac5912..f21bf8fe 100644 --- a/src/rua_common.c +++ b/src/rua_common.c @@ -24,10 +24,12 @@ #include #include -#include extern int asn1_xer_print; +int _rua_DRUA = 0; +#define DRUA _rua_DRUA + static const struct value_string rua_cause_radio_vals[] = { { RUA_CauseRadioNetwork_normal, "normal" }, { RUA_CauseRadioNetwork_connect_failed, "connect failed" }, @@ -224,3 +226,8 @@ RUA_IE_t *rua_new_ie(RUA_ProtocolIE_ID_t id, return buff; } + +void rua_set_log_area(int log_area) +{ + _rua_DRUA = log_area; +} diff --git a/src/rua_msg_factory.c b/src/rua_msg_factory.c index 7a6bebd6..e9747934 100644 --- a/src/rua_msg_factory.c +++ b/src/rua_msg_factory.c @@ -5,8 +5,10 @@ #include #include #include "asn1helpers.h" -#include +#define DRUA _rua_DRUA + +#define IUH_PPI_RUA 19 struct msgb *rua_new_udt(struct msgb *inmsg) { @@ -31,7 +33,7 @@ struct msgb *rua_new_udt(struct msgb *inmsg) ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_ConnectionlessTransfer, &out); - DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); + DEBUGP(DRUA, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); msgb_sctp_ppid(msg) = IUH_PPI_RUA; @@ -68,7 +70,7 @@ struct msgb *rua_new_conn(int is_ps, uint32_t context_id, struct msgb *inmsg) ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_Connect, &out); - DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); + DEBUGP(DRUA, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); msgb_sctp_ppid(msg) = IUH_PPI_RUA; @@ -104,7 +106,7 @@ struct msgb *rua_new_dt(int is_ps, uint32_t context_id, struct msgb *inmsg) ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_DirectTransfer, &out); - DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); + DEBUGP(DRUA, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); msgb_sctp_ppid(msg) = IUH_PPI_RUA; @@ -146,7 +148,7 @@ struct msgb *rua_new_disc(int is_ps, uint32_t context_id, struct msgb *inmsg) ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_Disconnect, &out); - DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); + DEBUGP(DRUA, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); msgb_sctp_ppid(msg) = IUH_PPI_RUA; diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 20635245..1fca2a43 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -14,7 +14,7 @@ noinst_HEADERS = test_common.h hnb-test.h hnb-test-layers.h test_helpers_SOURCES = test-helpers.c test_common.c test_helpers_LDADD = $(COMMON_LIBS) $(top_builddir)/src/libosmo-ranap.la -test_hnbap_SOURCES = $(top_srcdir)/src/hnbap_common.c $(top_builddir)/src/hnbap_decoder.c test-hnbap.c test_common.c +test_hnbap_SOURCES = test-hnbap.c test_common.c test_hnbap_LDADD = $(COMMON_LIBS) $(top_builddir)/src/libosmo-hnbap.la $(top_builddir)/src/libosmo-ranap.la hnb_test_SOURCES = hnb-test.c test_common.c hnb-test-ranap.c hnb-test-rua.c diff --git a/src/tests/hnb-test.h b/src/tests/hnb-test.h index 4af50a72..02efce0d 100644 --- a/src/tests/hnb-test.h +++ b/src/tests/hnb-test.h @@ -7,10 +7,7 @@ #define DEBUG #include -enum { - DMAIN, - DHNBAP, -}; +#include "test_common.h" /* 25.467 Section 7.1 */ diff --git a/src/tests/test-helpers.c b/src/tests/test-helpers.c index cfe2140e..5c617e52 100644 --- a/src/tests/test-helpers.c +++ b/src/tests/test-helpers.c @@ -209,6 +209,7 @@ int main(int argc, char **argv) asn1_xer_print = 0; test_common_init(); + ranap_set_log_area(DRANAP); test_iu_helpers(); test_asn1_helpers(); diff --git a/src/tests/test-hnbap.c b/src/tests/test-hnbap.c index 2343c2d8..48cca2b0 100644 --- a/src/tests/test-hnbap.c +++ b/src/tests/test-hnbap.c @@ -173,6 +173,8 @@ int main(int argc, char **argv) int rc; test_common_init(); + ranap_set_log_area(DRANAP); + hnbap_set_log_area(DHNBAP); log_set_log_level(osmo_stderr_target, LOGL_INFO); diff --git a/src/tests/test-ranap.c b/src/tests/test-ranap.c index a6df1866..b3ea4cb7 100644 --- a/src/tests/test-ranap.c +++ b/src/tests/test-ranap.c @@ -32,8 +32,6 @@ #include "test_common.h" -#include - extern void *tall_msgb_ctx; static void test_aper_int(uint32_t inp) @@ -98,6 +96,7 @@ int main(int argc, char **argv) //asn_debug = 1; test_common_init(); + ranap_set_log_area(DRANAP); test_aper_int(1); test_aper_int(2); diff --git a/src/tests/test_common.c b/src/tests/test_common.c index bfe487f7..899c73a9 100644 --- a/src/tests/test_common.c +++ b/src/tests/test_common.c @@ -33,14 +33,14 @@ #include #include +#include + #include #include #include #include -#include - -#include +#include "test_common.h" static const struct log_info_cat log_cat[] = { [DMAIN] = { @@ -83,8 +83,6 @@ int test_common_init(void) if (rc < 0) exit(1); - ranap_set_log_area(DRANAP); - log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE); log_set_use_color(osmo_stderr_target, 0); log_set_print_category(osmo_stderr_target, 0); diff --git a/src/tests/test_common.h b/src/tests/test_common.h index 836d9995..fdcac05f 100644 --- a/src/tests/test_common.h +++ b/src/tests/test_common.h @@ -1,4 +1,11 @@ #pragma once +enum { + DMAIN, + DHNBAP, + DRUA, + DRANAP, +}; + int test_common_init(void); void test_common_cleanup(void);