Commit 6af132f3 authored by Wei Yang's avatar Wei Yang Committed by Linus Torvalds

lib: test get_count_order/long in test_bitops.c

Add some tests for get_count_order/long in test_bitops.c.

[akpm@linux-foundation.org: define local `i']
[akpm@linux-foundation.org: enhancement, warning fix, cleanup per Geert]
[akpm@linux-foundation.org: fix loop bound, per Wei Yang]
Signed-off-by: default avatarWei Yang <richard.weiyang@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Link: http://lkml.kernel.org/r/20200602223728.32722-1-richard.weiyang@gmail.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 496df3d3
...@@ -2052,15 +2052,15 @@ config TEST_LKM ...@@ -2052,15 +2052,15 @@ config TEST_LKM
If unsure, say N. If unsure, say N.
config TEST_BITOPS config TEST_BITOPS
tristate "Test module for compilation of clear_bit/set_bit operations" tristate "Test module for compilation of bitops operations"
depends on m depends on m
help help
This builds the "test_bitops" module that is much like the This builds the "test_bitops" module that is much like the
TEST_LKM module except that it does a basic exercise of the TEST_LKM module except that it does a basic exercise of the
clear_bit and set_bit macros to make sure there are no compiler set/clear_bit macros and get_count_order/long to make sure there are
warnings from C=1 sparse checker or -Wextra compilations. It has no compiler warnings from C=1 sparse checker or -Wextra
no dependencies and doesn't run or load unless explicitly requested compilations. It has no dependencies and doesn't run or load unless
by name. for example: modprobe test_bitops. explicitly requested by name. for example: modprobe test_bitops.
If unsure, say N. If unsure, say N.
......
...@@ -9,7 +9,11 @@ ...@@ -9,7 +9,11 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/printk.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 */ /* use an enum because thats the most common BITMAP usage */
enum bitops_fun { enum bitops_fun {
...@@ -24,14 +28,59 @@ enum bitops_fun { ...@@ -24,14 +28,59 @@ enum bitops_fun {
static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH); 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) static int __init test_bitops_startup(void)
{ {
int i;
pr_warn("Loaded test module\n"); pr_warn("Loaded test module\n");
set_bit(BITOPS_4, g_bitmap); set_bit(BITOPS_4, g_bitmap);
set_bit(BITOPS_7, g_bitmap); set_bit(BITOPS_7, g_bitmap);
set_bit(BITOPS_11, g_bitmap); set_bit(BITOPS_11, g_bitmap);
set_bit(BITOPS_31, g_bitmap); set_bit(BITOPS_31, g_bitmap);
set_bit(BITOPS_88, 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; return 0;
} }
...@@ -55,6 +104,6 @@ static void __exit test_bitops_unstartup(void) ...@@ -55,6 +104,6 @@ static void __exit test_bitops_unstartup(void)
module_init(test_bitops_startup); module_init(test_bitops_startup);
module_exit(test_bitops_unstartup); module_exit(test_bitops_unstartup);
MODULE_AUTHOR("Jesse Brandeburg <jesse.brandeburg@intel.com>"); MODULE_AUTHOR("Jesse Brandeburg <jesse.brandeburg@intel.com>, Wei Yang <richard.weiyang@gmail.com>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Bit testing module"); MODULE_DESCRIPTION("Bit testing module");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment