Mocking was moved to .init() in order to separate it from test logic. No functional changes. Signed-off-by: Michał Winiarski <michal.winiarski@xxxxxxxxx> --- 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