forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
496df3d
commit 6af132f
Showing
2 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,11 @@ | |
#include <linux/module.h> | ||
#include <linux/printk.h> | ||
|
||
/* a tiny module only meant to test set/clear_bit */ | ||
/* a tiny module only meant to test | ||
* | ||
* set/clear_bit | ||
* get_count_order/long | ||
*/ | ||
|
||
/* use an enum because thats the most common BITMAP usage */ | ||
enum bitops_fun { | ||
|
@@ -24,14 +28,59 @@ enum bitops_fun { | |
|
||
static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH); | ||
|
||
static unsigned int order_comb[][2] = { | ||
{0x00000003, 2}, | ||
{0x00000004, 2}, | ||
{0x00001fff, 13}, | ||
{0x00002000, 13}, | ||
{0x50000000, 31}, | ||
{0x80000000, 31}, | ||
{0x80003000, 32}, | ||
}; | ||
|
||
#ifdef CONFIG_64BIT | ||
static unsigned long order_comb_long[][2] = { | ||
{0x0000000300000000, 34}, | ||
{0x0000000400000000, 34}, | ||
{0x00001fff00000000, 45}, | ||
{0x0000200000000000, 45}, | ||
{0x5000000000000000, 63}, | ||
{0x8000000000000000, 63}, | ||
{0x8000300000000000, 64}, | ||
}; | ||
#endif | ||
|
||
static int __init test_bitops_startup(void) | ||
{ | ||
int i; | ||
|
||
pr_warn("Loaded test module\n"); | ||
set_bit(BITOPS_4, g_bitmap); | ||
set_bit(BITOPS_7, g_bitmap); | ||
set_bit(BITOPS_11, g_bitmap); | ||
set_bit(BITOPS_31, g_bitmap); | ||
set_bit(BITOPS_88, g_bitmap); | ||
|
||
for (i = 0; i < ARRAY_SIZE(order_comb); i++) { | ||
if (order_comb[i][1] != get_count_order(order_comb[i][0])) | ||
pr_warn("get_count_order wrong for %x\n", | ||
order_comb[i][0]); | ||
} | ||
|
||
for (i = 0; i < ARRAY_SIZE(order_comb); i++) { | ||
if (order_comb[i][1] != get_count_order_long(order_comb[i][0])) | ||
pr_warn("get_count_order_long wrong for %x\n", | ||
order_comb[i][0]); | ||
} | ||
|
||
#ifdef CONFIG_64BIT | ||
for (i = 0; i < ARRAY_SIZE(order_comb_long); i++) { | ||
if (order_comb_long[i][1] != | ||
get_count_order_long(order_comb_long[i][0])) | ||
pr_warn("get_count_order_long wrong for %lx\n", | ||
order_comb_long[i][0]); | ||
} | ||
#endif | ||
return 0; | ||
} | ||
|
||
|
@@ -55,6 +104,6 @@ static void __exit test_bitops_unstartup(void) | |
module_init(test_bitops_startup); | ||
module_exit(test_bitops_unstartup); | ||
|
||
MODULE_AUTHOR("Jesse Brandeburg <[email protected]>"); | ||
MODULE_AUTHOR("Jesse Brandeburg <[email protected]>, Wei Yang <[email protected]>"); | ||
MODULE_LICENSE("GPL"); | ||
MODULE_DESCRIPTION("Bit testing module"); |