Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/module: test loading modules with a lot of relocations

Add a test in order to prevent regressions.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>

authored by

Ilya Leoshkevich and committed by
Heiko Carstens
90c53187 f3b7e73b

+116
+15
arch/s390/Kconfig
··· 945 945 946 946 endmenu 947 947 948 + config S390_MODULES_SANITY_TEST_HELPERS 949 + def_bool n 950 + 948 951 menu "Selftests" 949 952 950 953 config S390_UNWIND_SELFTEST ··· 974 971 975 972 Say N if you are unsure. 976 973 974 + config S390_MODULES_SANITY_TEST 975 + def_tristate n 976 + depends on KUNIT 977 + default KUNIT_ALL_TESTS 978 + prompt "Enable s390 specific modules tests" 979 + select S390_MODULES_SANITY_TEST_HELPERS 980 + help 981 + This option enables an s390 specific modules test. This option is 982 + not useful for distributions or general kernels, but only for 983 + kernel developers working on architecture code. 984 + 985 + Say N if you are unsure. 977 986 endmenu
+3
arch/s390/lib/Makefile
··· 17 17 obj-$(CONFIG_S390_UNWIND_SELFTEST) += test_unwind.o 18 18 CFLAGS_test_unwind.o += -fno-optimize-sibling-calls 19 19 20 + obj-$(CONFIG_S390_MODULES_SANITY_TEST) += test_modules.o 21 + obj-$(CONFIG_S390_MODULES_SANITY_TEST_HELPERS) += test_modules_helpers.o 22 + 20 23 lib-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
+35
arch/s390/lib/test_modules.c
··· 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");
+50
arch/s390/lib/test_modules.h
··· 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
+13
arch/s390/lib/test_modules_helpers.c
··· 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);