diff options
author | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2016-09-21 18:30:01 +0200 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2016-09-26 00:35:30 +0000 |
commit | 8319a6799ffc9d4c5e7e094b96af30cbebf89f65 (patch) | |
tree | b77723a0bfd00f6b10900d0e26211c20a313348f /tests/bits/bitrev_test.c | |
parent | 4fd6023b0383e7efa3b7b0211104a86ff5d3d4f6 (diff) |
bitrev_test: don't omit last byte from test result check
The osmo_hexdump of the output in sh_chk() omitted the last byte of the
returned bytes from the osmo_nibble_shift_*() functions.
Determine the number of bytes from nibbles divided by two plus one for any odd
nibble number. Output this number of bytes of output data.
Memset the output buffer to get well-defined bytes for unwritten places.
Also assert that we have enough buffer length for all nibbles.
Change-Id: I011f42bca555caec0dfe8688ff1f28303fa04fad
Diffstat (limited to 'tests/bits/bitrev_test.c')
-rw-r--r-- | tests/bits/bitrev_test.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/tests/bits/bitrev_test.c b/tests/bits/bitrev_test.c index b96241c5..ed3939a3 100644 --- a/tests/bits/bitrev_test.c +++ b/tests/bits/bitrev_test.c @@ -208,6 +208,9 @@ check16(uint16_t test, enum END e) static void sh_chk(const uint8_t *in, uint8_t len, unsigned int nib, bool r) { uint8_t x[len]; + int bytes = nib/2 + (nib & 1); + OSMO_ASSERT(len >= bytes); + memset(x, 0xcc, len); if (r) osmo_nibble_shift_right(x, in, nib); else @@ -217,7 +220,7 @@ static void sh_chk(const uint8_t *in, uint8_t len, unsigned int nib, bool r) osmo_hexdump_nospc(in, len), nib); /* do NOT combine those printfs: osmo_hexdump* use static buffer which WILL screw things up in that case */ - printf("\n OUT: %s\n", osmo_hexdump_nospc(x, nib/2)); + printf("\n OUT: %s\n", osmo_hexdump_nospc(x, bytes)); } int main(int argc, char **argv) |