summaryrefslogtreecommitdiffstats
path: root/tests/bits/bitrev_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/bits/bitrev_test.c')
-rw-r--r--tests/bits/bitrev_test.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/bits/bitrev_test.c b/tests/bits/bitrev_test.c
index 987f4d51..08f08278 100644
--- a/tests/bits/bitrev_test.c
+++ b/tests/bits/bitrev_test.c
@@ -205,6 +205,20 @@ check16(uint16_t test, enum END e)
printcheck16(e, test, test, (BE == e) ? s : NULL, print);
}
+static void sh_chk(const uint8_t *in, uint8_t len, unsigned int nib, bool r)
+{
+ uint8_t x[len];
+ if (r)
+ osmo_nibble_shift_right(x, in, nib);
+ else
+ osmo_nibble_shift_left_unal(x, in, nib);
+
+ printf("[%u] %s IN: %s, nibble %u:", len, r ? "R" : "L",
+ 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));
+}
int main(int argc, char **argv)
{
@@ -274,5 +288,16 @@ int main(int argc, char **argv)
check16(0, BE);
check16(0, LE);
+ printf("running nibble tests...\n");
+
+ const uint8_t in1[] = { 0xF0, 0x0D, 0xCA, 0xFE, 0xDE, 0xAD, 0xBE, 0xEF },
+ in2[] = { 0xB0, 0x0B, 0xBA, 0xBE, 0xFA, 0xCE };
+
+ for (offs = 0; offs < 13; offs++) {
+ sh_chk(in1, ARRAY_SIZE(in1), offs, true);
+ sh_chk(in1, ARRAY_SIZE(in1), offs, false);
+ sh_chk(in2, ARRAY_SIZE(in2), offs, true);
+ sh_chk(in2, ARRAY_SIZE(in2), offs, false);
+ }
return 0;
}