2020-05-30 00:46:25

by Wei Yang

[permalink] [raw]
Subject: [PATCH] lib: make a test module with get_count_order/long

A test module to make sure get_count_order/long returns the correct result.

Signed-off-by: Wei Yang <[email protected]>
---
lib/Kconfig.debug | 13 ++++++
lib/Makefile | 2 +
lib/test_getorder.c | 64 ++++++++++++++++++++++++++++++
tools/testing/selftests/lib/config | 1 +
4 files changed, 80 insertions(+)
create mode 100644 lib/test_getorder.c

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index c0ef216bb803..01e671151f42 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1999,6 +1999,19 @@ config TEST_BITOPS

If unsure, say N.

+config TEST_GETORDER
+ tristate "Test module for compilation of get_count_order operations"
+ depends on m
+ help
+ This builds the "test_getorder" module that is much like the
+ TEST_LKM module except that it does a basic exercise of the
+ get_count_order and get_count_order_long to make sure there are no
+ compiler warnings from C=1 sparse checker or -Wextra compilations.
+ It has no dependencies and doesn't run or load unless explicitly
+ requested by name. For example: modprobe test_getorder.
+
+ If unsure, say N.
+
config TEST_VMALLOC
tristate "Test module for stress/performance analysis of vmalloc allocator"
default n
diff --git a/lib/Makefile b/lib/Makefile
index 0d942f7c7478..806d4df8f7c7 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -81,6 +81,8 @@ obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
obj-$(CONFIG_TEST_BITOPS) += test_bitops.o
CFLAGS_test_bitops.o += -Werror
+obj-$(CONFIG_TEST_GETORDER) += test_getorder.o
+CFLAGS_test_getorder.o += -Werror
obj-$(CONFIG_TEST_PRINTF) += test_printf.o
obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
obj-$(CONFIG_TEST_STRSCPY) += test_strscpy.o
diff --git a/lib/test_getorder.c b/lib/test_getorder.c
new file mode 100644
index 000000000000..6492abc793af
--- /dev/null
+++ b/lib/test_getorder.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Author: Wei Yang <[email protected]>
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/printk.h>
+
+/* a tiny module only meant to test get_count_order/long */
+unsigned int order_comb[][2] = {
+ {0x00000003, 2},
+ {0x00000004, 2},
+ {0x00001fff, 13},
+ {0x00002000, 13},
+ {0x50000000, 31},
+ {0x80000000, 31},
+ {0x80003000, 32},
+};
+
+unsigned long order_comb_long[][2] = {
+ {0x0000000300000000, 34},
+ {0x0000000400000000, 34},
+ {0x00001fff00000000, 45},
+ {0x0000200000000000, 45},
+ {0x5000000000000000, 63},
+ {0x8000000000000000, 63},
+ {0x8000300000000000, 64},
+};
+
+static int __init test_getorder_startup(void)
+{
+ int i;
+
+ pr_warn("Loaded test module\n");
+ 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_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]);
+ }
+
+ return 0;
+}
+
+static void __exit test_getorder_unstartup(void)
+{
+ pr_warn("Unloaded test module\n");
+}
+
+module_init(test_getorder_startup);
+module_exit(test_getorder_unstartup);
+
+MODULE_AUTHOR("Wei Yang <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("get_count_order/long testing module");
diff --git a/tools/testing/selftests/lib/config b/tools/testing/selftests/lib/config
index b80ee3f6e265..2ad467d34648 100644
--- a/tools/testing/selftests/lib/config
+++ b/tools/testing/selftests/lib/config
@@ -3,3 +3,4 @@ CONFIG_TEST_BITMAP=m
CONFIG_PRIME_NUMBERS=m
CONFIG_TEST_STRSCPY=m
CONFIG_TEST_BITOPS=m
+CONFIG_TEST_GETORDER=m
--
2.23.0


2020-05-30 10:28:45

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] lib: make a test module with get_count_order/long

On Sat, May 30, 2020 at 12:43:28AM +0000, Wei Yang wrote:
> A test module to make sure get_count_order/long returns the correct result.

> lib/Kconfig.debug | 13 ++++++
> lib/Makefile | 2 +
> lib/test_getorder.c | 64 ++++++++++++++++++++++++++++++

I didn't get why it's not a part of test_bitops?

--
With Best Regards,
Andy Shevchenko


