All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime@cerno.tech>
To: David Gow <davidgow@google.com>
Cc: Matti Vaittinen <mazziesaccount@gmail.com>,
	Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Brendan Higgins <brendan.higgins@linux.dev>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	kunit-dev@googlegroups.com, Stephen Boyd <sboyd@kernel.org>,
	Jonathan Cameron <jic23@kernel.org>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH v5 1/8] drivers: kunit: Generic helpers for test device creation
Date: Thu, 23 Mar 2023 11:07:44 +0100	[thread overview]
Message-ID: <20230323100744.qirdtwsd327apau7@houat> (raw)
In-Reply-To: <CABVgOS=KUg+18wJe=O29tgOB0tQghAk030kONEm5fOzJHgKLgw@mail.gmail.com>

Hi David,

On Thu, Mar 23, 2023 at 03:30:34PM +0800, David Gow wrote:
> I think the questions we therefore need to answer are:
> - Do we specifically need a platform_device (or, any other specific
> device struct), or would any old struct device work? I can see why we
> would need a platform device for cases where we're testing things like
> device-tree properties (or, in the future, having e.g. USB-specific
> helpers which create usb_device). Most tests just use
> root_device_register() thus far, though.
> - What helpers do we need to make creating, using, and cleaning up
> these devices as simple as possible.
> 
> I think that in this particular case, we don't actually need a struct
> platform_device. Replacing these helpers with simple calls to
> root_device_register() and root_device_unregister() seems to work fine
> with this patch series for me. (It does break the
> drm_test_managed_run_action test, though.) So I don't think having
> these helpers actually help this series at the moment.

I'm not sure that a root_device is a good option, see below.

> That being said, if they used the KUnit resource system to
> automatically clean up the device when the test is finished (or
> otherwise exits), that would seem like a real advantage. The clk and
> drm examples both do this, and I'm hoping to add an API to make it
> even simpler going forward. (With the work-in-progress API described
> here[1], the whole thing should boil down to "struct device *dev =
> root_device_register(name); kunit_defer(root_device_unregister,
> dev);".)

Oh, yes, please make it happen :)

The current API is a bit of a pain compared to other managed APIs like
devm or drmm.

> So, I guess we have three cases we need to look at:
> - A test just needs any old struct device. Tests thus far have
> hardcoded, or had their own wrappers around root_device_register() for
> this.
> - A test needs a device attached to a bus (but doesn't care which
> bus). Thus far, people have used struct platform_device for this (see
> the DRM helpers, which use a platform device for managed resource
> tests[2]). Maybe the right solution here is something like a struct
> kunit_device?
> - A test needs a device attached to a specific bus. We'll probably
> need some more detailed faking of that bus. This covers cases like
> having fake USB devices, devicetree integration, etc.

Yeah, from the current discussion on the IIO and clk patchsets, and what
we've done in DRM, I guess there's two major use cases:

  * You test an (isolated) function that takes a device as an argument.
    Here you probably don't really care about what the device is as long
    as you can provide one. This is what is being done for the DRM
    helpers at the moment, even though it's not really isolated. The
    device is essentially mocked. This could be your points 1 and 2.

  * You want to probe the driver with a fake context. The device and
    drivers are very much real, but the device tree (or whatever) is
    mocked. This is what the clocks patches from Stephen are doing. This
    could be covered by your point 3.

> I'd suggest that, for the majority of cases which only care about the
> first case, let's just use root_device_register() directly, or have a
> thin wrapper like the old root_device-based version of the DRM
> helpers[3]. This will probable serve us well enough while we work out
> how to handle the other two cases properly (which is already being
> looked at for the CLK/DeviceTree patches and the DRM stuff).

I disagree, and I think your cases 1 and 2 should be merged. We were
initially using a root_device in DRM. We had to switch to
platform_device (but actually any device attached to a bus) because a
root device isn't attached to a bus and thus the devm resources are
never freed.

When a function takes a device as an argument, there's a good chance
that it will use devm nowadays, so we ended up exhausting resources
pools (like IDs iirc) when running a lot of tests in sequence.

So yeah, I think you can't just assume that a root device will do even
for a true unit test that would test an isolated function. It either
needs to be tied to a bus, or we need to force the devm resource release
when the root device is removed somehow.

