diff options
Diffstat (limited to 'tests/coding/coding_test.c')
-rw-r--r-- | tests/coding/coding_test.c | 238 |
1 files changed, 195 insertions, 43 deletions
diff --git a/tests/coding/coding_test.c b/tests/coding/coding_test.c index 2b0830f2..bdfe3002 100644 --- a/tests/coding/coding_test.c +++ b/tests/coding/coding_test.c @@ -44,6 +44,19 @@ 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; \ + } + +#ifdef DEBUG +#define printd(fmt, args...) printf(fmt, ##args) +#else +#define printd(fmt, args...) +#endif + static inline void dump_ubits(ubit_t *bursts_u, unsigned until) { printf("U-Bits:\n"); @@ -76,10 +89,12 @@ static void test_xcch(uint8_t *l2) 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 +106,9 @@ static void test_xcch(uint8_t *l2) 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,27 +127,29 @@ static void test_rach(uint8_t bsic, uint8_t ra) sbit_t bursts_s[36]; /* Encode L2 message */ + printd("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); - printf("U-Bits: %s\n", osmo_ubit_dump(bursts_u, 36)); + printd("U-Bits: %s\n", osmo_ubit_dump(bursts_u, 36)); - printf("S-Bits: %s\n", osmo_hexdump((uint8_t *)bursts_s, 36)); + printd("S-Bits: %s\n", osmo_hexdump((uint8_t *)bursts_s, 36)); /* Destroy some bits */ memset(bursts_s + 6, 0, 8); /* 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"); + printd("Decoded: %02x\n", result); if (ra != result) printf("FAIL [RACH]: encoded %u != %u decoded\n", ra, result); - printf("\n"); + printd("\n"); } static void test_rach_ext(uint8_t bsic, uint16_t ra) @@ -141,27 +160,45 @@ static void test_rach_ext(uint8_t bsic, uint16_t ra) sbit_t bursts_s[36]; /* Encode L2 message */ + printd("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); - printf("U-Bits: %s\n", osmo_ubit_dump(bursts_u, 36)); + printd("U-Bits: %s\n", osmo_ubit_dump(bursts_u, 36)); - printf("S-Bits: %s\n", osmo_hexdump((uint8_t *)bursts_s, 36)); + printd("S-Bits: %s\n", osmo_hexdump((uint8_t *)bursts_s, 36)); /* Destroy some bits */ memset(bursts_s + 9, 0, 8); /* 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"); + printd("Decoded: %02x\n", result); if (ra != result) printf("FAIL [RACH ext]: encoded %u != %u decoded\n", ra, result); - printf("\n"); + printd("\n"); +} + +static void test_rach_11bit_sample(uint8_t bsic, const sbit_t *payload) +{ + int n_errors, n_bits_total; + uint16_t ra11; + int rc; + + /* Decode, correcting errors */ + rc = gsm0503_rach_ext_decode_ber(&ra11, payload, bsic, &n_errors, &n_bits_total); + if (rc) { + printf("%s(): decoding failed (rc=%d)\n", __func__, rc); + return; + } + + printf("Decoded RA11: 0x%03x\n", ra11); } static void test_sch(uint8_t *info) @@ -169,6 +206,7 @@ static void test_sch(uint8_t *info) 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 +214,8 @@ static void test_sch(uint8_t *info) /* 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 +228,9 @@ static void test_sch(uint8_t *info) 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 +251,8 @@ static void test_fr(uint8_t *speech, int len) /* 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 +266,12 @@ static void test_fr(uint8_t *speech, int len) /* 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 +290,8 @@ static void test_hr(uint8_t *speech, int len) /* 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,25 +305,96 @@ static void test_hr(uint8_t *speech, int len) /* 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"); } -static void test_pdtch(uint8_t *l2, int len) +struct test_macblock { + bool is_egprs; + uint16_t exp_burst_bits; + uint16_t l2_len; + uint8_t l2[54]; +}; + +static const struct test_macblock test_macblock[] = { + /* Random frame */ + { false, + GSM0503_GPRS_BURSTS_NBITS, + 54, + { 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab, + 0xd9, 0x6d, 0x7d, 0x62, 0x24, 0xc9, 0xd2, 0x92, + 0xfa, 0x27, 0x5d, 0x71, 0x7a, 0x59, 0xa8, 0x42, + 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab, + 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab, + 0xd9, 0x6d, 0x7d, 0x62, 0x24, 0xc9, 0xd2, 0x92, + 0xfa, 0x27, 0x5d, 0x71, 0x7a, 0xa8 } + }, + /* jolly frame */ + { false, + GSM0503_GPRS_BURSTS_NBITS, + 23, + { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 } + }, +/* +GSM RLC/MAC: EGPRS DL HEADER + 0... .... .... 0000 = DL TFI: 0 + 0... .... crumb 1 of DL TFI (decoded above) + .00. .... = RRBP: Reserved Block: (N+13) mod 2715648 (0) + ...0 0... = ES/P: RRBP field is not valid (no Polling) (0) + .... .111 = USF: 7 + 01.. .... 0000 0000 .... ...0 = BSN: 1 + 01.. .... crumb 2 of BSN (decoded above) + ..00 .... = PR: 0 dB (included) to 3 dB (excluded) less than BCCH level - P0 (0) + .... 0000 crumb 0 of DL TFI (decoded above) + 0000 0000 crumb 1 of BSN (decoded above) + .00. .... = SPB (DL): No retransmission (0) + ...1 011. = CPS: MCS-1/P1 (0x0b) + .... ...0 crumb 0 of BSN (decoded above) +GSM RLC/MAC: EGPRS DL DATA BLOCK 1 (BSN 1) + .... ..0. = FBI: Current Block is not last RLC data block in TBF + .... ...0 = Extension: Extension octet follows immediately + 0000 100. = Length Indicator: 4 + .... ...0 = Extension: Extension octet follows immediately + 0010 000. = Length Indicator: 16 + .... ...1 = Extension: No extension octet follows + data segment: LI[0]=4 indicates: (Last segment of) LLC frame (4 octets) + Data (4 bytes) + Data: 012b2b2b + [Length: 4] + data segment: LI[1]=16 indicates: (Last segment of) LLC frame (16 octets) + Data (16 bytes) + Data: 43c0012b2b2b2b2b2b2b2b2b2b2b2b2b + [Length: 16] +*/ + { true, + GSM0503_GPRS_BURSTS_NBITS, + 27, + { 0x07, 0x40, 0x00, 0x16, 0x10, 0x42, 0x02, 0x56, + 0x56, 0x56, 0x86, 0x80, 0x03, 0x56, 0x56, 0x56, + 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, + 0x56, 0x56, 0x00 } + }, +}; + +static void test_pdtch(const struct test_macblock *tmb, int len) { - uint8_t result[len]; + uint8_t l2[len], result[len]; ubit_t bursts_u[116 * 4]; sbit_t bursts_s[116 * 4]; int n_errors, n_bits_total; int rc; /* Zero the not coded tail bits */ + memcpy(l2, tmb->l2, len); switch (len) { case 34: case 54: @@ -294,7 +409,11 @@ static void test_pdtch(uint8_t *l2, int len) /* Encode L2 message */ printf("Encoding: %s\n", osmo_hexdump(l2, len)); - gsm0503_pdtch_encode(bursts_u, l2, len); + if (tmb->is_egprs) + rc = gsm0503_pdtch_egprs_encode(bursts_u, l2, len); + else + rc = gsm0503_pdtch_encode(bursts_u, l2, len); + CHECK_RC_OR_RET(rc == (int)tmb->exp_burst_bits, "encoding"); /* Prepare soft-bits */ osmo_ubit2sbit(bursts_s, bursts_u, 116 * 4); @@ -303,13 +422,20 @@ static void test_pdtch(uint8_t *l2, int len) dump_sbits((uint8_t *)bursts_s, 348); /* Decode */ - rc = gsm0503_pdtch_decode(result, bursts_s, NULL, - &n_errors, &n_bits_total); + if (tmb->is_egprs) { + /* gsm0503_pdtch_egprs_decode() is meant to decode EGPRS UL frames, so we cannot use it here */ + rc = gsm0503_pdtch_egprs_decode(result, bursts_s, rc, NULL, &n_errors, &n_bits_total); + OSMO_ASSERT(rc == -EIO); + return; + } else { + 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"); @@ -330,19 +456,37 @@ uint8_t test_l2[][23] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }, }; -uint8_t test_macblock[][54] = { - /* Random frame */ - { 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab, - 0xd9, 0x6d, 0x7d, 0x62, 0x24, 0xc9, 0xd2, 0x92, - 0xfa, 0x27, 0x5d, 0x71, 0x7a, 0x59, 0xa8, 0x42, - 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab, - 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab, - 0xd9, 0x6d, 0x7d, 0x62, 0x24, 0xc9, 0xd2, 0x92, - 0xfa, 0x27, 0x5d, 0x71, 0x7a, 0xa8 }, - /* jolly frame */ - { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }, +/* 11-bit Access Burst soft-bits (payload only) from an EGPRS capable phone (BSIC 63) */ +static const sbit_t test_rach_11bit[6][36] = { + { 103, 109, -108, -110, 107, 108, -106, -120, -121, + -120, -105, 122, -104, -109, 108, 109, -109, -111, + 107, 111, -105, -119, -121, -104, 122, -120, 121, + -99, -121, -120, -122, -106, 109, 109, -108, -111 }, + + { 103, 109, -109, -109, 106, 107, -106, -121, -121, + -120, -106, 121, -120, 117, -122, 101, 109, -122, + 120, -120, 101, 118, 120, 102, -125, 101, 110, + -120, 121, -101, -121, -118, -121, -106, 108, 121 }, + + { -121, -122, -104, 123, -104, -108, 122, -104, -121, + -121, -102, 124, -105, -110, 107, 109, -108, -109, + 121, -122, 101, 107, -121, 105, 108, -110, -107, + 124, -104, -109, 120, -122, 100, 122, 104, -123 }, + + { -122, -123, -103, 123, -105, -109, 122, -105, -121, + -120, -104, 122, -120, 121, -101, -122, -120, -120, + -119, -105, 120, -106, -108, 123, -104, -113, 105, + 122, 101, -122, 119, -122, 117, -121, 119, -122 }, + + { 105, 110, -109, -109, 107, 108, -108, -120, -120, + -121, -106, 121, -104, -107, 106, 108, -108, -108, + 108, 107, -105, -120, -122, -104, 122, -119, 121, + -103, -122, -118, -120, -106, 108, 108, -110, -111 }, + + { 120, -103, -123, -104, 119, -121, 100, 123, 106, + -109, -107, 121, -122, 118, -121, 103, 108, -122, + 120, -119, 121, -103, -121, -119, -121, -103, 124, + -106, -108, 122, -103, -106, 121, -120, 119, -121 }, }; uint8_t test_speech_fr[33]; @@ -353,8 +497,8 @@ int main(int argc, char **argv) { int i, len_l2, len_mb; - len_l2 = sizeof(test_l2) / sizeof(test_l2[0]); - len_mb = sizeof(test_macblock) / sizeof(test_macblock[0]); + len_l2 = ARRAY_SIZE(test_l2); + len_mb = ARRAY_SIZE(test_macblock); for (i = 0; i < len_l2; i++) test_xcch(test_l2[i]); @@ -371,6 +515,10 @@ int main(int argc, char **argv) test_rach_ext(0x1a, i); } + for (i = 0; i < ARRAY_SIZE(test_rach_11bit); i++) + test_rach_11bit_sample(0x3f, test_rach_11bit[i]); + printf("\n"); + for (i = 0; i < len_l2; i++) test_sch(test_l2[i]); @@ -396,10 +544,14 @@ int main(int argc, char **argv) test_hr(test_l2[i], sizeof(test_l2[0])); for (i = 0; i < len_mb; i++) { - test_pdtch(test_macblock[i], 23); - test_pdtch(test_macblock[i], 34); - test_pdtch(test_macblock[i], 40); - test_pdtch(test_macblock[i], 54); + if (test_macblock[i].is_egprs) { + test_pdtch(&test_macblock[i], test_macblock[i].l2_len); + } else { + test_pdtch(&test_macblock[i], 23); + test_pdtch(&test_macblock[i], 34); + test_pdtch(&test_macblock[i], 40); + test_pdtch(&test_macblock[i], 54); + } } printf("Success\n"); |