~lkcamp/patches

drm: selftest: convert drm_rect selftest to KUnit v1 PROPOSED

Maíra Canal: 1
 drm: selftest: convert drm_rect selftest to KUnit

 4 files changed, 100 insertions(+), 100 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/28830/mbox | git am -3
Learn more about email & git

[PATCH] drm: selftest: convert drm_rect selftest to KUnit Export this patch

Considering the current adoption of the KUnit framework, convert the
DRM rect selftest to the KUnit API.

Signed-off-by: Maíra Canal <maira.canal@usp.br>
---
This test was originally assigned to Matheus and Carlos. They are focused on 
other projects and ask me to finish the conversion of this test. I end up 
making a bunch of modifications in order to match the standards of KUnit tests 
and the requests from Daniel Latypov.
---
 drivers/gpu/drm/Kconfig                       |  13 ++
 drivers/gpu/drm/selftests/Makefile            |   3 +-
 .../drm/selftests/test-drm_modeset_common.h   |   4 -
 drivers/gpu/drm/selftests/test-drm_rect.c     | 180 +++++++++---------
 4 files changed, 100 insertions(+), 100 deletions(-)

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 56f6ca74ebb6..713926f8d94e 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -92,6 +92,19 @@ config DRM_DAMAGE_HELPER_KUNIT_TEST

	  If in doubt, say "N".

config DRM_RECT_KUNIT_TEST
	tristate "KUnit tests for DRM rect"
	depends on DRM && KUNIT
	select DRM_KMS_HELPER
	default KUNIT_ALL_TESTS
	help
	  This option provides a KUnit module that can be used to run
	  an unit test on the DRM rect API. This option is not
	  useful for distributions or general kernels, but only for kernel
	  developers working on DRM and associated drivers.

	  If in doubt, say "N".

config DRM_KMS_HELPER
	tristate
	depends on DRM
diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile
index 311f6af2caf1..73428ec6495a 100644
--- a/drivers/gpu/drm/selftests/Makefile
+++ b/drivers/gpu/drm/selftests/Makefile
@@ -1,8 +1,9 @@
# SPDX-License-Identifier: GPL-2.0-only
test-drm_modeset-y := test-drm_modeset_common.o test-drm_plane_helper.o \
                      test-drm_format.o test-drm_framebuffer.o \
		      test-drm_dp_mst_helper.o test-drm_rect.o
					test-drm_dp_mst_helper.o

obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o test-drm_cmdline_parser.o

obj-$(CONFIG_DRM_DAMAGE_HELPER_KUNIT_TEST) += test-drm_damage_helper.o
obj-$(CONFIG_DRM_RECT_KUNIT_TEST) += test-drm_rect.o
diff --git a/drivers/gpu/drm/selftests/test-drm_modeset_common.h b/drivers/gpu/drm/selftests/test-drm_modeset_common.h
index cfb51d8da2bc..59f35332360a 100644
--- a/drivers/gpu/drm/selftests/test-drm_modeset_common.h
+++ b/drivers/gpu/drm/selftests/test-drm_modeset_common.h
@@ -16,10 +16,6 @@

#define FAIL_ON(x) FAIL((x), "%s", "FAIL_ON(" __stringify(x) ")\n")

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_plane_state(void *ignored);
int igt_check_drm_format_block_width(void *ignored);
int igt_check_drm_format_block_height(void *ignored);
diff --git a/drivers/gpu/drm/selftests/test-drm_rect.c b/drivers/gpu/drm/selftests/test-drm_rect.c
index 3a5ff38321f4..404c08927b43 100644
--- a/drivers/gpu/drm/selftests/test-drm_rect.c
+++ b/drivers/gpu/drm/selftests/test-drm_rect.c
@@ -3,15 +3,10 @@
 * Test cases for the drm_rect functions
 */

#define pr_fmt(fmt) "drm_rect: " fmt

#include <linux/limits.h>

#include <kunit/test.h>
#include <drm/drm_rect.h>

#include "test-drm_modeset_common.h"

