Message ID | 20220901055823.152983-3-bgray@linux.ibm.com (mailing list archive) |
---|---|
State | RFC |
Headers | show |
Series | Out-of-line static calls for powerpc64 ELF V2 | expand |
Le 01/09/2022 à 07:58, Benjamin Gray a écrit : > These tests are out-of-line only, so moving them to the > out-of-line file allows them to be run when an arch does > not implement inline static calls. These tests look like standalone code, would be better to have a new static_call_selftest.c that is built when CONFIG_STATIC_CALL_SELFTEST is set. > > Signed-off-by: Benjamin Gray <bgray@linux.ibm.com> > --- > kernel/static_call.c | 43 +++++++++++++++++++++++++++++++++++++ > kernel/static_call_inline.c | 43 ------------------------------------- > 2 files changed, 43 insertions(+), 43 deletions(-) > > diff --git a/kernel/static_call.c b/kernel/static_call.c > index e9c3e69f3837..953ec46e5691 100644 > --- a/kernel/static_call.c > +++ b/kernel/static_call.c > @@ -6,3 +6,46 @@ long __static_call_return0(void) > return 0; > } > EXPORT_SYMBOL_GPL(__static_call_return0); > + > +#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 */ > diff --git a/kernel/static_call_inline.c b/kernel/static_call_inline.c > index dc5665b62814..64d04d054698 100644 > --- a/kernel/static_call_inline.c > +++ b/kernel/static_call_inline.c > @@ -498,46 +498,3 @@ int __init static_call_init(void) > return 0; > } > 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 */ > -- > 2.37.2 >
diff --git a/kernel/static_call.c b/kernel/static_call.c index e9c3e69f3837..953ec46e5691 100644 --- a/kernel/static_call.c +++ b/kernel/static_call.c @@ -6,3 +6,46 @@ long __static_call_return0(void) return 0; } EXPORT_SYMBOL_GPL(__static_call_return0); + +#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 */ diff --git a/kernel/static_call_inline.c b/kernel/static_call_inline.c index dc5665b62814..64d04d054698 100644 --- a/kernel/static_call_inline.c +++ b/kernel/static_call_inline.c @@ -498,46 +498,3 @@ int __init static_call_init(void) return 0; } 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 */
These tests are out-of-line only, so moving them to the out-of-line file allows them to be run when an arch does not implement inline static calls. Signed-off-by: Benjamin Gray <bgray@linux.ibm.com> --- kernel/static_call.c | 43 +++++++++++++++++++++++++++++++++++++ kernel/static_call_inline.c | 43 ------------------------------------- 2 files changed, 43 insertions(+), 43 deletions(-)