[PATCH] osmo-pcu[master]: cosmetic: BitcompTest: make readable

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

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Sun Mar 26 22:25:06 UTC 2017


Review at  https://gerrit.osmocom.org/2167

cosmetic: BitcompTest: make readable

In order to understand what the bitcomp test is logging, cosmetically rearrange
the code:

- memset bits_data before assigning to destination bitvec.
- use macro CEIL_DIV_8 to clarify what (x+7)/8 does.
- rename check_result() to result_matches() and return a bool,
  also constify result_matches() args and pass a bitvec reference instead of
  copying the bitvec struct.
- rearrange logging lines to make readable what is going on there.
- drop unused 'init_flag'

There are obviously errors like double hexdumps per log line, multiple newlines
in a LOGP statement and so forth: these shall be fixed by subsequent patches.

Change-Id: Id0da9d9b67f4713d3a67e3532ed44b8cb1bd1d08
---
M tests/bitcomp/BitcompTest.cpp
1 file changed, 45 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/67/2167/1

diff --git a/tests/bitcomp/BitcompTest.cpp b/tests/bitcomp/BitcompTest.cpp
index 31b6d11..31aebd4 100644
--- a/tests/bitcomp/BitcompTest.cpp
+++ b/tests/bitcomp/BitcompTest.cpp
@@ -17,6 +17,7 @@
 #define MASK(n) (0xFF << (8-n))
 #define MAX_CRBB_LEN 23
 #define MAX_URBB_LEN 40
+#define CEIL_DIV_8(x) (((x) + 7)/8)
 
 void *tall_pcu_ctx;
 
@@ -120,23 +121,22 @@
 	return 1;
 }
 
-/* To verify the result with expected result */
-int check_result(bitvec bits, uint8_t *exp_data, unsigned int exp_len)
+bool result_matches(const bitvec &bits, const uint8_t *exp_data, unsigned int exp_len)
 {
 	if (bits.cur_bit != exp_len)
-		return 0;
+		return false;
 	size_t n = (exp_len / 8);
 	int rem = (exp_len % 8);
 
 	if (memcmp(exp_data, bits.data, n) == 0) {
 		if (rem == 0)
-			return 1;
+			return true;
 		if ((bits.data[n] & MASK(rem)) == ((*(exp_data + n)) & MASK(rem)))
-			return 1;
+			return true;
 		else
-			return 0;
+			return false;
 	} else
-		return 0;
+		return false;
 }
 
 /*  To test decoding of compressed bitmap by Tree based method
@@ -146,7 +146,6 @@
 static void test_EPDAN_decode_tree(void)
 {
 	bitvec dest;
-	int init_flag = 1;
 	unsigned int itr;
 	int rc;
 	uint8_t bits_data[RLC_EGPRS_MAX_WS/8];
@@ -154,47 +153,56 @@
 	printf("=== start %s ===\n", __func__);
 
 	for (itr = 0 ; itr < (sizeof(test) / sizeof(test_data)) ; itr++) {
+		memset(bits_data, 0, sizeof(bits_data));
 		dest.data = bits_data;
 		dest.data_len = sizeof(bits_data);
 		dest.cur_bit = 0;
-		memset(dest.data, 0, sizeof(bits_data));
-		LOGP(DRLCMACDL, LOGL_DEBUG, "\nTest:%d\nTree based decoding:"
-			"\nuncompressed data = %s\nlen = %d\n", itr + 1,
-			osmo_hexdump(test[itr].crbb_data,
-			(test[itr].crbb_len + 7)/8), test[itr].crbb_len
-		);
+		LOGP(DRLCMACDL, LOGL_DEBUG,
+		     "\nTest:%d\n"
+		     "Tree based decoding:\n"
+		     "uncompressed data = %s\n"
+		     "len = %d\n",
+		     itr + 1,
+		     osmo_hexdump(test[itr].crbb_data,
+				  CEIL_DIV_8(test[itr].crbb_len)),
+		     test[itr].crbb_len);
 		rc = egprs_compress::decompress_crbb(test[itr].crbb_len,
 			test[itr].cc, test[itr].crbb_data, &dest);
 		if (rc < 0) {
 			LOGP(DRLCMACUL, LOGL_NOTICE,
-				"\nFailed to decode CRBB: length %d, data %s",
-				test[itr].crbb_len, osmo_hexdump(
-				test[itr].crbb_data, (test[itr].crbb_len + 7)/8));
+			     "\nFailed to decode CRBB: length %d, data %s",
+			     test[itr].crbb_len,
+			     osmo_hexdump(test[itr].crbb_data,
+					  CEIL_DIV_8(test[itr].crbb_len)));
 		}
-		if (init_flag)
-			init_flag = 0;
 		if (test[itr].verify) {
-			if (check_result(dest, test[itr].ucmp_data,
-				test[itr].ucmp_len) == 0) {
-				LOGP(DRLCMACDL, LOGL_DEBUG, "\nTree based decoding"
-					":Error\nexpected data = %s\nexpected"
-					" len = %d\ndecoded data = %s\n"
-					"decoded len = %d\n",
-					osmo_hexdump(test[itr].ucmp_data,
-						(test[itr].ucmp_len + 7)/8),
-					test[itr].ucmp_len, osmo_hexdump(dest.data,
-						(dest.cur_bit + 7)/8), dest.cur_bit
-				);
+			if (!result_matches(dest, test[itr].ucmp_data,
+					    test[itr].ucmp_len)) {
+				LOGP(DRLCMACDL, LOGL_DEBUG,
+				     "\nTree based decoding: Error\n"
+				     "expected data = %s\n"
+				     "expected len = %d\n"
+				     "decoded data = %s\n"
+				     "decoded len = %d\n",
+				     osmo_hexdump(test[itr].ucmp_data,
+						  CEIL_DIV_8(test[itr].ucmp_len)),
+				     test[itr].ucmp_len,
+				     osmo_hexdump(dest.data,
+						  CEIL_DIV_8(dest.cur_bit)),
+				     dest.cur_bit);
 				OSMO_ASSERT(0);
 			}
 		}
-		LOGP(DRLCMACDL, LOGL_DEBUG, "\nexpected data = %s\nexpected len = %d"
-			"\ndecoded data = %s\ndecoded len = %d\n",
-			osmo_hexdump(test[itr].ucmp_data,
-			(test[itr].ucmp_len + 7)/8),
-			test[itr].ucmp_len, osmo_hexdump(dest.data,
-			(dest.cur_bit + 7)/8), dest.cur_bit
-		);
+		LOGP(DRLCMACDL, LOGL_DEBUG,
+		     "\nexpected data = %s\n"
+		     "expected len = %d\n"
+		     "decoded data = %s\n"
+		     "decoded len = %d\n",
+		     osmo_hexdump(test[itr].ucmp_data,
+				  CEIL_DIV_8(test[itr].ucmp_len)),
+		     test[itr].ucmp_len,
+		     osmo_hexdump(dest.data, CEIL_DIV_8(dest.cur_bit)),
+		     dest.cur_bit);
 	}
 
 	printf("=== end %s ===\n", __func__);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id0da9d9b67f4713d3a67e3532ed44b8cb1bd1d08
Gerrit-PatchSet: 1
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list