[PATCH] openbsc[master]: Fix tests after rate_ctr change

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/.

Max gerrit-no-reply at lists.osmocom.org
Tue Dec 19 12:13:33 UTC 2017


Review at  https://gerrit.osmocom.org/5491

Fix tests after rate_ctr change

Recent change lin libosmocore disallow registering rate_ctr with the
same name and indexing multiple times. To accommodate to this:

* allocate network struct once and use it for all tests
* free bts struct after each test

This is a backport of 4ab7268a902af24fcd4870148b709fed4fbf900c from
OsmoBSC.

Change-Id: Ic5fab86bca617cabcd59484066975e17ab2320b6
Related: OS#2757
---
M openbsc/tests/channel/channel_test.c
M openbsc/tests/gsm0408/gsm0408_test.c
M openbsc/tests/gsm0408/gsm0408_test.ok
3 files changed, 73 insertions(+), 67 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/91/5491/1

diff --git a/openbsc/tests/channel/channel_test.c b/openbsc/tests/channel/channel_test.c
index cf19aab..049786b 100644
--- a/openbsc/tests/channel/channel_test.c
+++ b/openbsc/tests/channel/channel_test.c
@@ -59,28 +59,23 @@
 }
 
 
-void test_request_chan(void)
+void test_request_chan(struct gsm_network *net)
 {
-	struct gsm_network *network;
 	struct gsm_bts *bts;
 
 	printf("Testing the gsm_subscriber chan logic\n");
 
-	/* Create a dummy network */
-	network = bsc_network_init(tall_bsc_ctx, 1, 1, NULL);
-	if (!network)
-		exit(1);
-	bts = gsm_bts_alloc(network, 0);
+	bts = gsm_bts_alloc(net, 0);
 	bts->location_area_code = 23;
-	s_conn.network = network;
+	s_conn.network = net;
 
 	/* Create a dummy subscriber */
 	struct gsm_subscriber *subscr = subscr_alloc();
 	subscr->lac = 23;
-	subscr->group = network->subscr_group;
+	subscr->group = net->subscr_group;
 
 	OSMO_ASSERT(subscr->group);
-	OSMO_ASSERT(subscr->group->net == network);
+	OSMO_ASSERT(subscr->group->net == net);
 
 	/* Ask for a channel... */
 	struct subscr_request *sr;
@@ -93,20 +88,15 @@
 }
 
 
-void test_bts_debug_print(void)
+void test_bts_debug_print(struct gsm_network *net)
 {
-	struct gsm_network *network;
 	struct gsm_bts *bts;
 	struct gsm_bts_trx *trx;
 
 	printf("Testing the lchan printing:");
 
-	/* Create a dummy network */
-	network = bsc_network_init(tall_bsc_ctx, 1, 1, NULL);
-	if (!network)
-		exit(1);
 	/* Add a BTS with some reasonanbly non-zero id */
-	bts = gsm_bts_alloc(network, 45);
+	bts = gsm_bts_alloc(net, 45);
 	/* Add a second TRX to test on multiple TRXs */
 	gsm_bts_trx_alloc(bts);
 
@@ -154,11 +144,18 @@
 
 int main(int argc, char **argv)
 {
+	struct gsm_network *network;
+
 	osmo_init_logging(&log_info);
 
-	test_request_chan();
+	/* Create a dummy network */
+	network = bsc_network_init(tall_bsc_ctx, 1, 1, NULL);
+	if (!network)
+		return EXIT_FAILURE;
+
+	test_request_chan(network);
 	test_dyn_ts_subslots();
-	test_bts_debug_print();
+	test_bts_debug_print(network);
 
 	return EXIT_SUCCESS;
 }
diff --git a/openbsc/tests/gsm0408/gsm0408_test.c b/openbsc/tests/gsm0408/gsm0408_test.c
index 3882f05..6f48599 100644
--- a/openbsc/tests/gsm0408/gsm0408_test.c
+++ b/openbsc/tests/gsm0408/gsm0408_test.c
@@ -145,30 +145,36 @@
 	}
 }
 
