Hi,

On Tue, Oct 24, 2023 at 04:09:58PM -0300, Carlos Eduardo Gallo Filho wrote:
> Add a single KUnit test case for the drm_framebuffer_lookup function.
> 
> Signed-off-by: Carlos Eduardo Gallo Filho <gcar...@disroot.org>
> ---
> v2:
>   - Reorder kunit cases alphabetically.
>   - Replace drm_mode_object_add() call to drm_framebuffer_init().
>   - Rely on drm_kunit_helper_alloc_device() for mock initialization.
> ---
>  drivers/gpu/drm/tests/drm_framebuffer_test.c | 26 ++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c 
> b/drivers/gpu/drm/tests/drm_framebuffer_test.c
> index a63f30985f75..fb9589dd8aed 100644
> --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
> +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
> @@ -526,10 +526,36 @@ static void drm_test_framebuffer_cleanup(struct kunit 
> *test)
>       KUNIT_ASSERT_EQ(test, dev->mode_config.num_fb, 0);
>  }
>  
> +static void drm_test_framebuffer_lookup(struct kunit *test)

Again, documentation.

> +{
> +     struct drm_framebuffer_test_priv *priv = test->priv;
> +     struct drm_device *dev = &priv->dev;
> +     struct drm_format_info format = { };
> +     struct drm_framebuffer fb1 = { .dev = dev, .format = &format };
> +     struct drm_framebuffer *fb2;
> +     uint32_t id = 0;
> +     int ret;
> +
> +     ret = drm_framebuffer_init(dev, &fb1, NULL);
> +     KUNIT_ASSERT_EQ(test, ret, 0);
> +     id = fb1.base.id;
> +
> +     /* Looking for fb1 */
> +     fb2 = drm_framebuffer_lookup(dev, NULL, id);
> +     KUNIT_EXPECT_PTR_EQ(test, fb2, &fb1);

I would rename the variables to expected_fb and fb (or returned_fb);

You also need to call drm_framebuffer_put on fb2.

> +     /* Looking for an inexistent framebuffer */
> +     fb2 = drm_framebuffer_lookup(dev, NULL, id + 1);
> +     KUNIT_EXPECT_NULL(test, fb2);

This should be a separate test

Maxime

Attachment: signature.asc
Description: PGP signature

Reply via email to