diff options
author | Ben Pfaff <blp@nicira.com> | 2012-04-11 12:07:51 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2012-04-13 20:43:37 -0700 |
commit | c2dd49322f538714572c66d72a1c142547c49b1d (patch) | |
tree | 8ec8115e13507f964bb57af91ed93b8ee26e33b5 /tests | |
parent | c7e7bb21ff20f6fb2ca6509d9cffeca895fcbc78 (diff) |
util: New function bitwise_one().
It's the obvious counterpart to bitwise_zero().
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/library.at | 3 | ||||
-rw-r--r-- | tests/test-util.c | 43 |
2 files changed, 45 insertions, 1 deletions
diff --git a/tests/library.at b/tests/library.at index ca5f29ca..dce69dea 100644 --- a/tests/library.at +++ b/tests/library.at @@ -100,7 +100,8 @@ nibble 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ]) AT_CLEANUP -AT_SETUP([test log_2_floor]) +AT_SETUP([test utility functions]) +AT_KEYWORDS([util]) AT_CHECK([test-util]) AT_CLEANUP diff --git a/tests/test-util.c b/tests/test-util.c index 82d08610..ed98295b 100644 --- a/tests/test-util.c +++ b/tests/test-util.c @@ -143,6 +143,47 @@ check_bitwise_zero(void) } } +static void +check_bitwise_one(void) +{ + unsigned int n_loops; + int dst_ofs; + int n_bits; + + n_loops = 0; + for (n_bits = 0; n_bits <= 64; n_bits++) { + for (dst_ofs = 0; dst_ofs < 64 - n_bits; dst_ofs++) { + ovs_be64 dst = htonll(random_uint64()); + ovs_be64 orig_dst = dst; + ovs_be64 expect; + + if (n_bits == 64) { + expect = htonll(UINT64_MAX); + } else { + uint64_t mask = (UINT64_C(1) << n_bits) - 1; + expect = orig_dst | htonll(mask << dst_ofs); + } + + bitwise_one(&dst, sizeof dst, dst_ofs, n_bits); + if (expect != dst) { + fprintf(stderr,"bitwise_one(0x%016"PRIx64",8,%d, %d) " + "yielded 0x%016"PRIx64" " + "instead of the expected 0x%016"PRIx64"\n", + ntohll(orig_dst), dst_ofs, + n_bits, + ntohll(dst), ntohll(expect)); + abort(); + } + + n_loops++; + } + } + + if (n_loops != 64 * (64 + 1) / 2) { + abort(); + } +} + int main(void) { @@ -170,5 +211,7 @@ main(void) check_bitwise_zero(); + check_bitwise_one(); + return 0; } |