-static inline void test_si2q_segfault(void)
+static inline struct gsm_bts *bts_init(void *ctx, struct gsm_network *net, const char *msg)
 {
-	struct gsm_bts *bts;
-	struct gsm_network *network = bsc_network_init(tall_bsc_ctx, 1, 1, NULL);
-	printf("Test SI2quater UARFCN (same scrambling code and diversity):\n");
-
-	if (!network)
+	struct gsm_bts *bts = gsm_bts_alloc(net, 0);
+	if (!bts) {
+		printf("BTS allocation failure in %s()\n", msg);
 		exit(1);
-	bts = gsm_bts_alloc(network, 0);
+	}
+	printf("BTS allocation OK in %s()\n", msg);
+
+	bts->network = net;
+
+	return bts;
+}
+
+static inline void test_si2q_segfault(struct gsm_network *net)
+{
+	struct gsm_bts *bts = bts_init(tall_bsc_ctx, net, __func__);
+	printf("Test SI2quater UARFCN (same scrambling code and diversity):\n");
 
 	_bts_uarfcn_add(bts, 10564, 319, 0);
 	_bts_uarfcn_add(bts, 10612, 319, 0);
 	gen(bts, __func__);
+
+	talloc_free(bts);
 }
 
-static inline void test_si2q_mu(void)
+static inline void test_si2q_mu(struct gsm_network *net)
 {
-	struct gsm_bts *bts;
-	struct gsm_network *network = bsc_network_init(tall_bsc_ctx, 1, 1, NULL);
+	struct gsm_bts *bts = bts_init(tall_bsc_ctx, net, __func__);
 	printf("Test SI2quater multiple UARFCNs:\n");
-
-	if (!network)
-		exit(1);
-	bts = gsm_bts_alloc(network, 0);
 
 	_bts_uarfcn_add(bts, 10564, 318, 0);
 	_bts_uarfcn_add(bts, 10612, 319, 0);
@@ -177,18 +183,14 @@
 	_bts_uarfcn_add(bts, 10613, 64, 0);
 	_bts_uarfcn_add(bts, 10613, 164, 0);
 	_bts_uarfcn_add(bts, 10613, 14, 0);
+
+	talloc_free(bts);
 }
 
-static inline void test_si2q_u(void)
+static inline void test_si2q_u(struct gsm_network *net)
 {
-	struct gsm_bts *bts;
-	struct gsm_network *network = bsc_network_init(tall_bsc_ctx, 1, 1, NULL);
+	struct gsm_bts *bts = bts_init(tall_bsc_ctx, net, __func__);
 	printf("Testing SYSINFO_TYPE_2quater UARFCN generation:\n");
-
-	if (!network)
-		exit(1);
-
-	bts = gsm_bts_alloc(network, 0);
 
 	/* first generate invalid SI as no UARFCN added */
 	gen(bts, __func__);
@@ -205,18 +207,14 @@
 	_bts_uarfcn_add(bts, 1982, 223, 1);
 	_bts_uarfcn_add(bts, 1982, 14, 0);
 	_bts_uarfcn_add(bts, 1982, 88, 0);
+
+	talloc_free(bts);
 }
 
-static inline void test_si2q_e(void)
+static inline void test_si2q_e(struct gsm_network *net)
 {
-	struct gsm_bts *bts;
-	struct gsm_network *network = bsc_network_init(tall_bsc_ctx, 1, 1, NULL);
+	struct gsm_bts *bts = bts_init(tall_bsc_ctx, net, __func__);
 	printf("Testing SYSINFO_TYPE_2quater EARFCN generation:\n");
-
-	if (!network)
-		exit(1);
-
-	bts = gsm_bts_alloc(network, 0);
 
 	bts->si_common.si2quater_neigh_list.arfcn = bts->si_common.data.earfcn_list;
 	bts->si_common.si2quater_neigh_list.meas_bw = bts->si_common.data.meas_bw_list;
@@ -238,18 +236,14 @@
 	add_earfcn_b(bts, 1965, OSMO_EARFCN_MEAS_INVALID);
 	add_earfcn_b(bts, 1967, 4);
 	add_earfcn_b(bts, 1982, 3);
+
+	talloc_free(bts);
 }
 
