From a829b45c8553765dfdd7201e1875a033a91d3a90 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Thu, 5 Apr 2018 03:02:35 +0200 Subject: use osmo_init_logging2() with proper talloc ctx Ironically, when deprecating osmo_init_logging() in I216837780e9405fdaec8059c63d10699c695b360, I forgot to change the callers within libosmocore itself, i.e. in the various regression tests. Change-Id: Ia36c248f99353d5baaa2533f46a2f60a8579bdf8 --- tests/abis/abis_test.c | 3 ++- tests/gb/bssgp_fc_test.c | 8 +++++--- tests/gb/gprs_bssgp_test.c | 5 ++++- tests/gb/gprs_ns_test.c | 3 ++- tests/gprs/gprs_test.c | 3 ++- tests/gsup/gsup_test.c | 3 ++- tests/lapd/lapd_test.c | 6 +++++- tests/msgb/msgb_test.c | 4 +++- tests/oap/oap_test.c | 4 +++- tests/sms/sms_test.c | 3 ++- tests/socket/socket_test.c | 11 +++++++---- tests/tlv/tlv_test.c | 2 +- tests/ussd/ussd_test.c | 3 ++- tests/vty/vty_test.c | 10 +++++++--- 14 files changed, 47 insertions(+), 21 deletions(-) diff --git a/tests/abis/abis_test.c b/tests/abis/abis_test.c index c0605c28..ca6daed8 100644 --- a/tests/abis/abis_test.c +++ b/tests/abis/abis_test.c @@ -199,7 +199,8 @@ static void test_sw_descr() int main(int argc, char **argv) { - osmo_init_logging(&info); + void *ctx = talloc_named_const(NULL, 0, "abis_test"); + osmo_init_logging2(ctx, &info); test_sw_descr(); test_simple_sw_config(); diff --git a/tests/gb/bssgp_fc_test.c b/tests/gb/bssgp_fc_test.c index ac690a56..cc387771 100644 --- a/tests/gb/bssgp_fc_test.c +++ b/tests/gb/bssgp_fc_test.c @@ -17,6 +17,7 @@ static unsigned long in_ctr = 1; static struct timeval tv_start; +void *ctx = NULL; int get_centisec_diff(void) { @@ -71,7 +72,7 @@ static void test_fc(uint32_t bucket_size_max, uint32_t bucket_leak_rate, uint32_t max_queue_depth, uint32_t pdu_len, uint32_t pdu_count) { - struct bssgp_flow_control *fc = talloc_zero(NULL, struct bssgp_flow_control); + struct bssgp_flow_control *fc = talloc_zero(ctx, struct bssgp_flow_control); int i; osmo_gettimeofday_override_time = (struct timeval){ @@ -133,6 +134,7 @@ int main(int argc, char **argv) uint32_t pdu_count = 20; /* messages */ int c; void *tall_msgb_ctx; + ctx = talloc_named_const(NULL, 0, "bssgp_fc_test"); static const struct option long_options[] = { { "bucket-size-max", 1, 0, 's' }, @@ -144,11 +146,11 @@ int main(int argc, char **argv) { 0, 0, 0, 0 } }; - osmo_init_logging(&info); + osmo_init_logging2(ctx, &info); log_set_use_color(osmo_stderr_target, 0); log_set_print_filename(osmo_stderr_target, 0); - tall_msgb_ctx = msgb_talloc_ctx_init(NULL, 0); + tall_msgb_ctx = msgb_talloc_ctx_init(ctx, 0); while ((c = getopt_long(argc, argv, "s:r:d:l:c:", long_options, NULL)) != -1) { diff --git a/tests/gb/gprs_bssgp_test.c b/tests/gb/gprs_bssgp_test.c index c38e1801..52e986e8 100644 --- a/tests/gb/gprs_bssgp_test.c +++ b/tests/gb/gprs_bssgp_test.c @@ -294,11 +294,14 @@ static struct log_info info = {}; int main(int argc, char **argv) { struct sockaddr_in bss_peer= {0}; + void *ctx = talloc_named_const(NULL, 0, "gprs_bssgp_test"); - osmo_init_logging(&info); + osmo_init_logging2(ctx, &info); log_set_use_color(osmo_stderr_target, 0); log_set_print_filename(osmo_stderr_target, 0); + msgb_talloc_ctx_init(ctx, 0); + bssgp_nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); bss_peer.sin_family = AF_INET; diff --git a/tests/gb/gprs_ns_test.c b/tests/gb/gprs_ns_test.c index 7e6b85cc..f70e4937 100644 --- a/tests/gb/gprs_ns_test.c +++ b/tests/gb/gprs_ns_test.c @@ -901,7 +901,8 @@ static struct log_info info = {}; int main(int argc, char **argv) { - osmo_init_logging(&info); + void *ctx = talloc_named_const(NULL, 0, "gprs_ns_test"); + osmo_init_logging2(ctx, &info); log_set_use_color(osmo_stderr_target, 0); log_set_print_filename(osmo_stderr_target, 0); osmo_signal_register_handler(SS_L_NS, &test_signal, NULL); diff --git a/tests/gprs/gprs_test.c b/tests/gprs/gprs_test.c index 6f16fb2f..70e30099 100644 --- a/tests/gprs/gprs_test.c +++ b/tests/gprs/gprs_test.c @@ -120,7 +120,8 @@ static struct log_info info = { int main(int argc, char **argv) { - osmo_init_logging(&info); + void *ctx = talloc_named_const(NULL, 0, "gprs_test"); + osmo_init_logging2(ctx, &info); test_gsm_03_03_apn(); diff --git a/tests/gsup/gsup_test.c b/tests/gsup/gsup_test.c index b55f1d97..acc7274f 100644 --- a/tests/gsup/gsup_test.c +++ b/tests/gsup/gsup_test.c @@ -329,7 +329,8 @@ static struct log_info info = { int main(int argc, char **argv) { - osmo_init_logging(&info); + void *ctx = talloc_named_const(NULL, 0, "gsup_test"); + osmo_init_logging2(ctx, &info); log_set_print_filename(osmo_stderr_target, 0); log_set_print_timestamp(osmo_stderr_target, 0); log_set_use_color(osmo_stderr_target, 0); diff --git a/tests/lapd/lapd_test.c b/tests/lapd/lapd_test.c index e627ba68..3f15afe2 100644 --- a/tests/lapd/lapd_test.c +++ b/tests/lapd/lapd_test.c @@ -29,6 +29,7 @@ #include #include +#include #include @@ -759,7 +760,10 @@ static void test_lapdm_desync() int main(int argc, char **argv) { - osmo_init_logging(&info); + void *ctx = talloc_named_const(NULL, 0, "lapd_test"); + osmo_init_logging2(ctx, &info); + + msgb_talloc_ctx_init(ctx, 0); /* Prevent the test from segfaulting */ dummy_l1_header_len = 0; diff --git a/tests/msgb/msgb_test.c b/tests/msgb/msgb_test.c index 05335467..ffaa1557 100644 --- a/tests/msgb/msgb_test.c +++ b/tests/msgb/msgb_test.c @@ -385,7 +385,9 @@ static struct log_info info = {}; int main(int argc, char **argv) { - osmo_init_logging(&info); + void *ctx = talloc_named_const(NULL, 0, "msgb_test"); + osmo_init_logging2(ctx, &info); + msgb_talloc_ctx_init(ctx, 0); test_msgb_api(); test_msgb_api_errors(); diff --git a/tests/oap/oap_test.c b/tests/oap/oap_test.c index dea5c11d..32676ca3 100644 --- a/tests/oap/oap_test.c +++ b/tests/oap/oap_test.c @@ -173,7 +173,9 @@ static struct log_info info = { int main(int argc, char **argv) { - osmo_init_logging(&info); + void *ctx = talloc_named_const(NULL, 0, "oap_test"); + osmo_init_logging2(ctx, &info); + msgb_talloc_ctx_init(ctx, 0); test_oap_messages_dec_enc(); diff --git a/tests/sms/sms_test.c b/tests/sms/sms_test.c index efbdf7ec..06153964 100644 --- a/tests/sms/sms_test.c +++ b/tests/sms/sms_test.c @@ -282,9 +282,10 @@ int main(int argc, char** argv) uint8_t septet_data[256]; int nchars; char result[256]; + void *ctx = talloc_named_const(NULL, 0, "sms_test"); /* Fake logging. */ - osmo_init_logging(&fake_log_info); + osmo_init_logging2(ctx, &fake_log_info); /* test 7-bit encoding */ for (i = 0; i < ARRAY_SIZE(test_encode); ++i) { diff --git a/tests/socket/socket_test.c b/tests/socket/socket_test.c index 11ef8da4..37e02819 100644 --- a/tests/socket/socket_test.c +++ b/tests/socket/socket_test.c @@ -35,6 +35,8 @@ #include "../config.h" +void *ctx = NULL; + static int test_sockinit(void) { int fd, rc; @@ -44,7 +46,7 @@ static int test_sockinit(void) fd = osmo_sock_init(AF_INET, SOCK_DGRAM, IPPROTO_UDP, "0.0.0.0", 0, OSMO_SOCK_F_BIND); OSMO_ASSERT(fd >= 0); - name = osmo_sock_get_name(NULL, fd); + name = osmo_sock_get_name(ctx, fd); /* expect it to be not connected. We cannot match on INADDR_ANY, * as apparently that won't work on FreeBSD if there's only one * address (e.g. 127.0.0.1) assigned to the entire system, like @@ -82,7 +84,7 @@ static int test_sockinit2(void) fd = osmo_sock_init2(AF_INET, SOCK_DGRAM, IPPROTO_UDP, "0.0.0.0", 0, NULL, 0, OSMO_SOCK_F_BIND); OSMO_ASSERT(fd >= 0); - name = osmo_sock_get_name(NULL, fd); + name = osmo_sock_get_name(ctx, fd); /* expect it to be not connected. We cannot match on INADDR_ANY, * as apparently that won't work on FreeBSD if there's only one * address (e.g. 127.0.0.1) assigned to the entire system, like @@ -111,7 +113,7 @@ static int test_sockinit2(void) fd = osmo_sock_init2(AF_INET, SOCK_DGRAM, IPPROTO_UDP, "127.0.0.1", 0, "127.0.0.1", 53, OSMO_SOCK_F_BIND|OSMO_SOCK_F_CONNECT); OSMO_ASSERT(fd >= 0); - name = osmo_sock_get_name(NULL, fd); + name = osmo_sock_get_name(ctx, fd); #ifndef __FreeBSD__ /* For some reason, on the jenkins.osmocom.org build slave with * FreeBSD 10 inside a jail, it fails. Works fine on laforge's @@ -134,7 +136,8 @@ static struct log_info info = { int main(int argc, char *argv[]) { - osmo_init_logging(&info); + ctx = talloc_named_const(NULL, 0, "socket_test"); + osmo_init_logging2(ctx, &info); log_set_use_color(osmo_stderr_target, 0); log_set_print_filename(osmo_stderr_target, 0); diff --git a/tests/tlv/tlv_test.c b/tests/tlv/tlv_test.c index 2e28e548..39732756 100644 --- a/tests/tlv/tlv_test.c +++ b/tests/tlv/tlv_test.c @@ -277,7 +277,7 @@ static void test_tlv_repeated_ie() int main(int argc, char **argv) { - //osmo_init_logging(&info); + //osmo_init_logging2(ctx, &info); test_tlv_shift_functions(); test_tlv_repeated_ie(); diff --git a/tests/ussd/ussd_test.c b/tests/ussd/ussd_test.c index 429c72de..1f79063b 100644 --- a/tests/ussd/ussd_test.c +++ b/tests/ussd/ussd_test.c @@ -122,8 +122,9 @@ int main(int argc, char **argv) uint16_t size; int i; struct msgb *msg; + void *ctx = talloc_named_const(NULL, 0, "ussd_test"); - osmo_init_logging(&info); + osmo_init_logging2(ctx, &info); memset(&req, 0, sizeof(req)); gsm0480_decode_ss_request((struct gsm48_hdr *) ussd_request, diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c index 42646eb4..a3478e1d 100644 --- a/tests/vty/vty_test.c +++ b/tests/vty/vty_test.c @@ -41,6 +41,7 @@ #include static enum event last_vty_connection_event = -1; +void *ctx = NULL; static void test_cmd_string_from_valstr(void) { @@ -55,7 +56,7 @@ static void test_cmd_string_from_valstr(void) /* check against character strings that could break printf */ - cmd = vty_cmd_string_from_valstr (NULL, printf_seq_vs, "[prefix%s%s%s%s%s]", "[sep%s%s%s%s%s]", "[end%s%s%s%s%s]", 1); + cmd = vty_cmd_string_from_valstr (ctx, printf_seq_vs, "[prefix%s%s%s%s%s]", "[sep%s%s%s%s%s]", "[end%s%s%s%s%s]", 1); printf ("Tested with %%s-strings, resulting cmd = '%s'\n", cmd); talloc_free (cmd); } @@ -428,12 +429,15 @@ int main(int argc, char **argv) .cat = default_categories, .num_cat = ARRAY_SIZE(default_categories), }; - void *stats_ctx = talloc_named_const(NULL, 1, "stats test context"); + void *stats_ctx; + + ctx = talloc_named_const(NULL, 0, "stats test context"); + stats_ctx = talloc_named_const(ctx, 1, "stats test context"); osmo_signal_register_handler(SS_L_VTY, vty_event_cb, NULL); /* Fake logging. */ - osmo_init_logging(&log_info); + osmo_init_logging2(ctx, &log_info); /* Init stats */ osmo_stats_init(stats_ctx); -- cgit v1.2.3