From: Stephen Boyd <sboyd@kernel.org>
To: David Gow <davidgow@google.com>
Cc: Michael Turquette <mturquette@baylibre.com>,
linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org,
patches@lists.linux.dev, kunit-dev@googlegroups.com,
linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org,
Brendan Higgins <brendan.higgins@linux.dev>,
Rae Moar <rmoar@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Rafael J . Wysocki <rafael@kernel.org>,
Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@google.com>,
Daniel Latypov <dlatypov@google.com>,
Christian Marangi <ansuelsmth@gmail.com>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Maxime Ripard <maxime@cerno.tech>
Subject: Re: [PATCH v5 11/11] clk: Add KUnit tests for clks registered with struct clk_parent_data
Date: Tue, 02 Jul 2024 15:25:47 -0700 [thread overview]
Message-ID: <c88fbeb65cfda6c568b4d8d69215139f.sboyd@kernel.org> (raw)
In-Reply-To: <CABVgOS=4Qnb7pvc_mmkPGdyVFGNWU9wdyn9p-QBKKG+rbJGtfA@mail.gmail.com>
Quoting David Gow (2024-06-13 00:56:08)
> On Tue, 4 Jun 2024 at 06:38, Stephen Boyd <sboyd@kernel.org> wrote:
> >
> > Test that clks registered with 'struct clk_parent_data' work as
> > intended and can find their parents.
> >
> > Cc: Christian Marangi <ansuelsmth@gmail.com>
> > Cc: Brendan Higgins <brendan.higgins@linux.dev>
> > Cc: David Gow <davidgow@google.com>
> > Cc: Rae Moar <rmoar@google.com>
> > Signed-off-by: Stephen Boyd <sboyd@kernel.org>
> > ---
>
> This seems good to me overall, but will break if we can't compile the
> dtbo.o file. Maybe these need to live behind a #if
> IS_ENABLED(CONFIG_OF) or equivalent.
>
> Also, there's a cast to kunit_action_t* which needs to use a wrapper.
>
> Otherwise,
> Reviewed-by: David Gow <davidgow@google.com>
>
> Cheers,
> -- David
>
> > drivers/clk/Kconfig | 1 +
> > drivers/clk/Makefile | 3 +-
> > drivers/clk/clk_parent_data_test.h | 10 +
> > drivers/clk/clk_test.c | 451 +++++++++++++++++++-
> > drivers/clk/kunit_clk_parent_data_test.dtso | 28 ++
> > 5 files changed, 491 insertions(+), 2 deletions(-)
> > create mode 100644 drivers/clk/clk_parent_data_test.h
> > create mode 100644 drivers/clk/kunit_clk_parent_data_test.dtso
> >
> > diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> > index f649f2a0279c..c33fdf9fdcd6 100644
> > --- a/drivers/clk/Kconfig
> > +++ b/drivers/clk/Kconfig
> > @@ -508,6 +508,7 @@ config CLK_KUNIT_TEST
> > tristate "Basic Clock Framework Kunit Tests" if !KUNIT_ALL_TESTS
> > depends on KUNIT
> > default KUNIT_ALL_TESTS
> > + select OF_OVERLAY if OF
> > help
> > Kunit tests for the common clock framework.
> >
> > diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
> > index 7b57e3d22cee..ed4e1a0e6943 100644
> > --- a/drivers/clk/Makefile
> > +++ b/drivers/clk/Makefile
> > @@ -2,7 +2,8 @@
> > # common clock types
> > obj-$(CONFIG_HAVE_CLK) += clk-devres.o clk-bulk.o clkdev.o
> > obj-$(CONFIG_COMMON_CLK) += clk.o
> > -obj-$(CONFIG_CLK_KUNIT_TEST) += clk_test.o
> > +obj-$(CONFIG_CLK_KUNIT_TEST) += clk_test.o \
> > + kunit_clk_parent_data_test.dtbo.o
>
> This breaks if CONFIG_OF isn't enabled, as there's no rule to compile it:
> make[5]: *** No rule to make target
> 'drivers/clk/kunit_clk_parent_data_test.dtbo.o', needed by
> 'drivers/clk/modules.order'. Stop.
>
Ah, I see that I need to set CONFIG_DTC or the DT compiler (dtc) won't
be built. Maybe I should just select OF_OVERLAY instead of being nice
and letting OF be disabled? The problem is that I can't test the
CONFIG_OF=n case easily then.
For now I'll go with 'select DTC', but it really feels like we should
just get rid of that Kconfig and build 'dtc' if it is needed.
> > diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
> > index 39e2b5ff4f51..bdf3c4bb2243 100644
> > --- a/drivers/clk/clk_test.c
> > +++ b/drivers/clk/clk_test.c
> > @@ -4,12 +4,19 @@
> > */
> > #include <linux/clk.h>
> > #include <linux/clk-provider.h>
> > +#include <linux/of.h>
> > +#include <linux/platform_device.h>
> >
> > /* Needed for clk_hw_get_clk() */
> > #include "clk.h"
[...]
> > +
> > +/**
> > + * struct clk_register_clk_parent_data_of_ctx - Context for clk_parent_data OF tests
> > + * @np: device node of clk under test
> > + * @hw: clk_hw for clk under test
> > + */
> > +struct clk_register_clk_parent_data_of_ctx {
> > + struct device_node *np;
> > + struct clk_hw hw;
> > +};
> > +
> > +static int clk_register_clk_parent_data_of_test_init(struct kunit *test)
> > +{
> > + struct clk_register_clk_parent_data_of_ctx *ctx;
> > +
> > + KUNIT_ASSERT_EQ(test, 0,
> > + of_overlay_apply_kunit(test, kunit_clk_parent_data_test));
> > +
> > + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
> > + if (!ctx)
> > + return -ENOMEM;
> > + test->priv = ctx;
> > +
> > + ctx->np = of_find_compatible_node(NULL, NULL, "test,clk-parent-data");
> > + if (!ctx->np)
> > + return -ENODEV;
> > +
> > + return kunit_add_action_or_reset(test, (kunit_action_t *)&of_node_put, ctx->np);
>
> We should use an action wrapper here (KUNIT_DEFINE_ACTION_WRAPPER()),
> as casting function pointers to kunit_action_t* breaks control-flow
> integrity.
Got it, thanks. Maybe there should be an of_node_put_kunit_exit() helper that
does that and can be used anywhere.
next prev parent reply other threads:[~2024-07-02 22:25 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-03 22:37 [PATCH v5 00/11] clk: Add kunit tests for fixed rate and parent data Stephen Boyd
2024-06-03 22:37 ` [PATCH v5 01/11] of/platform: Allow overlays to create platform devices from the root node Stephen Boyd
2024-06-05 23:47 ` Rob Herring (Arm)
2024-06-03 22:37 ` [PATCH v5 02/11] of: Add test managed wrappers for of_overlay_apply()/of_node_put() Stephen Boyd
2024-06-13 7:48 ` David Gow
2024-07-02 22:39 ` Stephen Boyd
2024-06-03 22:38 ` [PATCH v5 03/11] dt-bindings: vendor-prefixes: Add "test" vendor for KUnit and friends Stephen Boyd
2024-06-03 22:38 ` [PATCH v5 04/11] dt-bindings: test: Add KUnit empty node binding Stephen Boyd
2024-06-03 22:38 ` [PATCH v5 05/11] of: Add a KUnit test for overlays and test managed APIs Stephen Boyd
2024-06-05 23:47 ` Rob Herring
2024-06-06 15:23 ` Stephen Boyd
2024-06-13 7:50 ` David Gow
2024-07-02 21:45 ` Stephen Boyd
2024-06-03 22:38 ` [PATCH v5 06/11] platform: Add test managed platform_device/driver APIs Stephen Boyd
2024-06-04 13:48 ` Greg Kroah-Hartman
2024-06-13 7:50 ` David Gow
2024-06-03 22:38 ` [PATCH v5 07/11] dt-bindings: test: Add single clk consumer Stephen Boyd
2024-06-04 12:50 ` Rob Herring (Arm)
2024-06-04 13:05 ` Rob Herring
2024-06-04 18:28 ` Stephen Boyd
2024-06-04 20:19 ` Rob Herring
2024-06-04 20:52 ` Stephen Boyd
2024-06-04 20:53 ` Stephen Boyd
2024-06-03 22:38 ` [PATCH v5 08/11] clk: Add test managed clk provider/consumer APIs Stephen Boyd
2024-06-03 22:38 ` [PATCH v5 09/11] clk: Add KUnit tests for clk fixed rate basic type Stephen Boyd
2024-06-03 22:38 ` [PATCH v5 10/11] dt-bindings: clk: Add clk_parent_data test Stephen Boyd
2024-06-03 22:38 ` [PATCH v5 11/11] clk: Add KUnit tests for clks registered with struct clk_parent_data Stephen Boyd
2024-06-13 7:56 ` David Gow
2024-07-02 22:25 ` Stephen Boyd [this message]
2024-07-02 22:34 ` Stephen Boyd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c88fbeb65cfda6c568b4d8d69215139f.sboyd@kernel.org \
--to=sboyd@kernel.org \
--cc=ansuelsmth@gmail.com \
--cc=brendan.higgins@linux.dev \
--cc=conor+dt@kernel.org \
--cc=davidgow@google.com \
--cc=devicetree@vger.kernel.org \
--cc=dlatypov@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maxime@cerno.tech \
--cc=mturquette@baylibre.com \
--cc=patches@lists.linux.dev \
--cc=rafael@kernel.org \
--cc=rmoar@google.com \
--cc=robh@kernel.org \
--cc=saravanak@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).