Skip to content

Commit 6b1a4d5

Browse files
Tobin C. HardingShuah Khan
authored andcommitted
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: Kees Cook <[email protected]> Signed-off-by: Tobin C. Harding <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent eebf4dd commit 6b1a4d5

File tree

2 files changed

+9
-34
lines changed

2 files changed

+9
-34
lines changed

lib/test_bitmap.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <linux/slab.h>
1313
#include <linux/string.h>
1414

15+
#include "../tools/testing/selftests/kselftest_module.h"
16+
1517
static unsigned total_tests __initdata;
1618
static unsigned failed_tests __initdata;
1719

@@ -361,30 +363,16 @@ static void noinline __init test_mem_optimisations(void)
361363
}
362364
}
363365

364-
static int __init test_bitmap_init(void)
366+
static void __init selftest(void)
365367
{
366368
test_zero_clear();
367369
test_fill_set();
368370
test_copy();
369371
test_bitmap_arr32();
370372
test_bitmap_parselist();
371373
test_mem_optimisations();
372-
373-
if (failed_tests == 0)
374-
pr_info("all %u tests passed\n", total_tests);
375-
else
376-
pr_warn("failed %u out of %u tests\n",
377-
failed_tests, total_tests);
378-
379-
return failed_tests ? -EINVAL : 0;
380374
}
381375

382-
static void __exit test_bitmap_cleanup(void)
383-
{
384-
}
385-
386-
module_init(test_bitmap_init);
387-
module_exit(test_bitmap_cleanup);
388-
376+
KSTM_MODULE_LOADERS(test_bitmap);
389377
MODULE_AUTHOR("david decotigny <[email protected]>");
390378
MODULE_LICENSE("GPL");

lib/test_printf.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <linux/gfp.h>
2222
#include <linux/mm.h>
2323

24+
#include "../tools/testing/selftests/kselftest_module.h"
25+
2426
#define BUF_SIZE 256
2527
#define PAD_SIZE 16
2628
#define FILL_CHAR '$'
@@ -590,12 +592,11 @@ test_pointer(void)
590592
flags();
591593
}
592594

593-
static int __init
594-
test_printf_init(void)
595+
static void __init selftest(void)
595596
{
596597
alloced_buffer = kmalloc(BUF_SIZE + 2*PAD_SIZE, GFP_KERNEL);
597598
if (!alloced_buffer)
598-
return -ENOMEM;
599+
return;
599600
test_buffer = alloced_buffer + PAD_SIZE;
600601

601602
test_basic();
@@ -604,22 +605,8 @@ test_printf_init(void)
604605
test_pointer();
605606

606607
kfree(alloced_buffer);
607-
608-
if (failed_tests == 0)
609-
pr_info("all %u tests passed\n", total_tests);
610-
else
611-
pr_warn("failed %u out of %u tests\n", failed_tests, total_tests);
612-
613-
return failed_tests ? -EINVAL : 0;
614608
}
615609

616-
module_init(test_printf_init);
617-
618-
static void __exit test_printf_exit(void)
619-
{
620-
}
621-
622-
module_exit(test_printf_exit);
623-
610+
KSTM_MODULE_LOADERS(test_printf);
624611
MODULE_AUTHOR("Rasmus Villemoes <[email protected]>");
625612
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)