[MERGED] libosmocore[master]: use osmo_init_logging2() with proper talloc ctx

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Apr 6 06:43:40 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: use osmo_init_logging2() with proper talloc ctx
......................................................................


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
---
M tests/abis/abis_test.c
M tests/gb/bssgp_fc_test.c
M tests/gb/gprs_bssgp_test.c
M tests/gb/gprs_ns_test.c
M tests/gprs/gprs_test.c
M tests/gsup/gsup_test.c
M tests/lapd/lapd_test.c
M tests/msgb/msgb_test.c
M tests/oap/oap_test.c
M tests/sms/sms_test.c
M tests/socket/socket_test.c
M tests/tlv/tlv_test.c
M tests/ussd/ussd_test.c
M tests/vty/vty_test.c
14 files changed, 47 insertions(+), 21 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/tests/abis/abis_test.c b/tests/abis/abis_test.c
index c0605c2..ca6daed 100644
--- a/tests/abis/abis_test.c
+++ b/tests/abis/abis_test.c
@@ -199,7 +199,8 @@
 
 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 ac690a5..cc38777 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 @@
 		    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 @@
 	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 @@
 		{ 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 c38e180..52e986e 100644
--- a/tests/gb/gprs_bssgp_test.c
+++ b/tests/gb/gprs_bssgp_test.c
@@ -294,11 +294,14 @@
 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 7e6b85c..f70e493 100644
--- a/tests/gb/gprs_ns_test.c
+++ b/tests/gb/gprs_ns_test.c
@@ -901,7 +901,8 @@
 
 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 6f16fb2..70e3009 100644
--- a/tests/gprs/gprs_test.c
+++ b/tests/gprs/gprs_test.c
@@ -120,7 +120,8 @@
 
 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 b55f1d9..acc7274 100644
--- a/tests/gsup/gsup_test.c
+++ b/tests/gsup/gsup_test.c
@@ -329,7 +329,8 @@
 
 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 e627ba6..3f15afe 100644
--- a/tests/lapd/lapd_test.c
+++ b/tests/lapd/lapd_test.c
@@ -29,6 +29,7 @@
 #include <osmocom/gsm/rsl.h>
 
 #include <errno.h>
+#include <talloc.h>
 
 #include <string.h>
 
@@ -759,7 +760,10 @@
 
 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 0533546..ffaa155 100644
--- a/tests/msgb/msgb_test.c
+++ b/tests/msgb/msgb_test.c
@@ -385,7 +385,9 @@
 
 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 dea5c11..32676ca 100644
--- a/tests/oap/oap_test.c
+++ b/tests/oap/oap_test.c
@@ -173,7 +173,9 @@
 
 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 efbdf7e..0615396 100644
--- a/tests/sms/sms_test.c
+++ b/tests/sms/sms_test.c
@@ -282,9 +282,10 @@
 	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 11ef8da..37e0281 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 @@
 	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 @@
 	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 @@
 	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 @@
 
 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 2e28e54..3973275 100644
--- a/tests/tlv/tlv_test.c
+++ b/tests/tlv/tlv_test.c
@@ -277,7 +277,7 @@
 
 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 429c72d..1f79063 100644
--- a/tests/ussd/ussd_test.c
+++ b/tests/ussd/ussd_test.c
@@ -122,8 +122,9 @@
 	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 42646eb..a3478e1 100644
--- a/tests/vty/vty_test.c
+++ b/tests/vty/vty_test.c
@@ -41,6 +41,7 @@
 #include <osmocom/vty/stats.h>
 
 static enum event last_vty_connection_event = -1;
+void *ctx = NULL;
 
 static void test_cmd_string_from_valstr(void)
 {
@@ -55,7 +56,7 @@
 
 	/* 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 @@
 		.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);

-- 
To view, visit https://gerrit.osmocom.org/7637
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia36c248f99353d5baaa2533f46a2f60a8579bdf8
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list