Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1557361 > unrolled thread

[PATCH] lib: move sort self-test into a separate file

Started byArnd Bergmann <arnd@arndb.de>
First post2017-01-12 12:10 +0100
Last post2017-01-16 19:10 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] lib: move sort self-test into a separate file Arnd Bergmann <arnd@arndb.de> - 2017-01-12 12:10 +0100
    Re: [PATCH] lib: move sort self-test into a separate file Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-01-16 19:10 +0100

#1557361 — [PATCH] lib: move sort self-test into a separate file

FromArnd Bergmann <arnd@arndb.de>
Date2017-01-12 12:10 +0100
Subject[PATCH] lib: move sort self-test into a separate file
Message-ID<sYLqx-3g8-5@gated-at.bofh.it>
The lib/sort.c file gets included in the EFI stub for use outside
of the kernel address space, which now fails due to the addition
of a module_init() function:

00000000 R_ARM_ABS32       test_sort_init
drivers/firmware/efi/libstub/lib-sort.stub.o: absolute symbol references not allowed in the EFI stub
drivers/firmware/efi/libstub/Makefile:69: recipe for target 'drivers/firmware/efi/libstub/lib-sort.stub.o' failed

Other library tests live in a separate file, so doing the same here
is an easy way to avoid the problem.

Fixes: akpm-current ("lib: add CONFIG_TEST_SORT to enable self-test of sort()")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 lib/Makefile    |  1 +
 lib/sort.c      | 44 --------------------------------------------
 lib/test_sort.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 44 deletions(-)
 create mode 100644 lib/test_sort.c

diff --git a/lib/Makefile b/lib/Makefile
index f5e72a728285..54d814a462da 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -50,6 +50,7 @@ obj-$(CONFIG_TEST_KASAN) += test_kasan.o
 obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
 obj-$(CONFIG_TEST_LKM) += test_module.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
diff --git a/lib/sort.c b/lib/sort.c
index a9b156e7471b..975c6ef6fec7 100644
--- a/lib/sort.c
+++ b/lib/sort.c
@@ -103,47 +103,3 @@ void sort(void *base, size_t num, size_t size,
 }
 
 EXPORT_SYMBOL(sort);
-
-#ifdef CONFIG_TEST_SORT
-#include <linux/slab.h>
-#include <linux/module.h>
-/* a simple boot-time regression test */
-
-#define TEST_LEN 1000
-
-static int __init cmpint(const void *a, const void *b)
-{
-	return *(int *)a - *(int *)b;
-}
-
-static int __init test_sort_init(void)
-{
-	int *a, i, r = 1, err = -ENOMEM;
-
-	a = kmalloc_array(TEST_LEN, sizeof(*a), GFP_KERNEL);
-	if (!a)
-		return err;
-
-	for (i = 0; i < TEST_LEN; i++) {
-		r = (r * 725861) % 6599;
-		a[i] = r;
-	}
-
-	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");
-			goto exit;
-		}
-	err = 0;
-	pr_info("test passed\n");
-exit:
-	kfree(a);
-	return err;
-}
-
-module_init(test_sort_init);
-MODULE_LICENSE("GPL");
-#endif
diff --git a/lib/test_sort.c b/lib/test_sort.c
new file mode 100644
index 000000000000..d389c1cc2f6c
--- /dev/null
+++ b/lib/test_sort.c
@@ -0,0 +1,43 @@
+#include <linux/sort.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+
+/* a simple boot-time regression test */
+
+#define TEST_LEN 1000
+
+static int __init cmpint(const void *a, const void *b)
+{
+	return *(int *)a - *(int *)b;
+}
+
+static int __init test_sort_init(void)
+{
+	int *a, i, r = 1, err = -ENOMEM;
+
+	a = kmalloc_array(TEST_LEN, sizeof(*a), GFP_KERNEL);
+	if (!a)
+		return err;
+
+	for (i = 0; i < TEST_LEN; i++) {
+		r = (r * 725861) % 6599;
+		a[i] = r;
+	}
+
+	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");
+			goto exit;
+		}
+	err = 0;
+	pr_info("test passed\n");
+exit:
+	kfree(a);
+	return err;
+}
+
+module_init(test_sort_init);
+MODULE_LICENSE("GPL");
-- 
2.9.0

