Skip to content

Commit 6af132f

Browse files
RichardWeiYangtorvalds
authored andcommitted
lib: test get_count_order/long in test_bitops.c
Add some tests for get_count_order/long in test_bitops.c. [[email protected]: define local `i'] [[email protected]: enhancement, warning fix, cleanup per Geert] [[email protected]: fix loop bound, per Wei Yang] Signed-off-by: Wei Yang <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 496df3d commit 6af132f

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

lib/Kconfig.debug

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,15 +2052,15 @@ config TEST_LKM
20522052
If unsure, say N.
20532053

20542054
config TEST_BITOPS
2055-
tristate "Test module for compilation of clear_bit/set_bit operations"
2055+
tristate "Test module for compilation of bitops operations"
20562056
depends on m
20572057
help
20582058
This builds the "test_bitops" module that is much like the
20592059
TEST_LKM module except that it does a basic exercise of the
2060-
clear_bit and set_bit macros to make sure there are no compiler
2061-
warnings from C=1 sparse checker or -Wextra compilations. It has
2062-
no dependencies and doesn't run or load unless explicitly requested
2063-
by name. for example: modprobe test_bitops.
2060+
set/clear_bit macros and get_count_order/long to make sure there are
2061+
no compiler warnings from C=1 sparse checker or -Wextra
2062+
compilations. It has no dependencies and doesn't run or load unless
2063+
explicitly requested by name. for example: modprobe test_bitops.
20642064

20652065
If unsure, say N.
20662066

lib/test_bitops.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
#include <linux/module.h>
1010
#include <linux/printk.h>
1111

12-
/* a tiny module only meant to test set/clear_bit */
12+
/* a tiny module only meant to test
13+
*
14+
* set/clear_bit
15+
* get_count_order/long
16+
*/
1317

1418
/* use an enum because thats the most common BITMAP usage */
1519
enum bitops_fun {
@@ -24,14 +28,59 @@ enum bitops_fun {
2428

2529
static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH);
2630

31+
static unsigned int order_comb[][2] = {
32+
{0x00000003, 2},
33+
{0x00000004, 2},
34+
{0x00001fff, 13},
35+
{0x00002000, 13},
36+
{0x50000000, 31},
37+
{0x80000000, 31},
38+
{0x80003000, 32},
39+
};
40+
41+
#ifdef CONFIG_64BIT
42+
static unsigned long order_comb_long[][2] = {
43+
{0x0000000300000000, 34},
44+
{0x0000000400000000, 34},
45+
{0x00001fff00000000, 45},
46+
{0x0000200000000000, 45},
47+
{0x5000000000000000, 63},
48+
{0x8000000000000000, 63},
49+
{0x8000300000000000, 64},
50+
};
51+
#endif
52+
2753
static int __init test_bitops_startup(void)
2854
{
55+
int i;
56+
2957
pr_warn("Loaded test module\n");
3058
set_bit(BITOPS_4, g_bitmap);
3159
set_bit(BITOPS_7, g_bitmap);
3260
set_bit(BITOPS_11, g_bitmap);
3361
set_bit(BITOPS_31, g_bitmap);
3462
set_bit(BITOPS_88, g_bitmap);
63+
64+
for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
65+
if (order_comb[i][1] != get_count_order(order_comb[i][0]))
66+
pr_warn("get_count_order wrong for %x\n",
67+
order_comb[i][0]);
68+
}
69+
70+
for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
71+
if (order_comb[i][1] != get_count_order_long(order_comb[i][0]))
72+
pr_warn("get_count_order_long wrong for %x\n",
73+
order_comb[i][0]);
74+
}
75+
76+
#ifdef CONFIG_64BIT
77+
for (i = 0; i < ARRAY_SIZE(order_comb_long); i++) {
78+
if (order_comb_long[i][1] !=
79+
get_count_order_long(order_comb_long[i][0]))
80+
pr_warn("get_count_order_long wrong for %lx\n",
81+
order_comb_long[i][0]);
82+
}
83+
#endif
3584
return 0;
3685
}
3786

@@ -55,6 +104,6 @@ static void __exit test_bitops_unstartup(void)
55104
module_init(test_bitops_startup);
56105
module_exit(test_bitops_unstartup);
57106

58-
MODULE_AUTHOR("Jesse Brandeburg <[email protected]>");
107+
MODULE_AUTHOR("Jesse Brandeburg <[email protected]>, Wei Yang <[email protected]>");
59108
MODULE_LICENSE("GPL");
60109
MODULE_DESCRIPTION("Bit testing module");

0 commit comments

Comments
 (0)