-static inline void test_si2q_long(void)
+static inline void test_si2q_long(struct gsm_network *net)
 {
-	struct gsm_bts *bts;
-	struct gsm_network *network = bsc_network_init(tall_bsc_ctx, 1, 1, NULL);
+	struct gsm_bts *bts = bts_init(tall_bsc_ctx, net, __func__);
 	printf("Testing SYSINFO_TYPE_2quater combined EARFCN & UARFCN generation:\n");
-
-	if (!network)
-		exit(1);
-
-	bts = gsm_bts_alloc(network, 0);
 
 	bts->si_common.si2quater_neigh_list.arfcn = bts->si_common.data.earfcn_list;
 	bts->si_common.si2quater_neigh_list.meas_bw = bts->si_common.data.meas_bw_list;
@@ -286,6 +280,8 @@
 	_bts_uarfcn_add(bts, 1976, 224, 1);
 	_bts_uarfcn_add(bts, 1976, 225, 1);
 	_bts_uarfcn_add(bts, 1976, 226, 1);
+
+	talloc_free(bts);
 }
 
 static void test_mi_functionality(void)
@@ -671,10 +667,10 @@
 	OSMO_ASSERT(res == 1);
 }
 
-static void test_si_ba_ind(void)
+static void test_si_ba_ind(struct gsm_network *net)
 {
-	struct gsm_network *network = bsc_network_init(tall_bsc_ctx, 1, 1, NULL);
-	struct gsm_bts *bts = gsm_bts_alloc(network, 0);
+	struct gsm_bts *bts = bts_init(tall_bsc_ctx, net, __func__);
+
 	const struct gsm48_system_information_type_2 *si2 =
 		(struct gsm48_system_information_type_2 *) GSM_BTS_SI(bts, SYSINFO_TYPE_2);
 	const struct gsm48_system_information_type_2bis *si2bis =
@@ -690,7 +686,6 @@
 
 	int rc;
 
-	bts->network = network;
 	bts->c0->arfcn = 23;
 
 	printf("Testing if BA-IND is set as expected in SI2xxx and SI5xxx\n");
@@ -734,8 +729,16 @@
 
 int main(int argc, char **argv)
 {
+	struct gsm_network *net;
+
 	osmo_init_logging(&log_info);
 	log_set_log_level(osmo_stderr_target, LOGL_INFO);
+
+	net = bsc_network_init(tall_bsc_ctx, 1, 1, NULL);
+	if (!net) {
+		printf("Network init failure.\n");
+		return EXIT_FAILURE;
+	}
 
 	test_location_area_identifier();
 	test_mi_functionality();
@@ -746,13 +749,13 @@
 	test_range_encoding();
 	test_gsm411_rp_ref_wrap();
 
-	test_si2q_segfault();
-	test_si2q_e();
-	test_si2q_u();
-	test_si2q_mu();
-	test_si2q_long();
+	test_si2q_segfault(net);
+	test_si2q_e(net);
+	test_si2q_u(net);
+	test_si2q_mu(net);
+	test_si2q_long(net);
 
-	test_si_ba_ind();
+	test_si_ba_ind(net);
 
 	printf("Done.\n");
 
diff --git a/openbsc/tests/gsm0408/gsm0408_test.ok b/openbsc/tests/gsm0408/gsm0408_test.ok
index 4fff78f..1039883 100644
--- a/openbsc/tests/gsm0408/gsm0408_test.ok
+++ b/openbsc/tests/gsm0408/gsm0408_test.ok
@@ -62,6 +62,7 @@
 Allocated reference: 255
 Allocated reference: 0
 Allocated reference: 1
+BTS allocation OK in test_si2q_segfault()
 Test SI2quater UARFCN (same scrambling code and diversity):
 generating SI2quater for 0 EARFCNs and 1 UARFCNs...
 generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 88 0a 7e 0b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 
@@ -69,6 +70,7 @@
 generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 e8 0a 7f 52 88 0a 7e 0b 2b 2b 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 2 UARFCNs...
 generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 e8 0a 7f 52 88 0a 7e 0b 2b 2b 2b 2b 2b 2b 2b 2b 
+BTS allocation OK in test_si2q_e()
 Testing SYSINFO_TYPE_2quater EARFCN generation:
 generating SI2quater for 0 EARFCNs and 0 UARFCNs...
 generated invalid SI2quater [00/00]: [23] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
@@ -92,6 +94,7 @@
 added EARFCN 1982 - generating SI2quater for 7 EARFCNs and 0 UARFCNs...
 generated valid SI2quater [00/01]: [23] 59 06 07 40 20 04 86 59 83 be cc 1e 31 07 91 a8 3c ca 0f 5a 0a 03 2b 
 generated valid SI2quater [01/01]: [23] 59 06 07 42 20 04 86 59 83 d7 e4 1e fa c2 80 2b 2b 2b 2b 2b 2b 2b 2b 
+BTS allocation OK in test_si2q_u()
 Testing SYSINFO_TYPE_2quater UARFCN generation:
 generating SI2quater for 0 EARFCNs and 0 UARFCNs...
 generated invalid SI2quater [00/00]: [23] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
@@ -117,6 +120,7 @@
 generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 50 1c 3b 31 fa dd 88 85 7b c4 1c 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 11 UARFCNs...
 generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 58 1c 3b 25 7a ea 08 91 fb c4 1f b0 2b 2b 2b 
+BTS allocation OK in test_si2q_mu()
 Test SI2quater multiple UARFCNs:
 generating SI2quater for 0 EARFCNs and 1 UARFCNs...
 generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 88 0a 7c 0b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 
@@ -134,6 +138,7 @@
 generating SI2quater for 0 EARFCNs and 7 UARFCNs...
 generated valid SI2quater [00/01]: [23] 59 06 07 40 20 25 52 ea 10 81 ce a9 74 08 1f fa 54 ba 82 52 03 2b 2b 
 generated valid SI2quater [01/01]: [23] 59 06 07 42 20 25 52 e8 30 81 d3 7f fd b2 86 54 a2 02 9f 03 2b 2b 2b 
+BTS allocation OK in test_si2q_long()
 Testing SYSINFO_TYPE_2quater combined EARFCN & UARFCN generation:
 generating SI2quater for 17 EARFCNs and 1 UARFCNs...
 generated valid SI2quater [00/04]: [23] 59 06 07 40 80 25 0f 70 0c 1a 10 99 66 0f 04 83 c1 1c bb 2b 03 2b 2b 
@@ -201,6 +206,7 @@
 generated valid SI2quater [03/05]: [23] 59 06 07 46 a0 04 86 59 84 21 54 21 4f 61 0a 99 08 55 b7 2e ca c1 2b 
 generated valid SI2quater [04/05]: [23] 59 06 07 48 a0 04 86 59 84 2b 54 21 27 61 09 59 08 4b b7 2e ca c1 2b 
 generated valid SI2quater [05/05]: [23] 59 06 07 4a a0 04 86 59 84 26 53 97 65 60 2b 2b 2b 2b 2b 2b 2b 2b 2b 
+BTS allocation OK in test_si_ba_ind()
 Testing if BA-IND is set as expected in SI2xxx and SI5xxx
 SI2: 59 06 1a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
 SI2bis: 59 06 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5fab86bca617cabcd59484066975e17ab2320b6
Gerrit-PatchSet: 1
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>



More information about the gerrit-log mailing list