linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib: kunit: Convert test_sort to KUnit test
@ 2020-07-23  0:08 Vitor Massaru Iha
  2020-07-23  8:04 ` Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Vitor Massaru Iha @ 2020-07-23  0:08 UTC (permalink / raw)
  To: kunit-dev
  Cc: linux-kselftest, linux-kernel, brendanhiggins, skhan,
	linux-kernel-mentees, gregkh, tglx, fkostenzer,
	andriy.shevchenko, geert, paul.gortmaker, akpm, torvalds

This adds the conversion of the test_sort.c to KUnit test.

Please apply this commit first (linux-kselftest/kunit-fixes):
3f37d14b8a3152441f36b6bc74000996679f0998 kunit: kunit_config: Fix parsing of CONFIG options with space

Signed-off-by: Vitor Massaru Iha <vitor@massaru.org>
---
 lib/Kconfig.debug                 | 26 +++++++++++++++++---------
 lib/Makefile                      |  2 +-
 lib/{test_sort.c => sort_kunit.c} | 31 +++++++++++++++----------------
 3 files changed, 33 insertions(+), 26 deletions(-)
 rename lib/{test_sort.c => sort_kunit.c} (55%)

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 9ad9210d70a1..1fe19e78d7ca 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1874,15 +1874,6 @@ config TEST_MIN_HEAP

 	  If unsure, say N.

-config TEST_SORT
-	tristate "Array-based sort test"
-	depends on DEBUG_KERNEL || m
-	help
-	  This option enables the self-test function of 'sort()' at boot,
-	  or at module load time.
-
-	  If unsure, say N.
-
 config KPROBES_SANITY_TEST
 	bool "Kprobes sanity tests"
 	depends on DEBUG_KERNEL
@@ -2185,6 +2176,23 @@ config LINEAR_RANGES_TEST

 	  If unsure, say N.

+config SORT_KUNIT
+	tristate "KUnit test for Array-based sort"
+	depends on DEBUG_KERNEL || m
+	help
+	  This option enables the KUnit function of 'sort()' at boot,
+	  or at module load time.
+
+	  KUnit tests run during boot and output the results to the debug log
+	  in TAP format (http://testanything.org/). Only useful for kernel devs
+	  running the KUnit test harness, and not intended for inclusion into a
+	  production build.
+
+	  For more information on KUnit and unit tests in general please refer
+	  to the KUnit documentation in Documentation/dev-tools/kunit/.
+
+	  If unsure, say N.
+
 config TEST_UDELAY
 	tristate "udelay test driver"
 	help
diff --git a/lib/Makefile b/lib/Makefile
index b1c42c10073b..c22bb13b0a08 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -77,7 +77,6 @@ obj-$(CONFIG_TEST_LKM) += test_module.o
 obj-$(CONFIG_TEST_VMALLOC) += test_vmalloc.o
 obj-$(CONFIG_TEST_OVERFLOW) += test_overflow.o
 obj-$(CONFIG_TEST_RHASHTABLE) += test_rhashtable.o
-obj-$(CONFIG_TEST_SORT) += test_sort.o
 obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
@@ -318,3 +317,4 @@ obj-$(CONFIG_OBJAGG) += objagg.o
 # KUnit tests
 obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
 obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
+obj-$(CONFIG_SORT_KUNIT) += sort_kunit.o
diff --git a/lib/test_sort.c b/lib/sort_kunit.c
similarity index 55%
rename from lib/test_sort.c
rename to lib/sort_kunit.c
index 52edbe10f2e5..03ba1cf1285c 100644
--- a/lib/test_sort.c
+++ b/lib/sort_kunit.c
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 #include <linux/sort.h>
-#include <linux/slab.h>
-#include <linux/module.h>
+#include <kunit/test.h>

 /* a simple boot-time regression test */

@@ -12,13 +11,12 @@ static int __init cmpint(const void *a, const void *b)
 	return *(int *)a - *(int *)b;
 }

-static int __init test_sort_init(void)
+static void __init sort_test(struct kunit *test)
 {
-	int *a, i, r = 1, err = -ENOMEM;
+	int *a, i, r = 1;

 	a = kmalloc_array(TEST_LEN, sizeof(*a), GFP_KERNEL);
-	if (!a)
-		return err;
+	KUNIT_ASSERT_FALSE_MSG(test, a == NULL, "kmalloc_array failed");

 	for (i = 0; i < TEST_LEN; i++) {
 		r = (r * 725861) % 6599;
@@ -27,24 +25,25 @@ static int __init test_sort_init(void)

 	sort(a, TEST_LEN, sizeof(*a), cmpint, NULL);

-	err = -EINVAL;
 	for (i = 0; i < TEST_LEN-1; i++)
 		if (a[i] > a[i+1]) {
-			pr_err("test has failed\n");
+			KUNIT_FAIL(test, "test has failed");
 			goto exit;
 		}
-	err = 0;
-	pr_info("test passed\n");
 exit:
 	kfree(a);
-	return err;
 }

-static void __exit test_sort_exit(void)
-{
-}
+static struct kunit_case sort_test_cases[] = {
+	KUNIT_CASE(sort_test),
+	{}
+};
+
+static struct kunit_suite sort_test_suite = {
+	.name = "sort",
+	.test_cases = sort_test_cases,
+};

-module_init(test_sort_init);
-module_exit(test_sort_exit);
+kunit_test_suites(&sort_test_suite);

 MODULE_LICENSE("GPL");

base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847
--
2.26.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] lib: kunit: Convert test_sort to KUnit test
  2020-07-23  0:08 [PATCH] lib: kunit: Convert test_sort to KUnit test Vitor Massaru Iha
@ 2020-07-23  8:04 ` Andy Shevchenko
  2020-07-23 12:32   ` Vitor Massaru Iha
  2020-07-24 16:05 ` kernel test robot
  2020-07-24 23:43 ` kernel test robot
  2 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2020-07-23  8:04 UTC (permalink / raw)
  To: Vitor Massaru Iha
  Cc: kunit-dev, linux-kselftest, linux-kernel, brendanhiggins, skhan,
	linux-kernel-mentees, gregkh, tglx, fkostenzer, geert,
	paul.gortmaker, akpm, torvalds

On Wed, Jul 22, 2020 at 09:08:07PM -0300, Vitor Massaru Iha wrote:
> This adds the conversion of the test_sort.c to KUnit test.
> 
> Please apply this commit first (linux-kselftest/kunit-fixes):
> 3f37d14b8a3152441f36b6bc74000996679f0998 kunit: kunit_config: Fix parsing of CONFIG options with space

...

>  lib/{test_sort.c => sort_kunit.c} | 31 +++++++++++++++----------------

Is it established practice to put kunit as a suffix?
For me much better to do
	ls .../test* # and note shell completions
then drop shell completions and always do something like
	ls .../*_kunit.[cSsh]

Consider this, please.

P.S. Same question to KUnit folks.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] lib: kunit: Convert test_sort to KUnit test
  2020-07-23  8:04 ` Andy Shevchenko
