Signed-off-by: Peter Zijlstra (Intel) <pet...@infradead.org> --- lib/Kconfig.debug | 8 ++++++++ lib/Makefile | 1 + lib/test_static_call.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+)
--- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1955,6 +1955,14 @@ config TEST_STATIC_KEYS If unsure, say N. +config TEST_STATIC_CALL + tristate "Test static call" + depends on m + help + Test the static call interfaces. + + If unsure, say N. + config TEST_KMOD tristate "kmod stress tester" depends on m --- a/lib/Makefile +++ b/lib/Makefile @@ -79,6 +79,7 @@ obj-$(CONFIG_TEST_SORT) += test_sort.o obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o +obj-$(CONFIG_TEST_STATIC_CALL) += test_static_call.o obj-$(CONFIG_TEST_PRINTF) += test_printf.o obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o obj-$(CONFIG_TEST_STRSCPY) += test_strscpy.o --- /dev/null +++ b/lib/test_static_call.c @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <linux/module.h> +#include <linux/static_call.h> +#include <asm/bug.h> + +static int foo_a(int x) +{ + return x+1; +} + +static int foo_b(int x) +{ + return x*2; +} + +DEFINE_STATIC_CALL(foo, foo_a); + +static int __init test_static_call_init(void) +{ + WARN_ON(static_call(foo, 2) != 3); + + static_call_update(foo, foo_b); + + WARN_ON(static_call(foo, 2) != 4); + + static_call_update(foo, foo_a); + + WARN_ON(static_call(foo, 2) != 3); + + return 0; +} +module_init(test_static_call_init); + +static void __exit test_static_call_exit(void) +{ +} +module_exit(test_static_call_exit); + +MODULE_AUTHOR("Peter Zijlstra <pet...@infradead.org>"); +MODULE_LICENSE("GPL");