Change in osmo-msc[master]: VLR tests: use msgb_eq_data_print() for comparison

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 Feb 5 16:25:03 UTC 2019


Max has submitted this change and it was merged. ( https://gerrit.osmocom.org/12571 )

Change subject: VLR tests: use msgb_eq_data_print() for comparison
......................................................................

VLR tests: use msgb_eq_data_print() for comparison

This simplifies tests refactoring by showing exact byte where mismatch
happened. It also makes code more readable.

No changes in expected test output are necessary because the additional
logging will be triggered iff the test fails so the result will be
visible only during debugging of unit test issues.

Change-Id: If9771c973f2bc55580f4c146bdbeeb1609d56786
---
M tests/msc_vlr/msc_vlr_tests.c
1 file changed, 12 insertions(+), 11 deletions(-)

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



diff --git a/tests/msc_vlr/msc_vlr_tests.c b/tests/msc_vlr/msc_vlr_tests.c
index 296f055..eb6df09 100644
--- a/tests/msc_vlr/msc_vlr_tests.c
+++ b/tests/msc_vlr/msc_vlr_tests.c
@@ -570,15 +570,21 @@
 int __real_osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg);
 int __wrap_osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg)
 {
-	const char *is = osmo_hexdump_nospc(msg->data, msg->len);
+	uint8_t buf[512];
+	int len;
+
 	fprintf(stderr, "GSUP --> HLR: %s: %s\n",
-		osmo_gsup_message_type_name(msg->data[0]), is);
+		osmo_gsup_message_type_name(msg->data[0]), osmo_hexdump_nospc(msg->data, msg->len));
 
 	OSMO_ASSERT(gsup_tx_expected);
-	if (strcmp(gsup_tx_expected, is)) {
-		fprintf(stderr, "Mismatch! Expected:\n%s\n", gsup_tx_expected);
+	OSMO_ASSERT(strlen(gsup_tx_expected) <= (sizeof(buf) * 2));
+
+	len = osmo_hexparse(gsup_tx_expected, buf, sizeof(buf));
+	if (len < 1)
 		abort();
-	}
+
+	if (!msgb_eq_data_print(msg, buf, len))
+		abort();
 
 	talloc_free(msg);
 	gsup_tx_confirmed = true;
@@ -596,13 +602,8 @@
 
 	/* Mask the sequence number out before comparing */
 	msg->data[1] &= 0x3f;
-	if (msg->len != dtap_tx_expected->len
-	    || memcmp(msg->data, dtap_tx_expected->data, msg->len)) {
-		fprintf(stderr, "Mismatch! Expected:\n%s\n",
-		       osmo_hexdump_nospc(dtap_tx_expected->data,
-					  dtap_tx_expected->len));
+	if (!msgb_eq_data_print(msg, dtap_tx_expected->data, dtap_tx_expected->len))
 		abort();
-	}
 
 	btw("DTAP matches expected message");
 

-- 
To view, visit https://gerrit.osmocom.org/12571
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: If9771c973f2bc55580f4c146bdbeeb1609d56786
Gerrit-Change-Number: 12571
Gerrit-PatchSet: 4
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Stefan Sperling <stsp at stsp.name>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190205/74a3994a/attachment.htm>


More information about the gerrit-log mailing list