[PATCH 06/10] drm/tests: Add test for drm_framebuffer_lookup()
Maira Canal
mairacanal at riseup.net
Fri Sep 8 20:33:52 UTC 2023
Hi Carlos,
On 9/4/23 15:52, Carlos wrote:
> Hi Maíra,
>
> On 8/26/23 11:13, Maíra Canal wrote:
>> Hi Carlos,
>>
>> On 8/25/23 13:07, Carlos Eduardo Gallo Filho wrote:
>>> Add a single KUnit test case for the drm_framebuffer_lookup function.
>>>
>>> Signed-off-by: Carlos Eduardo Gallo Filho <gcarlos at disroot.org>
>>> ---
>>> drivers/gpu/drm/tests/drm_framebuffer_test.c | 28 ++++++++++++++++++++
>>> 1 file changed, 28 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c
>>> b/drivers/gpu/drm/tests/drm_framebuffer_test.c
>>> index 16d9cf4bed88..3d14d35b4c4d 100644
>>> --- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
>>> +++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
>>> @@ -8,6 +8,7 @@
>>> #include <kunit/test.h>
>>> #include <drm/drm_device.h>
>>> +#include <drm/drm_drv.h>
>>> #include <drm/drm_mode.h>
>>> #include <drm/drm_framebuffer.h>
>>> #include <drm/drm_fourcc.h>
>>> @@ -370,6 +371,10 @@ static int drm_framebuffer_test_init(struct
>>> kunit *test)
>>> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock);
>>> dev = &mock->dev;
>>> + dev->driver = kunit_kzalloc(test, sizeof(*dev->driver),
>>> GFP_KERNEL);
>>> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev->driver);
>>> +
>>> + idr_init_base(&dev->mode_config.object_idr, 1);
>>
>> Shouldn't we start to use drm_framebuffer_init()?
> Do you mean about replace drm_mode_object_add() to drm_framebuffer_init()?
Yeah.
> If so, what could be the advantages of using it? It seems to just do the
> same of drm_mode_object_add() (by actually calling it) but doing some more
> things which is not really needed by this test (like adding fb to device
> fb_list and etc). Am I missing something important?
I just suggested to minimize open-code in the tests. If we use the
function, we are incentivizing the usage of common code, which leads
to improved maintenance and less code repetition.
Best Regards,
- Maíra
>
> Thanks,
> Carlos
>
>> Best Regards,
>> - Maíra
>>
>>> mutex_init(&dev->mode_config.fb_lock);
>>> INIT_LIST_HEAD(&dev->mode_config.fb_list);
>>> dev->mode_config.num_fb = 0;
>>> @@ -530,8 +535,31 @@ 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)
>>> +{
>>> + struct drm_mock *mock = test->priv;
>>> + struct drm_device *dev = &mock->dev;
>>> + struct drm_framebuffer fb1 = { };
>>> + struct drm_framebuffer *fb2;
>>> + uint32_t id = 0;
>>> + int ret;
>>> +
>>> + ret = drm_mode_object_add(dev, &fb1.base, DRM_MODE_OBJECT_FB);
>>> + 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);
>>> +
>>> + /* Looking for an inexistent framebuffer */
>>> + fb2 = drm_framebuffer_lookup(dev, NULL, id + 1);
>>> + KUNIT_EXPECT_NULL(test, fb2);
>>> +}
>>> +
>>> static struct kunit_case drm_framebuffer_tests[] = {
>>> KUNIT_CASE(drm_test_framebuffer_cleanup),
>>> + KUNIT_CASE(drm_test_framebuffer_lookup),
>>> KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported),
>>> KUNIT_CASE_PARAM(drm_test_framebuffer_check_src_coords,
>>> check_src_coords_gen_params),
>>> KUNIT_CASE_PARAM(drm_test_framebuffer_create,
>>> drm_framebuffer_create_gen_params),
More information about the dri-devel
mailing list