diff options
author | Peter Zijlstra <peterz@infradead.org> | 2020-08-18 15:57:46 +0200 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2020-09-01 09:58:05 +0200 |
commit | f03c412915f5f69f2d17bcd20ecdd69320bcbf7b (patch) | |
tree | 7fdddaec7635ff18cfb0c956ce2b600865c7ca37 /kernel/static_call.c | |
parent | 1e7e47883830aae5e8246a22ca2fc6883c61acdf (diff) | |
download | lwn-f03c412915f5f69f2d17bcd20ecdd69320bcbf7b.tar.gz lwn-f03c412915f5f69f2d17bcd20ecdd69320bcbf7b.zip |
static_call: Add simple self-test for static calls
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20200818135804.922581202@infradead.org
Diffstat (limited to 'kernel/static_call.c')
-rw-r--r-- | kernel/static_call.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/kernel/static_call.c b/kernel/static_call.c index 753b2f1b4fb8..97142cb6bfa6 100644 --- a/kernel/static_call.c +++ b/kernel/static_call.c @@ -369,3 +369,46 @@ static void __init static_call_init(void) #endif } early_initcall(static_call_init); + +#ifdef CONFIG_STATIC_CALL_SELFTEST + +static int func_a(int x) +{ + return x+1; +} + +static int func_b(int x) +{ + return x+2; +} + +DEFINE_STATIC_CALL(sc_selftest, func_a); + +static struct static_call_data { + int (*func)(int); + int val; + int expect; +} static_call_data [] __initdata = { + { NULL, 2, 3 }, + { func_b, 2, 4 }, + { func_a, 2, 3 } +}; + +static int __init test_static_call_init(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(static_call_data); i++ ) { + struct static_call_data *scd = &static_call_data[i]; + + if (scd->func) + static_call_update(sc_selftest, scd->func); + + WARN_ON(static_call(sc_selftest)(scd->val) != scd->expect); + } + + return 0; +} +early_initcall(test_static_call_init); + +#endif /* CONFIG_STATIC_CALL_SELFTEST */ |