From 848de8f1df561f4253f754ec3f2415e541071420 Mon Sep 17 00:00:00 2001 From: Pravin Kumarvel Date: Fri, 2 Dec 2016 15:13:03 +0530 Subject: Add function to get uninterrupted bit run Function bitvec_rl_curbit added to get number of uninterrupted bits run in vector starting from the current bit till max number of bits. Test case is added to check bitvec_rl_curbit. Change-Id: Iae153d3639ea6b891c1fc10d7801a435c9492e26 --- tests/bitvec/bitvec_test.c | 42 +++++++++++++++++++++++++++++++++++++++++- tests/bitvec/bitvec_test.ok | 2 ++ 2 files changed, 43 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/bitvec/bitvec_test.c b/tests/bitvec/bitvec_test.c index a98a91c6..d0bc30c4 100644 --- a/tests/bitvec/bitvec_test.c +++ b/tests/bitvec/bitvec_test.c @@ -150,6 +150,18 @@ static inline void test_array_item(unsigned t, struct bitvec *b, unsigned int n, } } +static inline void test_bitvec_rl_curbit(struct bitvec *bv, bool b, int max_bits, + int result ) +{ + int num = 0; + int readIndex = bv->cur_bit; + OSMO_ASSERT(bv->cur_bit < max_bits); + num = bitvec_rl_curbit(bv, b, max_bits); + readIndex += num; + OSMO_ASSERT(bv->cur_bit == readIndex); + OSMO_ASSERT(num == result); +} + static void test_array() { struct bitvec b; @@ -245,7 +257,35 @@ int main(int argc, char **argv) test_array(); - printf("\nbitvec ok.\n"); + printf("\nbitvec_runlength....\n"); + bitvec_zero(&bv); + bitvec_set_uint(&bv, 0xff, 8); + bv.cur_bit -= 8; + test_bitvec_rl_curbit(&bv, 1, 64, 8); + + bitvec_zero(&bv); + bitvec_set_uint(&bv, 0xfc, 8); + bv.cur_bit -= 8; + test_bitvec_rl_curbit(&bv, 1, 64, 6); + + bitvec_zero(&bv); + test_bitvec_rl_curbit(&bv, 0, 52, 52); + + bitvec_zero(&bv); + bitvec_set_uint(&bv, 0xfc, 8); + bv.cur_bit -= 2; + test_bitvec_rl_curbit(&bv, 0, 64, 58); + + bitvec_zero(&bv); + bitvec_set_uint(&bv, 0x07, 8); + bitvec_set_uint(&bv, 0xf8, 8); + bv.cur_bit -= 11; + test_bitvec_rl_curbit(&bv, 1, 64, 8); + + bitvec_zero(&bv); + test_bitvec_rl_curbit(&bv, 1, 64, 0); + + printf("\nbitvec ok.\n"); return 0; } diff --git a/tests/bitvec/bitvec_test.ok b/tests/bitvec/bitvec_test.ok index e2561089..62819736 100644 --- a/tests/bitvec/bitvec_test.ok +++ b/tests/bitvec/bitvec_test.ok @@ -166,4 +166,6 @@ bits: 17, est: 1153, real: 1153, x: 0, y: 0 ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ ........ +bitvec_runlength.... + bitvec ok. -- cgit v1.2.3