Change in libosmocore[master]: tests/coding: check return value of encoding / decoding functions

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

fixeria gerrit-no-reply at lists.osmocom.org
Mon Mar 30 11:34:58 UTC 2020


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/17670 )


Change subject: tests/coding: check return value of encoding / decoding functions
......................................................................

tests/coding: check return value of encoding / decoding functions

Change-Id: I78850a4ab2fb7cd63bb4a3789f934634b6fb2cb7
---
M tests/coding/coding_test.c
1 file changed, 74 insertions(+), 11 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/70/17670/1

diff --git a/tests/coding/coding_test.c b/tests/coding/coding_test.c
index 2b0830f..bfdb8b9 100644
--- a/tests/coding/coding_test.c
+++ b/tests/coding/coding_test.c
@@ -76,10 +76,15 @@
 	ubit_t bursts_u[116 * 4];
 	sbit_t bursts_s[116 * 4];
 	int n_errors, n_bits_total;
+	int rc;
 
 	/* Encode L2 message */
 	printf("Encoding: %s\n", osmo_hexdump(l2, 23));
-	gsm0503_xcch_encode(bursts_u, l2);
+	rc = gsm0503_xcch_encode(bursts_u, l2);
+	if (rc) {
+		printf("%s(): encoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
 
 	/* Prepare soft-bits */
 	osmo_ubit2sbit(bursts_s, bursts_u, 116 * 4);
@@ -91,7 +96,12 @@
 	memset(bursts_s + 116, 0, 30);
 
 	/* Decode, correcting errors */
-	gsm0503_xcch_decode(result, bursts_s, &n_errors, &n_bits_total);
+	rc = gsm0503_xcch_decode(result, bursts_s, &n_errors, &n_bits_total);
+	if (rc) {
+		printf("%s(): decoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
+
 	printf("Decoded: %s\n", osmo_hexdump(result, 23));
 	printf("xcch_decode: n_errors=%d n_bits_total=%d ber=%.2f\n",
 		n_errors, n_bits_total, (float) n_errors / n_bits_total);
@@ -110,8 +120,12 @@
 	sbit_t bursts_s[36];
 
 	/* Encode L2 message */
+	printf("Encoding: %02x\n", ra);
 	rc = gsm0503_rach_ext_encode(bursts_u, ra, bsic, false);
-	printf("Encoding: %02x%s\n", ra, (rc != 0) ? " FAIL" : "");
+	if (rc) {
+		printf("%s(): encoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
 
 	/* Prepare soft-bits */
 	osmo_ubit2sbit(bursts_s, bursts_u, 36);
@@ -125,8 +139,12 @@
 
 	/* Decode, correcting errors */
 	rc = gsm0503_rach_decode_ber(&result, bursts_s, bsic, NULL, NULL);
-	printf("Decoded: %02x%s\n", result, (rc != 0) ? " FAIL" : "");
+	if (rc) {
+		printf("%s(): decoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
 
+	printf("Decoded: %02x\n", result);
 	if (ra != result)
 		printf("FAIL [RACH]: encoded %u != %u decoded\n", ra, result);
 
@@ -141,8 +159,12 @@
 	sbit_t bursts_s[36];
 
 	/* Encode L2 message */
+	printf("Encoding: %02x\n", ra);
 	rc = gsm0503_rach_ext_encode(bursts_u, ra, bsic, true);
-	printf("Encoding: %02x%s\n", ra, (rc != 0) ? " FAIL" : "");
+	if (rc) {
+		printf("%s(): encoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
 
 	/* Prepare soft-bits */
 	osmo_ubit2sbit(bursts_s, bursts_u, 36);
@@ -156,8 +178,12 @@
 
 	/* Decode, correcting errors */
 	rc = gsm0503_rach_ext_decode_ber(&result, bursts_s, bsic, NULL, NULL);
-	printf("Decoded: %02x%s\n", result, (rc != 0) ? " FAIL" : "");
+	if (rc) {
+		printf("%s(): decoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
 
+	printf("Decoded: %02x\n", result);
 	if (ra != result)
 		printf("FAIL [RACH ext]: encoded %u != %u decoded\n", ra, result);
 
@@ -169,6 +195,7 @@
 	uint8_t result[4];
 	ubit_t bursts_u[78];
 	sbit_t bursts_s[78];
+	int rc;
 
 	/* Zero bits 25 and above */
 	info[3] &= 1;
@@ -176,7 +203,11 @@
 
 	/* Encode L2 message */
 	printf("Encoding: %s\n", osmo_hexdump(info, 4));
-	gsm0503_sch_encode(bursts_u, info);
+	rc = gsm0503_sch_encode(bursts_u, info);
+	if (rc) {
+		printf("%s(): encoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
 
 	/* Prepare soft-bits */
 	osmo_ubit2sbit(bursts_s, bursts_u, 78);
@@ -189,7 +220,12 @@
 	memset(bursts_s + 6, 0, 10);
 
 	/* Decode, correcting errors */
-	gsm0503_sch_decode(result, bursts_s);
+	rc = gsm0503_sch_decode(result, bursts_s);
+	if (rc) {
+		printf("%s(): decoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
+
 	printf("Decoded: %s\n", osmo_hexdump(result, 4));
 
 	OSMO_ASSERT(!memcmp(info, result, 4));
@@ -210,7 +246,11 @@
 
 	/* Encode L2 message */
 	printf("Encoding: %s\n", osmo_hexdump(speech, len));
-	gsm0503_tch_fr_encode(bursts_u, speech, len, 1);
+	rc = gsm0503_tch_fr_encode(bursts_u, speech, len, 1);
+	if (rc) {
+		printf("%s(): encoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
 
 	/* Prepare soft-bits */
 	osmo_ubit2sbit(bursts_s, bursts_u, 116 * 8);
@@ -224,6 +264,11 @@
 	/* Decode, correcting errors */
 	rc = gsm0503_tch_fr_decode(result, bursts_s, 1, len == 31,
 		&n_errors, &n_bits_total);
+	if (rc < 0) {
+		printf("%s(): decoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
+
 	printf("Decoded: %s\n", osmo_hexdump(result, len));
 	printf("tch_fr_decode: n_errors=%d n_bits_total=%d ber=%.2f\n",
 		n_errors, n_bits_total, (float)n_errors/n_bits_total);
@@ -247,7 +292,11 @@
 
 	/* Encode L2 message */
 	printf("Encoding: %s\n", osmo_hexdump(speech, len));
-	gsm0503_tch_hr_encode(bursts_u, speech, len);
+	rc = gsm0503_tch_hr_encode(bursts_u, speech, len);
+	if (rc) {
+		printf("%s(): encoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
 
 	/* Prepare soft-bits */
 	osmo_ubit2sbit(bursts_s, bursts_u, 116 * 6);
@@ -261,6 +310,11 @@
 	/* Decode, correcting errors */
 	rc = gsm0503_tch_hr_decode(result, bursts_s, 0,
 		&n_errors, &n_bits_total);
+	if (rc < 0) {
+		printf("%s(): decoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
+
 	printf("Decoded: %s\n", osmo_hexdump(result, len));
 	printf("tch_hr_decode: n_errors=%d n_bits_total=%d ber=%.2f\n",
 		n_errors, n_bits_total, (float)n_errors/n_bits_total);
@@ -294,7 +348,11 @@
 
 	/* Encode L2 message */
 	printf("Encoding: %s\n", osmo_hexdump(l2, len));
-	gsm0503_pdtch_encode(bursts_u, l2, len);
+	rc = gsm0503_pdtch_encode(bursts_u, l2, len);
+	if (rc < 0) {
+		printf("%s(): encoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
 
 	/* Prepare soft-bits */
 	osmo_ubit2sbit(bursts_s, bursts_u, 116 * 4);
@@ -305,6 +363,11 @@
 	/* Decode */
 	rc = gsm0503_pdtch_decode(result, bursts_s, NULL,
 		&n_errors, &n_bits_total);
+	if (rc < 0) {
+		printf("%s(): decoding failed (rc=%d)\n", __func__, rc);
+		return;
+	}
+
 	printf("Decoded: %s\n", osmo_hexdump(result, len));
 	printf("pdtch_decode: n_errors=%d n_bits_total=%d ber=%.2f\n",
 		n_errors, n_bits_total, (float)n_errors/n_bits_total);

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I78850a4ab2fb7cd63bb4a3789f934634b6fb2cb7
Gerrit-Change-Number: 17670
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <axilirator at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200330/3b5855ba/attachment.htm>


More information about the gerrit-log mailing list