Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bitmap: exclude nbits == 0 cases from bitmap test

Bitmap API handles nbits == 0 in most cases correctly, i.e. it doesn't
dereferene underlying bitmap and returns a sane value where convenient,
or implementation defined, or undef.

Implicitly testing nbits == 0 case, however, may make an impression that
this is a regular case. This is wrong. In most cases nbits == 0 is a
sign of an error on a client side. The tests should not make such an
implression.

This patch reworks the existing tests to not test nbits == 0. The
following patch adds an explicit test for it with an appropriate
precaution.

Signed-off-by: Yury Norov <ynorov@nvidia.com>

+4 -4
+4 -4
lib/test_bitmap.c
··· 653 653 654 654 memset(arr, 0xa5, sizeof(arr)); 655 655 656 - for (nbits = 0; nbits < EXP1_IN_BITS; ++nbits) { 656 + for (nbits = 1; nbits < EXP1_IN_BITS; ++nbits) { 657 657 bitmap_to_arr32(arr, exp1, nbits); 658 658 bitmap_from_arr32(bmap2, arr, nbits); 659 659 expect_eq_bitmap(bmap2, exp1, nbits); ··· 681 681 682 682 memset(arr, 0xa5, sizeof(arr)); 683 683 684 - for (nbits = 0; nbits < EXP1_IN_BITS; ++nbits) { 684 + for (nbits = 1; nbits < EXP1_IN_BITS; ++nbits) { 685 685 memset(bmap2, 0xff, sizeof(arr)); 686 686 bitmap_to_arr64(arr, exp1, nbits); 687 687 bitmap_from_arr64(bmap2, arr, nbits); ··· 714 714 unsigned int start, nbits; 715 715 716 716 for (start = 0; start < 1024; start += 8) { 717 - for (nbits = 0; nbits < 1024 - start; nbits += 8) { 717 + for (nbits = 1; nbits < 1024 - start; nbits += 8) { 718 718 memset(bmap1, 0x5a, sizeof(bmap1)); 719 719 memset(bmap2, 0x5a, sizeof(bmap2)); 720 720 ··· 873 873 874 874 /* Test outline implementation */ 875 875 w = bitmap_weight(exp1, EXP1_IN_BITS); 876 - for (bit = 0; bit < EXP1_IN_BITS; bit++) { 876 + for (bit = 1; bit < EXP1_IN_BITS; bit++) { 877 877 w1 = bitmap_weight(exp1, bit); 878 878 w2 = bitmap_weight_from(exp1, bit, EXP1_IN_BITS); 879 879 expect_eq_uint(w1 + w2, w);