~lkcamp/patches

drm: selftest: convert drm_internal_frame_buffer_create selftest to KUnit v2 PROPOSED

Gabriel Lima Luz: 1
 drm: selftest: convert drm_internal_frame_buffer_create selftest to KUnit

 4 files changed, 35 insertions(+), 17 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~lkcamp/patches/patches/26626/mbox | git am -3
Learn more about email & git

[PATCH v2 1/1] drm: selftest: convert drm_internal_frame_buffer_create selftest to KUnit Export this patch

Remove custom functions for testing framebuffer and replace with KUnit
framework. Keep the tested functions and data the same.

use KUNIT_ARRAY_PARAM to parse test name, expected results and
parameters. This groups 47 testcases to 1 with the same coverage. KUnit
output announces 1 result if all tests passed.

Co-developed-by: Janislley Sousa <janislley@gmail.com>
Signed-off-by: Janislley Sousa <janislley@gmail.com>
Signed-off-by: Gabriel Lima Luz <gabriel.luz.lima@hotmail.com>
---
 drivers/gpu/drm/Kconfig                       | 12 ++++++-
 drivers/gpu/drm/Makefile                      |  2 +-
 drivers/gpu/drm/selftests/Makefile            |  3 +-
 .../gpu/drm/selftests/test-drm_framebuffer.c  | 35 +++++++++++--------
 4 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index cea777ae7fb9..7b5ed3c8abdd 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -27,6 +27,16 @@ menuconfig DRM
	  details.  You should also select and configure AGP
	  (/dev/agpgart) support if it is available for your platform.

config DRM_FRAMEBUFFER_KUNIT_TEST
        tristate "Test for DRM framebuffer" if !KUNIT_ALL_TESTS
        depends on DRM && KUNIT=y
		help
		  This option provides a KUnit modula that can be used to run
		  an unit test on the DRM framebuffer. This option is not useful
		  for distributions or general kernels, but is useful for
		  kernels developers working on DRM.
        default KUNIT_ALL_TESTS

config DRM_MIPI_DBI
	tristate
	depends on DRM
@@ -481,4 +491,4 @@ config DRM_PANEL_ORIENTATION_QUIRKS

config DRM_LIB_RANDOM
	bool
	default n
	default n
\ No newline at end of file
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index ad1112154898..e632c43c9b7d 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -58,7 +58,7 @@ drm_kms_helper-$(CONFIG_DRM_DP_AUX_CHARDEV) += drm_dp_aux_dev.o
drm_kms_helper-$(CONFIG_DRM_DP_CEC) += drm_dp_cec.o

obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o
obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/
obj-y += selftests/

obj-$(CONFIG_DRM)	+= drm.o
obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o
diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile
index 484c35c7edd0..6faf5223189b 100644
--- a/drivers/gpu/drm/selftests/Makefile
+++ b/drivers/gpu/drm/selftests/Makefile
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_cmdline_parser.o \
				    test-drm_format.o test-drm_framebuffer.o test-drm_rect.o \
				    test-drm_format.o test-drm_rect.o \
				    test-drm_plane_helper.o test-drm_dp_mst_helper.o \
				    test-drm_damage_helper.o 
obj-$(CONFIG_DRM_FRAMEBUFFER_KUNIT_TEST) += test-drm_framebuffer.o 
\ No newline at end of file
diff --git a/drivers/gpu/drm/selftests/test-drm_framebuffer.c b/drivers/gpu/drm/selftests/test-drm_framebuffer.c
index 721a58637b76..05dfc9da7866 100644
--- a/drivers/gpu/drm/selftests/test-drm_framebuffer.c
+++ b/drivers/gpu/drm/selftests/test-drm_framebuffer.c
@@ -3,8 +3,9 @@
 * Test cases for the drm_framebuffer functions
 */

#include <linux/module.h>
#include <linux/kernel.h>
//#include <linux/module.h>
//#include <linux/kernel.h>
#include <kunit/test.h>

#include <drm/drm_device.h>
#include <drm/drm_mode.h>
@@ -339,7 +340,7 @@ static struct drm_device mock_drm_device = {
	},
};

static int execute_drm_mode_fb_cmd2(struct drm_mode_fb_cmd2 *r)
static int execute_drm_mode_fb_cmd2(const struct drm_mode_fb_cmd2 *r)
{
	int buffer_created = 0;

@@ -361,21 +362,27 @@ int igt_check_drm_framebuffer_create(void *ignored)
	return 0;
}

static int __init test_drm_framebuffer_init(void)
static void case_to_desc(struct drm_framebuffer_test *test,
			 char *desc)
{
       int err;
	strcpy(desc, test->name);
}

       err = run_selftests(tests, ARRAY_SIZE(tests), NULL);
KUNIT_ARRAY_PARAM(framebuffer,createbuffer_tests, case_to_desc);

       return err > 0 ? 0 : err;
}
static void drm_internal_framebuffer_create_test(struct kunit *test){
	const struct drm_framebuffer_test *test_param = (const struct drm_framebuffer_test *)(test->param_value);
	KUNIT_ASSERT_EQ(test,test_param->buffer_created,execute_drm_mode_fb_cmd2(&test_param->cmd));

static void __exit test_drm_framebuffer_exit(void)
{
}

module_init(test_drm_framebuffer_init);
module_exit(test_drm_framebuffer_exit);
static struct kunit_case drm_framebuffer_tests[] = {
	KUNIT_CASE_PARAM(drm_internal_framebuffer_create_test,framebuffer_gen_params),
};

static struct kunit_suite drm_framebuffer_suite = {
	.name = "drm_framebuffer",
	.test_cases = drm_framebuffer_tests,
};

MODULE_AUTHOR("ARM");
MODULE_LICENSE("GPL");
kunit_test_suite(drm_framebuffer_suite);
\ No newline at end of file
-- 
2.25.1
Hi,

On 11/17/21 20:28, Gabriel Lima Luz wrote: