From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F343620322; Mon, 12 May 2025 13:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747055290; cv=none; b=MaGadFZH1DKM5bDvflMwycVR/3RUpOq1kagPWLzsp41yXi9OprAGKmiRw6RN5Da7MQT1XCDgCUd0azojip4lRNOWPipLXeR0bKFFL5Rx5uVOudJJBRBoLJCuMh1/xkySdYYP+8F2jHPAJB0WlAVnG8tu/6Q86mA4ji9HFIu9IWI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747055290; c=relaxed/simple; bh=L/ygKotVona9hpqVIxQudrM7GlWBo+Jqwoy2120O/7Y=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=i3wVINiY6UTPnSluCYqd9JvPargbpd4TcFsLP9Ej5H3Roy4K9Qc99Vyuft9QKi+gG19tkqmyti8bvxB6x1LlzUlPzvyrwSTvFSLbC88wkCwDQiul6QDjADx4ACJzHL2LlaS4kIVTkvosGRId0D3nE3DXJZKGrG64mrJ9HvAP08Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Z+7s4jUS; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Z+7s4jUS" Received: by mail.gandi.net (Postfix) with ESMTPSA id 6A0A643A16; Mon, 12 May 2025 13:07:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1747055278; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=scF82COXENOANTX0XuGgGIX8CHRYAWPYfrRvVtVwT9s=; b=Z+7s4jUSjbR3FreMQFN0yQFw2fwkIg5Z6loMmcXZOlR3W75IxBtackBXEBL8u84wYktTL6 SZTxbSjm2cHz04u/gar7VywlZOXseN1FisXCk+DVMYYIASz1csNj3eCLWzHDH5VB5eaq/K IbOehuiqo+0yFyA+Bw0unAI5/CGfV62Pohny+0y7fDOjR5/gnHM0JRpDgzN9Zo0yt4PXfj fugrQbt8H/9FgdCHLLpHqXr+TrP/LL+a+MZdEwMCpU8oKkaiP5dIFQnTMNvy/5fCXVjDAS zrQZjWNWtu7AIMLvc4bLLx2qthJgz+RKmHstzBvbbgkJut21WtPC5aXpLfYc5g== Message-ID: Date: Mon, 12 May 2025 15:07:55 +0200 Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v18 6/8] drm/vkms: Create KUnit tests for YUV conversions To: Melissa Wen , =?UTF-8?Q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , rdunlap@infradead.org, arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi, Simona Vetter , Rodrigo Siqueira , Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, linux-doc@vger.kernel.org, Pekka Paalanen References: <20250415-yuv-v18-0-f2918f71ec4b@bootlin.com> <20250415-yuv-v18-6-f2918f71ec4b@bootlin.com> Content-Language: en-US From: Louis Chauvet Autocrypt: addr=louis.chauvet@bootlin.com; keydata= xsFNBGCG5KEBEAD1yQ5C7eS4rxD0Wj7JRYZ07UhWTbBpbSjHjYJQWx/qupQdzzxe6sdrxYSY 5K81kIWbtQX91pD/wH5UapRF4kwMXTAqof8+m3XfYcEDVG31Kf8QkJTG/gLBi1UfJgGBahbY hjP40kuUR/mr7M7bKoBP9Uh0uaEM+DuKl6bSXMSrJ6fOtEPOtnfBY0xVPmqIKfLFEkjh800v jD1fdwWKtAIXf+cQtC9QWvcdzAmQIwmyFBmbg+ccqao1OIXTgu+qMAHfgKDjYctESvo+Szmb DFBZudPbyTAlf2mVKpoHKMGy3ndPZ19RboKUP0wjrF+Snif6zRFisHK7D/mqpgUftoV4HjEH bQO9bTJZXIoPJMSb+Lyds0m83/LYfjcWP8w889bNyD4Lzzzu+hWIu/OObJeGEQqY01etOLMh deuSuCG9tFr0DY6l37d4VK4dqq4Snmm87IRCb3AHAEMJ5SsO8WmRYF8ReLIk0tJJPrALv8DD lnLnwadBJ9H8djZMj24+GC6MJjN8dDNWctpBXgGZKuCM7Ggaex+RLHP/+14Vl+lSLdFiUb3U ljBXuc9v5/9+D8fWlH03q+NCa1dVgUtsP2lpolOV3EE85q1HdMyt5K91oB0hLNFdTFYwn1bW WJ2FaRhiC1yV4kn/z8g7fAp57VyIb6lQfS1Wwuj5/53XYjdipQARAQABzSlMb3VpcyBDaGF1 dmV0IDxsb3Vpcy5jaGF1dmV0QGJvb3RsaW4uY29tPsLBlAQTAQgAPgIbAwULCQgHAgYVCgkI CwIEFgIDAQIeAQIXgBYhBItxBK6aJy1mk/Un8uwYg/VeC0ClBQJmlnw+BQkH8Ms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8qJ3Gj7xyw8D9dzxhCR2DIFmZL84En N7Rj+k4VIGY7M/cVvxL81jlbMGMERMmb96Cua9z1ROviGA1He2gbHOcp6qmLNu3nprleG8PL ZRNdEAC0iZapoyiXlVCKLFIwUPnxUz5iarqIfQU8sa1VXYYd/AAAFI6Wv3zfNtGicjgHP8rN CIegqm2Av1939XXGZJVI9f3hEoUn04rvxCgcDcUvn7I0WTZ4JB9G5qAGvQLXeXK6Byu77qTx eC7PUIIEKN3X47e8xTSj2reVTlanDr8yeqZhxpKHaS0laF8RbD85geZtAK67qEByX2KC9DUo eHBFuXpYMzGQnf2SG105ePI2f4h5iAfbTW9VWH989fx4f2hVlDwTe08/NhPdwq/Houov9f/+ uPpYEMlHCNwE8GRV7aEjd/dvu87PQPm4zFtC3jgQaUKCbYYlHmYYRlrLQenX3QSorrQNPbfz uQkNLDVcjgD2fxBpemT7EhHYBz+ugsfbtdsH+4jVCo5WLb/HxE6o5zvSIkXknWh1DhFj/qe9 Zb9PGmfp8T8Ty+c/hjE5x6SrkRCX8qPXIvfSWLlb8M0lpcpFK+tB+kZlu5I3ycQDNLTk3qmf PdjUMWb5Ld21PSyCrtGc/hTKwxMoHsOZPy6UB8YJ5omZdsavcjKMrDpybguOfxUmGYs2H3MJ ghIUQMMOe0267uQcmMNDPRueGWTLXcuyz0Tpe62Whekc3gNMl0JrNz6Gty8OBb/ETijfSHPE qGHYuyAZJo9A/IazHuJ+4n+gm4kQl1WLfxoRMzYHCA== In-Reply-To: <20250415-yuv-v18-6-f2918f71ec4b@bootlin.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeftddufeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddvjeenucfhrhhomhepnfhouhhishcuvehhrghuvhgvthcuoehlohhuihhsrdgthhgruhhvvghtsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeetfffhgefgvdeuieduvdehieehhedtteffgffftdeihffhkeetvdfgvdeijeffkeenucffohhmrghinheprhgvrgguthhhvgguohgtshdrihhopdgsohhothhlihhnrdgtohhmnecukfhppeeltddrkeelrdduieefrdduvdejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledtrdekledrudeifedruddvjedphhgvlhhopegludelvddrudeikedrtddrvddtngdpmhgrihhlfhhrohhmpehlohhuihhsrdgthhgruhhvvghtsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvgedprhgtphhtthhopehmvghlihhsshgrrdhsrhifsehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhgrihhrrggtrghnrghlsehrihhsvghuphdrnhgvthdprhgtphhtthhopehhrghmohhhrghmmhgvugdrshgrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhgrrghrthgvnhdrlhgrnhhkh hhorhhstheslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehmrhhiphgrrhgusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehtiihimhhmvghrmhgrnhhnsehsuhhsvgdruggvpdhrtghpthhtoheprghirhhlihgvugesghhmrghilhdrtghomhdprhgtphhtthhopehrughunhhlrghpsehinhhfrhgruggvrggurdhorhhg X-GND-Sasl: louis.chauvet@bootlin.com Hi Maxime, Did you have the time to look at this patch? Pekka added his Acked-by, but as you made some remarks about this patch, I would like to have your validation before applying it. Thanks a lot, Louis Chauvet Le 15/04/2025 à 15:55, Louis Chauvet a écrit : > From: Arthur Grillo > > Create KUnit tests to test the conversion between YUV and RGB. Test each > conversion and range combination with some common colors. > > The code used to compute the expected result can be found in comment. > > [Louis Chauvet: > - fix minor formating issues (whitespace, double line) > - change expected alpha from 0x0000 to 0xffff > - adapt to the new get_conversion_matrix usage > - apply the changes from Arthur > - move struct pixel_yuv_u8 to the test itself] > > Signed-off-by: Arthur Grillo > Acked-by: Pekka Paalanen > Signed-off-by: Louis Chauvet > --- > drivers/gpu/drm/vkms/tests/Makefile | 1 + > drivers/gpu/drm/vkms/tests/vkms_format_test.c | 280 ++++++++++++++++++++++++++ > drivers/gpu/drm/vkms/vkms_formats.c | 7 +- > drivers/gpu/drm/vkms/vkms_formats.h | 5 + > 4 files changed, 291 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/vkms/tests/Makefile b/drivers/gpu/drm/vkms/tests/Makefile > index 9ded37b67a46..0ee077942ae2 100644 > --- a/drivers/gpu/drm/vkms/tests/Makefile > +++ b/drivers/gpu/drm/vkms/tests/Makefile > @@ -1,3 +1,4 @@ > # SPDX-License-Identifier: GPL-2.0-only > > obj-$(CONFIG_DRM_VKMS_KUNIT_TEST) += vkms_config_test.o > +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += vkms_format_test.o > diff --git a/drivers/gpu/drm/vkms/tests/vkms_format_test.c b/drivers/gpu/drm/vkms/tests/vkms_format_test.c > new file mode 100644 > index 000000000000..2e1daef94831 > --- /dev/null > +++ b/drivers/gpu/drm/vkms/tests/vkms_format_test.c > @@ -0,0 +1,280 @@ > +// SPDX-License-Identifier: GPL-2.0+ > + > +#include > + > +#include > +#include > + > +#include "../../drm_crtc_internal.h" > + > +#include "../vkms_formats.h" > + > +#define TEST_BUFF_SIZE 50 > + > +MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); > + > +/** > + * struct pixel_yuv_u8 - Internal representation of a pixel color. > + * @y: Luma value, stored in 8 bits, without padding, using > + * machine endianness > + * @u: Blue difference chroma value, stored in 8 bits, without padding, using > + * machine endianness > + * @v: Red difference chroma value, stored in 8 bits, without padding, using > + * machine endianness > + */ > +struct pixel_yuv_u8 { > + u8 y, u, v; > +}; > + > +/* > + * struct yuv_u8_to_argb_u16_case - Reference values to test the color > + * conversions in VKMS between YUV to ARGB > + * > + * @encoding: Encoding used to convert RGB to YUV > + * @range: Range used to convert RGB to YUV > + * @n_colors: Count of test colors in this case > + * @format_pair.name: Name used for this color conversion, used to > + * clarify the test results > + * @format_pair.rgb: RGB color tested > + * @format_pair.yuv: Same color as @format_pair.rgb, but converted to > + * YUV using @encoding and @range. > + */ > +struct yuv_u8_to_argb_u16_case { > + enum drm_color_encoding encoding; > + enum drm_color_range range; > + size_t n_colors; > + struct format_pair { > + char *name; > + struct pixel_yuv_u8 yuv; > + struct pixel_argb_u16 argb; > + } colors[TEST_BUFF_SIZE]; > +}; > + > +/* > + * The YUV color representation were acquired via the colour python framework. > + * Below are the function calls used for generating each case. > + * > + * For more information got to the docs: > + * https://colour.readthedocs.io/en/master/generated/colour.RGB_to_YCbCr.html > + */ > +static struct yuv_u8_to_argb_u16_case yuv_u8_to_argb_u16_cases[] = { > + /* > + * colour.RGB_to_YCbCr(, > + * K=colour.WEIGHTS_YCBCR["ITU-R BT.601"], > + * in_bits = 16, > + * in_legal = False, > + * in_int = True, > + * out_bits = 8, > + * out_legal = False, > + * out_int = True) > + * > + * Tests cases for color conversion generated by converting RGB > + * values to YUV BT601 full range using the ITU-R BT.601 weights. > + */ > + { > + .encoding = DRM_COLOR_YCBCR_BT601, > + .range = DRM_COLOR_YCBCR_FULL_RANGE, > + .n_colors = 6, > + .colors = { > + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, > + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, > + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, > + { "red", { 0x4c, 0x55, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, > + { "green", { 0x96, 0x2c, 0x15 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, > + { "blue", { 0x1d, 0xff, 0x6b }, { 0xffff, 0x0000, 0x0000, 0xffff }}, > + }, > + }, > + /* > + * colour.RGB_to_YCbCr(, > + * K=colour.WEIGHTS_YCBCR["ITU-R BT.601"], > + * in_bits = 16, > + * in_legal = False, > + * in_int = True, > + * out_bits = 8, > + * out_legal = True, > + * out_int = True) > + * Tests cases for color conversion generated by converting RGB > + * values to YUV BT601 limited range using the ITU-R BT.601 weights. > + */ > + { > + .encoding = DRM_COLOR_YCBCR_BT601, > + .range = DRM_COLOR_YCBCR_LIMITED_RANGE, > + .n_colors = 6, > + .colors = { > + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, > + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, > + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, > + { "red", { 0x51, 0x5a, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, > + { "green", { 0x91, 0x36, 0x22 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, > + { "blue", { 0x29, 0xf0, 0x6e }, { 0xffff, 0x0000, 0x0000, 0xffff }}, > + }, > + }, > + /* > + * colour.RGB_to_YCbCr(, > + * K=colour.WEIGHTS_YCBCR["ITU-R BT.709"], > + * in_bits = 16, > + * in_legal = False, > + * in_int = True, > + * out_bits = 8, > + * out_legal = False, > + * out_int = True) > + * Tests cases for color conversion generated by converting RGB > + * values to YUV BT709 full range using the ITU-R BT.709 weights. > + */ > + { > + .encoding = DRM_COLOR_YCBCR_BT709, > + .range = DRM_COLOR_YCBCR_FULL_RANGE, > + .n_colors = 6, > + .colors = { > + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, > + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, > + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, > + { "red", { 0x36, 0x63, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, > + { "green", { 0xb6, 0x1e, 0x0c }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, > + { "blue", { 0x12, 0xff, 0x74 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, > + }, > + }, > + /* > + * colour.RGB_to_YCbCr(, > + * K=colour.WEIGHTS_YCBCR["ITU-R BT.709"], > + * in_bits = 16, > + * int_legal = False, > + * in_int = True, > + * out_bits = 8, > + * out_legal = True, > + * out_int = True) > + * Tests cases for color conversion generated by converting RGB > + * values to YUV BT709 limited range using the ITU-R BT.709 weights. > + */ > + { > + .encoding = DRM_COLOR_YCBCR_BT709, > + .range = DRM_COLOR_YCBCR_LIMITED_RANGE, > + .n_colors = 6, > + .colors = { > + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, > + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, > + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, > + { "red", { 0x3f, 0x66, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, > + { "green", { 0xad, 0x2a, 0x1a }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, > + { "blue", { 0x20, 0xf0, 0x76 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, > + }, > + }, > + /* > + * colour.RGB_to_YCbCr(, > + * K=colour.WEIGHTS_YCBCR["ITU-R BT.2020"], > + * in_bits = 16, > + * in_legal = False, > + * in_int = True, > + * out_bits = 8, > + * out_legal = False, > + * out_int = True) > + * Tests cases for color conversion generated by converting RGB > + * values to YUV BT2020 full range using the ITU-R BT.2020 weights. > + */ > + { > + .encoding = DRM_COLOR_YCBCR_BT2020, > + .range = DRM_COLOR_YCBCR_FULL_RANGE, > + .n_colors = 6, > + .colors = { > + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, > + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, > + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, > + { "red", { 0x43, 0x5c, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, > + { "green", { 0xad, 0x24, 0x0b }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, > + { "blue", { 0x0f, 0xff, 0x76 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, > + }, > + }, > + /* > + * colour.RGB_to_YCbCr(, > + * K=colour.WEIGHTS_YCBCR["ITU-R BT.2020"], > + * in_bits = 16, > + * in_legal = False, > + * in_int = True, > + * out_bits = 8, > + * out_legal = True, > + * out_int = True) > + * Tests cases for color conversion generated by converting RGB > + * values to YUV BT2020 limited range using the ITU-R BT.2020 weights. > + */ > + { > + .encoding = DRM_COLOR_YCBCR_BT2020, > + .range = DRM_COLOR_YCBCR_LIMITED_RANGE, > + .n_colors = 6, > + .colors = { > + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, > + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, > + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, > + { "red", { 0x4a, 0x61, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, > + { "green", { 0xa4, 0x2f, 0x19 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, > + { "blue", { 0x1d, 0xf0, 0x77 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, > + }, > + }, > +}; > + > +/* > + * vkms_format_test_yuv_u8_to_argb_u16 - Testing the conversion between YUV > + * colors to ARGB colors in VKMS > + * > + * This test will use the functions get_conversion_matrix_to_argb_u16 and > + * argb_u16_from_yuv888 to convert YUV colors (stored in > + * yuv_u8_to_argb_u16_cases) into ARGB colors. > + * > + * The conversion between YUV and RGB is not totally reversible, so there may be > + * some difference between the expected value and the result. > + * In addition, there may be some rounding error as the input color is 8 bits > + * and output color is 16 bits. > + */ > +static void vkms_format_test_yuv_u8_to_argb_u16(struct kunit *test) > +{ > + const struct yuv_u8_to_argb_u16_case *param = test->param_value; > + struct pixel_argb_u16 argb; > + > + for (size_t i = 0; i < param->n_colors; i++) { > + const struct format_pair *color = ¶m->colors[i]; > + struct conversion_matrix matrix; > + > + get_conversion_matrix_to_argb_u16 > + (DRM_FORMAT_NV12, param->encoding, param->range, &matrix); > + > + argb = argb_u16_from_yuv888(color->yuv.y, color->yuv.u, color->yuv.v, &matrix); > + > + KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.a, color->argb.a), 0x1ff, > + "On the A channel of the color %s expected 0x%04x, got 0x%04x", > + color->name, color->argb.a, argb.a); > + KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.r, color->argb.r), 0x1ff, > + "On the R channel of the color %s expected 0x%04x, got 0x%04x", > + color->name, color->argb.r, argb.r); > + KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.g, color->argb.g), 0x1ff, > + "On the G channel of the color %s expected 0x%04x, got 0x%04x", > + color->name, color->argb.g, argb.g); > + KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.b, color->argb.b), 0x1ff, > + "On the B channel of the color %s expected 0x%04x, got 0x%04x", > + color->name, color->argb.b, argb.b); > + } > +} > + > +static void vkms_format_test_yuv_u8_to_argb_u16_case_desc(struct yuv_u8_to_argb_u16_case *t, > + char *desc) > +{ > + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s - %s", > + drm_get_color_encoding_name(t->encoding), drm_get_color_range_name(t->range)); > +} > + > +KUNIT_ARRAY_PARAM(yuv_u8_to_argb_u16, yuv_u8_to_argb_u16_cases, > + vkms_format_test_yuv_u8_to_argb_u16_case_desc > +); > + > +static struct kunit_case vkms_format_test_cases[] = { > + KUNIT_CASE_PARAM(vkms_format_test_yuv_u8_to_argb_u16, yuv_u8_to_argb_u16_gen_params), > + {} > +}; > + > +static struct kunit_suite vkms_format_test_suite = { > + .name = "vkms-format", > + .test_cases = vkms_format_test_cases, > +}; > + > +kunit_test_suite(vkms_format_test_suite); > + > +MODULE_LICENSE("GPL"); > +MODULE_DESCRIPTION("Kunit test for vkms format conversion"); > diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c > index 8f7a5d54a076..9972780f3fa9 100644 > --- a/drivers/gpu/drm/vkms/vkms_formats.c > +++ b/drivers/gpu/drm/vkms/vkms_formats.c > @@ -7,6 +7,8 @@ > #include > #include > > +#include > + > #include "vkms_formats.h" > > /** > @@ -247,8 +249,8 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(const __le16 *pixel) > return out_pixel; > } > > -static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 channel_2, > - const struct conversion_matrix *matrix) > +VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 channel_2, > + const struct conversion_matrix *matrix) > { > u16 r, g, b; > s64 fp_y, fp_channel_1, fp_channel_2; > @@ -278,6 +280,7 @@ static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 channel > > return argb_u16_from_u16161616(0xffff, r, g, b); > } > +EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888); > > /* > * The following functions are read_line function for each pixel format supported by VKMS. > diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkms_formats.h > index d583855cb320..b4fe62ab9c65 100644 > --- a/drivers/gpu/drm/vkms/vkms_formats.h > +++ b/drivers/gpu/drm/vkms/vkms_formats.h > @@ -13,4 +13,9 @@ void get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encod > enum drm_color_range range, > struct conversion_matrix *matrix); > > +#if IS_ENABLED(CONFIG_KUNIT) > +struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 channel_2, > + const struct conversion_matrix *matrix); > +#endif > + > #endif /* _VKMS_FORMATS_H_ */ > -- Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com