Skip to contentSkip to conversation

Increase coverage on drm_framebuffer.c

PATCH RESEND Applied Carlos Eduardo Gallo Filho 3 participants 15 messages Sep 11, 2024 – Sep 16, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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 | 375 ++++++++++++++++++-
 3 files changed, 361 insertions(+), 17 deletions(-)
Signature · 1 line
2.44.2
#1 lore raw

PATCH RESEND 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
index 06f03b78c9c4..3882a88b6631 100644
@@ -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, &params->cmd, NULL);
-	KUNIT_EXPECT_EQ(test, params->buffer_created, buffer_created);
+	priv->buffer_created = false;
+	drm_internal_framebuffer_create(dev, &params->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
#2 lore raw

PATCH RESEND v4 2/9 drm/tests: Add parameters to the drm_test_framebuffer_create test

In reply to 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

---
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
index 3882a88b6631..3ed987423322 100644
@@ -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
#3 lore raw

PATCH RESEND v4 3/9 drm/tests: Replace strcpy to strscpy on drm_test_framebuffer_create test

In reply to 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.

---
 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
index 3ed987423322..4b1884be9d7a 100644
@@ -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
#4 lore raw

PATCH RESEND v4 4/9 drm/tests: Add test case for drm_internal_framebuffer_create()

In reply to Carlos Eduardo Gallo Filho

Introduce 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
index 4b1884be9d7a..2ea3abfd5e7a 100644
@@ -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),
 	{ }
 };
 
Signature · 1 line
2.44.2
#5 lore raw

PATCH RESEND v4 5/9 drm/tests: Add test for drm_framebuffer_check_src_coords()

In reply to Carlos Eduardo Gallo Filho

Add 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
index 888aadb6a4ac..9cd85ac789bb 100644
@@ -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
#6 lore raw

PATCH RESEND v4 6/9 drm/tests: Add test for drm_framebuffer_cleanup()

In reply to Carlos Eduardo Gallo Filho

Add 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
index 1924e3f9538e..908583d74b20 100644
@@ -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),
 	{ }
Signature · 1 line
2.44.2
#7 lore raw

PATCH RESEND v4 7/9 drm/tests: Add test for drm_framebuffer_lookup()

In reply to 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.

---
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
index 908583d74b20..e11b5bc9a105 100644
@@ -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
#8 lore raw

PATCH RESEND v4 8/9 drm/tests: Add test for drm_framebuffer_init()

In reply to 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.

---
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
index 9cd85ac789bb..47e6e8577b62 100644
@@ -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
#9 lore raw

Re: [PATCH v4 RESEND 8/9] drm/tests: Add test for drm_framebuffer_init()

drivers/gpu/drm/tests/drm_framebuffer_test.c static void drm_test_framebuffer_lookup_inexistent(struct kunit *test) · line 619

Quoted 11 lines · Carlos Eduardo Gallo Filho
drivers/gpu/drm/tests/drm_framebuffer_test.c +11 -0
+/* 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.

Quoted 2 lines
(quoted diff) +2 -0
+	KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+}
Signature · 1 line
Jani Nikula, Intel
#10 lore raw

PATCH RESEND v4 9/9 drm/tests: Add test for drm_framebuffer_free()

In reply to Carlos Eduardo Gallo Filho

Add 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
index df4cc0e8e263..e943205a2394 100644
@@ -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
maintainer Applied
#11 lore raw
In reply to Carlos Eduardo Gallo Filho
Quoted 8 lines · Carlos Eduardo Gallo Filho

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

#12 lore raw
Quoted 11 lines · Maxime Ripard
Quoted 8 lines · Carlos Eduardo Gallo Filho

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

Signature · 1 line
Jani Nikula, Intel
maintainer
#13 lore raw
Quoted 9 lines · Jani Nikula
Quoted 8 lines · Maxime Ripard
Quoted 7 lines · Carlos Eduardo Gallo Filho

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.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

[...]

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

#14 lore raw
Quoted 18 lines · Maxime Ripard
Quoted 9 lines · Jani Nikula
Quoted 8 lines · Maxime Ripard
Quoted 7 lines · Carlos Eduardo Gallo Filho

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.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

[...]

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].

Quoted 5 lines

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 ]---

Signature · 1 line
Jani Nikula, Intel