Increase coverage on drm_framebuffer.c
Subsystems (2)
cover Increase coverage on drm_framebuffer.c
This patchset includes new KUnit tests for 7 untested functions from drm_framebuffer.c and improvements to the existent one.
The first patch replace the use of dev_private member from drm_device mock on the existent test by embedding it into an outer struct containing a generic pointer.
The patches 2 and 3 extends the test of drm_internal_framebuffer_create() by creating a new test case and adding new parameters to the existent case.
Finally, the remainder of this set contains 7 new test cases, one for each of the follow functions:
- drm_framebuffer_check_src_coords()
- drm_framebuffer_cleanup()
- drm_framebuffer_lookup()
- drm_framebuffer_init()
- drm_framebuffer_free()
- drm_mode_addfb2()
- drm_fb_release()
---
Carlos Eduardo Gallo Filho (10):
drm/tests: Stop using deprecated dev_private member on drm_framebuffer
tests
drm/tests: Add parameters to the drm_test_framebuffer_create test drm/tests: Add test case for drm_internal_framebuffer_create() drm/tests: Add test for drm_framebuffer_check_src_coords() drm/tests: Add test for drm_framebuffer_cleanup() drm/tests: Add test for drm_framebuffer_lookup() drm/tests: Add test for drm_framebuffer_init()
drm/tests: Add test for drm_framebuffer_free()
drm/tests: Add test for drm_mode_addfb2()
drm/tests: Add test for drm_fb_release()
drivers/gpu/drm/drm_framebuffer.c | 1 + drivers/gpu/drm/tests/drm_framebuffer_test.c | 563 ++++++++++++++++++- 2 files changed, 553 insertions(+), 11 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/10 drm/tests: Stop using deprecated dev_private member on drm_framebuffer tests
The dev_private member of drm_device is deprecated and its use should be avoided. Stop using it by embedding the drm_device onto a mock struct with a void pointer like dev_private, using it instead.
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 29 +++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/gpu/drm/tests/drm_framebuffer_test.c +19 -10
@@ -317,11 +317,17 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { }, }; +struct drm_mock { +struct drm_device dev; +void *private; +}; +static struct drm_framebuffer *fb_create_mock (struct drm_device *dev,struct drm_file *file_priv,const struct drm_mode_fb_cmd2 *mode_cmd) { -int *buffer_created = dev->dev_private; +struct drm_mock *mock =container_of (dev,typeof (*mock), dev); +int *buffer_created = mock->private; *buffer_created =1 ;return ERR_PTR (-EINVAL ); }
@@ -332,16 +338,18 @@ static struct drm_mode_config_funcs mock_config_funcs = {static int drm_framebuffer_test_init (struct kunit *test) { -struct drm_device *mock; +struct drm_mock *mock; +struct drm_device *dev; mock =kunit_kzalloc (test,sizeof (*mock),GFP_KERNEL );KUNIT_ASSERT_NOT_ERR_OR_NULL (test, mock); + dev = &mock->dev; - mock->mode_config.min_width =MIN_WIDTH ; - mock->mode_config.max_width =MAX_WIDTH ; - mock->mode_config.min_height =MIN_HEIGHT ; - mock->mode_config.max_height =MAX_HEIGHT ; - mock->mode_config.funcs = &mock_config_funcs; + dev->mode_config.min_width =MIN_WIDTH ; + dev->mode_config.max_width =MAX_WIDTH ; + dev->mode_config.min_height =MIN_HEIGHT ; + dev->mode_config.max_height =MAX_HEIGHT ; + dev->mode_config.funcs = &mock_config_funcs; test->priv = mock;return 0 ;
@@ -350,11 +358,12 @@ static int drm_framebuffer_test_init(struct kunit *test)static void drm_test_framebuffer_create (struct kunit *test) {const struct drm_framebuffer_test *params = test->param_value; -struct drm_device *mock = test->priv; +struct drm_mock *mock = test->priv; +struct drm_device *dev = &mock->dev;int buffer_created =0 ; - mock->dev_private = &buffer_created; -drm_internal_framebuffer_create (mock, ¶ms->cmd,NULL ); + mock->private = &buffer_created; +drm_internal_framebuffer_create (dev, ¶ms->cmd,NULL );KUNIT_EXPECT_EQ (test, params->buffer_created, buffer_created); }
Signature · 1 line
2.41.0
Re: [PATCH 01/10] drm/tests: Stop using deprecated dev_private member on drm_framebuffer tests
Hi Carlos,
Quoted 14 lines · Carlos Eduardo Gallo Filho
The
dev_privatemember ofdrm_deviceis deprecated and its use should be avoided. Stop using it by embedding thedrm_deviceonto a mock struct with a void pointer likedev_private, using it instead.Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 29 +++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-)drivers/gpu/drm/tests/drm_framebuffer_test.c +0
-0
drivers/gpu/drm/tests/drm_framebuffer_test.c static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { · line 323
Quoted 7 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +4
-0@@ -317,11 +317,17 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { }, }; +struct drm_mock { +struct drm_device dev; +void *private; +};
Could we call it drm_device_mock or maybe drm_framebuffer_mock? I believe that drm_mock its a bit generic.
Also, wouldn't be better to create a int buffer_created variable instead of creating a void *private?
Best Regards,
- Maíra
Quoted 52 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +15
-10+static struct drm_framebuffer *fb_create_mock (struct drm_device *dev,struct drm_file *file_priv,const struct drm_mode_fb_cmd2 *mode_cmd) { -int *buffer_created = dev->dev_private; +struct drm_mock *mock =container_of (dev,typeof (*mock), dev); +int *buffer_created = mock->private; *buffer_created =1 ;return ERR_PTR (-EINVAL ); }@@ -332,16 +338,18 @@ static struct drm_mode_config_funcs mock_config_funcs = {static int drm_framebuffer_test_init (struct kunit *test) { -struct drm_device *mock; +struct drm_mock *mock; +struct drm_device *dev; mock =kunit_kzalloc (test,sizeof (*mock),GFP_KERNEL );KUNIT_ASSERT_NOT_ERR_OR_NULL (test, mock); + dev = &mock->dev; - mock->mode_config.min_width =MIN_WIDTH ; - mock->mode_config.max_width =MAX_WIDTH ; - mock->mode_config.min_height =MIN_HEIGHT ; - mock->mode_config.max_height =MAX_HEIGHT ; - mock->mode_config.funcs = &mock_config_funcs; + dev->mode_config.min_width =MIN_WIDTH ; + dev->mode_config.max_width =MAX_WIDTH ; + dev->mode_config.min_height =MIN_HEIGHT ; + dev->mode_config.max_height =MAX_HEIGHT ; + dev->mode_config.funcs = &mock_config_funcs; test->priv = mock;return 0 ;@@ -350,11 +358,12 @@ static int drm_framebuffer_test_init(struct kunit *test)static void drm_test_framebuffer_create (struct kunit *test) {const struct drm_framebuffer_test *params = test->param_value; -struct drm_device *mock = test->priv; +struct drm_mock *mock = test->priv; +struct drm_device *dev = &mock->dev;int buffer_created =0 ; - mock->dev_private = &buffer_created; -drm_internal_framebuffer_create (mock, ¶ms->cmd,NULL ); + mock->private = &buffer_created; +drm_internal_framebuffer_create (dev, ¶ms->cmd,NULL );KUNIT_EXPECT_EQ (test, params->buffer_created, buffer_created); }
Re: [PATCH 01/10] drm/tests: Stop using deprecated dev_private member on drm_framebuffer tests
Hi Maíra, thanks for reviewing!
Quoted 12 lines · Maíra Canal
Hi Carlos,
Quoted 9 lines · Carlos Eduardo Gallo Filho
The
dev_privatemember ofdrm_deviceis deprecated and its use should be avoided. Stop using it by embedding thedrm_deviceonto a mock struct with a void pointer likedev_private, using it instead.Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>---
drivers/gpu/drm/tests/drm_framebuffer_test.c| 29 +++++++++++++-------1 file changed, 19 insertions(+), 10 deletions(-)
Quoted 15 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c static const struct drm_framebuffer_test · line 323
Quoted 12 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +3
-0@@ -317,11 +317,17 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { }, }; +struct drm_mock { + struct drm_device dev; + void *private; +};Could we call it
drm_device_mockor maybedrm_framebuffer_mock? I believe thatdrm_mockits a bit generic.
I could agree that it's a bit generic. Exclusively for this patch, drm_device_mock could be a good candidate, but later in this patchset I use that same struct to allocate a drm_file mock too, so I think that the name must at least fit well to it too. In that case I would prefer naming it drm_framebuffer_mock, but doesn't it looks like a name for a drm_framebuffer mock, which isn't the case? I'm trying to figure out another name to it but I'm not able to do that.
Quoted 2 lines
Also, wouldn't be better to create a
int buffer_createdvariable instead of creating avoid *private?
Again, I could agree with that for this patch only, but the void *private is used in that way in some other tests from this series too. Anyway, I noticed that all but one test is using it to "return" integer (boolean, to be honest) values from mocked functions, except by the fb_create_addfb2_mock function on patch 9, that use it to return a reference to a drm_framebuffer. So, in that case,do you think it would be better to have explicitly some boolean on the struct instead of this void pointer? If so, should I keep that void pointer for fb_create_addfb2_mock use or should I replace it to a drm_framebuffer pointer?
By the way, I guess that having a void pointer on a general purpose struct like that would let further tests to adapt it to its own use, but I don't really know if it worth the effort.
Thanks,
Carlos
Quoted 51 lines
Best Regards,
- MaíraQuoted 48 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +3
-1+ static struct drm_framebuffer *fb_create_mock(struct drm_device *dev, struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd) { - int *buffer_created = dev->dev_private; + struct drm_mock *mock = container_of(dev, typeof(*mock), dev); + int *buffer_created = mock->private; *buffer_created = 1; return ERR_PTR(-EINVAL);}
drivers/gpu/drm/tests/drm_framebuffer_test.c +12
-7@@ -332,16 +338,18 @@ static struct drm_mode_config_funcs mock_config_funcs = { static int drm_framebuffer_test_init(struct kunit *test) { - struct drm_device *mock; + struct drm_mock *mock; + struct drm_device *dev; mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); + dev = &mock->dev; - mock->mode_config.min_width = MIN_WIDTH; - mock->mode_config.max_width = MAX_WIDTH; - mock->mode_config.min_height = MIN_HEIGHT; - mock->mode_config.max_height = MAX_HEIGHT; - mock->mode_config.funcs = &mock_config_funcs; + dev->mode_config.min_width = MIN_WIDTH; + dev->mode_config.max_width = MAX_WIDTH; + dev->mode_config.min_height = MIN_HEIGHT; + dev->mode_config.max_height = MAX_HEIGHT; + dev->mode_config.funcs = &mock_config_funcs; test->priv = mock; return 0;@@ -350,11 +358,12 @@ static int drm_framebuffer_test_init(struct kunit *test) static void drm_test_framebuffer_create(struct kunit *test) { const struct drm_framebuffer_test *params = test->param_value; - struct drm_device *mock = test->priv; + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; int buffer_created = 0; - mock->dev_private = &buffer_created; - drm_internal_framebuffer_create(mock, ¶ms->cmd, NULL); + mock->private = &buffer_created; + drm_internal_framebuffer_create(dev, ¶ms->cmd, NULL); KUNIT_EXPECT_EQ(test, params->buffer_created, buffer_created); }
PATCH 2/10 drm/tests: Add parameters to the drm_test_framebuffer_create test
In reply to Carlos Eduardo Gallo FilhoExtend the existing test case to cover:
1. Invalid flag atribute in the struct drm_mode_fb_cmd2.
2. Pixel format which requires non-linear modifier with DRM_FORMAT_MOD_LINEAR set.
3. Non-zero buffer offset for an unused plane
Also replace strcpy to strscpy on test_to_desc for improved security and reliability.
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 23 +++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/gpu/drm/tests/drm_framebuffer_test.c +22 -1
@@ -19,6 +19,8 @@#define MIN_HEIGHT 4#define MAX_HEIGHT 4096 +#define DRM_MODE_FB_INVALID BIT(2) +struct drm_framebuffer_test {int buffer_created;struct drm_mode_fb_cmd2 cmd;
@@ -83,6 +85,18 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { .pitches = { 4 * MAX_WIDTH, 0, 0 }, } }, +{ .buffer_created = 0, .name = "ABGR8888 Non-zero buffer offset for unused plane", + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, + .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, UINT_MAX / 2, 0 }, + .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS, + } +}, +{ .buffer_created = 0, .name = "ABGR8888 Invalid flag", + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, + .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 }, + .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_INVALID, + } +}, { .buffer_created = 1, .name = "ABGR8888 Set DRM_MODE_FB_MODIFIERS without modifiers", .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 },
@@ -262,6 +276,13 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) }, } }, +{ .buffer_created = 0, .name = "YUV420_10BIT Invalid modifier(DRM_FORMAT_MOD_LINEAR)", + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YUV420_10BIT, + .handles = { 1, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS, + .modifier = { DRM_FORMAT_MOD_LINEAR, 0, 0 }, + .pitches = { MAX_WIDTH, 0, 0 }, + } +}, { .buffer_created = 1, .name = "X0L2 Normal sizes", .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_X0L2, .handles = { 1, 0, 0 }, .pitches = { 1200, 0, 0 }
@@ -369,7 +390,7 @@ static void drm_test_framebuffer_create(struct kunit *test)static void drm_framebuffer_test_to_desc (const struct drm_framebuffer_test *t,char *desc) { -strcpy (desc, t->name); +strscpy (desc, t->name,KUNIT_PARAM_DESC_SIZE ); } KUNIT_ARRAY_PARAM(drm_framebuffer_create, drm_framebuffer_create_cases,
Signature · 1 line
2.41.0
Re: [PATCH 02/10] drm/tests: Add parameters to the drm_test_framebuffer_create test
Hi Carlos,
Quoted 61 lines · Carlos Eduardo Gallo Filho
Extend the existing test case to cover:
1. Invalid flag atribute in the structdrm_mode_fb_cmd2.
2. Pixel format which requires non-linear modifier withDRM_FORMAT_MOD_LINEARset.
3. Non-zero buffer offset for an unused planeAlso replace strcpy to strscpy on
test_to_descfor improved security and reliability.Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 23 +++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/tests/drm_framebuffer_test.c +21
-0@@ -19,6 +19,8 @@#define MIN_HEIGHT 4#define MAX_HEIGHT 4096 +#define DRM_MODE_FB_INVALID BIT(2) +struct drm_framebuffer_test {int buffer_created;struct drm_mode_fb_cmd2 cmd;@@ -83,6 +85,18 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { .pitches = { 4 * MAX_WIDTH, 0, 0 }, } }, +{ .buffer_created = 0, .name = "ABGR8888 Non-zero buffer offset for unused plane", + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, + .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, UINT_MAX / 2, 0 }, + .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS, + } +}, +{ .buffer_created = 0, .name = "ABGR8888 Invalid flag", + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, + .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 }, + .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_INVALID, + } +}, { .buffer_created = 1, .name = "ABGR8888 Set DRM_MODE_FB_MODIFIERS without modifiers", .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 },@@ -262,6 +276,13 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) }, } }, +{ .buffer_created = 0, .name = "YUV420_10BIT Invalid modifier(DRM_FORMAT_MOD_LINEAR)", + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YUV420_10BIT, + .handles = { 1, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS, + .modifier = { DRM_FORMAT_MOD_LINEAR, 0, 0 }, + .pitches = { MAX_WIDTH, 0, 0 }, + } +}, { .buffer_created = 1, .name = "X0L2 Normal sizes", .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_X0L2, .handles = { 1, 0, 0 }, .pitches = { 1200, 0, 0 }
drivers/gpu/drm/tests/drm_framebuffer_test.c static void drm_test_framebuffer_create(struct kunit *test) · line 393
Quoted 5 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +1
-1@@ -369,7 +390,7 @@ static void drm_test_framebuffer_create(struct kunit *test)static void drm_framebuffer_test_to_desc (const struct drm_framebuffer_test *t,char *desc) { -strcpy (desc, t->name); +strscpy (desc, t->name,KUNIT_PARAM_DESC_SIZE );
I believe this change should be done in a separate patch.
Best Regards,
- Maíra
Quoted 3 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +0
-0} KUNIT_ARRAY_PARAM(drm_framebuffer_create, drm_framebuffer_create_cases,
PATCH 3/10 drm/tests: Add test case for drm_internal_framebuffer_create()
In reply to Carlos Eduardo Gallo FilhoIntroduce a test to cover the creation of framebuffer with modifier on a device that doesn't support it.
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/gpu/drm/tests/drm_framebuffer_test.c +28 -0
@@ -396,7 +396,35 @@ static void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, cKUNIT_ARRAY_PARAM (drm_framebuffer_create, drm_framebuffer_create_cases, drm_framebuffer_test_to_desc); +/* +* This test is very similar to drm_test_framebuffer_create, except that it +* set mock->mode_config.fb_modifiers_not_supported member to 1, covering +* the case of trying to create a framebuffer with modifiers without the +* device really supporting it. +*/ +static void drm_test_framebuffer_modifiers_not_supported (struct kunit *test) +{ +struct drm_mock *mock = test->priv; +struct drm_device *dev = &mock->dev; +int buffer_created =0 ; + +/* A valid cmd with modifier */ +struct drm_mode_fb_cmd2 cmd = { + .width =MAX_WIDTH , .height =MAX_HEIGHT , + .pixel_format =DRM_FORMAT_ABGR8888 , .handles = {1 ,0 ,0 }, + .offsets = {UINT_MAX /2 ,0 ,0 }, .pitches = {4 *MAX_WIDTH ,0 ,0 }, + .flags =DRM_MODE_FB_MODIFIERS , + }; + + mock->private = &buffer_created; + dev->mode_config.fb_modifiers_not_supported =1 ; + +drm_internal_framebuffer_create (dev, &cmd,NULL ); +KUNIT_EXPECT_EQ (test,0 , buffer_created); +} +static struct kunit_case drm_framebuffer_tests[] = { +KUNIT_CASE (drm_test_framebuffer_modifiers_not_supported),KUNIT_CASE_PARAM (drm_test_framebuffer_create, drm_framebuffer_create_gen_params), { } };
Signature · 1 line
2.41.0
Re: [PATCH 03/10] drm/tests: Add test case for drm_internal_framebuffer_create()
Hi Carlos,
Quoted 35 lines · Carlos Eduardo Gallo Filho
Introduce a test to cover the creation of framebuffer with modifier on a device that doesn't support it.
Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/gpu/drm/tests/drm_framebuffer_test.c +19
-0@@ -396,7 +396,35 @@ static void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, cKUNIT_ARRAY_PARAM (drm_framebuffer_create, drm_framebuffer_create_cases, drm_framebuffer_test_to_desc); +/* +* This test is very similar to drm_test_framebuffer_create, except that it +* set mock->mode_config.fb_modifiers_not_supported member to 1, covering +* the case of trying to create a framebuffer with modifiers without the +* device really supporting it. +*/ +static void drm_test_framebuffer_modifiers_not_supported (struct kunit *test) +{ +struct drm_mock *mock = test->priv; +struct drm_device *dev = &mock->dev; +int buffer_created =0 ; + +/* A valid cmd with modifier */ +struct drm_mode_fb_cmd2 cmd = { + .width =MAX_WIDTH , .height =MAX_HEIGHT , + .pixel_format =DRM_FORMAT_ABGR8888 , .handles = {1 ,0 ,0 }, + .offsets = {UINT_MAX /2 ,0 ,0 }, .pitches = {4 *MAX_WIDTH ,0 ,0 }, + .flags =DRM_MODE_FB_MODIFIERS , + };
drivers/gpu/drm/tests/drm_framebuffer_test.c static void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, c · line 427
Quoted 10 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +9
-0+ + mock->private = &buffer_created; + dev->mode_config.fb_modifiers_not_supported =1 ; + +drm_internal_framebuffer_create (dev, &cmd,NULL ); +KUNIT_EXPECT_EQ (test,0 , buffer_created); +} +static struct kunit_case drm_framebuffer_tests[] = { +KUNIT_CASE (drm_test_framebuffer_modifiers_not_supported),
Could we preserve alphabetical order?
Best Regards,
- Maíra
Quoted 3 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +0
-0KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), { } };
Re: [PATCH 03/10] drm/tests: Add test case for drm_internal_framebuffer_create()
Hi Maíra,
Quoted 47 lines · Maíra Canal
Hi Carlos,
Quoted 44 lines · Carlos Eduardo Gallo Filho
Introduce a test to cover the creation of framebuffer with modifier on a device that doesn't support it.
Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>---
drivers/gpu/drm/tests/drm_framebuffer_test.c| 28 ++++++++++++++++++++1 file changed, 28 insertions(+)drivers/gpu/drm/tests/drm_framebuffer_test.c +0
-0@@ -396,7 +396,35 @@ static void drm_framebuffer_test_to_desc(conststruct
drm_framebuffer_test*t, cKUNIT_ARRAY_PARAM(drm_framebuffer_create, drm_framebuffer_create_cases, drm_framebuffer_test_to_desc);
+/*
+ * This test is very similar todrm_test_framebuffer_create, except that it
+ * setmock->mode_config.fb_modifiers_not_supportedmember to 1, covering
+ * the case of trying to create a framebuffer with modifiers without the
+ * device really supporting it.
+ */
+static voiddrm_test_framebuffer_modifiers_not_supported(struct kunit *test)drivers/gpu/drm/tests/drm_framebuffer_test.c +10
-0+{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + int buffer_created = 0; + + /* A valid cmd with modifier */ + struct drm_mode_fb_cmd2 cmd = { + .width = MAX_WIDTH, .height = MAX_HEIGHT, + .pixel_format = DRM_FORMAT_ABGR8888, .handles = { 1, 0, 0 }, + .offsets = { UINT_MAX / 2, 0, 0 }, .pitches = { 4 *
MAX_WIDTH, 0, 0 },
+ .flags =DRM_MODE_FB_MODIFIERS,
+ };drivers/gpu/drm/tests/drm_framebuffer_test.c +4
-0+ + mock->private = &buffer_created; + dev->mode_config.fb_modifiers_not_supported = 1; +
Quoted 9 lines
Quoted 6 lines
+
drm_internal_framebuffer_create(dev, &cmd, NULL); +KUNIT_EXPECT_EQ(test, 0, buffer_created);drivers/gpu/drm/tests/drm_framebuffer_test.c +2
-0+} +static struct
kunit_casedrm_framebuffer_tests[] = { +KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported),Could we preserve alphabetical order?
I've see a lot of other tests files with this ordered by every KUNIT_CASE() coming before KUNIT_CASE_PARAM(), with each set ordered among themselves. Did younoticed that or are you suggesting ordering it even so? Or maybe you're referring about another unordered thing that I didn't noticed?
Thanks,
Carlos
Quoted 6 lines
Best Regards,
- MaíraQuoted 3 lines
KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), { }
};
Re: [PATCH 03/10] drm/tests: Add test case for drm_internal_framebuffer_create()
Hi Carlos,
Quoted 59 lines · Carlos
Hi Maíra,
Quoted 47 lines · Maíra Canal
Hi Carlos,
Quoted 44 lines · Carlos Eduardo Gallo Filho
Introduce a test to cover the creation of framebuffer with modifier on a device that doesn't support it.
Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>---
drivers/gpu/drm/tests/drm_framebuffer_test.c| 28 ++++++++++++++++++++1 file changed, 28 insertions(+)drivers/gpu/drm/tests/drm_framebuffer_test.c +0
-0@@ -396,7 +396,35 @@ static void drm_framebuffer_test_to_desc(conststruct
drm_framebuffer_test*t, cKUNIT_ARRAY_PARAM(drm_framebuffer_create, drm_framebuffer_create_cases, drm_framebuffer_test_to_desc);
+/*
+ * This test is very similar todrm_test_framebuffer_create, except that it
+ * setmock->mode_config.fb_modifiers_not_supportedmember to 1, covering
+ * the case of trying to create a framebuffer with modifiers without the
+ * device really supporting it.
+ */
+static voiddrm_test_framebuffer_modifiers_not_supported(struct kunit *test)drivers/gpu/drm/tests/drm_framebuffer_test.c +10
-0+{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + int buffer_created = 0; + + /* A valid cmd with modifier */ + struct drm_mode_fb_cmd2 cmd = { + .width = MAX_WIDTH, .height = MAX_HEIGHT, + .pixel_format = DRM_FORMAT_ABGR8888, .handles = { 1, 0, 0 }, + .offsets = { UINT_MAX / 2, 0, 0 }, .pitches = { 4 *
MAX_WIDTH, 0, 0 },
+ .flags =DRM_MODE_FB_MODIFIERS,
+ };drivers/gpu/drm/tests/drm_framebuffer_test.c +4
-0+ + mock->private = &buffer_created; + dev->mode_config.fb_modifiers_not_supported = 1; +Quoted 9 lines
Quoted 6 lines
+
drm_internal_framebuffer_create(dev, &cmd, NULL); +KUNIT_EXPECT_EQ(test, 0, buffer_created);drivers/gpu/drm/tests/drm_framebuffer_test.c +2
-0+} +static struct
kunit_casedrm_framebuffer_tests[] = { +KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported),Could we preserve alphabetical order?
Quoted 4 lines
I've see a lot of other tests files with this ordered by every
KUNIT_CASE()coming beforeKUNIT_CASE_PARAM(), with each set ordered among themselves. Did younoticed that or are you suggesting ordering it even so? Or maybe you're referring about another unordered thing that I didn't noticed?
Actually, I was suggesting to keep the alphabetical order related to the tests naming. So, drm_test_framebuffer_create would come ahead of drm_test_framebuffer_modifiers_not_supported.
Best Regards,
- Maíra
Quoted 10 lines
Thanks,
CarlosQuoted 6 lines
Best Regards,
- MaíraQuoted 3 lines
KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), { }
};
PATCH 4/10 drm/tests: Add test for drm_framebuffer_check_src_coords()
In reply to Carlos Eduardo Gallo FilhoAdd a parametrized test for the drm_framebuffer_check_src_coords function.
--- drivers/gpu/drm/drm_framebuffer.c | 1 + drivers/gpu/drm/tests/drm_framebuffer_test.c | 61 ++++++++++++++++++++ 2 files changed, 62 insertions(+)
drivers/gpu/drm/drm_framebuffer.c +1 -0
@@ -99,6 +99,7 @@ int drm_framebuffer_check_src_coords(uint32_t src_x, uint32_t src_y,return 0 ; } +EXPORT_SYMBOL_FOR_TESTS_ONLY (drm_framebuffer_check_src_coords);/** * drm_mode_addfb - add an FB to the graphics configuration
drivers/gpu/drm/tests/drm_framebuffer_test.c +61 -0
80 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH 04/10] drm/tests: Add test for drm_framebuffer_check_src_coords()
Hi Carlos,
Quoted 41 lines · Carlos Eduardo Gallo Filho
Add a parametrized test for the
drm_framebuffer_check_src_coordsfunction.Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>--- drivers/gpu/drm/drm_framebuffer.c | 1 + drivers/gpu/drm/tests/drm_framebuffer_test.c | 61 ++++++++++++++++++++ 2 files changed, 62 insertions(+)drivers/gpu/drm/drm_framebuffer.c +1
-0@@ -99,6 +99,7 @@ int drm_framebuffer_check_src_coords(uint32_t src_x, uint32_t src_y,return 0 ; } +EXPORT_SYMBOL_FOR_TESTS_ONLY (drm_framebuffer_check_src_coords);/** * drm_mode_addfb - add an FB to the graphics configuration drivers/gpu/drm/tests/drm_framebuffer_test.c +4
-0@@ -9,11 +9,15 @@#include <drm/drm_device.h> #include <drm/drm_mode.h> +#include <drm/drm_framebuffer.h> #include <drm/drm_fourcc.h> #include <drm/drm_print.h> #include "../drm_crtc_internal.h" +#define FB_WIDTH 800 +#define FB_HEIGHT 600 +#define MIN_WIDTH 4#define MAX_WIDTH 4096#define MIN_HEIGHT 4
drivers/gpu/drm/tests/drm_framebuffer_test.c static void drm_test_framebuffer_modifiers_not_supported(struct kunit *test) · line 431
Quoted 5 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +2
-0@@ -423,8 +427,65 @@ static void drm_test_framebuffer_modifiers_not_supported(struct kunit *test)KUNIT_EXPECT_EQ (test,0 , buffer_created); } +/* Parameters for testing drm_framebuffer_check_src_coords function */ +struct check_src_coords_case {
Could we preserve the drm_framebuffer_ prefix?
drivers/gpu/drm/tests/drm_framebuffer_test.c static void drm_test_framebuffer_modifiers_not_supported(struct kunit *test) · line 433
Quoted 2 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +2
-0+const char *name;/* Description of the parameter case */ +const int expect;/* Expected return value by the function */
I'm not sure if those comments are needed.
Quoted 26 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +26
-0+ +/* Deltas to be applied on source */ +const uint32_t dsrc_x; +const uint32_t dsrc_y; +const uint32_t dsrc_w; +const uint32_t dsrc_h; +}; + +static const struct check_src_coords_case check_src_coords_cases[] = { + { .name ="Success: source fits into fb" , + .expect =0 , + }, + { .name ="Fail: overflowing fb with x-axis coordinate" , + .expect = -ENOSPC , .dsrc_x =1 , + }, + { .name ="Fail: overflowing fb with y-axis coordinate" , + .expect = -ENOSPC , .dsrc_y =1 , + }, + { .name ="Fail: overflowing fb with source width" , + .expect = -ENOSPC , .dsrc_w =1 , + }, + { .name ="Fail: overflowing fb with source height" , + .expect = -ENOSPC , .dsrc_h =1 , + }, +}; +
drivers/gpu/drm/tests/drm_framebuffer_test.c static void drm_test_framebuffer_modifiers_not_supported(struct kunit *test) · line 469
Quoted 10 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +10
-0+static void drm_test_framebuffer_check_src_coords (struct kunit *test) +{ +const struct check_src_coords_case *params = test->param_value; +const uint32_t src_x =0 + params->dsrc_x; +const uint32_t src_y =0 + params->dsrc_y; +const uint32_t src_w = (FB_WIDTH <<16 ) + params->dsrc_w; +const uint32_t src_h = (FB_HEIGHT <<16 ) + params->dsrc_h; +const struct drm_framebuffer fb = { + .width =FB_WIDTH , + .height =FB_HEIGHT ,
Couldn't FB_WIDTH and FB_HEIGHT be tests parameters that we variate? I would like to see edge cases like width = height = 0 and width = height = INT_MAX.
Best Regards,
- Maíra
Quoted 22 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +17
-0+ }; +int ret; + + ret =drm_framebuffer_check_src_coords (src_x, src_y, src_w, src_h, &fb); +KUNIT_EXPECT_EQ (test, ret, params->expect); +} + +static void check_src_coords_test_to_desc (const struct check_src_coords_case *t, +char *desc) +{ +strscpy (desc, t->name,KUNIT_PARAM_DESC_SIZE ); +} + +KUNIT_ARRAY_PARAM (check_src_coords, check_src_coords_cases, + check_src_coords_test_to_desc); +static struct kunit_case drm_framebuffer_tests[] = {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), { } };
PATCH 5/10 drm/tests: Add test for drm_framebuffer_cleanup()
In reply to Carlos Eduardo Gallo FilhoAdd a single KUnit test case for the drm_framebuffer_cleanup function.
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/gpu/drm/tests/drm_framebuffer_test.c +49 -0
@@ -370,6 +370,9 @@ static int drm_framebuffer_test_init(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, mock); dev = &mock->dev; +mutex_init (&dev->mode_config.fb_lock); +INIT_LIST_HEAD (&dev->mode_config.fb_list); + dev->mode_config.num_fb =0 ; dev->mode_config.min_width =MIN_WIDTH ; dev->mode_config.max_width =MAX_WIDTH ; dev->mode_config.min_height =MIN_HEIGHT ;
@@ -380,6 +383,14 @@ static int drm_framebuffer_test_init(struct kunit *test)return 0 ; } +static void drm_framebuffer_test_exit (struct kunit *test) +{ +struct drm_mock *mock = test->priv; +struct drm_device *dev = &mock->dev; + +mutex_destroy (&dev->mode_config.fb_lock); +} +static void drm_test_framebuffer_create (struct kunit *test) {const struct drm_framebuffer_test *params = test->param_value;
@@ -483,7 +494,44 @@ static void check_src_coords_test_to_desc(const struct check_src_coords_case *t,KUNIT_ARRAY_PARAM (check_src_coords, check_src_coords_cases, check_src_coords_test_to_desc); +static void drm_test_framebuffer_cleanup (struct kunit *test) +{ +struct drm_mock *mock = test->priv; +struct drm_device *dev = &mock->dev; +struct list_head *fb_list = &dev->mode_config.fb_list; +struct drm_framebuffer fb1 = { .dev = dev }; +struct drm_framebuffer fb2 = { .dev = dev }; + +/* This must result on [fb_list] -> fb1 -> fb2 */ +list_add_tail (&fb1.head, fb_list); +list_add_tail (&fb2.head, fb_list); + dev->mode_config.num_fb =2 ; + +KUNIT_ASSERT_PTR_EQ (test, fb_list->prev, &fb2.head); +KUNIT_ASSERT_PTR_EQ (test, fb_list->next, &fb1.head); +KUNIT_ASSERT_PTR_EQ (test, fb1.head.prev, fb_list); +KUNIT_ASSERT_PTR_EQ (test, fb1.head.next, &fb2.head); +KUNIT_ASSERT_PTR_EQ (test, fb2.head.prev, &fb1.head); +KUNIT_ASSERT_PTR_EQ (test, fb2.head.next, fb_list); + +drm_framebuffer_cleanup (&fb1); + +/* Now [fb_list] -> fb2 */ +KUNIT_ASSERT_PTR_EQ (test, fb_list->prev, &fb2.head); +KUNIT_ASSERT_PTR_EQ (test, fb_list->next, &fb2.head); +KUNIT_ASSERT_PTR_EQ (test, fb2.head.prev, fb_list); +KUNIT_ASSERT_PTR_EQ (test, fb2.head.next, fb_list); +KUNIT_ASSERT_EQ (test, dev->mode_config.num_fb,1 ); + +drm_framebuffer_cleanup (&fb2); + +/* Now fb_list is empty */ +KUNIT_ASSERT_TRUE (test,list_empty (fb_list)); +KUNIT_ASSERT_EQ (test, dev->mode_config.num_fb,0 ); +} +static struct kunit_case drm_framebuffer_tests[] = { +KUNIT_CASE (drm_test_framebuffer_cleanup),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),
@@ -493,6 +541,7 @@ static struct kunit_case drm_framebuffer_tests[] = {static struct kunit_suite drm_framebuffer_test_suite = { .name ="drm_framebuffer" , .init = drm_framebuffer_test_init, + .exit = drm_framebuffer_test_exit, .test_cases = drm_framebuffer_tests, };
Signature · 1 line
2.41.0
Re: [PATCH 05/10] drm/tests: Add test for drm_framebuffer_cleanup()
Hi Carlos,
Quoted 12 lines · Carlos Eduardo Gallo Filho
Add a single KUnit test case for the
drm_framebuffer_cleanupfunction.Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+)drivers/gpu/drm/tests/drm_framebuffer_test.c +0
-0
drivers/gpu/drm/tests/drm_framebuffer_test.c static int drm_framebuffer_test_init(struct kunit *test) · line 373
Quoted 4 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +1
-0@@ -370,6 +370,9 @@ static int drm_framebuffer_test_init(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, mock); dev = &mock->dev; +mutex_init (&dev->mode_config.fb_lock);
What about drmm_mutex_init()?
Best Regards,
- Maíra
Quoted 73 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +48
-0+INIT_LIST_HEAD (&dev->mode_config.fb_list); + dev->mode_config.num_fb =0 ; dev->mode_config.min_width =MIN_WIDTH ; dev->mode_config.max_width =MAX_WIDTH ; dev->mode_config.min_height =MIN_HEIGHT ;@@ -380,6 +383,14 @@ static int drm_framebuffer_test_init(struct kunit *test)return 0 ; } +static void drm_framebuffer_test_exit (struct kunit *test) +{ +struct drm_mock *mock = test->priv; +struct drm_device *dev = &mock->dev; + +mutex_destroy (&dev->mode_config.fb_lock); +} +static void drm_test_framebuffer_create (struct kunit *test) {const struct drm_framebuffer_test *params = test->param_value;@@ -483,7 +494,44 @@ static void check_src_coords_test_to_desc(const struct check_src_coords_case *t,KUNIT_ARRAY_PARAM (check_src_coords, check_src_coords_cases, check_src_coords_test_to_desc); +static void drm_test_framebuffer_cleanup (struct kunit *test) +{ +struct drm_mock *mock = test->priv; +struct drm_device *dev = &mock->dev; +struct list_head *fb_list = &dev->mode_config.fb_list; +struct drm_framebuffer fb1 = { .dev = dev }; +struct drm_framebuffer fb2 = { .dev = dev }; + +/* This must result on [fb_list] -> fb1 -> fb2 */ +list_add_tail (&fb1.head, fb_list); +list_add_tail (&fb2.head, fb_list); + dev->mode_config.num_fb =2 ; + +KUNIT_ASSERT_PTR_EQ (test, fb_list->prev, &fb2.head); +KUNIT_ASSERT_PTR_EQ (test, fb_list->next, &fb1.head); +KUNIT_ASSERT_PTR_EQ (test, fb1.head.prev, fb_list); +KUNIT_ASSERT_PTR_EQ (test, fb1.head.next, &fb2.head); +KUNIT_ASSERT_PTR_EQ (test, fb2.head.prev, &fb1.head); +KUNIT_ASSERT_PTR_EQ (test, fb2.head.next, fb_list); + +drm_framebuffer_cleanup (&fb1); + +/* Now [fb_list] -> fb2 */ +KUNIT_ASSERT_PTR_EQ (test, fb_list->prev, &fb2.head); +KUNIT_ASSERT_PTR_EQ (test, fb_list->next, &fb2.head); +KUNIT_ASSERT_PTR_EQ (test, fb2.head.prev, fb_list); +KUNIT_ASSERT_PTR_EQ (test, fb2.head.next, fb_list); +KUNIT_ASSERT_EQ (test, dev->mode_config.num_fb,1 ); + +drm_framebuffer_cleanup (&fb2); + +/* Now fb_list is empty */ +KUNIT_ASSERT_TRUE (test,list_empty (fb_list)); +KUNIT_ASSERT_EQ (test, dev->mode_config.num_fb,0 ); +} +static struct kunit_case drm_framebuffer_tests[] = { +KUNIT_CASE (drm_test_framebuffer_cleanup),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),@@ -493,6 +541,7 @@ static struct kunit_case drm_framebuffer_tests[] = {static struct kunit_suite drm_framebuffer_test_suite = { .name ="drm_framebuffer" , .init = drm_framebuffer_test_init, + .exit = drm_framebuffer_test_exit, .test_cases = drm_framebuffer_tests, };
Re: [PATCH 05/10] drm/tests: Add test for drm_framebuffer_cleanup()
Hi Maíra,
Quoted 10 lines · Maíra Canal
Hi Carlos,
Quoted 7 lines · Carlos Eduardo Gallo Filho
Add a single KUnit test case for the
drm_framebuffer_cleanupfunction.Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>---
drivers/gpu/drm/tests/drm_framebuffer_test.c| 49 ++++++++++++++++++++1 file changed, 49 insertions(+)
Quoted 11 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c static int drm_framebuffer_test_init(struct kunit · line 373
Quoted 9 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +0
-0@@ -370,6 +370,9 @@ static int drm_framebuffer_test_init(struct kunit *test) KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); dev = &mock->dev; + mutex_init(&dev->mode_config.fb_lock);What about
drmm_mutex_init()?
I took a look into it and as far I understand it would be useful if the drm_device was allocated with drmm_kalloc(), sure? As far we are using kunit_kalloc here and the drm_device is automatically deallocated when the test finishes, what would be the better by using drmm_mutex_init?
It isn't that I don't wanna use it, I just didn't understand how exactly it works and how could I use it in that code. Should I replace the drm_device allocation to use drmm?
Thanks,
Carlos
Quoted 75 lines
Best Regards,
- MaíraQuoted 72 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +2
-0+INIT_LIST_HEAD (&dev->mode_config.fb_list); + dev->mode_config.num_fb = 0; dev->mode_config.min_width = MIN_WIDTH; dev->mode_config.max_width = MAX_WIDTH;
dev->mode_config.min_height=MIN_HEIGHT;drivers/gpu/drm/tests/drm_framebuffer_test.c +7
-0@@ -380,6 +383,14 @@ static int drm_framebuffer_test_init(struct kunit *test) return 0; } +static void drm_framebuffer_test_exit(struct kunit *test) +{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + + mutex_destroy(&dev->mode_config.fb_lock); +} + static void drm_test_framebuffer_create(struct kunit *test) {const struct
drm_framebuffer_test*params =test->param_value;drivers/gpu/drm/tests/drm_framebuffer_test.c +36
-0@@ -483,7 +494,44 @@ static void check_src_coords_test_to_desc(conststruct check_src_coords_case *t, KUNIT_ARRAY_PARAM(check_src_coords, check_src_coords_cases, check_src_coords_test_to_desc); +static void drm_test_framebuffer_cleanup(struct kunit *test) +{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + struct list_head *fb_list = &dev->mode_config.fb_list; + struct drm_framebuffer fb1 = { .dev = dev }; + struct drm_framebuffer fb2 = { .dev = dev }; + + /* This must result on [fb_list] -> fb1 -> fb2 */ + list_add_tail(&fb1.head, fb_list); + list_add_tail(&fb2.head, fb_list); + dev->mode_config.num_fb = 2; + + KUNIT_ASSERT_PTR_EQ(test, fb_list->prev, &fb2.head); + KUNIT_ASSERT_PTR_EQ(test, fb_list->next, &fb1.head); + KUNIT_ASSERT_PTR_EQ(test, fb1.head.prev, fb_list); + KUNIT_ASSERT_PTR_EQ(test, fb1.head.next, &fb2.head); + KUNIT_ASSERT_PTR_EQ(test, fb2.head.prev, &fb1.head); + KUNIT_ASSERT_PTR_EQ(test, fb2.head.next, fb_list); + + drm_framebuffer_cleanup(&fb1); + + /* Now [fb_list] -> fb2 */ + KUNIT_ASSERT_PTR_EQ(test, fb_list->prev, &fb2.head); + KUNIT_ASSERT_PTR_EQ(test, fb_list->next, &fb2.head); + KUNIT_ASSERT_PTR_EQ(test, fb2.head.prev, fb_list); + KUNIT_ASSERT_PTR_EQ(test, fb2.head.next, fb_list); + KUNIT_ASSERT_EQ(test, dev->mode_config.num_fb, 1); + + drm_framebuffer_cleanup(&fb2); + + /* Now fb_list is empty */ + KUNIT_ASSERT_TRUE(test, list_empty(fb_list)); + KUNIT_ASSERT_EQ(test, dev->mode_config.num_fb, 0); +} + static struct kunit_case drm_framebuffer_tests[] = { + KUNIT_CASE(drm_test_framebuffer_cleanup),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),drivers/gpu/drm/tests/drm_framebuffer_test.c +1
-0@@ -493,6 +541,7 @@ static struct kunit_case drm_framebuffer_tests[] = { static struct kunit_suite drm_framebuffer_test_suite = { .name = "drm_framebuffer", .init = drm_framebuffer_test_init, + .exit = drm_framebuffer_test_exit, .test_cases = drm_framebuffer_tests, };
Re: [PATCH 05/10] drm/tests: Add test for drm_framebuffer_cleanup()
Hi Carlos,
Quoted 24 lines · Carlos
Hi Maíra,
Quoted 10 lines · Maíra Canal
Hi Carlos,
Quoted 7 lines · Carlos Eduardo Gallo Filho
Add a single KUnit test case for the
drm_framebuffer_cleanupfunction.Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>---
drivers/gpu/drm/tests/drm_framebuffer_test.c| 49 ++++++++++++++++++++1 file changed, 49 insertions(+)Quoted 11 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c static int drm_framebuffer_test_init(struct kunit · line 373
Quoted 9 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +0
-0@@ -370,6 +370,9 @@ static int drm_framebuffer_test_init(struct kunit *test) KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); dev = &mock->dev; + mutex_init(&dev->mode_config.fb_lock);What about
drmm_mutex_init()?
Quoted 2 lines
I took a look into it and as far I understand it would be useful if the
drm_devicewas allocated withdrmm_kalloc(), sure? As far we
I'm not sure if we can allocate drm_device with drmm_kzalloc(), as we need a DRM device for drmm_kzalloc(). drmm_kzalloc() is just a &drm_device managed version of kzalloc().
Quoted 4 lines
are using
kunit_kallochere and thedrm_deviceis automatically deallocated when the test finishes, what would be the better by usingdrmm_mutex_init?
Actually, thinking it better now, I think we cannot use drmm_mutex_init() here, as we are not calling drm_dev_put().
Best Regards,
- Maíra
Quoted 82 lines
It isn't that I don't wanna use it, I just didn't understand how exactly it works and how could I use it in that code. Should I replace the
drm_deviceallocation to use drmm?Thanks,
CarlosQuoted 75 lines
Best Regards,
- MaíraQuoted 72 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +2
-0+INIT_LIST_HEAD (&dev->mode_config.fb_list); + dev->mode_config.num_fb = 0; dev->mode_config.min_width = MIN_WIDTH; dev->mode_config.max_width = MAX_WIDTH;
dev->mode_config.min_height=MIN_HEIGHT;drivers/gpu/drm/tests/drm_framebuffer_test.c +7
-0@@ -380,6 +383,14 @@ static int drm_framebuffer_test_init(struct kunit *test) return 0; } +static void drm_framebuffer_test_exit(struct kunit *test) +{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + + mutex_destroy(&dev->mode_config.fb_lock); +} + static void drm_test_framebuffer_create(struct kunit *test) {const struct
drm_framebuffer_test*params =test->param_value;drivers/gpu/drm/tests/drm_framebuffer_test.c +36
-0@@ -483,7 +494,44 @@ static void check_src_coords_test_to_desc(conststruct check_src_coords_case *t, KUNIT_ARRAY_PARAM(check_src_coords, check_src_coords_cases, check_src_coords_test_to_desc); +static void drm_test_framebuffer_cleanup(struct kunit *test) +{ + struct drm_mock *mock = test->priv; + struct drm_device *dev = &mock->dev; + struct list_head *fb_list = &dev->mode_config.fb_list; + struct drm_framebuffer fb1 = { .dev = dev }; + struct drm_framebuffer fb2 = { .dev = dev }; + + /* This must result on [fb_list] -> fb1 -> fb2 */ + list_add_tail(&fb1.head, fb_list); + list_add_tail(&fb2.head, fb_list); + dev->mode_config.num_fb = 2; + + KUNIT_ASSERT_PTR_EQ(test, fb_list->prev, &fb2.head); + KUNIT_ASSERT_PTR_EQ(test, fb_list->next, &fb1.head); + KUNIT_ASSERT_PTR_EQ(test, fb1.head.prev, fb_list); + KUNIT_ASSERT_PTR_EQ(test, fb1.head.next, &fb2.head); + KUNIT_ASSERT_PTR_EQ(test, fb2.head.prev, &fb1.head); + KUNIT_ASSERT_PTR_EQ(test, fb2.head.next, fb_list); + + drm_framebuffer_cleanup(&fb1); + + /* Now [fb_list] -> fb2 */ + KUNIT_ASSERT_PTR_EQ(test, fb_list->prev, &fb2.head); + KUNIT_ASSERT_PTR_EQ(test, fb_list->next, &fb2.head); + KUNIT_ASSERT_PTR_EQ(test, fb2.head.prev, fb_list); + KUNIT_ASSERT_PTR_EQ(test, fb2.head.next, fb_list); + KUNIT_ASSERT_EQ(test, dev->mode_config.num_fb, 1); + + drm_framebuffer_cleanup(&fb2); + + /* Now fb_list is empty */ + KUNIT_ASSERT_TRUE(test, list_empty(fb_list)); + KUNIT_ASSERT_EQ(test, dev->mode_config.num_fb, 0); +} + static struct kunit_case drm_framebuffer_tests[] = { + KUNIT_CASE(drm_test_framebuffer_cleanup),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),drivers/gpu/drm/tests/drm_framebuffer_test.c +1
-0@@ -493,6 +541,7 @@ static struct kunit_case drm_framebuffer_tests[] = { static struct kunit_suite drm_framebuffer_test_suite = { .name = "drm_framebuffer", .init = drm_framebuffer_test_init, + .exit = drm_framebuffer_test_exit, .test_cases = drm_framebuffer_tests, };
Maxime Ripard
maintainerRe: [PATCH 05/10] drm/tests: Add test for drm_framebuffer_cleanup()
Quoted 28 lines · Maira Canal
Hi Carlos,
Quoted 25 lines · Carlos
Hi Maíra,
Quoted 22 lines · Maíra Canal
Hi Carlos,
Quoted 13 lines · Carlos Eduardo Gallo Filho
Add a single KUnit test case for the
drm_framebuffer_cleanupfunction.Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>---
drivers/gpu/drm/tests/drm_framebuffer_test.c| 49 ++++++++++++++++++++1 file changed, 49 insertions(+)drivers/gpu/drm/tests/drm_framebuffer_test.c +0
-0drivers/gpu/drm/tests/drm_framebuffer_test.c static int drm_framebuffer_test_init(struct · line 373
Quoted 4 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +0
-0@@ -370,6 +370,9 @@ static int drm_framebuffer_test_init(struct kunit *test) KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); dev = &mock->dev; + mutex_init(&dev->mode_config.fb_lock);What about
drmm_mutex_init()?
Quoted 6 lines
Quoted 2 lines
I took a look into it and as far I understand it would be useful if the
drm_devicewas allocated withdrmm_kalloc(), sure? As far weI'm not sure if we can allocate
drm_devicewithdrmm_kzalloc(), as we need a DRM device fordrmm_kzalloc().drmm_kzalloc()is just a&drm_devicemanaged version ofkzalloc().
We should use drm_kunit_helper_alloc_drm_device_with_driver
Maxime
PATCH 6/10 drm/tests: Add test for drm_framebuffer_lookup()
In reply to Carlos Eduardo Gallo FilhoAdd a single KUnit test case for the drm_framebuffer_lookup function.
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/gpu/drm/tests/drm_framebuffer_test.c +28 -0
@@ -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 );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),
Signature · 1 line
2.41.0
Re: [PATCH 06/10] drm/tests: Add test for drm_framebuffer_lookup()
Hi Carlos,
Quoted 20 lines · Carlos Eduardo Gallo Filho
Add a single KUnit test case for the
drm_framebuffer_lookupfunction.Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/gpu/drm/tests/drm_framebuffer_test.c +1
-0@@ -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>
drivers/gpu/drm/tests/drm_framebuffer_test.c static int drm_framebuffer_test_init(struct kunit *test) · line 377
Quoted 7 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +4
-0@@ -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()?
Best Regards,
- Maíra
Quoted 35 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +23
-0mutex_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),
Re: [PATCH 06/10] drm/tests: Add test for drm_framebuffer_lookup()
Hi Maíra,
Quoted 23 lines · Maíra Canal
Hi Carlos,
Quoted 20 lines · Carlos Eduardo Gallo Filho
Add a single KUnit test case for the
drm_framebuffer_lookupfunction.Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>---
drivers/gpu/drm/tests/drm_framebuffer_test.c| 28 ++++++++++++++++++++1 file changed, 28 insertions(+)drivers/gpu/drm/tests/drm_framebuffer_test.c +1
-0@@ -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)
Quoted 8 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c static int drm_framebuffer_test_init(struct kunit *test) · line 377
Quoted 6 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +3
-0KUNIT_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()? 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?
Thanks,
Carlos
Quoted 38 lines
Best Regards,
- MaíraQuoted 35 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +0
-0mutex_init (&dev->mode_config.fb_lock); INIT_LIST_HEAD(&dev->mode_config.fb_list);
dev->mode_config.num_fb= 0;drivers/gpu/drm/tests/drm_framebuffer_test.c +22
-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),
Re: [PATCH 06/10] drm/tests: Add test for drm_framebuffer_lookup()
Hi Carlos,
Quoted 34 lines · Carlos
Hi Maíra,
Quoted 23 lines · Maíra Canal
Hi Carlos,
Quoted 20 lines · Carlos Eduardo Gallo Filho
Add a single KUnit test case for the
drm_framebuffer_lookupfunction.Signed-off-by Carlos Eduardo Gallo Filho <[email protected]>---
drivers/gpu/drm/tests/drm_framebuffer_test.c| 28 ++++++++++++++++++++1 file changed, 28 insertions(+)drivers/gpu/drm/tests/drm_framebuffer_test.c +1
-0@@ -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)Quoted 8 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c static int drm_framebuffer_test_init(struct kunit *test) · line 377
Quoted 6 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +3
-0KUNIT_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()?
Quoted 1 line
Do you mean about replace
drm_mode_object_add()todrm_framebuffer_init()?
Yeah.
Quoted 4 lines
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 devicefb_listand 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
Quoted 42 lines
Thanks,
CarlosQuoted 38 lines
Best Regards,
- MaíraQuoted 35 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +0
-0mutex_init (&dev->mode_config.fb_lock); INIT_LIST_HEAD(&dev->mode_config.fb_list);
dev->mode_config.num_fb= 0;drivers/gpu/drm/tests/drm_framebuffer_test.c +22
-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),