From: "Michał Winiarski" <michal.winiarski@intel.com>
To: <dri-devel@lists.freedesktop.org>, <linux-kselftest@vger.kernel.org>
Cc: "Brendan Higgins" <brendanhiggins@google.com>,
"Daniel Latypov" <dlatypov@google.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"David Airlie" <airlied@linux.ie>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Petri Latvala" <petri.latvala@intel.com>,
"Arkadiusz Hiler" <arek@hiler.eu>,
"Michał Winiarski" <michal.winiarski@intel.com>
Subject: [RFC 04/10] drm: test-drm_framebuffer: Convert to KUnit
Date: Tue, 18 Jan 2022 00:22:53 +0100 [thread overview]
Message-ID: <20220117232259.180459-5-michal.winiarski@intel.com> (raw)
In-Reply-To: <20220117232259.180459-1-michal.winiarski@intel.com>
Mocking was moved to .init() in order to separate it from test logic.
No functional changes.
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
---
drivers/gpu/drm/selftests/Makefile | 3 +-
.../gpu/drm/selftests/drm_modeset_selftests.h | 1 -
.../gpu/drm/selftests/test-drm_framebuffer.c | 109 +++++++++++-------
.../drm/selftests/test-drm_modeset_common.h | 1 -
4 files changed, 68 insertions(+), 46 deletions(-)
diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile
index 76c127613d1a..1235eadca884 100644
--- a/drivers/gpu/drm/selftests/Makefile
+++ b/drivers/gpu/drm/selftests/Makefile
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only
test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \
test-drm_modeset_common.o \
- test-drm_framebuffer.o \
test-drm_damage_helper.o test-drm_dp_mst_helper.o \
test-drm_rect.o
@@ -9,4 +8,4 @@ obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o
obj-$(CONFIG_DRM_KUNIT_TEST) := \
test-drm_cmdline_parser.o test-drm_plane_helper.o \
- test-drm_format.o
+ test-drm_format.o test-drm_framebuffer.o
diff --git a/drivers/gpu/drm/selftests/drm_modeset_selftests.h b/drivers/gpu/drm/selftests/drm_modeset_selftests.h
index 5f253d9e573c..66f6b31e1a7f 100644
--- a/drivers/gpu/drm/selftests/drm_modeset_selftests.h
+++ b/drivers/gpu/drm/selftests/drm_modeset_selftests.h
@@ -10,7 +10,6 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero)
selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped)
selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped)
selftest(drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned)
-selftest(check_drm_framebuffer_create, igt_check_drm_framebuffer_create)
selftest(damage_iter_no_damage, igt_damage_iter_no_damage)
selftest(damage_iter_no_damage_fractional_src, igt_damage_iter_no_damage_fractional_src)
selftest(damage_iter_no_damage_src_moved, igt_damage_iter_no_damage_src_moved)
diff --git a/drivers/gpu/drm/selftests/test-drm_framebuffer.c b/drivers/gpu/drm/selftests/test-drm_framebuffer.c
index 61b44d3a6a61..faa01cefe4e5 100644
--- a/drivers/gpu/drm/selftests/test-drm_framebuffer.c
+++ b/drivers/gpu/drm/selftests/test-drm_framebuffer.c
@@ -3,6 +3,7 @@
* Test cases for the drm_framebuffer functions
*/
+#include <kunit/test.h>
#include <linux/kernel.h>
#include <drm/drm_device.h>
@@ -12,20 +13,67 @@
#include "../drm_crtc_internal.h"
-#include "test-drm_modeset_common.h"
-
#define MIN_WIDTH 4
#define MAX_WIDTH 4096
#define MIN_HEIGHT 4
#define MAX_HEIGHT 4096
-struct drm_framebuffer_test {
+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;
+
+ return ERR_PTR(-EINVAL);
+}
+
+static const struct drm_mode_config_funcs mock_config_funcs = {
+ .fb_create = fb_create_mock,
+};
+
+static int drm_framebuffer_test_init(struct kunit *test)
+{
+ struct drm_device *mock;
+
+ mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock);
+
+ mock->mode_config = (struct drm_mode_config) {
+ .min_width = MIN_WIDTH,
+ .max_width = MAX_WIDTH,
+ .min_height = MIN_HEIGHT,
+ .max_height = MAX_HEIGHT,
+ .allow_fb_modifiers = true,
+ .funcs = &mock_config_funcs,
+ };
+
+ test->priv = mock;
+
+ return 0;
+}
+
+struct drm_framebuffer_create_test {
int buffer_created;
struct drm_mode_fb_cmd2 cmd;
const char *name;
};
-static struct drm_framebuffer_test createbuffer_tests[] = {
+static void test_drm_framebuffer_create(struct kunit *test)
+{
+ const struct drm_framebuffer_create_test *params = test->param_value;
+ struct drm_device *mock = test->priv;
+ int buffer_created = 0;
+
+ mock->dev_private = &buffer_created;
+
+ drm_internal_framebuffer_create(mock, ¶ms->cmd, NULL);
+
+ KUNIT_EXPECT_EQ(test, buffer_created, params->buffer_created);
+}
+
+static const struct drm_framebuffer_create_test drm_framebuffer_create_tests[] = {
{ .buffer_created = 1, .name = "ABGR8888 normal sizes",
.cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_ABGR8888,
.handles = { 1, 0, 0 }, .pitches = { 4 * 600, 0, 0 },
@@ -304,48 +352,25 @@ static struct drm_framebuffer_test createbuffer_tests[] = {
},
};
-static struct drm_framebuffer *fb_create_mock(struct drm_device *dev,
- struct drm_file *file_priv,
- const struct drm_mode_fb_cmd2 *mode_cmd)
+static void drm_framebuffer_create_desc(const struct drm_framebuffer_create_test *t,
+ char *desc)
{
- int *buffer_created = dev->dev_private;
- *buffer_created = 1;
- return ERR_PTR(-EINVAL);
+ sprintf(desc, "%s", t->name);
}
-static struct drm_mode_config_funcs mock_config_funcs = {
- .fb_create = fb_create_mock,
-};
+KUNIT_ARRAY_PARAM(drm_framebuffer_create,
+ drm_framebuffer_create_tests,
+ drm_framebuffer_create_desc);
-static struct drm_device mock_drm_device = {
- .mode_config = {
- .min_width = MIN_WIDTH,
- .max_width = MAX_WIDTH,
- .min_height = MIN_HEIGHT,
- .max_height = MAX_HEIGHT,
- .allow_fb_modifiers = true,
- .funcs = &mock_config_funcs,
- },
+static struct kunit_case drm_framebuffer_tests[] = {
+ KUNIT_CASE_PARAM(test_drm_framebuffer_create, drm_framebuffer_create_gen_params),
+ {}
};
-static int execute_drm_mode_fb_cmd2(struct drm_mode_fb_cmd2 *r)
-{
- int buffer_created = 0;
-
- mock_drm_device.dev_private = &buffer_created;
- drm_internal_framebuffer_create(&mock_drm_device, r, NULL);
- return buffer_created;
-}
-
-int igt_check_drm_framebuffer_create(void *ignored)
-{
- int i = 0;
-
- for (i = 0; i < ARRAY_SIZE(createbuffer_tests); i++) {
- FAIL(createbuffer_tests[i].buffer_created !=
- execute_drm_mode_fb_cmd2(&createbuffer_tests[i].cmd),
- "Test %d: \"%s\" failed\n", i, createbuffer_tests[i].name);
- }
+static struct kunit_suite drm_framebuffer_test_suite = {
+ .name = "drm_framebuffer_tests",
+ .init = drm_framebuffer_test_init,
+ .test_cases = drm_framebuffer_tests,
+};
- return 0;
-}
+kunit_test_suite(drm_framebuffer_test_suite);
diff --git a/drivers/gpu/drm/selftests/test-drm_modeset_common.h b/drivers/gpu/drm/selftests/test-drm_modeset_common.h
index f6cfce2a5863..c09f38b791ad 100644
--- a/drivers/gpu/drm/selftests/test-drm_modeset_common.h
+++ b/drivers/gpu/drm/selftests/test-drm_modeset_common.h
@@ -20,7 +20,6 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored);
int igt_drm_rect_clip_scaled_not_clipped(void *ignored);
int igt_drm_rect_clip_scaled_clipped(void *ignored);
int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored);
-int igt_check_drm_framebuffer_create(void *ignored);
int igt_damage_iter_no_damage(void *ignored);
int igt_damage_iter_no_damage_fractional_src(void *ignored);
int igt_damage_iter_no_damage_src_moved(void *ignored);
--
2.34.1
next prev parent reply other threads:[~2022-01-17 23:24 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-17 23:22 [RFC 00/10] drm: selftests: Convert to KUnit Michał Winiarski
2022-01-17 23:22 ` [RFC 01/10] drm: test-drm_cmdline_parser: " Michał Winiarski
2022-01-17 23:22 ` [RFC 02/10] drm: test-drm_plane_helper: " Michał Winiarski
2022-01-17 23:22 ` [RFC 03/10] drm: test-drm_format: " Michał Winiarski
2022-01-17 23:22 ` Michał Winiarski [this message]
2022-01-17 23:22 ` [RFC 05/10] drm: test-drm_damage_helper: " Michał Winiarski
2022-01-17 23:22 ` [RFC 06/10] drm: test-drm_dp_mst_helper: " Michał Winiarski
2022-01-19 0:28 ` Daniel Latypov
2022-01-21 0:48 ` Michał Winiarski
2022-01-21 1:00 ` Daniel Latypov
2022-01-17 23:22 ` [RFC 07/10] drm: test-drm_rect: " Michał Winiarski
2022-01-17 23:22 ` [RFC 09/10] drm: selftests: " Michał Winiarski
2022-01-17 23:22 ` [RFC 10/10] drm: test: Simplify testing on UML with kunit.py Michał Winiarski
2022-01-18 23:58 ` [RFC 00/10] drm: selftests: Convert to KUnit Daniel Latypov
2022-01-20 22:20 ` Michał Winiarski
2022-01-21 0:20 ` Daniel Latypov
2022-01-19 16:11 ` Daniel Vetter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220117232259.180459-5-michal.winiarski@intel.com \
--to=michal.winiarski@intel.com \
--cc=airlied@linux.ie \
--cc=arek@hiler.eu \
--cc=brendanhiggins@google.com \
--cc=daniel@ffwll.ch \
--cc=dlatypov@google.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=petri.latvala@intel.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox