Commit 90c53187 authored by Ilya Leoshkevich's avatar Ilya Leoshkevich Committed by Heiko Carstens
Browse files

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



Add a test in order to prevent regressions.

Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: default avatarHeiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: default avatarHeiko Carstens <hca@linux.ibm.com>
parent f3b7e73b
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -945,6 +945,9 @@ config S390_GUEST

endmenu

config S390_MODULES_SANITY_TEST_HELPERS
	def_bool n

menu "Selftests"

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

	  Say N if you are unsure.

config S390_MODULES_SANITY_TEST
	def_tristate n
	depends on KUNIT
	default KUNIT_ALL_TESTS
	prompt "Enable s390 specific modules tests"
	select S390_MODULES_SANITY_TEST_HELPERS
	help
	  This option enables an s390 specific modules test. This option is
	  not useful for distributions or general kernels, but only for
	  kernel developers working on architecture code.

	  Say N if you are unsure.
endmenu
+3 −0
Original line number Diff line number Diff line
@@ -17,4 +17,7 @@ KASAN_SANITIZE_uaccess.o := n
obj-$(CONFIG_S390_UNWIND_SELFTEST) += test_unwind.o
CFLAGS_test_unwind.o += -fno-optimize-sibling-calls

obj-$(CONFIG_S390_MODULES_SANITY_TEST) += test_modules.o
obj-$(CONFIG_S390_MODULES_SANITY_TEST_HELPERS) += test_modules_helpers.o

lib-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
+35 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0+

#include <kunit/test.h>
#include <linux/module.h>

#include "test_modules.h"

#define DECLARE_RETURN(i) int test_modules_return_ ## i(void)
REPEAT_10000(DECLARE_RETURN);

/*
 * Test that modules with many relocations are loaded properly.
 */
static void test_modules_many_vmlinux_relocs(struct kunit *test)
{
	int result = 0;

#define CALL_RETURN(i) result += test_modules_return_ ## i()
	REPEAT_10000(CALL_RETURN);
	KUNIT_ASSERT_EQ(test, result, 49995000);
}

static struct kunit_case modules_testcases[] = {
	KUNIT_CASE(test_modules_many_vmlinux_relocs),
	{}
};

static struct kunit_suite modules_test_suite = {
	.name = "modules_test_s390",
	.test_cases = modules_testcases,
};

kunit_test_suites(&modules_test_suite);

MODULE_LICENSE("GPL");
+50 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0+ */
#ifndef TEST_MODULES_H
#define TEST_MODULES_H

#define __REPEAT_10000_3(f, x) \
	f(x ## 0); \
	f(x ## 1); \
	f(x ## 2); \
	f(x ## 3); \
	f(x ## 4); \
	f(x ## 5); \
	f(x ## 6); \
	f(x ## 7); \
	f(x ## 8); \
	f(x ## 9)
#define __REPEAT_10000_2(f, x) \
	__REPEAT_10000_3(f, x ## 0); \
	__REPEAT_10000_3(f, x ## 1); \
	__REPEAT_10000_3(f, x ## 2); \
	__REPEAT_10000_3(f, x ## 3); \
	__REPEAT_10000_3(f, x ## 4); \
	__REPEAT_10000_3(f, x ## 5); \
	__REPEAT_10000_3(f, x ## 6); \
	__REPEAT_10000_3(f, x ## 7); \
	__REPEAT_10000_3(f, x ## 8); \
	__REPEAT_10000_3(f, x ## 9)
#define __REPEAT_10000_1(f, x) \
	__REPEAT_10000_2(f, x ## 0); \
	__REPEAT_10000_2(f, x ## 1); \
	__REPEAT_10000_2(f, x ## 2); \
	__REPEAT_10000_2(f, x ## 3); \
	__REPEAT_10000_2(f, x ## 4); \
	__REPEAT_10000_2(f, x ## 5); \
	__REPEAT_10000_2(f, x ## 6); \
	__REPEAT_10000_2(f, x ## 7); \
	__REPEAT_10000_2(f, x ## 8); \
	__REPEAT_10000_2(f, x ## 9)
#define REPEAT_10000(f) \
	__REPEAT_10000_1(f, 0); \
	__REPEAT_10000_1(f, 1); \
	__REPEAT_10000_1(f, 2); \
	__REPEAT_10000_1(f, 3); \
	__REPEAT_10000_1(f, 4); \
	__REPEAT_10000_1(f, 5); \
	__REPEAT_10000_1(f, 6); \
	__REPEAT_10000_1(f, 7); \
	__REPEAT_10000_1(f, 8); \
	__REPEAT_10000_1(f, 9)

#endif
+13 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0+

#include <linux/export.h>

#include "test_modules.h"

#define DEFINE_RETURN(i) \
	int test_modules_return_ ## i(void) \
	{ \
		return 1 ## i - 10000; \
	} \
	EXPORT_SYMBOL_GPL(test_modules_return_ ## i)
REPEAT_10000(DEFINE_RETURN);