* [PATCH v4 RESEND 1/9] drm/tests: Stop using deprecated dev_private member on drm_framebuffer tests
2024-09-11 0:15 [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Carlos Eduardo Gallo Filho
@ 2024-09-11 0:15 ` Carlos Eduardo Gallo Filho
2024-09-11 0:15 ` [PATCH v4 RESEND 2/9] drm/tests: Add parameters to the drm_test_framebuffer_create test Carlos Eduardo Gallo Filho
` (8 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Carlos Eduardo Gallo Filho @ 2024-09-11 0:15 UTC (permalink / raw)
To: dri-devel
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Maíra Canal, André Almeida,
Arthur Grillo, Tales Lelo da Aparecida,
Carlos Eduardo Gallo Filho
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.
Signed-off-by: Carlos Eduardo Gallo Filho <gcarlos@disroot.org>
Acked-by: Maxime Ripard <mripard@kernel.org>
---
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(-)
diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c
index 06f03b78c9c4..3882a88b6631 100644
--- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
+++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
@@ -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)
--
2.44.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v4 RESEND 2/9] drm/tests: Add parameters to the drm_test_framebuffer_create test
2024-09-11 0:15 [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Carlos Eduardo Gallo Filho
2024-09-11 0:15 ` [PATCH v4 RESEND 1/9] drm/tests: Stop using deprecated dev_private member on drm_framebuffer tests Carlos Eduardo Gallo Filho
@ 2024-09-11 0:15 ` Carlos Eduardo Gallo Filho
2024-09-11 0:15 ` [PATCH v4 RESEND 3/9] drm/tests: Replace strcpy to strscpy on " Carlos Eduardo Gallo Filho
` (7 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Carlos Eduardo Gallo Filho @ 2024-09-11 0:15 UTC (permalink / raw)
To: dri-devel
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Maíra Canal, André Almeida,
Arthur Grillo, Tales Lelo da Aparecida,
Carlos Eduardo Gallo Filho
Extend 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
Signed-off-by: Carlos Eduardo Gallo Filho <gcarlos@disroot.org>
Acked-by: Maxime Ripard <mripard@kernel.org>
---
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(+)
diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c
index 3882a88b6631..3ed987423322 100644
--- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
+++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
@@ -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 }
--
2.44.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v4 RESEND 3/9] drm/tests: Replace strcpy to strscpy on drm_test_framebuffer_create test
2024-09-11 0:15 [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Carlos Eduardo Gallo Filho
2024-09-11 0:15 ` [PATCH v4 RESEND 1/9] drm/tests: Stop using deprecated dev_private member on drm_framebuffer tests Carlos Eduardo Gallo Filho
2024-09-11 0:15 ` [PATCH v4 RESEND 2/9] drm/tests: Add parameters to the drm_test_framebuffer_create test Carlos Eduardo Gallo Filho
@ 2024-09-11 0:15 ` Carlos Eduardo Gallo Filho
2024-09-11 0:15 ` [PATCH v4 RESEND 4/9] drm/tests: Add test case for drm_internal_framebuffer_create() Carlos Eduardo Gallo Filho
` (6 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Carlos Eduardo Gallo Filho @ 2024-09-11 0:15 UTC (permalink / raw)
To: dri-devel
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Maíra Canal, André Almeida,
Arthur Grillo, Tales Lelo da Aparecida,
Carlos Eduardo Gallo Filho
Replace the use of strcpy to strscpy on the test_to_desc of the
drm_test_framebuffer_create test for better security and reliability.
Signed-off-by: Carlos Eduardo Gallo Filho <gcarlos@disroot.org>
Acked-by: Maxime Ripard <mripard@kernel.org>
---
drivers/gpu/drm/tests/drm_framebuffer_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c
index 3ed987423322..4b1884be9d7a 100644
--- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
+++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
@@ -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,
--
2.44.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v4 RESEND 4/9] drm/tests: Add test case for drm_internal_framebuffer_create()
2024-09-11 0:15 [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Carlos Eduardo Gallo Filho
` (2 preceding siblings ...)
2024-09-11 0:15 ` [PATCH v4 RESEND 3/9] drm/tests: Replace strcpy to strscpy on " Carlos Eduardo Gallo Filho
@ 2024-09-11 0:15 ` Carlos Eduardo Gallo Filho
2024-09-11 0:15 ` [PATCH v4 RESEND 5/9] drm/tests: Add test for drm_framebuffer_check_src_coords() Carlos Eduardo Gallo Filho
` (5 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Carlos Eduardo Gallo Filho @ 2024-09-11 0:15 UTC (permalink / raw)
To: dri-devel
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Maíra Canal, André Almeida,
Arthur Grillo, Tales Lelo da Aparecida,
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 <gcarlos@disroot.org>
---
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(+)
diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c
index 4b1884be9d7a..2ea3abfd5e7a 100644
--- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
+++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
@@ -415,8 +415,32 @@ static void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, c
KUNIT_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),
{ }
};
--
2.44.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v4 RESEND 5/9] drm/tests: Add test for drm_framebuffer_check_src_coords()
2024-09-11 0:15 [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Carlos Eduardo Gallo Filho
` (3 preceding siblings ...)
2024-09-11 0:15 ` [PATCH v4 RESEND 4/9] drm/tests: Add test case for drm_internal_framebuffer_create() Carlos Eduardo Gallo Filho
@ 2024-09-11 0:15 ` Carlos Eduardo Gallo Filho
2024-09-11 0:15 ` [PATCH v4 RESEND 6/9] drm/tests: Add test for drm_framebuffer_cleanup() Carlos Eduardo Gallo Filho
` (4 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Carlos Eduardo Gallo Filho @ 2024-09-11 0:15 UTC (permalink / raw)
To: dri-devel
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Maíra Canal, André Almeida,
Arthur Grillo, Tales Lelo da Aparecida,
Carlos Eduardo Gallo Filho
Add a parametrized test for the drm_framebuffer_check_src_coords function.
Signed-off-by: Carlos Eduardo Gallo Filho <gcarlos@disroot.org>
Acked-by: Maxime Ripard <mripard@kernel.org>
---
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(+)
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index 888aadb6a4ac..9cd85ac789bb 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -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
diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c
index 2ea3abfd5e7a..1924e3f9538e 100644
--- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
+++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
@@ -10,6 +10,7 @@
#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>
#include <drm/drm_kunit_helpers.h>
#include <drm/drm_print.h>
@@ -438,7 +439,67 @@ static void drm_test_framebuffer_modifiers_not_supported(struct kunit *test)
KUNIT_EXPECT_EQ(test, PTR_ERR(fb), -EINVAL);
}
+/* Parameters for testing drm_framebuffer_check_src_coords function */
+struct drm_framebuffer_check_src_coords_case {
+ const char *name;
+ const int expect;
+ const unsigned int fb_size;
+ const uint32_t src_x;
+ const uint32_t src_y;
+
+ /* Deltas to be applied on source */
+ const uint32_t dsrc_w;
+ const uint32_t dsrc_h;
+};
+
+static const struct drm_framebuffer_check_src_coords_case
+drm_framebuffer_check_src_coords_cases[] = {
+ { .name = "Success: source fits into fb",
+ .expect = 0,
+ },
+ { .name = "Fail: overflowing fb with x-axis coordinate",
+ .expect = -ENOSPC, .src_x = 1, .fb_size = UINT_MAX,
+ },
+ { .name = "Fail: overflowing fb with y-axis coordinate",
+ .expect = -ENOSPC, .src_y = 1, .fb_size = UINT_MAX,
+ },
+ { .name = "Fail: overflowing fb with source width",
+ .expect = -ENOSPC, .dsrc_w = 1, .fb_size = UINT_MAX - 1,
+ },
+ { .name = "Fail: overflowing fb with source height",
+ .expect = -ENOSPC, .dsrc_h = 1, .fb_size = UINT_MAX - 1,
+ },
+};
+
+static void drm_test_framebuffer_check_src_coords(struct kunit *test)
+{
+ const struct drm_framebuffer_check_src_coords_case *params = test->param_value;
+ const uint32_t src_x = params->src_x;
+ const uint32_t src_y = params->src_y;
+ const uint32_t src_w = (params->fb_size << 16) + params->dsrc_w;
+ const uint32_t src_h = (params->fb_size << 16) + params->dsrc_h;
+ const struct drm_framebuffer fb = {
+ .width = params->fb_size,
+ .height = params->fb_size
+ };
+ 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 drm_framebuffer_check_src_coords_case *t,
+ char *desc)
+{
+ strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
+}
+
+KUNIT_ARRAY_PARAM(check_src_coords, drm_framebuffer_check_src_coords_cases,
+ check_src_coords_test_to_desc);
+
static struct kunit_case drm_framebuffer_tests[] = {
+ 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),
KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported),
{ }
--
2.44.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v4 RESEND 6/9] drm/tests: Add test for drm_framebuffer_cleanup()
2024-09-11 0:15 [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Carlos Eduardo Gallo Filho
` (4 preceding siblings ...)
2024-09-11 0:15 ` [PATCH v4 RESEND 5/9] drm/tests: Add test for drm_framebuffer_check_src_coords() Carlos Eduardo Gallo Filho
@ 2024-09-11 0:15 ` Carlos Eduardo Gallo Filho
2024-09-11 0:15 ` [PATCH v4 RESEND 7/9] drm/tests: Add test for drm_framebuffer_lookup() Carlos Eduardo Gallo Filho
` (3 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Carlos Eduardo Gallo Filho @ 2024-09-11 0:15 UTC (permalink / raw)
To: dri-devel
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Maíra Canal, André Almeida,
Arthur Grillo, Tales Lelo da Aparecida,
Carlos Eduardo Gallo Filho
Add a single KUnit test case for the drm_framebuffer_cleanup function.
Signed-off-by: Carlos Eduardo Gallo Filho <gcarlos@disroot.org>
Acked-by: Maxime Ripard <mripard@kernel.org>
---
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(+)
diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c
index 1924e3f9538e..908583d74b20 100644
--- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
+++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
@@ -498,8 +498,40 @@ check_src_coords_test_to_desc(const struct drm_framebuffer_check_src_coords_case
KUNIT_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),
{ }
--
2.44.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v4 RESEND 7/9] drm/tests: Add test for drm_framebuffer_lookup()
2024-09-11 0:15 [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Carlos Eduardo Gallo Filho
` (5 preceding siblings ...)
2024-09-11 0:15 ` [PATCH v4 RESEND 6/9] drm/tests: Add test for drm_framebuffer_cleanup() Carlos Eduardo Gallo Filho
@ 2024-09-11 0:15 ` Carlos Eduardo Gallo Filho
2024-09-11 0:15 ` [PATCH v4 RESEND 8/9] drm/tests: Add test for drm_framebuffer_init() Carlos Eduardo Gallo Filho
` (2 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Carlos Eduardo Gallo Filho @ 2024-09-11 0:15 UTC (permalink / raw)
To: dri-devel
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Maíra Canal, André Almeida,
Arthur Grillo, Tales Lelo da Aparecida,
Carlos Eduardo Gallo Filho
Add 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.
Signed-off-by: Carlos Eduardo Gallo Filho <gcarlos@disroot.org>
Acked-by: Maxime Ripard <mripard@kernel.org>
---
v2:
- Reorder kunit cases alphabetically.
- Replace drm_mode_object_add() call to drm_framebuffer_init().
- Rely on drm_kunit_helper_alloc_device() for mock initialization.
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(+)
diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c
index 908583d74b20..e11b5bc9a105 100644
--- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
+++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
@@ -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),
{ }
};
--
2.44.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v4 RESEND 8/9] drm/tests: Add test for drm_framebuffer_init()
2024-09-11 0:15 [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Carlos Eduardo Gallo Filho
` (6 preceding siblings ...)
2024-09-11 0:15 ` [PATCH v4 RESEND 7/9] drm/tests: Add test for drm_framebuffer_lookup() Carlos Eduardo Gallo Filho
@ 2024-09-11 0:15 ` Carlos Eduardo Gallo Filho
2024-09-16 8:48 ` Jani Nikula
2024-09-11 0:15 ` [PATCH v4 RESEND 9/9] drm/tests: Add test for drm_framebuffer_free() Carlos Eduardo Gallo Filho
2024-09-11 12:19 ` [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Maxime Ripard
9 siblings, 1 reply; 15+ messages in thread
From: Carlos Eduardo Gallo Filho @ 2024-09-11 0:15 UTC (permalink / raw)
To: dri-devel
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Maíra Canal, André Almeida,
Arthur Grillo, Tales Lelo da Aparecida,
Carlos Eduardo Gallo Filho
Add 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.
Signed-off-by: Carlos Eduardo Gallo Filho <gcarlos@disroot.org>
---
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(+)
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index 9cd85ac789bb..47e6e8577b62 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -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
diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c
index e11b5bc9a105..72314805839d 100644
--- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
+++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
@@ -5,6 +5,7 @@
* Copyright (c) 2022 Maíra Canal <mairacanal@riseup.net>
*/
+#include <kunit/device.h>
#include <kunit/test.h>
#include <drm/drm_device.h>
@@ -568,10 +569,93 @@ static void drm_test_framebuffer_lookup_inexistent(struct kunit *test)
KUNIT_EXPECT_NULL(test, fb);
}
+/*
+ * Test if drm_framebuffer_init initializes the framebuffer successfully,
+ * asserting that its modeset object struct and its refcount are correctly
+ * set and that strictly one framebuffer is initialized.
+ */
+static void drm_test_framebuffer_init(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 fb1 = { .dev = dev, .format = &format };
+ struct drm_framebuffer_funcs funcs = { };
+ int ret;
+
+ ret = drm_framebuffer_init(dev, &fb1, &funcs);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
+ /* Check if fb->funcs is actually set to the drm_framebuffer_funcs passed on */
+ KUNIT_EXPECT_PTR_EQ(test, fb1.funcs, &funcs);
+
+ /* The fb->comm must be set to the current running process */
+ KUNIT_EXPECT_STREQ(test, fb1.comm, current->comm);
+
+ /* The fb->base must be successfully initialized */
+ KUNIT_EXPECT_NE(test, fb1.base.id, 0);
+ KUNIT_EXPECT_EQ(test, fb1.base.type, DRM_MODE_OBJECT_FB);
+ KUNIT_EXPECT_EQ(test, kref_read(&fb1.base.refcount), 1);
+ KUNIT_EXPECT_PTR_EQ(test, fb1.base.free_cb, &drm_framebuffer_free);
+
+ /* There must be just that one fb initialized */
+ KUNIT_EXPECT_EQ(test, dev->mode_config.num_fb, 1);
+ KUNIT_EXPECT_PTR_EQ(test, dev->mode_config.fb_list.prev, &fb1.head);
+ KUNIT_EXPECT_PTR_EQ(test, dev->mode_config.fb_list.next, &fb1.head);
+
+ drm_framebuffer_cleanup(&fb1);
+}
+
+/* Try to init a framebuffer without setting its format */
+static void drm_test_framebuffer_init_bad_format(struct kunit *test)
+{
+ struct drm_framebuffer_test_priv *priv = test->priv;
+ struct drm_device *dev = &priv->dev;
+ struct drm_framebuffer fb1 = { .dev = dev, .format = NULL };
+ struct drm_framebuffer_funcs funcs = { };
+ int ret;
+
+ /* Fails if fb.format isn't set */
+ ret = drm_framebuffer_init(dev, &fb1, &funcs);
+ KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+}
+
+/*
+ * Test calling drm_framebuffer_init() passing a framebuffer linked to a
+ * different drm_device parent from the one passed on the first argument, which
+ * must fail.
+ */
+static void drm_test_framebuffer_init_dev_mismatch(struct kunit *test)
+{
+ struct drm_framebuffer_test_priv *priv = test->priv;
+ struct drm_device *right_dev = &priv->dev;
+ struct drm_device *wrong_dev;
+ struct device *wrong_dev_parent;
+ struct drm_format_info format = { };
+ struct drm_framebuffer fb1 = { .dev = right_dev, .format = &format };
+ struct drm_framebuffer_funcs funcs = { };
+ int ret;
+
+ wrong_dev_parent = kunit_device_register(test, "drm-kunit-wrong-device-mock");
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, wrong_dev_parent);
+
+ wrong_dev = __drm_kunit_helper_alloc_drm_device(test, wrong_dev_parent,
+ sizeof(struct drm_device),
+ 0, 0);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, wrong_dev);
+
+ /* Fails if fb->dev doesn't point to the drm_device passed on first arg */
+ ret = drm_framebuffer_init(wrong_dev, &fb1, &funcs);
+ KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+}
+
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_init),
+ KUNIT_CASE(drm_test_framebuffer_init_bad_format),
+ KUNIT_CASE(drm_test_framebuffer_init_dev_mismatch),
KUNIT_CASE(drm_test_framebuffer_lookup),
KUNIT_CASE(drm_test_framebuffer_lookup_inexistent),
KUNIT_CASE(drm_test_framebuffer_modifiers_not_supported),
--
2.44.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v4 RESEND 8/9] drm/tests: Add test for drm_framebuffer_init()
2024-09-11 0:15 ` [PATCH v4 RESEND 8/9] drm/tests: Add test for drm_framebuffer_init() Carlos Eduardo Gallo Filho
@ 2024-09-16 8:48 ` Jani Nikula
0 siblings, 0 replies; 15+ messages in thread
From: Jani Nikula @ 2024-09-16 8:48 UTC (permalink / raw)
To: Carlos Eduardo Gallo Filho, dri-devel
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Maíra Canal, André Almeida,
Arthur Grillo, Tales Lelo da Aparecida,
Carlos Eduardo Gallo Filho
On Tue, 10 Sep 2024, Carlos Eduardo Gallo Filho <gcarlos@disroot.org> wrote:
> +/* Try to init a framebuffer without setting its format */
> +static void drm_test_framebuffer_init_bad_format(struct kunit *test)
> +{
> + struct drm_framebuffer_test_priv *priv = test->priv;
> + struct drm_device *dev = &priv->dev;
> + struct drm_framebuffer fb1 = { .dev = dev, .format = NULL };
> + struct drm_framebuffer_funcs funcs = { };
> + int ret;
> +
> + /* Fails if fb.format isn't set */
> + ret = drm_framebuffer_init(dev, &fb1, &funcs);
Not only does this fail, it spits a WARN_ON_ONCE() in dmesg. Which in
turn gets flagged as a failure in the test in our CI.
What's the policy with kunit tests causing warnings? I think it's
reasonable for any CI to flag dmesg warnings. We shouldn't be hitting
those. Filtering the warnigs is a tricky business.
BR,
Jani.
> + KUNIT_EXPECT_EQ(test, ret, -EINVAL);
> +}
--
Jani Nikula, Intel
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v4 RESEND 9/9] drm/tests: Add test for drm_framebuffer_free()
2024-09-11 0:15 [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Carlos Eduardo Gallo Filho
` (7 preceding siblings ...)
2024-09-11 0:15 ` [PATCH v4 RESEND 8/9] drm/tests: Add test for drm_framebuffer_init() Carlos Eduardo Gallo Filho
@ 2024-09-11 0:15 ` Carlos Eduardo Gallo Filho
2024-09-11 12:19 ` [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Maxime Ripard
9 siblings, 0 replies; 15+ messages in thread
From: Carlos Eduardo Gallo Filho @ 2024-09-11 0:15 UTC (permalink / raw)
To: dri-devel
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Maíra Canal, André Almeida,
Arthur Grillo, Tales Lelo da Aparecida,
Carlos Eduardo Gallo Filho
Add a single KUnit test case for the drm_framebuffer_free function.
Signed-off-by: Carlos Eduardo Gallo Filho <gcarlos@disroot.org>
Acked-by: Maxime Ripard <mripard@kernel.org>
---
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(+)
diff --git a/drivers/gpu/drm/drm_mode_object.c b/drivers/gpu/drm/drm_mode_object.c
index df4cc0e8e263..e943205a2394 100644
--- a/drivers/gpu/drm/drm_mode_object.c
+++ b/drivers/gpu/drm/drm_mode_object.c
@@ -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)
diff --git a/drivers/gpu/drm/tests/drm_framebuffer_test.c b/drivers/gpu/drm/tests/drm_framebuffer_test.c
index 72314805839d..6ea04cc8f324 100644
--- a/drivers/gpu/drm/tests/drm_framebuffer_test.c
+++ b/drivers/gpu/drm/tests/drm_framebuffer_test.c
@@ -358,6 +358,7 @@ static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = {
struct drm_framebuffer_test_priv {
struct drm_device dev;
bool buffer_created;
+ bool buffer_freed;
};
static struct drm_framebuffer *fb_create_mock(struct drm_device *dev,
@@ -649,10 +650,59 @@ static void drm_test_framebuffer_init_dev_mismatch(struct kunit *test)
KUNIT_EXPECT_EQ(test, ret, -EINVAL);
}
+static void destroy_free_mock(struct drm_framebuffer *fb)
+{
+ struct drm_framebuffer_test_priv *priv = container_of(fb->dev, typeof(*priv), dev);
+
+ priv->buffer_freed = true;
+}
+
+static struct drm_framebuffer_funcs framebuffer_funcs_free_mock = {
+ .destroy = destroy_free_mock,
+};
+
+/*
+ * In summary, the drm_framebuffer_free() function must implicitly call
+ * fb->funcs->destroy() and garantee that the framebufer object is unregistered
+ * from the drm_device idr pool.
+ */
+static void drm_test_framebuffer_free(struct kunit *test)
+{
+ struct drm_framebuffer_test_priv *priv = test->priv;
+ struct drm_device *dev = &priv->dev;
+ struct drm_mode_object *obj;
+ struct drm_framebuffer fb = {
+ .dev = dev,
+ .funcs = &framebuffer_funcs_free_mock,
+ };
+ int id, ret;
+
+ priv->buffer_freed = false;
+
+ /*
+ * Mock a framebuffer that was not unregistered at the moment of the
+ * drm_framebuffer_free() call.
+ */
+ ret = drm_mode_object_add(dev, &fb.base, DRM_MODE_OBJECT_FB);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+ id = fb.base.id;
+
+ drm_framebuffer_free(&fb.base.refcount);
+
+ /* The framebuffer object must be unregistered */
+ obj = drm_mode_object_find(dev, NULL, id, DRM_MODE_OBJECT_FB);
+ KUNIT_EXPECT_PTR_EQ(test, obj, NULL);
+ KUNIT_EXPECT_EQ(test, fb.base.id, 0);
+
+ /* Test if fb->funcs->destroy() was called */
+ KUNIT_EXPECT_EQ(test, priv->buffer_freed, true);
+}
+
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_free),
KUNIT_CASE(drm_test_framebuffer_init),
KUNIT_CASE(drm_test_framebuffer_init_bad_format),
KUNIT_CASE(drm_test_framebuffer_init_dev_mismatch),
--
2.44.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c
2024-09-11 0:15 [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Carlos Eduardo Gallo Filho
` (8 preceding siblings ...)
2024-09-11 0:15 ` [PATCH v4 RESEND 9/9] drm/tests: Add test for drm_framebuffer_free() Carlos Eduardo Gallo Filho
@ 2024-09-11 12:19 ` Maxime Ripard
2024-09-13 7:31 ` Jani Nikula
9 siblings, 1 reply; 15+ messages in thread
From: Maxime Ripard @ 2024-09-11 12:19 UTC (permalink / raw)
To: dri-devel, Carlos Eduardo Gallo Filho
Cc: Maarten Lankhorst, Thomas Zimmermann, David Airlie,
Maíra Canal, André Almeida, Arthur Grillo,
Tales Lelo da Aparecida, Simona Vetter
On Tue, 10 Sep 2024 21:15:25 -0300, Carlos Eduardo Gallo Filho wrote:
> 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.
>
> [...]
Applied to misc/kernel.git (drm-misc-next).
Thanks!
Maxime
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c
2024-09-11 12:19 ` [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c Maxime Ripard
@ 2024-09-13 7:31 ` Jani Nikula
2024-09-13 7:41 ` Maxime Ripard
0 siblings, 1 reply; 15+ messages in thread
From: Jani Nikula @ 2024-09-13 7:31 UTC (permalink / raw)
To: Maxime Ripard, dri-devel, Carlos Eduardo Gallo Filho
Cc: Maarten Lankhorst, Thomas Zimmermann, David Airlie,
Maíra Canal, André Almeida, Arthur Grillo,
Tales Lelo da Aparecida, Simona Vetter
On Wed, 11 Sep 2024, Maxime Ripard <mripard@kernel.org> wrote:
> On Tue, 10 Sep 2024 21:15:25 -0300, Carlos Eduardo Gallo Filho wrote:
>> 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.
>>
>> [...]
>
> Applied to misc/kernel.git (drm-misc-next).
How was this series itself tested? It would be prudent to Cc: intel-gfx
on stuff like this to run it through our CI. I don't think it ever
passed [1].
BR,
Jani.
[1] https://intel-gfx-ci.01.org/tree/drm-tip/shards-all.html?testfilter=drm_framebuffer
--
Jani Nikula, Intel
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c
2024-09-13 7:31 ` Jani Nikula
@ 2024-09-13 7:41 ` Maxime Ripard
2024-09-13 9:13 ` Jani Nikula
0 siblings, 1 reply; 15+ messages in thread
From: Maxime Ripard @ 2024-09-13 7:41 UTC (permalink / raw)
To: Jani Nikula
Cc: dri-devel, Carlos Eduardo Gallo Filho, Maarten Lankhorst,
Thomas Zimmermann, David Airlie, Maíra Canal,
André Almeida, Arthur Grillo, Tales Lelo da Aparecida,
Simona Vetter
[-- Attachment #1: Type: text/plain, Size: 925 bytes --]
On Fri, Sep 13, 2024 at 10:31:08AM GMT, Jani Nikula wrote:
> On Wed, 11 Sep 2024, Maxime Ripard <mripard@kernel.org> wrote:
> > On Tue, 10 Sep 2024 21:15:25 -0300, Carlos Eduardo Gallo Filho wrote:
> >> 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.
> >>
> >> [...]
> >
> > Applied to misc/kernel.git (drm-misc-next).
>
> How was this series itself tested? It would be prudent to Cc: intel-gfx
> on stuff like this to run it through our CI. I don't think it ever
> passed [1].
I'm not sure what's going on, but:
./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm//tests
Works like a charm with this series
Maxime
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 273 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v4 RESEND 0/9] Increase coverage on drm_framebuffer.c
2024-09-13 7:41 ` Maxime Ripard
@ 2024-09-13 9:13 ` Jani Nikula
0 siblings, 0 replies; 15+ messages in thread
From: Jani Nikula @ 2024-09-13 9:13 UTC (permalink / raw)
To: Maxime Ripard
Cc: dri-devel, Carlos Eduardo Gallo Filho, Maarten Lankhorst,
Thomas Zimmermann, David Airlie, Maíra Canal,
André Almeida, Arthur Grillo, Tales Lelo da Aparecida,
Simona Vetter
On Fri, 13 Sep 2024, Maxime Ripard <mripard@kernel.org> wrote:
> On Fri, Sep 13, 2024 at 10:31:08AM GMT, Jani Nikula wrote:
>> On Wed, 11 Sep 2024, Maxime Ripard <mripard@kernel.org> wrote:
>> > On Tue, 10 Sep 2024 21:15:25 -0300, Carlos Eduardo Gallo Filho wrote:
>> >> 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.
>> >>
>> >> [...]
>> >
>> > Applied to misc/kernel.git (drm-misc-next).
>>
>> How was this series itself tested? It would be prudent to Cc: intel-gfx
>> on stuff like this to run it through our CI. I don't think it ever
>> passed [1].
>
> I'm not sure what's going on, but:
>
> ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm//tests
>
> Works like a charm with this series
We consistently hit the below warning in drm_framebuffer_free().
Looks like drm_test_framebuffer_free() fails to initialize the
framebuffer, there's no call to drm_framebuffer_init(), leaving
fb->filp_head list uninitialized. The list_empty() check in
drm_framebuffer_free() blows up. Why it doesn't fail for you, I don't
understand.
BR,
Jani.
<4> [131.574236] ------------[ cut here ]------------
<4> [131.574244] drm-kunit-mock-device drm_test_framebuffer_free.drm-kunit-mock-device: [drm] drm_WARN_ON(!list_empty(&fb->filp_head))
<4> [131.574269] WARNING: CPU: 8 PID: 1261 at drivers/gpu/drm/drm_framebuffer.c:832 drm_framebuffer_free+0x71/0x80
<4> [131.574281] Modules linked in: drm_framebuffer_test drm_kunit_helpers kunit vgem drm_shmem_helper snd_hda_codec_hdmi r8153_ecm cdc_ether usbnet i915 x86_pkg_temp_thermal coretemp kvm_intel kvm snd_hda_intel snd_intel_dspcfg mei_gsc_proxy snd_hda_codec prime_numbers crct10dif_pclmul r8152 snd_hwdep i2c_algo_bit crc32_pclmul wmi_bmof mii ghash_clmulni_intel ttm e1000e snd_hda_core video i2c_i801 mei_me drm_display_helper ptp i2c_mux snd_pcm thunderbolt mei drm_buddy pps_core i2c_smbus intel_lpss_pci wmi [last unloaded: drm_framebuffer_test]
<4> [131.574378] CPU: 8 UID: 0 PID: 1261 Comm: kunit_try_catch Tainted: G N 6.11.0-rc7-CI_DRM_15393-g2c6794afc551+ #1
<4> [131.574386] Tainted: [N]=TEST
<4> [131.574389] Hardware name: Intel Corporation Meteor Lake Client Platform/MTL-P LP5x T3 RVP, BIOS MTLPFWI1.R00.3471.D91.2401310918 01/31/2024
<4> [131.574393] RIP: 0010:drm_framebuffer_free+0x71/0x80
<4> [131.574400] Code: 4c 8b 6f 50 4d 85 ed 75 03 4c 8b 2f e8 48 c5 03 00 48 c7 c1 88 00 4f 82 4c 89 ea 48 c7 c7 53 8f 45 82 48 89 c6 e8 1f be 80 ff <0f> 0b eb ad 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90
<4> [131.574405] RSP: 0018:ffffc900013efd60 EFLAGS: 00010282
<4> [131.574413] RAX: 0000000000000000 RBX: ffffc900013efdc8 RCX: 0000000000000000
<4> [131.574418] RDX: 0000000000000002 RSI: ffffffff8243ccc2 RDI: 00000000ffffffff
<4> [131.574422] RBP: ffff8881190f9000 R08: 0000000000000000 R09: ffffc900013efb90
<4> [131.574425] R10: 0000000000000001 R11: 0000000000000001 R12: ffffc900013efda0
<4> [131.574429] R13: ffff888114cb9b40 R14: ffffffffa030e520 R15: ffffc9000169f8e0
<4> [131.574434] FS: 0000000000000000(0000) GS:ffff88885fc00000(0000) knlGS:0000000000000000
<4> [131.574441] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
<4> [131.574448] CR2: 000055cc6f2feed0 CR3: 000000000663a002 CR4: 0000000000f70ef0
<4> [131.574455] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
<4> [131.574463] DR3: 0000000000000000 DR6: 00000000ffff07f0 DR7: 0000000000000400
<4> [131.574470] PKRU: 55555554
<4> [131.574477] Call Trace:
<4> [131.574483] <TASK>
<4> [131.574491] ? __warn+0x8c/0x190
<4> [131.574505] ? drm_framebuffer_free+0x71/0x80
<4> [131.574518] ? report_bug+0x1f8/0x200
<4> [131.574535] ? prb_read_valid+0x16/0x20
<4> [131.574553] ? handle_bug+0x3c/0x70
<4> [131.574566] ? exc_invalid_op+0x18/0x70
<4> [131.574579] ? asm_exc_invalid_op+0x1a/0x20
<4> [131.574593] ? __pfx_kunit_generic_run_threadfn_adapter+0x10/0x10 [kunit]
<4> [131.574636] ? drm_framebuffer_free+0x71/0x80
<4> [131.574658] drm_test_framebuffer_free+0x88/0x220 [drm_framebuffer_test]
<4> [131.574709] kunit_try_run_case+0x6d/0x150 [kunit]
<4> [131.574724] ? __kthread_parkme+0x31/0xa0
<4> [131.574732] ? lockdep_hardirqs_on+0x7b/0x100
<4> [131.574744] ? __pfx_kunit_generic_run_threadfn_adapter+0x10/0x10 [kunit]
<4> [131.574757] kunit_generic_run_threadfn_adapter+0x19/0x40 [kunit]
<4> [131.574771] kthread+0xeb/0x120
<4> [131.574779] ? __pfx_kthread+0x10/0x10
<4> [131.574788] ret_from_fork+0x2c/0x50
<4> [131.574796] ? __pfx_kthread+0x10/0x10
<4> [131.574803] ret_from_fork_asm+0x1a/0x30
<4> [131.574821] </TASK>
<4> [131.574824] irq event stamp: 1017
<4> [131.574829] hardirqs last enabled at (1023): [<ffffffff8113ec40>] console_unlock+0x110/0x120
<4> [131.574841] hardirqs last disabled at (1028): [<ffffffff8113ec25>] console_unlock+0xf5/0x120
<4> [131.574851] softirqs last enabled at (14): [<ffffffff810a492c>] handle_softirqs+0x2ec/0x3f0
<4> [131.574859] softirqs last disabled at (5): [<ffffffff810a50a7>] irq_exit_rcu+0x87/0xc0
<4> [131.574867] ---[ end trace 0000000000000000 ]---
--
Jani Nikula, Intel
^ permalink raw reply [flat|nested] 15+ messages in thread