[MERGED] libosmocore[master]: gsm0808_test: cosmetic: re-arrange struct init; print hexdum...

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 Mar 23 12:25:05 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: gsm0808_test: cosmetic: re-arrange struct init; print hexdump on failure
......................................................................


gsm0808_test: cosmetic: re-arrange struct init; print hexdump on failure

I am going to ehance the test to actually include leading-zero MNC, but first I
would like to simplify how the test source struct is initialized, before I edit
around in it.

Also, when the memcmp() fails, print hexdumps of expected and actual result for
comparison. I needed it to figure out a test failure, might as well keep it.

Change-Id: I77cd4b9142510c6914298b720d9c19ab68f9ebef
---
M tests/gsm0808/gsm0808_test.c
1 file changed, 32 insertions(+), 24 deletions(-)

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



diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index c3c86dc..c25344a 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -1005,37 +1005,45 @@
 		0x92,  0x72,  0x54,  0x24,  0x43,  0x00,  0x2,
 		0x92,  0x83,  0x54,  0x25,  0x44,  0x00,  0x77
 	};
-	struct osmo_cell_global_id id;
 	uint8_t rc_enc;
 	int rc_dec, i;
 
-	memset(&enc_cil, 0, sizeof(enc_cil));
-
-	enc_cil.id_discr = CELL_IDENT_WHOLE_GLOBAL;
-
-	id.lai.plmn.mcc = 0x123;
-	osmo_mnc_from_str("456", &id.lai.plmn.mnc, &id.lai.plmn.mnc_3_digits);
-	id.lai.lac = 0x2342;
-	id.cell_identity = 1;
-	memcpy(&enc_cil.id_list[0].global, &id, sizeof(id));
-
-	id.lai.plmn.mcc = 0x124;
-	osmo_mnc_from_str("457", &id.lai.plmn.mnc, &id.lai.plmn.mnc_3_digits);
-	id.lai.lac = 0x2443;
-	id.cell_identity = 2;
-	memcpy(&enc_cil.id_list[1].global, &id, sizeof(id));
-
-	id.lai.plmn.mcc = 0x125;
-	osmo_mnc_from_str("458", &id.lai.plmn.mnc, &id.lai.plmn.mnc_3_digits);
-	id.lai.lac = 0x2544;
-	id.cell_identity = 119;
-	memcpy(&enc_cil.id_list[2].global, &id, sizeof(id));
-
-	enc_cil.id_list_len = 3;
+	enc_cil = (struct gsm0808_cell_id_list2){
+		.id_discr = CELL_IDENT_WHOLE_GLOBAL,
+		.id_list_len = 3,
+		.id_list = {
+			{
+				.global = {
+					.lai = { .plmn = { .mcc = 0x123, .mnc = 456 },
+						 .lac = 0x2342 },
+					.cell_identity = 1,
+				}
+			},
+			{
+				.global = {
+					.lai = { .plmn = { .mcc = 0x124, .mnc = 457 },
+						 .lac = 0x2443 },
+					.cell_identity = 2,
+				}
+			},
+			{
+				.global = {
+					.lai = { .plmn = { .mcc = 0x125, .mnc = 458 },
+						 .lac = 0x2544 },
+					.cell_identity = 119,
+				}
+			},
+		}
+	};
 
 	msg = msgb_alloc(1024, "output buffer");
 	rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
 	OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
+	if (memcmp(cil_enc_expected, msg->data, msg->len)) {
+		printf("   got: %s\n", osmo_hexdump(msg->data, msg->len));
+		printf("expect: %s\n", osmo_hexdump(cil_enc_expected, sizeof(cil_enc_expected)));
+		OSMO_ASSERT(false);
+	}
 	OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
 
 	rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I77cd4b9142510c6914298b720d9c19ab68f9ebef
Gerrit-PatchSet: 3
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
Gerrit-Reviewer: Stefan Sperling <ssperling at sysmocom.de>



More information about the gerrit-log mailing list