[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAGS_qxryWVOT9cBtKk28=NupbLP6_AiCj0P3np2GpMVKkyQOLg@mail.gmail.com>
Date: Wed, 12 Apr 2023 17:04:26 -0700
From: Daniel Latypov <dlatypov@...gle.com>
To: Stephen Boyd <sboyd@...nel.org>
Cc: Michael Turquette <mturquette@...libre.com>,
linux-kernel@...r.kernel.org, linux-clk@...r.kernel.org,
patches@...ts.linux.dev,
Brendan Higgins <brendan.higgins@...ux.dev>,
David Gow <davidgow@...gle.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
Frank Rowand <frowand.list@...il.com>,
Christian Marangi <ansuelsmth@...il.com>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
devicetree@...r.kernel.org, linux-kselftest@...r.kernel.org,
kunit-dev@...glegroups.com, Maxime Ripard <maxime@...no.tech>
Subject: Re: [PATCH v3 05/11] of: Add a KUnit test for overlays and test
managed APIs
On Mon, Mar 27, 2023 at 3:22 PM Stephen Boyd <sboyd@...nel.org> wrote:
>
> Test the KUnit test managed overlay APIs. Confirm that platform devices
> are created and destroyed properly. This provides us confidence that the
> test managed work correctly and can be relied upon to provide tests with
> fake platform devices and device nodes via overlays compiled into the
> kernel image.
>
The discussion around kunit_cleanup() caught my eye below, so one
small comment about that.
<snip>
> +/* Test that of_overlay_apply_kunit() cleans up after the test is finished */
> +static void of_overlay_apply_kunit_cleanup(struct kunit *test)
> +{
> + struct device *dev;
> + struct device_node *np;
> +
> + KUNIT_ASSERT_EQ(test, 0,
> + of_overlay_apply_kunit(test, kunit_overlay_test));
> +
> + np = of_find_node_by_name(NULL, kunit_node_name);
> + of_node_put(np); /* Not derefing 'np' after this */
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, np);
> +
> + dev = bus_find_device(&platform_bus_type, NULL, np, bus_match_np);
> + put_device(dev); /* Not derefing 'device' after this */
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
> +
> + /* Remove overlay */
> + kunit_cleanup(test);
Note: this cleans up *all* resources associated with `test`.
Right now, it's probably fine, but this probably isn't the safest approach.
Notably, two of the new/upcoming API changes rely on resource,
kunit/static_stub.h and kunit_add_action() [1].
Calling kunit_cleanup() undoes all the stubs and immediately triggers
all the actions.
Perhaps you can create your own local `struct kunit` like in [2]
E.g.
struct kunit subtest; // not sure what to call this...
kunit_init_test(&subtest, "fake test", NULL);
/* use subtest */
kunit_cleanup(&subtest);
There's also already-submitted code doing similar things in
lib/kunit/kunit-test.c you can look at, but it's in init/exit funcs.
See kunit_resource_test_init() and kunit_resource_test_exit().
[1] https://lore.kernel.org/linux-kselftest/20230331080411.981038-2-davidgow@google.com/
[2] https://lore.kernel.org/linux-kselftest/20230403201930.2019419-1-rmoar@google.com/
Daniel
Powered by blists - more mailing lists