Max has submitted this change and it was merged.

Change subject: coding test: cosmetic cleanup
......................................................................


coding test: cosmetic cleanup

* remove duplicate code: use function from libosmocore
* use utility function to dump ubits
* reformat for easier reading
* link against libosmocore

Change-Id: I8c31b0954176a2c53305936a025c92a793b6d9b6
---
M tests/Makefile.am
M tests/coding/coding_test.c
2 files changed, 55 insertions(+), 102 deletions(-)

Approvals:
  Vadim Yanitskiy: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/tests/Makefile.am b/tests/Makefile.am
index e11092d..c609d6a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -165,7 +165,7 @@
 socket_socket_test_SOURCES = socket/socket_test.c
 
 coding_coding_test_SOURCES = coding/coding_test.c
-coding_coding_test_LDADD = \
+coding_coding_test_LDADD = $(LDADD) \
   $(top_builddir)/src/gsm/libosmogsm.la \
   $(top_builddir)/src/codec/libosmocodec.la \
   $(top_builddir)/src/coding/libosmocoding.la
diff --git a/tests/coding/coding_test.c b/tests/coding/coding_test.c
index 9a00f0d..6c1bd84 100644
--- a/tests/coding/coding_test.c
+++ b/tests/coding/coding_test.c
@@ -40,27 +40,6 @@
 /* set condition to 1, to show debugging */
 #define printd if (0) printf
 
