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/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has submitted this change. ( 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, 39 insertions(+), 14 deletions(-) Approvals: pespin: Looks good to me, but someone else must approve laforge: Looks good to me, approved Jenkins Builder: Verified diff --git a/tests/coding/coding_test.c b/tests/coding/coding_test.c index 2b0830f..94e404a 100644 --- a/tests/coding/coding_test.c +++ b/tests/coding/coding_test.c @@ -44,6 +44,13 @@ return; \ } while(0) +/* Similar to OSMO_ASSERT, but does not panic() */ +#define CHECK_RC_OR_RET(exp, action) \ + if (!(exp)) { \ + printf("%s(%s): assert %s failed\n", __func__, action, #exp); \ + return; \ + } + static inline void dump_ubits(ubit_t *bursts_u, unsigned until) { printf("U-Bits:\n"); @@ -76,10 +83,12 @@ 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); + CHECK_RC_OR_RET(rc == 0, "encoding"); /* Prepare soft-bits */ osmo_ubit2sbit(bursts_s, bursts_u, 116 * 4); @@ -91,7 +100,9 @@ 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); + CHECK_RC_OR_RET(rc == 0, "decoding"); + 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 +121,9 @@ 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" : ""); + CHECK_RC_OR_RET(rc == 0, "encoding"); /* Prepare soft-bits */ osmo_ubit2sbit(bursts_s, bursts_u, 36); @@ -125,8 +137,9 @@ /* Decode, correcting errors */ rc = gsm0503_rach_decode_ber(&result, bursts_s, bsic, NULL, NULL); - printf("Decoded: %02x%s\n", result, (rc != 0) ? " FAIL" : ""); + CHECK_RC_OR_RET(rc == 0, "decoding"); + printf("Decoded: %02x\n", result); if (ra != result) printf("FAIL [RACH]: encoded %u != %u decoded\n", ra, result); @@ -141,8 +154,9 @@ 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" : ""); + CHECK_RC_OR_RET(rc == 0, "encoding"); /* Prepare soft-bits */ osmo_ubit2sbit(bursts_s, bursts_u, 36); @@ -156,8 +170,9 @@ /* Decode, correcting errors */ rc = gsm0503_rach_ext_decode_ber(&result, bursts_s, bsic, NULL, NULL); - printf("Decoded: %02x%s\n", result, (rc != 0) ? " FAIL" : ""); + CHECK_RC_OR_RET(rc == 0, "decoding"); + printf("Decoded: %02x\n", result); if (ra != result) printf("FAIL [RACH ext]: encoded %u != %u decoded\n", ra, result); @@ -169,6 +184,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 +192,8 @@ /* Encode L2 message */ printf("Encoding: %s\n", osmo_hexdump(info, 4)); - gsm0503_sch_encode(bursts_u, info); + rc = gsm0503_sch_encode(bursts_u, info); + CHECK_RC_OR_RET(rc == 0, "encoding"); /* Prepare soft-bits */ osmo_ubit2sbit(bursts_s, bursts_u, 78); @@ -189,7 +206,9 @@ memset(bursts_s + 6, 0, 10); /* Decode, correcting errors */ - gsm0503_sch_decode(result, bursts_s); + rc = gsm0503_sch_decode(result, bursts_s); + CHECK_RC_OR_RET(rc == 0, "decoding"); + printf("Decoded: %s\n", osmo_hexdump(result, 4)); OSMO_ASSERT(!memcmp(info, result, 4)); @@ -210,7 +229,8 @@ /* 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); + CHECK_RC_OR_RET(rc == 0, "encoding"); /* Prepare soft-bits */ osmo_ubit2sbit(bursts_s, bursts_u, 116 * 8); @@ -224,11 +244,12 @@ /* Decode, correcting errors */ rc = gsm0503_tch_fr_decode(result, bursts_s, 1, len == 31, &n_errors, &n_bits_total); + CHECK_RC_OR_RET(rc == len, "decoding"); + 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); - OSMO_ASSERT(rc == len); OSMO_ASSERT(!memcmp(speech, result, len)); printf("\n"); @@ -247,7 +268,8 @@ /* 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); + CHECK_RC_OR_RET(rc == 0, "encoding"); /* Prepare soft-bits */ osmo_ubit2sbit(bursts_s, bursts_u, 116 * 6); @@ -261,11 +283,12 @@ /* Decode, correcting errors */ rc = gsm0503_tch_hr_decode(result, bursts_s, 0, &n_errors, &n_bits_total); + CHECK_RC_OR_RET(rc == len, "decoding"); + 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); - OSMO_ASSERT(rc == len); OSMO_ASSERT(!memcmp(speech, result, len)); printf("\n"); @@ -294,7 +317,8 @@ /* 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); + CHECK_RC_OR_RET(rc == GSM0503_GPRS_BURSTS_NBITS, "encoding"); /* Prepare soft-bits */ osmo_ubit2sbit(bursts_s, bursts_u, 116 * 4); @@ -305,11 +329,12 @@ /* Decode */ rc = gsm0503_pdtch_decode(result, bursts_s, NULL, &n_errors, &n_bits_total); + CHECK_RC_OR_RET(rc == len, "decoding"); + 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); - OSMO_ASSERT(rc == len); OSMO_ASSERT(!memcmp(l2, result, len)); printf("\n"); -- 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: 2 Gerrit-Owner: fixeria <axilirator at gmail.com> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <axilirator at gmail.com> Gerrit-Reviewer: laforge <laforge at osmocom.org> Gerrit-Reviewer: pespin <pespin at sysmocom.de> Gerrit-MessageType: merged -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200401/488b30fe/attachment.htm>