From: Maxime Ripard <mripard@kernel.org>
To: Luca Ceresoli <luca.ceresoli@bootlin.com>
Cc: "Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Jonathan Corbet" <corbet@lwn.net>,
"Andrzej Hajda" <andrzej.hajda@intel.com>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Robert Foss" <rfoss@kernel.org>,
"Laurent Pinchart" <Laurent.pinchart@ideasonboard.com>,
"Jonas Karlman" <jonas@kwiboo.se>,
"Jernej Skrabec" <jernej.skrabec@gmail.com>,
"Anusha Srivatsa" <asrivats@redhat.com>,
"Paul Kocialkowski" <paulk@sys-base.io>,
"Dmitry Baryshkov" <lumag@kernel.org>,
"Hervé Codina" <herve.codina@bootlin.com>,
"Hui Pu" <Hui.Pu@gehealthcare.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 2/2] drm/tests: bridge: add a KUnit test for devm_drm_bridge_alloc()
Date: Mon, 14 Apr 2025 17:49:16 +0200 [thread overview]
Message-ID: <20250414-misty-hungry-woodlouse-dbbd64@houat> (raw)
In-Reply-To: <20250409-drm-bridge-alloc-doc-test-v7-2-a3ca4b97597f@bootlin.com>
[-- Attachment #1: Type: text/plain, Size: 3182 bytes --]
Hi,
On Wed, Apr 09, 2025 at 04:50:35PM +0200, Luca Ceresoli wrote:
> Add a basic KUnit test for the newly introduced drm_bridge_alloc().
>
> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
>
> ---
>
> Changed in v7:
> - rebase on current drm-misc-next, which now has a drm_bridge_test.c file
> - cleanup commit message
>
> Changed in v6:
> - update to new devm_drm_bridge_alloc() API
> - remove drm_test_drm_bridge_put test, not straightforward to write with
> the new API and the current notification mechanism
> - do not allocate a drm_device: a bridge is allocated without one
> - rename some identifiers for easier code reading
>
> This patch was added in v5.
> ---
> drivers/gpu/drm/tests/drm_bridge_test.c | 60 +++++++++++++++++++++++++++++++++
> 1 file changed, 60 insertions(+)
>
> diff --git a/drivers/gpu/drm/tests/drm_bridge_test.c b/drivers/gpu/drm/tests/drm_bridge_test.c
> index ff88ec2e911c9cc9a718483f09d4c764f45f991a..87fb64744b67f0780457a546aba77ba945a0ce67 100644
> --- a/drivers/gpu/drm/tests/drm_bridge_test.c
> +++ b/drivers/gpu/drm/tests/drm_bridge_test.c
> @@ -8,6 +8,7 @@
> #include <drm/drm_bridge_helper.h>
> #include <drm/drm_kunit_helpers.h>
>
> +#include <kunit/device.h>
> #include <kunit/test.h>
>
> struct drm_bridge_init_priv {
> @@ -407,11 +408,70 @@ static struct kunit_suite drm_bridge_helper_reset_crtc_test_suite = {
> .test_cases = drm_bridge_helper_reset_crtc_tests,
> };
>
> +struct drm_bridge_alloc_test_ctx {
> + struct device *dev;
> +};
You don't need a struct there then, you can just pass the device pointer.
> +/*
> + * Mimick the typical struct defined by a bridge driver, which embeds a
> + * bridge plus other fields.
> + */
> +struct dummy_drm_bridge {
> + int dummy; // ensure we test non-zero @bridge offset
> + struct drm_bridge bridge;
> +};
drm_bridge_init_priv gives you that already.
> +static const struct drm_bridge_funcs drm_bridge_dummy_funcs = {
> +};
> +
> +static int drm_test_bridge_alloc_init(struct kunit *test)
> +{
> + struct drm_bridge_alloc_test_ctx *ctx;
> +
> + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
> +
> + ctx->dev = kunit_device_register(test, "drm-bridge-dev");
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->dev);
> +
> + test->priv = ctx;
> +
> + return 0;
> +}
> +
> +/*
> + * Test that the allocation and initialization of a bridge works as
> + * expected and doesn't report any error.
> + */
> +static void drm_test_drm_bridge_alloc(struct kunit *test)
> +{
> + struct drm_bridge_alloc_test_ctx *ctx = test->priv;
> + struct dummy_drm_bridge *dummy;
> +
> + dummy = devm_drm_bridge_alloc(ctx->dev, struct dummy_drm_bridge, bridge,
> + &drm_bridge_dummy_funcs);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dummy);
Why did you need the dummy value in dummy_drm_bridge if you're not using
it?
We'd need a couple more tests, in particular some to make sure the
bridge pointer is properly cleaned up when the device goes away, but not
when we have called drm_bridge_get pointer on it, etc.
Maxime
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2025-04-14 15:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 14:50 [PATCH v7 0/2] drm/bridge: add docs and kunit test for devm_drm_bridge_alloc() Luca Ceresoli
2025-04-09 14:50 ` [PATCH v7 1/2] drm/bridge: documentat bridge allocation and lifecycle Luca Ceresoli
2025-04-14 15:40 ` Maxime Ripard
2025-04-15 11:22 ` Luca Ceresoli
2025-04-09 14:50 ` [PATCH v7 2/2] drm/tests: bridge: add a KUnit test for devm_drm_bridge_alloc() Luca Ceresoli
2025-04-14 15:49 ` Maxime Ripard [this message]
2025-04-15 11:22 ` Luca Ceresoli
2025-05-15 8:11 ` Maxime Ripard
2025-05-16 15:38 ` Luca Ceresoli
2025-05-22 15:53 ` 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=20250414-misty-hungry-woodlouse-dbbd64@houat \
--to=mripard@kernel.org \
--cc=Hui.Pu@gehealthcare.com \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=andrzej.hajda@intel.com \
--cc=asrivats@redhat.com \
--cc=corbet@lwn.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=herve.codina@bootlin.com \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=lumag@kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=neil.armstrong@linaro.org \
--cc=paulk@sys-base.io \
--cc=rfoss@kernel.org \
--cc=simona@ffwll.ch \
--cc=thomas.petazzoni@bootlin.com \
--cc=tzimmermann@suse.de \
/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