Skip to content

Commit 90c5318

Browse files
iii-ihcahca
authored andcommitted
s390/module: test loading modules with a lot of relocations
Add a test in order to prevent regressions. Signed-off-by: Ilya Leoshkevich <[email protected]> Reviewed-by: Heiko Carstens <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Christian Borntraeger <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent f3b7e73 commit 90c5318

File tree

5 files changed

+116
-0
lines changed

5 files changed

+116
-0
lines changed

arch/s390/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,9 @@ config S390_GUEST
945945

946946
endmenu
947947

948+
config S390_MODULES_SANITY_TEST_HELPERS
949+
def_bool n
950+
948951
menu "Selftests"
949952

950953
config S390_UNWIND_SELFTEST
@@ -971,4 +974,16 @@ config S390_KPROBES_SANITY_TEST
971974

972975
Say N if you are unsure.
973976

977+
config S390_MODULES_SANITY_TEST
978+
def_tristate n
979+
depends on KUNIT
980+
default KUNIT_ALL_TESTS
981+
prompt "Enable s390 specific modules tests"
982+
select S390_MODULES_SANITY_TEST_HELPERS
983+
help
984+
This option enables an s390 specific modules test. This option is
985+
not useful for distributions or general kernels, but only for
986+
kernel developers working on architecture code.
987+
988+
Say N if you are unsure.
974989
endmenu

arch/s390/lib/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ KASAN_SANITIZE_uaccess.o := n
1717
obj-$(CONFIG_S390_UNWIND_SELFTEST) += test_unwind.o
1818
CFLAGS_test_unwind.o += -fno-optimize-sibling-calls
1919

20+
obj-$(CONFIG_S390_MODULES_SANITY_TEST) += test_modules.o
21+
obj-$(CONFIG_S390_MODULES_SANITY_TEST_HELPERS) += test_modules_helpers.o
22+
2023
lib-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o

arch/s390/lib/test_modules.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
3+
#include <kunit/test.h>
4+
#include <linux/module.h>
5+
6+
#include "test_modules.h"
7+
8+
#define DECLARE_RETURN(i) int test_modules_return_ ## i(void)
9+
REPEAT_10000(DECLARE_RETURN);
10+
11+
/*
12+
* Test that modules with many relocations are loaded properly.
13+
*/
14+
static void test_modules_many_vmlinux_relocs(struct kunit *test)
15+
{
16+
int result = 0;
17+
18+
#define CALL_RETURN(i) result += test_modules_return_ ## i()
19+
REPEAT_10000(CALL_RETURN);
20+
KUNIT_ASSERT_EQ(test, result, 49995000);
21+
}
22+
23+
static struct kunit_case modules_testcases[] = {
24+
KUNIT_CASE(test_modules_many_vmlinux_relocs),
25+
{}
26+
};
27+
28+
static struct kunit_suite modules_test_suite = {
29+
.name = "modules_test_s390",
30+
.test_cases = modules_testcases,
31+
};
32+
33+
kunit_test_suites(&modules_test_suite);
34+
35+
MODULE_LICENSE("GPL");

arch/s390/lib/test_modules.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* SPDX-License-Identifier: GPL-2.0+ */
2+
#ifndef TEST_MODULES_H
3+
#define TEST_MODULES_H
4+
5+
#define __REPEAT_10000_3(f, x) \
6+
f(x ## 0); \
7+
f(x ## 1); \
8+
f(x ## 2); \
9+
f(x ## 3); \
10+
f(x ## 4); \
11+
f(x ## 5); \
12+
f(x ## 6); \
13+
f(x ## 7); \
14+
f(x ## 8); \
15+
f(x ## 9)
16+
#define __REPEAT_10000_2(f, x) \
17+
__REPEAT_10000_3(f, x ## 0); \
18+
__REPEAT_10000_3(f, x ## 1); \
19+
__REPEAT_10000_3(f, x ## 2); \
20+
__REPEAT_10000_3(f, x ## 3); \
21+
__REPEAT_10000_3(f, x ## 4); \
22+
__REPEAT_10000_3(f, x ## 5); \
23+
__REPEAT_10000_3(f, x ## 6); \
24+
__REPEAT_10000_3(f, x ## 7); \
25+
__REPEAT_10000_3(f, x ## 8); \
26+
__REPEAT_10000_3(f, x ## 9)
27+
#define __REPEAT_10000_1(f, x) \
28+
__REPEAT_10000_2(f, x ## 0); \
29+
__REPEAT_10000_2(f, x ## 1); \
30+
__REPEAT_10000_2(f, x ## 2); \
31+
__REPEAT_10000_2(f, x ## 3); \
32+
__REPEAT_10000_2(f, x ## 4); \
33+
__REPEAT_10000_2(f, x ## 5); \
34+
__REPEAT_10000_2(f, x ## 6); \
35+
__REPEAT_10000_2(f, x ## 7); \
36+
__REPEAT_10000_2(f, x ## 8); \
37+
__REPEAT_10000_2(f, x ## 9)
38+
#define REPEAT_10000(f) \
39+
__REPEAT_10000_1(f, 0); \
40+
__REPEAT_10000_1(f, 1); \
41+
__REPEAT_10000_1(f, 2); \
42+
__REPEAT_10000_1(f, 3); \
43+
__REPEAT_10000_1(f, 4); \
44+
__REPEAT_10000_1(f, 5); \
45+
__REPEAT_10000_1(f, 6); \
46+
__REPEAT_10000_1(f, 7); \
47+
__REPEAT_10000_1(f, 8); \
48+
__REPEAT_10000_1(f, 9)
49+
50+
#endif

arch/s390/lib/test_modules_helpers.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
3+
#include <linux/export.h>
4+
5+
#include "test_modules.h"
6+
7+
#define DEFINE_RETURN(i) \
8+
int test_modules_return_ ## i(void) \
9+
{ \
10+
return 1 ## i - 10000; \
11+
} \
12+
EXPORT_SYMBOL_GPL(test_modules_return_ ## i)
13+
REPEAT_10000(DEFINE_RETURN);

0 commit comments

Comments
 (0)