int igt_drm_rect_clip_scaled_div_by_zero(void *ignored)
static void igt_drm_rect_clip_scaled_div_by_zero(struct kunit *test)
{
	struct drm_rect src, dst, clip;
	bool visible;
@@ -23,21 +18,23 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored)
	drm_rect_init(&src, 0, 0, 0, 0);
	drm_rect_init(&dst, 0, 0, 0, 0);
	drm_rect_init(&clip, 1, 1, 1, 1);

	visible = drm_rect_clip_scaled(&src, &dst, &clip);
	FAIL(visible, "Destination not be visible\n");
	FAIL(drm_rect_visible(&src), "Source should not be visible\n");

	KUNIT_EXPECT_FALSE_MSG(test, visible, "Destination not be visible");
	KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible");

	drm_rect_init(&src, 0, 0, 0, 0);
	drm_rect_init(&dst, 3, 3, 0, 0);
	drm_rect_init(&clip, 1, 1, 1, 1);

	visible = drm_rect_clip_scaled(&src, &dst, &clip);
	FAIL(visible, "Destination not be visible\n");
	FAIL(drm_rect_visible(&src), "Source should not be visible\n");

	return 0;
	KUNIT_EXPECT_FALSE_MSG(test, visible, "Destination not be visible");
	KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible");
}

int igt_drm_rect_clip_scaled_not_clipped(void *ignored)
static void igt_drm_rect_clip_scaled_not_clipped(struct kunit *test)
{
	struct drm_rect src, dst, clip;
	bool visible;
@@ -49,14 +46,12 @@ int igt_drm_rect_clip_scaled_not_clipped(void *ignored)

	visible = drm_rect_clip_scaled(&src, &dst, &clip);

	FAIL(src.x1 != 0 || src.x2 != 1 << 16 ||
	     src.y1 != 0 || src.y2 != 1 << 16,
	     "Source badly clipped\n");
	FAIL(dst.x1 != 0 || dst.x2 != 1 ||
	     dst.y1 != 0 || dst.y2 != 1,
	     "Destination badly clipped\n");
	FAIL(!visible, "Destination should be visible\n");
	FAIL(!drm_rect_visible(&src), "Source should be visible\n");
	KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 0 || src.x2 != 1 << 16
			|| src.y1 != 0 || src.y2 != 1 << 16, "Source badly clipped");
	KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 0 || dst.x2 != 1
			|| dst.y1 != 0 || dst.y2 != 1, "Destination badly clipped");
	KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible");
	KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible");

	/* 2:1 scaling */
	drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
@@ -65,14 +60,12 @@ int igt_drm_rect_clip_scaled_not_clipped(void *ignored)

	visible = drm_rect_clip_scaled(&src, &dst, &clip);

	FAIL(src.x1 != 0 || src.x2 != 2 << 16 ||
	     src.y1 != 0 || src.y2 != 2 << 16,
	     "Source badly clipped\n");
	FAIL(dst.x1 != 0 || dst.x2 != 1 ||
	     dst.y1 != 0 || dst.y2 != 1,
	     "Destination badly clipped\n");
	FAIL(!visible, "Destination should be visible\n");
	FAIL(!drm_rect_visible(&src), "Source should be visible\n");
	KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 0 || src.x2 != 2 << 16
			|| src.y1 != 0 || src.y2 != 2 << 16, "Source badly clipped");
	KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 0 || dst.x2 != 1
			|| dst.y1 != 0 || dst.y2 != 1, "Destination badly clipped");
	KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible");
	KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible");

	/* 1:2 scaling */
	drm_rect_init(&src, 0, 0, 1 << 16, 1 << 16);
@@ -81,19 +74,15 @@ int igt_drm_rect_clip_scaled_not_clipped(void *ignored)

	visible = drm_rect_clip_scaled(&src, &dst, &clip);

	FAIL(src.x1 != 0 || src.x2 != 1 << 16 ||
	     src.y1 != 0 || src.y2 != 1 << 16,
	     "Source badly clipped\n");
	FAIL(dst.x1 != 0 || dst.x2 != 2 ||
	     dst.y1 != 0 || dst.y2 != 2,
	     "Destination badly clipped\n");
	FAIL(!visible, "Destination should be visible\n");
	FAIL(!drm_rect_visible(&src), "Source should be visible\n");

	return 0;
	KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 0 || src.x2 != 1 << 16
			|| src.y1 != 0 || src.y2 != 1 << 16, "Source badly clipped");
	KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 0 || dst.x2 != 2 || dst.y1 != 0
			|| dst.y2 != 2, "Destination badly clipped");
	KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible");
	KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible");
}

