diff options
author | Pravin Kumarvel <pmanohar@radisys.com> | 2016-12-02 15:13:03 +0530 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-01-06 10:37:42 +0000 |
commit | 848de8f1df561f4253f754ec3f2415e541071420 (patch) | |
tree | e0d2286ddcbb19791fedc1dd28cbc2609c7b85b4 /tests/bitvec | |
parent | 592fcc97c004b7e3e84ed6960ea9989157c94f75 (diff) |
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
Diffstat (limited to 'tests/bitvec')
-rw-r--r-- | tests/bitvec/bitvec_test.c | 42 | ||||
-rw-r--r-- | tests/bitvec/bitvec_test.ok | 2 |
2 files changed, 43 insertions, 1 deletions
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. |