[PATCH 3/8] kunit: Add test managed platform_device/driver APIs
Maxime Ripard
maxime at cerno.tech
Fri Mar 3 06:35:28 PST 2023
On Fri, Mar 03, 2023 at 03:15:31PM +0800, David Gow wrote:
> On Thu, 2 Mar 2023 at 09:38, Stephen Boyd <sboyd at kernel.org> wrote:
> >
> > Introduce KUnit resource wrappers around platform_driver_register(),
> > platform_device_alloc(), and platform_device_add() so that test authors
> > can register platform drivers/devices from their tests and have the
> > drivers/devices automatically be unregistered when the test is done.
> >
> > This makes test setup code simpler when a platform driver or platform
> > device is needed. Add a few test cases at the same time to make sure the
> > APIs work as intended.
> >
> > Cc: Brendan Higgins <brendan.higgins at linux.dev>
> > Cc: David Gow <davidgow at google.com>
> > Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
> > Cc: "Rafael J. Wysocki" <rafael at kernel.org>
> > Signed-off-by: Stephen Boyd <sboyd at kernel.org>
> > ---
> >
> > Should this be moved to drivers/base/ and called platform_kunit.c?
> > The include/kunit/platform_driver.h could also be
> > kunit/platform_device.h to match linux/platform_device.h if that is more
> > familiar.
>
> DRM has a similar thing already (albeit with a root_device, which is
> more common with KUnit tests generally):
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/drm/drm_kunit_helpers.h
>
> But that's reasonably drm-specific, so it makes sense that it lives
> with DRM stuff. platform_device is a bit more generic.
I'd be very happy to get something from the core to address the same
thing.
I think the main thing we needed that isn't covered by this patch is we
wanted the device to be bound to its driver, so with probe being called
before calling the test (see 57a84a97bbda).
Maxime
More information about the linux-um
mailing list