int igt_drm_rect_clip_scaled_clipped(void *ignored)
static void igt_drm_rect_clip_scaled_clipped(struct kunit *test)
{
	struct drm_rect src, dst, clip;
	bool visible;
@@ -105,14 +94,12 @@ int igt_drm_rect_clip_scaled_clipped(void *ignored)

	visible = drm_rect_clip_scaled(&src, &dst, &clip);

	FAIL(src.x1 != 0 || src.x2 != 1 << 16 ||
	     src.y1 != 0 || src.y2 != 1 << 16,
	     "Source badly clipped\n");
	FAIL(dst.x1 != 0 || dst.x2 != 1 ||
	     dst.y1 != 0 || dst.y2 != 1,
	     "Destination badly clipped\n");
	FAIL(!visible, "Destination should be visible\n");
	FAIL(!drm_rect_visible(&src), "Source should be visible\n");
	KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 0 || src.x2 != 1 << 16
			|| src.y1 != 0 || src.y2 != 1 << 16, "Source badly clipped");
	KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 0 || dst.x2 != 1
			|| dst.y1 != 0 || dst.y2 != 1, "Destination badly clipped");
	KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible");
	KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible");

	/* 1:1 scaling bottom/right clip */
	drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
@@ -121,14 +108,12 @@ int igt_drm_rect_clip_scaled_clipped(void *ignored)

	visible = drm_rect_clip_scaled(&src, &dst, &clip);

	FAIL(src.x1 != 1 << 16 || src.x2 != 2 << 16 ||
	     src.y1 != 1 << 16 || src.y2 != 2 << 16,
	     "Source badly clipped\n");
	FAIL(dst.x1 != 1 || dst.x2 != 2 ||
	     dst.y1 != 1 || dst.y2 != 2,
	     "Destination badly clipped\n");
	FAIL(!visible, "Destination should be visible\n");
	FAIL(!drm_rect_visible(&src), "Source should be visible\n");
	KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 1 << 16 || src.x2 != 2 << 16
			|| src.y1 != 1 << 16 || src.y2 != 2 << 16, "Source badly clipped");
	KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 1 || dst.x2 != 2
			|| dst.y1 != 1 || dst.y2 != 2, "Destination badly clipped");
	KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible");
	KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible");

	/* 2:1 scaling top/left clip */
	drm_rect_init(&src, 0, 0, 4 << 16, 4 << 16);
@@ -137,14 +122,12 @@ int igt_drm_rect_clip_scaled_clipped(void *ignored)

	visible = drm_rect_clip_scaled(&src, &dst, &clip);

	FAIL(src.x1 != 0 || src.x2 != 2 << 16 ||
	     src.y1 != 0 || src.y2 != 2 << 16,
	     "Source badly clipped\n");
	FAIL(dst.x1 != 0 || dst.x2 != 1 ||
	     dst.y1 != 0 || dst.y2 != 1,
	     "Destination badly clipped\n");
	FAIL(!visible, "Destination should be visible\n");
	FAIL(!drm_rect_visible(&src), "Source should be visible\n");
	KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 0 || src.x2 != 2 << 16
			|| src.y1 != 0 || src.y2 != 2 << 16, "Source badly clipped");
	KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 0 || dst.x2 != 1
			|| dst.y1 != 0 || dst.y2 != 1, "Destination badly clipped");
	KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible");
	KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible");

	/* 2:1 scaling bottom/right clip */
	drm_rect_init(&src, 0, 0, 4 << 16, 4 << 16);
@@ -153,14 +136,12 @@ int igt_drm_rect_clip_scaled_clipped(void *ignored)

	visible = drm_rect_clip_scaled(&src, &dst, &clip);

	FAIL(src.x1 != 2 << 16 || src.x2 != 4 << 16 ||
	     src.y1 != 2 << 16 || src.y2 != 4 << 16,
	     "Source badly clipped\n");
	FAIL(dst.x1 != 1 || dst.x2 != 2 ||
	     dst.y1 != 1 || dst.y2 != 2,
	     "Destination badly clipped\n");
	FAIL(!visible, "Destination should be visible\n");
	FAIL(!drm_rect_visible(&src), "Source should be visible\n");
	KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 2 << 16 || src.x2 != 4 << 16
			|| src.y1 != 2 << 16 || src.y2 != 4 << 16, "Source badly clipped");
	KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 1 || dst.x2 != 2
			|| dst.y1 != 1 || dst.y2 != 2, "Destination badly clipped");
	KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible");
	KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible");

	/* 1:2 scaling top/left clip */
	drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