Maxime

  parent reply	other threads:[~2023-03-23 10:07 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-22  9:05 [PATCH v5 0/8] Support ROHM BU27034 ALS sensor Matti Vaittinen
2023-03-22  9:05 ` Matti Vaittinen
2023-03-22  9:05 ` [PATCH v5 1/8] drivers: kunit: Generic helpers for test device creation Matti Vaittinen
2023-03-22 12:04   ` Greg Kroah-Hartman
2023-03-22 12:07   ` Greg Kroah-Hartman
2023-03-22 13:48     ` Matti Vaittinen
2023-03-22 18:57       ` Greg Kroah-Hartman
2023-03-23  7:17         ` Vaittinen, Matti
2023-03-23  8:58           ` Greg Kroah-Hartman
2023-03-23  9:20             ` Matti Vaittinen
2023-03-23 10:25               ` Greg Kroah-Hartman
2023-03-23 10:43                 ` Matti Vaittinen
2023-03-23 10:01             ` Matti Vaittinen
2023-03-23 10:27               ` Greg Kroah-Hartman
2023-03-23 11:00                 ` Matti Vaittinen
2023-03-23 10:12         ` Maxime Ripard
2023-03-23 10:21           ` Greg Kroah-Hartman
2023-03-23 12:16             ` Matti Vaittinen
2023-03-23 12:29               ` Maxime Ripard
2023-03-23 13:02                 ` Matti Vaittinen
2023-03-23 16:36                   ` Maxime Ripard
2023-03-24  6:11                     ` Matti Vaittinen
2023-03-24  6:34                       ` David Gow
2023-03-24  6:51                         ` Matti Vaittinen
2023-03-24  9:52                           ` David Gow
2023-03-24 10:05                             ` Matti Vaittinen
2023-03-24 10:17                               ` Matti Vaittinen
2023-03-25  4:35                                 ` David Gow
2023-03-25  7:26                                   ` Matti Vaittinen
2023-03-24 12:46                         ` Maxime Ripard
2023-03-24 12:31                       ` Maxime Ripard
2023-03-25  5:40                         ` David Gow
2023-03-29 19:43                           ` Maxime Ripard
2023-03-25 17:50                         ` Jonathan Cameron
2023-03-26 17:16                           ` Lars-Peter Clausen
2023-04-01 15:30                             ` Jonathan Cameron
2023-03-29 19:46                           ` Maxime Ripard
2023-04-01 15:36                             ` Jonathan Cameron
2023-03-24 12:36             ` Maxime Ripard
2023-03-24 12:43               ` Greg Kroah-Hartman
2023-03-24 13:02                 ` Maxime Ripard
2023-03-24 13:42                   ` Greg Kroah-Hartman
2023-03-22 12:08   ` Greg Kroah-Hartman
2023-03-23  7:30   ` David Gow
2023-03-23  8:35     ` Matti Vaittinen
2023-03-23  9:02     ` Greg Kroah-Hartman
2023-03-23 10:07     ` Maxime Ripard [this message]
2023-03-22  9:06 ` [PATCH v5 2/8] drm/tests: helpers: Use generic helpers Matti Vaittinen
2023-03-22  9:06   ` Matti Vaittinen
2023-03-22  9:06 ` [PATCH v5 3/8] dt-bindings: iio: light: Support ROHM BU27034 Matti Vaittinen
2023-03-22  9:06 ` [PATCH v5 4/8] iio: light: Add gain-time-scale helpers Matti Vaittinen
2023-03-22  9:07 ` [PATCH v5 5/8] iio: test: test " Matti Vaittinen
2023-03-24  6:29   ` Matti Vaittinen
2023-03-22  9:07 ` [PATCH v5 6/8] MAINTAINERS: Add IIO " Matti Vaittinen
2023-03-22  9:07 ` [PATCH v5 7/8] iio: light: ROHM BU27034 Ambient Light Sensor Matti Vaittinen
2023-03-26 16:19   ` Jonathan Cameron
2023-03-27  7:16     ` Vaittinen, Matti
2023-03-22  9:08 ` [PATCH v5 8/8] MAINTAINERS: Add ROHM BU27034 Matti Vaittinen
2023-03-22 10:01 ` [PATCH v5 0/8] Support ROHM BU27034 ALS sensor Andy Shevchenko
2023-03-22 10:01   ` Andy Shevchenko
2023-03-22 10:34   ` Javier Martinez Canillas
2023-03-22 10:34     ` Javier Martinez Canillas
2023-03-22 10:59     ` Matti Vaittinen
2023-03-22 10:59       ` Matti Vaittinen
2023-03-22 11:02       ` Andy Shevchenko
2023-03-22 11:02         ` Andy Shevchenko
2023-03-23  9:28       ` Maxime Ripard
2023-03-23  9:28         ` Maxime Ripard

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=20230323100744.qirdtwsd327apau7@houat \
    --to=maxime@cerno.tech \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=jic23@kernel.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=mazziesaccount@gmail.com \
    --cc=rafael@kernel.org \
    --cc=sboyd@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.