Commit 6b1a4d5b authored by Tobin C. Harding's avatar Tobin C. Harding Committed by Shuah Khan

lib: Use new kselftest header

We just added a new C header file for use with test modules that are
intended to be run with kselftest.  We can reduce code duplication by
using this header.

Use new kselftest header to reduce code duplication in test_printf and
test_bitmap test modules.
Acked-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarTobin C. Harding <tobin@kernel.org>
Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
parent eebf4dd4
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h> #include <linux/string.h>
#include "../tools/testing/selftests/kselftest_module.h"
static unsigned total_tests __initdata; static unsigned total_tests __initdata;
static unsigned failed_tests __initdata; static unsigned failed_tests __initdata;
...@@ -361,7 +363,7 @@ static void noinline __init test_mem_optimisations(void) ...@@ -361,7 +363,7 @@ static void noinline __init test_mem_optimisations(void)
} }
} }
static int __init test_bitmap_init(void) static void __init selftest(void)
{ {
test_zero_clear(); test_zero_clear();
test_fill_set(); test_fill_set();
...@@ -369,22 +371,8 @@ static int __init test_bitmap_init(void) ...@@ -369,22 +371,8 @@ static int __init test_bitmap_init(void)
test_bitmap_arr32(); test_bitmap_arr32();
test_bitmap_parselist(); test_bitmap_parselist();
test_mem_optimisations(); test_mem_optimisations();
if (failed_tests == 0)
pr_info("all %u tests passed\n", total_tests);
else
pr_warn("failed %u out of %u tests\n",
failed_tests, total_tests);
return failed_tests ? -EINVAL : 0;
} }
static void __exit test_bitmap_cleanup(void) KSTM_MODULE_LOADERS(test_bitmap);
{
}
module_init(test_bitmap_init);
module_exit(test_bitmap_cleanup);
MODULE_AUTHOR("david decotigny <david.decotigny@googlers.com>"); MODULE_AUTHOR("david decotigny <david.decotigny@googlers.com>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/mm.h> #include <linux/mm.h>
#include "../tools/testing/selftests/kselftest_module.h"
#define BUF_SIZE 256 #define BUF_SIZE 256
#define PAD_SIZE 16 #define PAD_SIZE 16
#define FILL_CHAR '$' #define FILL_CHAR '$'
...@@ -590,12 +592,11 @@ test_pointer(void) ...@@ -590,12 +592,11 @@ test_pointer(void)
flags(); flags();
} }
static int __init static void __init selftest(void)
test_printf_init(void)
{ {
alloced_buffer = kmalloc(BUF_SIZE + 2*PAD_SIZE, GFP_KERNEL); alloced_buffer = kmalloc(BUF_SIZE + 2*PAD_SIZE, GFP_KERNEL);
if (!alloced_buffer) if (!alloced_buffer)
return -ENOMEM; return;
test_buffer = alloced_buffer + PAD_SIZE; test_buffer = alloced_buffer + PAD_SIZE;
test_basic(); test_basic();
...@@ -604,22 +605,8 @@ test_printf_init(void) ...@@ -604,22 +605,8 @@ test_printf_init(void)
test_pointer(); test_pointer();
kfree(alloced_buffer); kfree(alloced_buffer);
if (failed_tests == 0)
pr_info("all %u tests passed\n", total_tests);
else
pr_warn("failed %u out of %u tests\n", failed_tests, total_tests);
return failed_tests ? -EINVAL : 0;
} }
module_init(test_printf_init); KSTM_MODULE_LOADERS(test_printf);
static void __exit test_printf_exit(void)
{
}
module_exit(test_printf_exit);
MODULE_AUTHOR("Rasmus Villemoes <linux@rasmusvillemoes.dk>"); MODULE_AUTHOR("Rasmus Villemoes <linux@rasmusvillemoes.dk>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
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