Add documentation and KUnit tests for functions on drm_framebuffer.c
Subsystems (2)
cover Add documentation and KUnit tests for functions on drm_framebuffer.c
This series adds documentation and unit tests for drm_framebuffer_check_src_coords() and drm_internal_framebuffer_create() functions on drm_framebuffer.c, including new parameters to the, until then, only existent test.
Many thanks,
Carlos
Carlos Eduardo Gallo Filho (4):
drm: Add kernel-doc for drm_framebuffer_check_src_coords() drm/tests: Add test for drm_framebuffer_check_src_coords() drm/tests: Add parameters to the drm_test_framebuffer_create test drm/tests: Add test case for drm_internal_framebuffer_create()
drivers/gpu/drm/drm_framebuffer.c | 16 +- drivers/gpu/drm/tests/drm_framebuffer_test.c | 149 +++++++++++++++++++ 2 files changed, 164 insertions(+), 1 deletion(-)
Signature · 1 line
2.41.0
PATCH 1/4 drm: Add kernel-doc for drm_framebuffer_check_src_coords()
--- drivers/gpu/drm/drm_framebuffer.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_framebuffer.c +15 -1
@@ -73,6 +73,21 @@* drm_framebuffer. */ +/** +* drm_framebuffer_check_src_coords - check if the source with given +* coordinates and sizes is inside the framebuffer +* @src_x: source x coordinate +* @src_y: source y coordinate +* @src_w: source width +* @src_h: source height +* @fb: pointer to the framebuffer to check +* +* This function checks if an object with the given set of coordinates and +* sizes fits inside the framebuffer by looking at its size. +* +* Returns: +* Zero on success, negative errno on failure. +*/ int drm_framebuffer_check_src_coords (uint32_t src_x,uint32_t src_y,uint32_t src_w,uint32_t src_h,const struct drm_framebuffer *fb)
@@ -82,7 +97,6 @@ int drm_framebuffer_check_src_coords(uint32_t src_x, uint32_t src_y, fb_width = fb->width <<16 ; fb_height = fb->height <<16 ; -/* Make sure source coordinates are inside the fb. */ if (src_w > fb_width || src_x > fb_width - src_w || src_h > fb_height ||
Signature · 1 line
2.41.0
PATCH 2/4 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/tests/drm_framebuffer_test.c | 107 +++++++++++++++++++ 1 file changed, 107 insertions(+)
drivers/gpu/drm/tests/drm_framebuffer_test.c +107 -0
@@ -9,6 +9,7 @@#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>
@@ -366,8 +367,114 @@ 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); +struct check_src_coords_case { +const int expect; +const uint32_t src_x; +const uint32_t src_y; +const uint32_t src_w; +const uint32_t src_h; +const struct drm_framebuffer fb; +const char *name; +}; + +static const struct check_src_coords_case check_src_coords_cases[] = { + { .name ="source inside framebuffer" , + .expect =0 , + .src_x =500 <<16 , .src_y =700 <<16 , + .src_w =100 <<16 , .src_h =100 <<16 , + .fb = { .width =600 , .height =800 } + }, + { .name ="out of bound with normal sizes and coordinates" , + .expect = -ENOSPC , + .src_x = (500 <<16 ) +1 , .src_y = (700 <<16 ) +1 , + .src_w =100 <<16 , .src_h =100 <<16 , + .fb = { .width =600 , .height =800 } + }, + { .name ="source width higher than framebuffer width" , + .expect = -ENOSPC , + .src_x =0 , .src_y =700 <<16 , + .src_w = (600 <<16 ) +1 , .src_h =100 <<16 , + .fb = { .width =600 , .height =800 } + }, + { .name ="source width equal framebuffer width with x coordinates 0" , + .expect =0 , + .src_x =0 , .src_y =700 <<16 , + .src_w =600 <<16 , .src_h =100 <<16 , + .fb = { .width =600 , .height =800 } + }, + { .name ="source width equal framebuffer width with non-zero x coordinate" , + .expect = -ENOSPC , + .src_x =1 , .src_y =700 <<16 , + .src_w =600 <<16 , .src_h =100 <<16 , + .fb = { .width =600 , .height =800 } + }, + { .name ="out of bound with normal width and x" , + .expect = -ENOSPC , + .src_x = (500 <<16 ) +1 , .src_y =700 <<16 , + .src_w =100 <<16 , .src_h =100 <<16 , + .fb = { .width =600 , .height =800 } + }, + { .name ="x coordinate higher than framebuffer width" , + .expect = -ENOSPC , + .src_x = (600 <<16 ) +1 , .src_y =700 <<16 , + .src_w =0 , .src_h =100 <<16 , + .fb = { .width =600 , .height =800 } + }, + { .name ="source height higher than framebuffer height" , + .expect = -ENOSPC , + .src_x =700 <<16 , .src_y =0 , + .src_w =100 <<16 , .src_h = (600 <<16 ) +1 , + .fb = { .width =800 , .height =600 } + }, + { .name ="source height equal framebuffer height with y coordinates 0" , + .expect =0 , + .src_x =700 <<16 , .src_y =0 , + .src_w =100 <<16 , .src_h =600 <<16 , + .fb = { .width =800 , .height =600 } + }, + { .name ="source height equal framebuffer height with non-zero y coordinate" , + .expect = -ENOSPC , + .src_x =700 <<16 , .src_y =1 , + .src_w =100 <<16 , .src_h =600 <<16 , + .fb = { .width =800 , .height =600 } + }, + { .name ="out of bound with normal height and y" , + .expect = -ENOSPC , + .src_x =700 <<16 , .src_y = (500 <<16 ) +1 , + .src_w =100 <<16 , .src_h =100 <<16 , + .fb = { .width =800 , .height =600 } + }, + { .name ="y coordinate higher than framebuffer height" , + .expect = -ENOSPC , + .src_x =700 <<16 , .src_y = (600 <<16 ) +1 , + .src_w =100 <<16 , .src_h =0 , + .fb = { .width =800 , .height =600 } + }, +}; + +static void drm_test_framebuffer_check_src_coords (struct kunit *test) +{ +const struct check_src_coords_case *params = test->param_value; +int r; + + r =drm_framebuffer_check_src_coords (params->src_x, params->src_y, + params->src_w, params->src_h, + ¶ms->fb); +KUNIT_EXPECT_EQ (test, r, params->expect); +} + +static void check_src_coords_test_to_desc (const struct check_src_coords_case *t, +char *desc) +{ +strcpy (desc, t->name); +} + +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_PARAM (drm_test_framebuffer_create, drm_framebuffer_create_gen_params), +KUNIT_CASE_PARAM (drm_test_framebuffer_check_src_coords, check_src_coords_gen_params), { } };
Signature · 1 line
2.41.0
Maxime Ripard
maintainerRe: [PATCH 2/4] drm/tests: Add test for drm_framebuffer_check_src_coords()
Hi,
Quoted 30 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/tests/drm_framebuffer_test.c | 107 +++++++++++++++++++ 1 file changed, 107 insertions(+)drivers/gpu/drm/tests/drm_framebuffer_test.c +8
-0@@ -9,6 +9,7 @@#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> @@ -366,8 +367,114 @@ 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); +struct check_src_coords_case { +const int expect; +const uint32_t src_x; +const uint32_t src_y; +const uint32_t src_w; +const uint32_t src_h; +const struct drm_framebuffer fb;
drivers/gpu/drm/tests/drm_framebuffer_test.c static void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, c · line 386
Quoted 10 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +10
-0+const char *name; +}; + +static const struct check_src_coords_case check_src_coords_cases[] = { + { .name ="source inside framebuffer" , + .expect =0 , + .src_x =500 <<16 , .src_y =700 <<16 , + .src_w =100 <<16 , .src_h =100 <<16 , + .fb = { .width =600 , .height =800 } + },
Generally speaking, a small comment explaining what the test is doing and what is the expected result is would be nice. A couple of months/years down the line, obvious tests might not be so obvious anymore.
...
drivers/gpu/drm/tests/drm_framebuffer_test.c static void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, c · line 470
Quoted 5 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +5
-0+static void check_src_coords_test_to_desc (const struct check_src_coords_case *t, +char *desc) +{ +strcpy (desc, t->name); +}
strscpy
drivers/gpu/drm/tests/drm_framebuffer_test.c static void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, c · line 477
Quoted 6 lines
drivers/gpu/drm/tests/drm_framebuffer_test.c +4
-0+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_PARAM (drm_test_framebuffer_create, drm_framebuffer_create_gen_params), +KUNIT_CASE_PARAM (drm_test_framebuffer_check_src_coords, check_src_coords_gen_params),
I'd prefer to keep them ordered alphabetically.
Thanks!
Maxime
PATCH 3/4 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
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/gpu/drm/tests/drm_framebuffer_test.c +21 -0
@@ -20,6 +20,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;
@@ -84,6 +86,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 },
@@ -263,6 +277,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 }
Signature · 1 line
2.41.0
PATCH 4/4 drm/tests: Add test case for drm_internal_framebuffer_create()
In reply to Carlos Eduardo Gallo FilhoIntroduce a test to cover the creation of a framebuffer with a setted modifier and a driver that don't support modifiers.
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/gpu/drm/tests/drm_framebuffer_test.c +21 -0
@@ -388,6 +388,26 @@ 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); +static void drm_test_framebuffer_modifiers_not_supported (struct kunit *test) +{ +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 , + }; +struct drm_device *mock = test->priv; +int buffer_created =0 ; + + mock->dev_private = &buffer_created; + mock->mode_config.fb_modifiers_not_supported =1 ; + +drm_internal_framebuffer_create (mock, &cmd,NULL ); +KUNIT_EXPECT_EQ (test,0 , buffer_created); + + mock->mode_config.fb_modifiers_not_supported =0 ; +} +struct check_src_coords_case {const int expect;const uint32_t src_x;
@@ -494,6 +514,7 @@ 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_create, drm_framebuffer_create_gen_params),KUNIT_CASE_PARAM (drm_test_framebuffer_check_src_coords, check_src_coords_gen_params), { }
Signature · 1 line
2.41.0