@ 2020-07-23 12:32   ` Vitor Massaru Iha
  0 siblings, 0 replies; 5+ messages in thread
From: Vitor Massaru Iha @ 2020-07-23 12:32 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: KUnit Development, open list:KERNEL SELFTEST FRAMEWORK,
	Linux Kernel Mailing List, Brendan Higgins, Shuah Khan,
	linux-kernel-mentees, Greg Kroah-Hartman, tglx, fkostenzer,
	geert, paul.gortmaker, akpm, torvalds

On Thu, Jul 23, 2020 at 5:04 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Wed, Jul 22, 2020 at 09:08:07PM -0300, Vitor Massaru Iha wrote:
> > This adds the conversion of the test_sort.c to KUnit test.
> >
> > Please apply this commit first (linux-kselftest/kunit-fixes):
> > 3f37d14b8a3152441f36b6bc74000996679f0998 kunit: kunit_config: Fix parsing of CONFIG options with space
>
> ...
>
> >  lib/{test_sort.c => sort_kunit.c} | 31 +++++++++++++++----------------
>
> Is it established practice to put kunit as a suffix?

Not yet. https://lore.kernel.org/linux-kselftest/20200620054944.167330-1-davidgow@google.com/T/#u

Thanks

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] lib: kunit: Convert test_sort to KUnit test
  2020-07-23  0:08 [PATCH] lib: kunit: Convert test_sort to KUnit test Vitor Massaru Iha
  2020-07-23  8:04 ` Andy Shevchenko