[toc] | [next] | [standalone]


#1559961

FromAndy Shevchenko <andy.shevchenko@gmail.com>
Date2017-01-16 19:10 +0100
Message-ID<t0jTb-42i-17@gated-at.bofh.it>
In reply to#1557361
On Thu, Jan 12, 2017 at 1:05 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> The lib/sort.c file gets included in the EFI stub for use outside
> of the kernel address space, which now fails due to the addition
> of a module_init() function:
>
> 00000000 R_ARM_ABS32       test_sort_init
> drivers/firmware/efi/libstub/lib-sort.stub.o: absolute symbol references not allowed in the EFI stub
> drivers/firmware/efi/libstub/Makefile:69: recipe for target 'drivers/firmware/efi/libstub/lib-sort.stub.o' failed
>
> Other library tests live in a separate file, so doing the same here
> is an easy way to avoid the problem.
>

FWIW:
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Fixes: akpm-current ("lib: add CONFIG_TEST_SORT to enable self-test of sort()")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  lib/Makefile    |  1 +
>  lib/sort.c      | 44 --------------------------------------------
>  lib/test_sort.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 44 insertions(+), 44 deletions(-)
>  create mode 100644 lib/test_sort.c
>
> diff --git a/lib/Makefile b/lib/Makefile
> index f5e72a728285..54d814a462da 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -50,6 +50,7 @@ obj-$(CONFIG_TEST_KASAN) += test_kasan.o
>  obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
>  obj-$(CONFIG_TEST_LKM) += test_module.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
> diff --git a/lib/sort.c b/lib/sort.c
> index a9b156e7471b..975c6ef6fec7 100644
> --- a/lib/sort.c
> +++ b/lib/sort.c
> @@ -103,47 +103,3 @@ void sort(void *base, size_t num, size_t size,
>  }
>
>  EXPORT_SYMBOL(sort);
> -
> -#ifdef CONFIG_TEST_SORT
> -#include <linux/slab.h>
> -#include <linux/module.h>
> -/* a simple boot-time regression test */
> -
> -#define TEST_LEN 1000
> -
> -static int __init cmpint(const void *a, const void *b)
> -{
> -       return *(int *)a - *(int *)b;
> -}
> -
> -static int __init test_sort_init(void)
> -{
> -       int *a, i, r = 1, err = -ENOMEM;
> -
> -       a = kmalloc_array(TEST_LEN, sizeof(*a), GFP_KERNEL);
> -       if (!a)
> -               return err;
> -
> -       for (i = 0; i < TEST_LEN; i++) {
> -               r = (r * 725861) % 6599;
> -               a[i] = r;
> -       }
> -
> -       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");
> -                       goto exit;
> -               }
> -       err = 0;
> -       pr_info("test passed\n");
> -exit:
> -       kfree(a);
> -       return err;
> -}
> -
> -module_init(test_sort_init);
> -MODULE_LICENSE("GPL");
> -#endif
> diff --git a/lib/test_sort.c b/lib/test_sort.c
> new file mode 100644
> index 000000000000..d389c1cc2f6c
> --- /dev/null
> +++ b/lib/test_sort.c
> @@ -0,0 +1,43 @@
> +#include <linux/sort.h>
> +#include <linux/slab.h>
> +#include <linux/module.h>
> +
> +/* a simple boot-time regression test */
> +
> +#define TEST_LEN 1000
> +
> +static int __init cmpint(const void *a, const void *b)
> +{
> +       return *(int *)a - *(int *)b;
> +}
> +
> +static int __init test_sort_init(void)
> +{
> +       int *a, i, r = 1, err = -ENOMEM;
> +
> +       a = kmalloc_array(TEST_LEN, sizeof(*a), GFP_KERNEL);
> +       if (!a)
> +               return err;
> +
> +       for (i = 0; i < TEST_LEN; i++) {
> +               r = (r * 725861) % 6599;
> +               a[i] = r;
> +       }
> +
> +       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");
> +                       goto exit;
> +               }
> +       err = 0;
> +       pr_info("test passed\n");
> +exit:
> +       kfree(a);
> +       return err;
> +}
> +
> +module_init(test_sort_init);
> +MODULE_LICENSE("GPL");
> --
> 2.9.0
>



-- 
With Best Regards,
Andy Shevchenko

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web