[PATCH] clk: tests: Add tests for clk lookup by name

Chen-Yu Tsai wenst at chromium.org
Wed Oct 8 20:24:22 PDT 2025


On Thu, Oct 9, 2025 at 7:58 AM Brian Masney <bmasney at redhat.com> wrote:
>
> On Thu, Oct 02, 2025 at 05:20:35PM +0800, Chen-Yu Tsai wrote:
> > Clk lookup (by name) recently gained some performance improvements at
> > the expense of more complexity within the lookup code.
> >
> > To make sure that this works as intended and doesn't break, add some
> > basic tests for this part of the CCF.
> >
> > A new "clk_hw_lookup()" function is added purely for running kunit
> > tests.
> >
> > Signed-off-by: Chen-Yu Tsai <wenst at chromium.org>
> > ---
> >  drivers/clk/clk.c      | 11 +++++++
> >  drivers/clk/clk.h      |  4 +++
> >  drivers/clk/clk_test.c | 66 +++++++++++++++++++++++++++++++++++++++++-
> >  3 files changed, 80 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> > index 85d2f2481acf..a17d0070d11f 100644
> > --- a/drivers/clk/clk.c
> > +++ b/drivers/clk/clk.c
> > @@ -778,6 +778,17 @@ struct clk *__clk_lookup(const char *name)
> >       return !core ? NULL : core->hw->clk;
> >  }
> >
> > +#if IS_ENABLED(CONFIG_CLK_KUNIT_TEST)
> > +/* This is only provided for kunit tests to test the core lookup functions. */
> > +struct clk_hw *clk_hw_lookup(const char *name)
> > +{
> > +     struct clk_core *core = clk_core_lookup(name);
> > +
> > +     return !core ? NULL : core->hw;
> > +}
> > +EXPORT_SYMBOL_GPL(clk_hw_lookup);
> > +#endif
>
> Use EXPORT_SYMBOL_IF_KUNIT instead for consistency with the rest of the
> kernel. In clk_test.c, you'll also need to add:
>
> MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");

Didn't know about this one. Thanks!

> Since clk_hw_lookup() is only used by kunit, why not just put this new
> function in clk-test.c, and use EXPORT_SYMBOL_IF_KUNIT on
> clk_core_lookup?

Then we end up sort of exposing clk_core_lookup as well?

I believe Stephen wants to keep things contained as much as possible.


ChenYu



More information about the linux-arm-kernel mailing list