9
9
#include <linux/module.h>
10
10
#include <linux/printk.h>
11
11
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
+ */
13
17
14
18
/* use an enum because thats the most common BITMAP usage */
15
19
enum bitops_fun {
@@ -24,14 +28,59 @@ enum bitops_fun {
24
28
25
29
static DECLARE_BITMAP (g_bitmap , BITOPS_LENGTH ) ;
26
30
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
+
27
53
static int __init test_bitops_startup (void )
28
54
{
55
+ int i ;
56
+
29
57
pr_warn ("Loaded test module\n" );
30
58
set_bit (BITOPS_4 , g_bitmap );
31
59
set_bit (BITOPS_7 , g_bitmap );
32
60
set_bit (BITOPS_11 , g_bitmap );
33
61
set_bit (BITOPS_31 , g_bitmap );
34
62
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
35
84
return 0 ;
36
85
}
37
86
@@ -55,6 +104,6 @@ static void __exit test_bitops_unstartup(void)
55
104
module_init (test_bitops_startup );
56
105
module_exit (test_bitops_unstartup );
57
106
58
- MODULE_AUTHOR (
"Jesse Brandeburg <[email protected] >" );
107
+ MODULE_AUTHOR (
"Jesse Brandeburg <[email protected] >, Wei Yang <[email protected] > " );
59
108
MODULE_LICENSE ("GPL" );
60
109
MODULE_DESCRIPTION ("Bit testing module" );
0 commit comments