2020-05-30 21:22:10

by Wei Yang

[permalink] [raw]
Subject: Re: [PATCH] lib: make a test module with get_count_order/long

On Sat, May 30, 2020 at 01:25:31PM +0300, Andy Shevchenko wrote:
>On Sat, May 30, 2020 at 12:43:28AM +0000, Wei Yang wrote:
>> A test module to make sure get_count_order/long returns the correct result.
>
>> lib/Kconfig.debug | 13 ++++++
>> lib/Makefile | 2 +
>> lib/test_getorder.c | 64 ++++++++++++++++++++++++++++++
>
>I didn't get why it's not a part of test_bitops?
>

I see the document of test_bitops says it does exercise on clear_bit and
set_bit. So not sure it is proper to put them together.

>--
>With Best Regards,
>Andy Shevchenko
>

--
Wei Yang
Help you, Help me

2020-05-30 21:58:58

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] lib: make a test module with get_count_order/long

On Sun, May 31, 2020 at 12:23 AM Wei Yang <[email protected]> wrote:
> On Sat, May 30, 2020 at 01:25:31PM +0300, Andy Shevchenko wrote:
> >On Sat, May 30, 2020 at 12:43:28AM +0000, Wei Yang wrote:
> >> A test module to make sure get_count_order/long returns the correct result.
> >
> >> lib/Kconfig.debug | 13 ++++++
> >> lib/Makefile | 2 +
> >> lib/test_getorder.c | 64 ++++++++++++++++++++++++++++++
> >
> >I didn't get why it's not a part of test_bitops?
> >
>
> I see the document of test_bitops says it does exercise on clear_bit and
> set_bit. So not sure it is proper to put them together.

It's not a problem to amend a documentation as well :-)

--
With Best Regards,
Andy Shevchenko

2020-05-31 12:50:55

by Wei Yang

[permalink] [raw]
Subject: Re: [PATCH] lib: make a test module with get_count_order/long

On Sun, May 31, 2020 at 12:56:29AM +0300, Andy Shevchenko wrote:
>On Sun, May 31, 2020 at 12:23 AM Wei Yang <[email protected]> wrote:
>> On Sat, May 30, 2020 at 01:25:31PM +0300, Andy Shevchenko wrote:
>> >On Sat, May 30, 2020 at 12:43:28AM +0000, Wei Yang wrote:
>> >> A test module to make sure get_count_order/long returns the correct result.
>> >
>> >> lib/Kconfig.debug | 13 ++++++
>> >> lib/Makefile | 2 +
>> >> lib/test_getorder.c | 64 ++++++++++++++++++++++++++++++
>> >
>> >I didn't get why it's not a part of test_bitops?
>> >
>>
>> I see the document of test_bitops says it does exercise on clear_bit and
>> set_bit. So not sure it is proper to put them together.
>
>It's not a problem to amend a documentation as well :-)
>

Sure. I am fine with this.

Andrew, do you expect me to merge it into test_bitops.c?

>--
>With Best Regards,
>Andy Shevchenko

--
Wei Yang
Help you, Help me

2020-06-02 01:05:08

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] lib: make a test module with get_count_order/long

On Sun, 31 May 2020 12:47:09 +0000 Wei Yang <[email protected]> wrote:

> On Sun, May 31, 2020 at 12:56:29AM +0300, Andy Shevchenko wrote:
> >On Sun, May 31, 2020 at 12:23 AM Wei Yang <[email protected]> wrote:
> >> On Sat, May 30, 2020 at 01:25:31PM +0300, Andy Shevchenko wrote:
> >> >On Sat, May 30, 2020 at 12:43:28AM +0000, Wei Yang wrote:
> >> >> A test module to make sure get_count_order/long returns the correct result.
> >> >
> >> >> lib/Kconfig.debug | 13 ++++++
> >> >> lib/Makefile | 2 +
> >> >> lib/test_getorder.c | 64 ++++++++++++++++++++++++++++++
> >> >
> >> >I didn't get why it's not a part of test_bitops?
> >> >
> >>
> >> I see the document of test_bitops says it does exercise on clear_bit and
> >> set_bit. So not sure it is proper to put them together.
> >
> >It's not a problem to amend a documentation as well :-)
> >
>
> Sure. I am fine with this.
>
> Andrew, do you expect me to merge it into test_bitops.c?
>

Yes please.