[PATCH] osmo-bsc[master]: add test for gsm48_ra_id_by_bts()

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

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Mon Mar 5 00:00:24 UTC 2018


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

add test for gsm48_ra_id_by_bts()

Change-Id: I7bd55126848ed2c246d64cf672e1e6772da64be7
---
M tests/gsm0408/gsm0408_test.c
M tests/gsm0408/gsm0408_test.ok
2 files changed, 121 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/75/7075/1

diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index 14cd81c..d1d50f1 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -32,6 +32,7 @@
 #include <osmocom/bsc/abis_rsl.h>
 
 #include <osmocom/core/application.h>
+#include <osmocom/core/byteswap.h>
 #include <osmocom/gsm/sysinfo.h>
 #include <osmocom/gsm/gsm48.h>
 
@@ -707,6 +708,117 @@
 	OSMO_ASSERT(si5ter->bcch_frequency_list[0] & 0x10);
 }
 
+struct test_gsm48_ra_id_by_bts {
+	struct osmo_plmn_id plmn;
+	uint16_t lac;
+	uint8_t rac;
+	struct gsm48_ra_id expect;
+};
+static const struct test_gsm48_ra_id_by_bts test_gsm48_ra_id_by_bts_data[] = {
+	{
+		.plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = false },
+		.lac = 3,
+		.rac = 4,
+		.expect = {
+			.digits = { 0x00, 0xf1, 0x20 },
+			.lac = 0x0300, /* network byte order of 3 */
+			.rac = 4,
+		},
+	},
+	{
+		.plmn = { .mcc = 1, .mnc = 2, .mnc_3_digits = true },
+		.lac = 3,
+		.rac = 4,
+		.expect = {
+			.digits = { 0x00, 0xf1, 0x20 }, /* FAIL: should be { 0x00, 0x21, 0x00 }, */
+			.lac = 0x0300, /* network byte order of 3 */
+			.rac = 4,
+		},
+	},
+	{
+		.plmn = { .mcc = 0, .mnc = 0, .mnc_3_digits = false },
+		.lac = 0,
+		.rac = 0,
+		.expect = {
+			.digits = { 0x00, 0xf0, 0x00 },
+		},
+	},
+	{
+		.plmn = { .mcc = 0, .mnc = 0, .mnc_3_digits = true },
+		.lac = 0,
+		.rac = 0,
+		.expect = {
+			.digits = { 0x00, 0xf0, 0x00 }, /* FAIL: should be { 0, 0, 0 } */
+		},
+	},
+	{
+		.plmn = { .mcc = 999, .mnc = 999, .mnc_3_digits = false },
+		.lac = 65535,
+		.rac = 255,
+		.expect = {
+			.digits = { 0x99, 0x99, 0x99 },
+			.lac = 0xffff,
+			.rac = 0xff,
+		},
+	},
+	{
+		.plmn = { .mcc = 909, .mnc = 90, .mnc_3_digits = false },
+		.lac = 0xabcd,
+		.rac = 0xab,
+		.expect = {
+			.digits = { 0x09, 0xf9, 0x09 },
+			.lac = 0xcdab,
+			.rac = 0xab,
+		},
+	},
+	{
+		.plmn = { .mcc = 909, .mnc = 90, .mnc_3_digits = true },
+		.lac = 0xabcd,
+		.rac = 0xab,
+		.expect = {
+			.digits = { 0x09, 0xf9, 0x09 }, /* FAIL: should be { 0x09, 0x09, 0x90 }, */
+			.lac = 0xcdab,
+			.rac = 0xab,
+		},
+	},
+};
+
+static void test_gsm48_ra_id_by_bts()
+{
+	int i;
+	bool pass = true;
+
+	for (i = 0; i < ARRAY_SIZE(test_gsm48_ra_id_by_bts_data); i++) {
+		struct gsm_network net;
+		struct gsm_bts bts;
+		const struct test_gsm48_ra_id_by_bts *t = &test_gsm48_ra_id_by_bts_data[i];
+		struct gsm48_ra_id result = {};
+		bool ok;
+
+		net.country_code = t->plmn.mcc;
+		net.network_code = t->plmn.mnc;
+		bts.network = &net;
+		bts.location_area_code = t->lac;
+		bts.gprs.rac = t->rac;
+
+		gsm48_ra_id_by_bts((uint8_t*)&result, &bts);
+
+		ok = (t->expect.digits[0] == result.digits[0])
+		     && (t->expect.digits[1] == result.digits[1])
+		     && (t->expect.digits[2] == result.digits[2])
+		     && (t->expect.lac == result.lac)
+		     && (t->expect.rac == result.rac);
+		printf("%s[%d]: digits='%02x%02x%02x' lac=0x%04x=htons(%u) rac=0x%02x=%u %s\n",
+		       __func__, i,
+		       result.digits[0], result.digits[1], result.digits[2],
+		       result.lac, osmo_ntohs(result.lac), result.rac, result.rac,
+		       ok ? "pass" : "FAIL");
+		pass = pass && ok;
+	}
+
+	OSMO_ASSERT(pass);
+}
+
 static const struct log_info_cat log_categories[] = {
 };
 
@@ -744,6 +856,8 @@
 
 	test_si_ba_ind(net);
 
+	test_gsm48_ra_id_by_bts();
+
 	printf("Done.\n");
 
 	return EXIT_SUCCESS;
diff --git a/tests/gsm0408/gsm0408_test.ok b/tests/gsm0408/gsm0408_test.ok
index b85141a..686018b 100644
--- a/tests/gsm0408/gsm0408_test.ok
+++ b/tests/gsm0408/gsm0408_test.ok
@@ -214,4 +214,11 @@
 SI5: 06 1d 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
 SI5bis: 06 05 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
 SI5ter: 06 06 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+test_gsm48_ra_id_by_bts[0]: digits='00f120' lac=0x0300=htons(3) rac=0x04=4 pass
+test_gsm48_ra_id_by_bts[1]: digits='00f120' lac=0x0300=htons(3) rac=0x04=4 pass
+test_gsm48_ra_id_by_bts[2]: digits='00f000' lac=0x0000=htons(0) rac=0x00=0 pass
+test_gsm48_ra_id_by_bts[3]: digits='00f000' lac=0x0000=htons(0) rac=0x00=0 pass
+test_gsm48_ra_id_by_bts[4]: digits='999999' lac=0xffff=htons(65535) rac=0xff=255 pass
+test_gsm48_ra_id_by_bts[5]: digits='09f909' lac=0xcdab=htons(43981) rac=0xab=171 pass
+test_gsm48_ra_id_by_bts[6]: digits='09f909' lac=0xcdab=htons(43981) rac=0xab=171 pass
 Done.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7bd55126848ed2c246d64cf672e1e6772da64be7
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list