-static int ubits2sbits(ubit_t *ubits, sbit_t *sbits, int count)
-{
-       int i;
-
-       for (i = 0; i < count; i++) {
-               if (*ubits == 0x23) {
-                       ubits++;
-                       sbits++;
-                       continue;
-               }
-
-               if ((*ubits++) & 1) {
-                       *sbits++ = -127;
-               } else {
-                       *sbits++ = 127;
-               }
-       }
-
-       return count;
-}
-
 static void test_xcch(uint8_t *l2)
 {
        uint8_t result[23];
@@ -73,21 +52,17 @@
        gsm0503_xcch_encode(bursts_u, l2);
 
        /* Prepare soft-bits */
-       ubits2sbits(bursts_u, bursts_s, 116 * 4);
+       osmo_ubit2sbit(bursts_s, bursts_u, 116 * 4);
 
        printd("U-Bits:\n");
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u, 57),
-               bursts_u[57], bursts_u[58]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 116, 57),
-               bursts_u[57 + 116], bursts_u[58 + 116]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 116, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 232, 57),
-               bursts_u[57 + 232], bursts_u[58 + 232]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 232, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 348, 57),
-               bursts_u[57 + 348], bursts_u[58 + 348]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 348, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u, 57), bursts_u[57], 
bursts_u[58]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 116, 57), 
bursts_u[57 + 116], bursts_u[58 + 116]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 116, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 232, 57), 
bursts_u[57 + 232], bursts_u[58 + 232]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 232, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 348, 57), 
bursts_u[57 + 348], bursts_u[58 + 348]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 348, 57));
 
        printd("S-Bits:\n");
        printd("%s %02x  %02x  ", osmo_hexdump((uint8_t *)bursts_s, 57),
@@ -130,13 +105,11 @@
        gsm0503_rach_encode(bursts_u, &ra, bsic);
 
        /* Prepare soft-bits */
-       ubits2sbits(bursts_u, bursts_s, 36);
+       osmo_ubit2sbit(bursts_s, bursts_u, 36);
 
-       printd("U-Bits:\n");
-       printd("%s\n", osmo_hexdump(bursts_u, 36));
+       printd("U-Bits: %s\n", osmo_ubit_dump(bursts_u, 36));
 
-       printd("S-Bits:\n");
-       printd("%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);
@@ -165,13 +138,11 @@
        gsm0503_sch_encode(bursts_u, info);
 
        /* Prepare soft-bits */
-       ubits2sbits(bursts_u, bursts_s, 78);
+       osmo_ubit2sbit(bursts_s, bursts_u, 78);
 
-       printd("U-Bits:\n");
-       printd("%s\n", osmo_hexdump(bursts_u, 78));
+       printd("U-Bits: %s\n", osmo_ubit_dump(bursts_u, 78));
 
-       printd("S-Bits:\n");
-       printd("%s\n", osmo_hexdump((uint8_t *)bursts_s, 78));
+       printd("S-Bits: %s\n", osmo_hexdump((uint8_t *)bursts_s, 78));
 
        /* Destroy some bits */
        memset(bursts_s + 6, 0, 10);
@@ -201,33 +172,25 @@
        gsm0503_tch_fr_encode(bursts_u, speech, len, 1);
 
        /* Prepare soft-bits */
-       ubits2sbits(bursts_u, bursts_s, 116 * 8);
+       osmo_ubit2sbit(bursts_s, bursts_u, 116 * 8);
 
        printd("U-Bits:\n");
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u, 57),
-               bursts_u[57], bursts_u[58]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 116, 57),
-               bursts_u[57 + 116], bursts_u[58 + 116]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 116, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 232, 57),
-               bursts_u[57 + 232], bursts_u[58 + 232]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 232, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 348, 57),
-               bursts_u[57 + 348], bursts_u[58 + 348]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 348, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 464, 57),
-               bursts_u[57 + 464], bursts_u[58 + 464]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 464, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 580, 57),
-               bursts_u[57 + 580], bursts_u[58 + 580]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 580, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 696, 57),
-               bursts_u[57 + 696], bursts_u[58 + 696]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 696, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 812, 57),
-               bursts_u[57 + 812], bursts_u[58 + 812]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 812, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u, 57), bursts_u[57], 
bursts_u[58]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 116, 57), 
bursts_u[57 + 116], bursts_u[58 + 116]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 116, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 232, 57), 
bursts_u[57 + 232], bursts_u[58 + 232]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 232, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 348, 57), 
bursts_u[57 + 348], bursts_u[58 + 348]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 348, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 464, 57), 
bursts_u[57 + 464], bursts_u[58 + 464]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 464, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 580, 57), 
bursts_u[57 + 580], bursts_u[58 + 580]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 580, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 696, 57), 
bursts_u[57 + 696], bursts_u[58 + 696]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 696, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 812, 57), 
bursts_u[57 + 812], bursts_u[58 + 812]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 812, 57));
 
        printd("S-Bits:\n");
        printd("%s %02x  %02x  ", osmo_hexdump((uint8_t *)bursts_s, 57),
@@ -287,27 +250,21 @@
        gsm0503_tch_hr_encode(bursts_u, speech, len);
 
        /* Prepare soft-bits */
-       ubits2sbits(bursts_u, bursts_s, 116 * 6);
+       osmo_ubit2sbit(bursts_s, bursts_u, 116 * 6);
 
        printd("U-Bits:\n");
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u, 57),
-               bursts_u[57], bursts_u[58]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 116, 57),
-               bursts_u[57 + 116], bursts_u[58 + 116]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 116, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 232, 57),
-               bursts_u[57 + 232], bursts_u[58 + 232]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 232, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 348, 57),
-               bursts_u[57 + 348], bursts_u[58 + 348]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 348, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 464, 57),
-               bursts_u[57 + 464], bursts_u[58 + 464]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 464, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 580, 57),
-               bursts_u[57 + 580], bursts_u[58 + 580]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 580, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u, 57), bursts_u[57], 
bursts_u[58]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 116, 57), 
bursts_u[57 + 116], bursts_u[58 + 116]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 116, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 232, 57), 
bursts_u[57 + 232], bursts_u[58 + 232]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 232, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 348, 57), 
bursts_u[57 + 348], bursts_u[58 + 348]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 348, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 464, 57), 
bursts_u[57 + 464], bursts_u[58 + 464]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 464, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 580, 57), 
bursts_u[57 + 580], bursts_u[58 + 580]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 580, 57));
 
        printd("S-Bits:\n");
        printd("%s %02x  %02x  ", osmo_hexdump((uint8_t *)bursts_s, 57),
@@ -371,21 +328,17 @@
        gsm0503_pdtch_encode(bursts_u, l2, len);
 
        /* Prepare soft-bits */
-       ubits2sbits(bursts_u, bursts_s, 116 * 4);
+       osmo_ubit2sbit(bursts_s, bursts_u, 116 * 4);
 
        printd("U-Bits:\n");
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u, 57),
-               bursts_u[57], bursts_u[58]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 116, 57),
-               bursts_u[57 + 116], bursts_u[58 + 116]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 116, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 232, 57),
-               bursts_u[57 + 232], bursts_u[58 + 232]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 232, 57));
-       printd("%s %02x  %02x  ", osmo_hexdump(bursts_u + 348, 57),
-               bursts_u[57 + 348], bursts_u[58 + 348]);
-       printd("%s\n", osmo_hexdump(bursts_u + 59 + 348, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u, 57), bursts_u[57], 
bursts_u[58]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 116, 57), 
bursts_u[57 + 116], bursts_u[58 + 116]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 116, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 232, 57), 
bursts_u[57 + 232], bursts_u[58 + 232]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 232, 57));
+       printd("%s %02x  %02x  ", osmo_ubit_dump(bursts_u + 348, 57), 
bursts_u[57 + 348], bursts_u[58 + 348]);
+       printd("%s\n",            osmo_ubit_dump(bursts_u + 59 + 348, 57));
 
        printd("S-Bits:\n");
        printd("%s %02x  %02x  ", osmo_hexdump((uint8_t *)bursts_s, 57),

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I8c31b0954176a2c53305936a025c92a793b6d9b6
Gerrit-PatchSet: 4
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Max <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <[email protected]>
Gerrit-Reviewer: Vadim Yanitskiy <[email protected]>
Gerrit-Reviewer: fixeria <[email protected]>

Reply via email to