Increase coverage on drm_framebuffer.c
Subsystems (2)
v4 cover Increase coverage on drm_framebuffer.c
This patchset includes new KUnit tests for 5 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 4 extends the test of drm_internal_framebuffer_create() by creating a new test case and adding new parameters to the existent case.
The patch 3 just replace a strcpy() call to strscpy().
Finally, the remainder of this set contains 5 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()
---
v3:
- Drop drm_mode_addfb2 and drm_fb_release tests (patches 10 and 11 from v2)
---
Carlos Eduardo Gallo Filho (9):
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: Replace strcpy to strscpy on 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()
drivers/gpu/drm/drm_framebuffer.c | 2 + drivers/gpu/drm/drm_mode_object.c | 1 + drivers/gpu/drm/tests/drm_framebuffer_test.c | 373 ++++++++++++++++++- 3 files changed, 359 insertions(+), 17 deletions(-)
Signature · 1 line
2.44.2
PATCH v4 1/9 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.
The new mock struct allows to share variables and even further mocks over the tests in a cleaner way than using dev_private void pointer.
Also start using drm_kunit_helper_alloc_drm_device() for allocating the drm_device mock.
---
v2:
- Start using drm_kunit_helper_alloc_drm_device() for drm_device mock.
- Rename struct drm_mock to drm_framebuffer_test_priv
v3:
- Replace the use of void pointer on drm_framebuffer_test_priv struct.
- Document struct drm_framebuffer_test_priv here.
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 54 ++++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-)
drivers/gpu/drm/tests/drm_framebuffer_test.c +38 -16
@@ -8,8 +8,10 @@#include <kunit/test.h> #include <drm/drm_device.h> +#include <drm/drm_drv.h> #include <drm/drm_mode.h> #include <drm/drm_fourcc.h> +#include <drm/drm_kunit_helpers.h> #include <drm/drm_print.h> #include "../drm_crtc_internal.h"
@@ -317,12 +319,25 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { }, }; +/* +* This struct is intended to provide a way to mocked functions communicate +* with the outer test when it can't be achieved by using its return value. In +* this way, the functions that receive the mocked drm_device, for example, can +* grab a reference to this and actually return something to be used on some +* expectation. +*/ +struct drm_framebuffer_test_priv { +struct drm_device dev; +bool buffer_created; +}; +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; - *buffer_created =1 ; +struct drm_framebuffer_test_priv *priv =container_of (dev,typeof (*priv), dev); + + priv->buffer_created = true;return ERR_PTR (-EINVAL ); }
@@ -332,30 +347,37 @@ static struct drm_mode_config_funcs mock_config_funcs = {static int drm_framebuffer_test_init (struct kunit *test) { -struct drm_device *mock; +struct device *parent; +struct drm_framebuffer_test_priv *priv; +struct drm_device *dev; + + parent =drm_kunit_helper_alloc_device (test); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, parent); - mock =kunit_kzalloc (test,sizeof (*mock),GFP_KERNEL ); -KUNIT_ASSERT_NOT_ERR_OR_NULL (test, mock); + priv =drm_kunit_helper_alloc_drm_device (test, parent,typeof (*priv), + dev,0 ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, priv); + dev = &priv->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; + test->priv = priv;return 0 ; }static void drm_test_framebuffer_create (struct kunit *test) {const struct drm_framebuffer_test *params = test->param_value; -struct drm_device *mock = test->priv; -int buffer_created =0 ; +struct drm_framebuffer_test_priv *priv = test->priv; +struct drm_device *dev = &priv->dev; - mock->dev_private = &buffer_created; -drm_internal_framebuffer_create (mock, ¶ms->cmd,NULL ); -KUNIT_EXPECT_EQ (test, params->buffer_created, buffer_created); + priv->buffer_created = false; +drm_internal_framebuffer_create (dev, ¶ms->cmd,NULL ); +KUNIT_EXPECT_EQ (test, params->buffer_created, priv->buffer_created); }static void drm_framebuffer_test_to_desc (const struct drm_framebuffer_test *t,char *desc)
Signature · 1 line
2.44.2
PATCH v4 2/9 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. Buffer offset for inexistent plane
---
v2:
- Remove strcpy to strscpy change.
v3:
- Rename and commment the "Buffer offset for inexistent plane" test case.
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/gpu/drm/tests/drm_framebuffer_test.c +27 -0
@@ -21,6 +21,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;
@@ -85,6 +87,24 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { .pitches = { 4 * MAX_WIDTH, 0, 0 }, } }, + +/* + * All entries in members that represents per-plane values (@modifier, @handles, + * @pitches and @offsets) must be zero when unused. + */ +{ .buffer_created = 0, .name = "ABGR8888 Buffer offset for inexistent 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 },
@@ -264,6 +284,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.44.2
PATCH v4 3/9 drm/tests: Replace strcpy to strscpy on drm_test_framebuffer_create test
In reply to Carlos Eduardo Gallo FilhoReplace the use of strcpy to strscpy on the test_to_desc of the drm_test_framebuffer_create test for better security and reliability.
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tests/drm_framebuffer_test.c +1 -1
@@ -409,7 +409,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.44.2
PATCH v4 4/9 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.
---
v2:
- Reorder kunit cases alphabetically.
v3:
- Replace the use of void pointer on drm_framebuffer_test_priv struct.
- Test return value of drm_internal_framebuffer_create().
- Change test documentation to don't rely on another test.
v4:
- Reorder expectation value.
- Remove unneeded expectation.
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/gpu/drm/tests/drm_framebuffer_test.c +24 -0
@@ -415,8 +415,32 @@ 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); +/* Tries to create a framebuffer with modifiers without drm_device supporting it */ +static void drm_test_framebuffer_modifiers_not_supported (struct kunit *test) +{ +struct drm_framebuffer_test_priv *priv = test->priv; +struct drm_device *dev = &priv->dev; +struct drm_framebuffer *fb; + +/* 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 , + }; + + priv->buffer_created = false; + dev->mode_config.fb_modifiers_not_supported =1 ; + + fb =drm_internal_framebuffer_create (dev, &cmd,NULL ); +KUNIT_EXPECT_EQ (test, priv->buffer_created, false); +KUNIT_EXPECT_EQ (test,PTR_ERR (fb), -EINVAL ); +} +static struct kunit_case drm_framebuffer_tests[] = {KUNIT_CASE_PARAM (drm_test_framebuffer_create, drm_framebuffer_create_gen_params), +KUNIT_CASE (drm_test_framebuffer_modifiers_not_supported), { } };
Signature · 1 line
2.44.2
PATCH v4 5/9 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.
---
v2:
- Order kunit cases alphabetically.
- Rename check_src_coords_case to drm_framebuffer_check_src_coords_case.
- Remove unnecessary comments.
- Add framebuffer size as a parameter and use edge values.
--- 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
74 lines not on this page · raw message
Signature · 1 line
2.44.2
PATCH v4 6/9 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.
---
v2:
- Reorder kunit cases alphabetically.
- Rely on drm_kunit_helper_alloc_device() for mock initialization.
v3:
- Init framebuffers using drm_framebuffer_init().
- Add documentation.
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/gpu/drm/tests/drm_framebuffer_test.c +32 -0
@@ -498,8 +498,40 @@ check_src_coords_test_to_desc(const struct drm_framebuffer_check_src_coords_caseKUNIT_ARRAY_PARAM (check_src_coords, drm_framebuffer_check_src_coords_cases, check_src_coords_test_to_desc); +/* +* Test if drm_framebuffer_cleanup() really pops out the framebuffer object +* from device's fb_list and decrement the number of framebuffers for that +* device, which is the only things it does. +*/ +static void drm_test_framebuffer_cleanup (struct kunit *test) +{ +struct drm_framebuffer_test_priv *priv = test->priv; +struct drm_device *dev = &priv->dev; +struct list_head *fb_list = &dev->mode_config.fb_list; +struct drm_format_info format = { }; +struct drm_framebuffer fb1 = { .dev = dev, .format = &format }; +struct drm_framebuffer fb2 = { .dev = dev, .format = &format }; + +/* This will result on [fb_list] -> fb2 -> fb1 */ +drm_framebuffer_init (dev, &fb1,NULL ); +drm_framebuffer_init (dev, &fb2,NULL ); + +drm_framebuffer_cleanup (&fb1); + +/* Now fb2 is the only one element on fb_list */ +KUNIT_ASSERT_TRUE (test,list_is_singular (&fb2.head)); +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_PARAM (drm_test_framebuffer_check_src_coords, check_src_coords_gen_params), +KUNIT_CASE (drm_test_framebuffer_cleanup),KUNIT_CASE_PARAM (drm_test_framebuffer_create, drm_framebuffer_create_gen_params),KUNIT_CASE (drm_test_framebuffer_modifiers_not_supported), { }
Signature · 1 line
2.44.2
PATCH v4 7/9 drm/tests: Add test for drm_framebuffer_lookup()
In reply to Carlos Eduardo Gallo FilhoAdd two KUnit test cases for the drm_framebuffer_lookup function, one for the base case, that tests if the lookup finds the correct framebuffer object and another that tests the lookup for an inexistent framebuffer.
---
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.
v3:
- Rename framebuffer variables.
- Add documentation.
- Split the lookup for inexistent framebuffer into another test.
- Call drm_framebuffer_put after lookup on drm_test_framebuffer_lookup test.
--- drivers/gpu/drm/tests/drm_framebuffer_test.c | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/gpu/drm/tests/drm_framebuffer_test.c +41 -0
@@ -529,10 +529,51 @@ static void drm_test_framebuffer_cleanup(struct kunit *test)KUNIT_ASSERT_EQ (test, dev->mode_config.num_fb,0 ); } +/* +* Initialize a framebuffer, lookup its id and test if the returned reference +* matches. +*/ +static void drm_test_framebuffer_lookup (struct kunit *test) +{ +struct drm_framebuffer_test_priv *priv = test->priv; +struct drm_device *dev = &priv->dev; +struct drm_format_info format = { }; +struct drm_framebuffer expected_fb = { .dev = dev, .format = &format }; +struct drm_framebuffer *returned_fb; +uint32_t id =0 ; +int ret; + + ret =drm_framebuffer_init (dev, &expected_fb,NULL ); +KUNIT_ASSERT_EQ (test, ret,0 ); + id = expected_fb.base.id; + +/* Looking for expected_fb */ + returned_fb =drm_framebuffer_lookup (dev,NULL , id); +KUNIT_EXPECT_PTR_EQ (test, returned_fb, &expected_fb); +drm_framebuffer_put (returned_fb); + +drm_framebuffer_cleanup (&expected_fb); +} + +/* Try to lookup an id that is not linked to a framebuffer */ +static void drm_test_framebuffer_lookup_inexistent (struct kunit *test) +{ +struct drm_framebuffer_test_priv *priv = test->priv; +struct drm_device *dev = &priv->dev; +struct drm_framebuffer *fb; +uint32_t id =0 ; + +/* Looking for an inexistent framebuffer */ + fb =drm_framebuffer_lookup (dev,NULL , id); +KUNIT_EXPECT_NULL (test, fb); +} +static struct kunit_case drm_framebuffer_tests[] = {KUNIT_CASE_PARAM (drm_test_framebuffer_check_src_coords, check_src_coords_gen_params),KUNIT_CASE (drm_test_framebuffer_cleanup),KUNIT_CASE_PARAM (drm_test_framebuffer_create, drm_framebuffer_create_gen_params), +KUNIT_CASE (drm_test_framebuffer_lookup), +KUNIT_CASE (drm_test_framebuffer_lookup_inexistent),KUNIT_CASE (drm_test_framebuffer_modifiers_not_supported), { } };
Signature · 1 line
2.44.2
PATCH v4 8/9 drm/tests: Add test for drm_framebuffer_init()
In reply to Carlos Eduardo Gallo FilhoAdd three KUnit test cases for the drm_framebuffer_init function:
1. Test if expected values are being set after drm_framebuffer_init() call.
2. Try to init a framebuffer without setting its format.
3. Try calling drm_framebuffer_init() with mismatch of the drm_device passed at the first argument and the one pointed by fb->dev.
---
v2:
- Reorder kunit cases alphabetically.
- Let fb1.dev unset instead of set it to wrong_drm to test mismatched drm_device passed as drm_framebuffer_init() argument.
- Clean the framebuffer object.
v3:
- Split into three tests.
- Add documentation.
- Stop testing lookup here.
v4:
- Export drm_framebuffer_free for test.
- Document what is expected on drm_test_framebuffer_init test.
- Use a valid drm_device on drm_test_framebuffer_init_dev_mismatch test.
--- drivers/gpu/drm/drm_framebuffer.c | 1 + drivers/gpu/drm/tests/drm_framebuffer_test.c | 84 ++++++++++++++++++++ 2 files changed, 85 insertions(+)
drivers/gpu/drm/drm_framebuffer.c +1 -0
@@ -839,6 +839,7 @@ void drm_framebuffer_free(struct kref *kref) fb->funcs->destroy (fb); } +EXPORT_SYMBOL_FOR_TESTS_ONLY (drm_framebuffer_free);/** * drm_framebuffer_init - initialize a framebuffer
drivers/gpu/drm/tests/drm_framebuffer_test.c +84 -0
100 lines not on this page · raw message
Signature · 1 line
2.44.2
PATCH v4 9/9 drm/tests: Add test for drm_framebuffer_free()
In reply to Carlos Eduardo Gallo FilhoAdd a single KUnit test case for the drm_framebuffer_free function.
---
v2:
- Reorder kunit cases alphabetically.
v3:
- Replace the use of void pointer on drm_framebuffer_test_priv struct.
- Remove the test with unregistered framebuffer object.
- Add documentation.
v4:
- Export drm_mode_object_add for test.
--- drivers/gpu/drm/drm_mode_object.c | 1 + drivers/gpu/drm/tests/drm_framebuffer_test.c | 50 ++++++++++++++++++++ 2 files changed, 51 insertions(+)
drivers/gpu/drm/drm_mode_object.c +1 -0
@@ -81,6 +81,7 @@ int drm_mode_object_add(struct drm_device *dev, {return __drm_mode_object_add (dev, obj, obj_type, true,NULL ); } +EXPORT_SYMBOL_FOR_TESTS_ONLY (drm_mode_object_add);void drm_mode_object_register (struct drm_device *dev,struct drm_mode_object *obj)
drivers/gpu/drm/tests/drm_framebuffer_test.c +50 -0
66 lines not on this page · raw message
Signature · 1 line
2.44.2