@@ -169,14 +150,12 @@ int igt_drm_rect_clip_scaled_clipped(void *ignored)

	visible = drm_rect_clip_scaled(&src, &dst, &clip);

	FAIL(src.x1 != 0 || src.x2 != 1 << 16 ||
	     src.y1 != 0 || src.y2 != 1 << 16,
	     "Source badly clipped\n");
	FAIL(dst.x1 != 0 || dst.x2 != 2 ||
	     dst.y1 != 0 || dst.y2 != 2,
	     "Destination badly clipped\n");
	FAIL(!visible, "Destination should be visible\n");
	FAIL(!drm_rect_visible(&src), "Source should be visible\n");
	KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 0 || src.x2 != 1 << 16
			|| src.y1 != 0 || src.y2 != 1 << 16, "Source badly clipped");
	KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 0 || dst.x2 != 2
			|| dst.y1 != 0 || dst.y2 != 2, "Destination badly clipped");
	KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible");
	KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible");

	/* 1:2 scaling bottom/right clip */
	drm_rect_init(&src, 0, 0, 2 << 16, 2 << 16);
@@ -185,19 +164,15 @@ int igt_drm_rect_clip_scaled_clipped(void *ignored)

	visible = drm_rect_clip_scaled(&src, &dst, &clip);

	FAIL(src.x1 != 1 << 16 || src.x2 != 2 << 16 ||
	     src.y1 != 1 << 16 || src.y2 != 2 << 16,
	     "Source badly clipped\n");
	FAIL(dst.x1 != 2 || dst.x2 != 4 ||
	     dst.y1 != 2 || dst.y2 != 4,
	     "Destination badly clipped\n");
	FAIL(!visible, "Destination should be visible\n");
	FAIL(!drm_rect_visible(&src), "Source should be visible\n");

	return 0;
	KUNIT_EXPECT_FALSE_MSG(test, src.x1 != 1 << 16 || src.x2 != 2 << 16
			|| src.y1 != 1 << 16 || src.y2 != 2 << 16, "Source badly clipped");
	KUNIT_EXPECT_FALSE_MSG(test, dst.x1 != 2 || dst.x2 != 4
			|| dst.y1 != 2 || dst.y2 != 4, "Destination badly clipped");
	KUNIT_EXPECT_TRUE_MSG(test, visible, "Destination should be visible");
	KUNIT_EXPECT_TRUE_MSG(test, drm_rect_visible(&src), "Source should be visible");
}

int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored)
static void igt_drm_rect_clip_scaled_signed_vs_unsigned(struct kunit *test)
{
	struct drm_rect src, dst, clip;
	bool visible;
@@ -216,8 +191,23 @@ int igt_drm_rect_clip_scaled_signed_vs_unsigned(void *ignored)

	visible = drm_rect_clip_scaled(&src, &dst, &clip);

	FAIL(visible, "Destination should not be visible\n");
	FAIL(drm_rect_visible(&src), "Source should not be visible\n");

	return 0;
	KUNIT_EXPECT_FALSE_MSG(test, visible, "Destination should not be visible");
	KUNIT_EXPECT_FALSE_MSG(test, drm_rect_visible(&src), "Source should not be visible");
}

static struct kunit_case drm_rect_test_cases[] = {
	KUNIT_CASE(igt_drm_rect_clip_scaled_div_by_zero),
	KUNIT_CASE(igt_drm_rect_clip_scaled_not_clipped),
	KUNIT_CASE(igt_drm_rect_clip_scaled_clipped),
	KUNIT_CASE(igt_drm_rect_clip_scaled_signed_vs_unsigned),
	{ }
};

static struct kunit_suite drm_rect_test_suite = {
	.name = "drm_rect",
	.test_cases = drm_rect_test_cases,
};

kunit_test_suite(drm_rect_test_suite);

MODULE_LICENSE("GPL");
-- 
2.34.1