@ 2020-07-24 16:05 ` kernel test robot
  2020-07-24 23:43 ` kernel test robot
  2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2020-07-24 16:05 UTC (permalink / raw)
  To: Vitor Massaru Iha, kunit-dev
  Cc: kbuild-all, linux-kselftest, linux-kernel, brendanhiggins, skhan,
	linux-kernel-mentees, gregkh, tglx, fkostenzer,
	andriy.shevchenko

[-- Attachment #1: Type: text/plain, Size: 1324 bytes --]

Hi Vitor,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on d43c7fb05765152d4d4a39a8ef957c4ea14d8847]

url:    https://github.com/0day-ci/linux/commits/Vitor-Massaru-Iha/lib-kunit-Convert-test_sort-to-KUnit-test/20200723-081244
base:    d43c7fb05765152d4d4a39a8ef957c4ea14d8847
config: h8300-allyesconfig (attached as .config)
compiler: h8300-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=h8300 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> WARNING: modpost: vmlinux.o(.data+0x4fc70): Section mismatch in reference from the variable sort_test_cases to the variable .init.text:sort_test
   The variable sort_test_cases references
   the variable __init sort_test
   If the reference is valid then annotate the
   variable with or __refdata (see linux/init.h) or name the variable:
   

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 55695 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] lib: kunit: Convert test_sort to KUnit test
  2020-07-23  0:08 [PATCH] lib: kunit: Convert test_sort to KUnit test Vitor Massaru Iha
  2020-07-23  8:04 ` Andy Shevchenko
  2020-07-24 16:05 ` kernel test robot
@ 2020-07-24 23:43 ` kernel test robot
  2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2020-07-24 23:43 UTC (permalink / raw)
  To: Vitor Massaru Iha, kunit-dev
  Cc: kbuild-all, linux-kselftest, linux-kernel, brendanhiggins, skhan,
	linux-kernel-mentees, gregkh, tglx, fkostenzer,
	andriy.shevchenko

[-- Attachment #1: Type: text/plain, Size: 1330 bytes --]

Hi Vitor,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on d43c7fb05765152d4d4a39a8ef957c4ea14d8847]

url:    https://github.com/0day-ci/linux/commits/Vitor-Massaru-Iha/lib-kunit-Convert-test_sort-to-KUnit-test/20200723-081244
base:    d43c7fb05765152d4d4a39a8ef957c4ea14d8847
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> WARNING: modpost: lib/sort_kunit.o(.data+0x11c): Section mismatch in reference from the variable sort_test_cases to the function .init.text:sort_test()
   The variable sort_test_cases references
   the function __init sort_test()
   If the reference is valid then annotate the
   variable with or __refdata (see linux/init.h) or name the variable:
   

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 57237 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-24 23:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23  0:08 [PATCH] lib: kunit: Convert test_sort to KUnit test Vitor Massaru Iha
2020-07-23  8:04 ` Andy Shevchenko
2020-07-23 12:32   ` Vitor Massaru Iha
2020-07-24 16:05 ` kernel test robot
2020-07-24 23:43 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).