mbox series

[RFC,0/1] KUnit tests for drm_format_helper

Message ID 20220530102017.471865-1-jose.exposito89@gmail.com (mailing list archive)
Headers show
Series KUnit tests for drm_format_helper | expand

Message

José Expósito May 30, 2022, 10:20 a.m. UTC
Hello everyone,

Recently Javier added a new task in the ToDo list [1] to create KUnit
tests for the functions present in "drm_format_helper".

This patch, marked as RFC to start the conversation, includes tests for
"drm_fb_xrgb8888_to_rgb332".

Since the conversion functions present in "drm_format_helper" convert
from XRGB8888 to another format, my plan is to create a set of XRGB8888
data to test all the available conversions.

To illustrate it with an example, the code present in this patch:

	{
		.name = "Single pixel source",
		.pitch = 1 * 4,
		.dst_pitch = 0,
		.clip = CLIP(0, 0, 1, 1),
		.xrgb8888 = { 0x01FF0000 },
		.expected = { 0xE0 },
	}

In a follow up patch, should look like:

	{
		.name = "Single pixel source",
		.pitch = 1 * 4,
		.clip = CLIP(0, 0, 1, 1),
		.xrgb8888 = { 0x01FF0000 },
		.expected = {
			{
				.dst_format = DRM_FORMAT_RGB332,
				.dst_pitch = 0,
				.conv_func = drm_fb_xrgb8888_to_rgb332,
				.result = { 0xE0 },
			},
			{ ... },
		},
	}

What is tested?

 - Different values for the X in XRGB8888 to make sure it is ignored
 - Different clip values: Single pixel and full and partial buffer
 - Well know colors: White, black, red, green, blue, magenta, yellow
   and cyan
 - Other colors: Randomly picked
 - Destination pitch

What is NOT tested?

 - NULL destination buffer: Because there is not validation in place
 - Out of bounds destination buffer: The size of the buffer is not
   checked. The conversion function could cause out of bound errors
 - Out of bounds source buffer: Similary to the destination buffer, the
   source buffer is read without checking its size
 - Invalid clip values: Because there is no clip validation.
   Example: clip out of or bigger than the source buffer
 - Invalid destination pitch: A dst_pitch < (clip->width * dst_pixsize)
   could cause issues.
 - "Big" source buffers. I don't know if this kind of tests could be of
   interest

How to run the tests?

 My .kunitconfig:

 	CONFIG_KUNIT=y
 	CONFIG_DRM=y
 	CONFIG_DRM_FORMAR_HELPER_TEST=y

 $ ./tools/testing/kunit/kunit.py run --arch=x86_64

Feedback?

 It'd be great to know your ideas about what else we could test, if you
 think that we should make the functions safer by checking the buffers
 and clip sizes or anything else.

Thanks a lot,
José Expósito

[1] https://cgit.freedesktop.org/drm/drm-misc/commit/?id=596c35b1440e

José Expósito (1):
  drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()

 drivers/gpu/drm/Kconfig                  |  12 ++
 drivers/gpu/drm/Makefile                 |   3 +
 drivers/gpu/drm/drm_format_helper_test.c | 166 +++++++++++++++++++++++
 3 files changed, 181 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_format_helper_test.c