Re: [PATCH v6 0/7] Adds support for ConfigFS to VKMS!
On Mon, May 13, 2024 at 12:03:07PM +0300, Marius Vlad wrote: > Hi all, > On Mon, May 13, 2024 at 10:08:38AM +0200, José Expósito wrote: > > On Fri, May 10, 2024 at 06:19:45PM +0200, Louis Chauvet wrote: > > > Le 09/05/24 - 18:18, Jim Shargo a écrit : > > > > Sima--thanks SO MUCH for going through with everything leaving a > > > > detailed review. I am excited to go through your feedback. > > > > > > > > It makes me extremely happy to see these patches get people excited. > > > > > > > > They've bounced between a few people, and I recently asked to take > > > > them over again from the folks who were most recently looking at them > > > > but haven't since had capacity to revisit them. I'd love to contribute > > > > more but I am currently pretty swamped and I probably couldn't > > > > realistically make too much headway before the middle of June. > > > > > > > > José--if you've got capacity and interest, I'd love to see this work > > > > get in! Thanks!! Please let me know your timeline and if you want to > > > > split anything up or have any questions, I'd love to help if possible. > > > > But most important to me is seeing the community benefit from the > > > > feature. > > > > > > > > And (in case it got lost in the shuffle of all these patches) the IGT > > > > tests really make it much easier to develop this thing. Marius has > > > > posted the most recent patches: > > > > https://lore.kernel.org/igt-dev/?q=configfs > > > > > > > > Thanks! > > > > -- Jim > > > > > > > > > > > > > > > > On Wed, May 8, 2024 at 2:17 PM José Expósito > > > > wrote: > > > > > > > > > > Hi everyone, > > > > > > > > > > I wasn't aware of these patches, but I'm really glad they are getting > > > > > some attention, thanks a lot for your review Sima. > > > > > > > > > > Given that it's been a while since the patches were emailed, I'm not > > > > > sure if the original authors of the patches could implement your > > > > > comments. If not, I can work on it. Please let me know. > > > > > > > > > > I'm working on a Mutter feature that'd greatly benefit from this uapi > > > > > and I'm sure other compositors would find it useful. > > > > > > > > > > I'll start working on a new version in a few days if nobody else is > > > > > already working on it. > > > > > > > > > > Best wishes, > > > > > José Expósito > > > > > > Hi all! > > > > > > Very nice to see other people working on this subject. As the series > > > seemed inactive, I started two weeks ago to rebase it on top of [1]. I > > > also started some work to use drmm_* helpers instead of using lists in > > > vkms. I currently struggle with a deadlock during rmmod. > > > > > > I need to clean my commits, but I can share a WIP version. > > > > Hi Louis, > > > > If you could share a RFC/WIP series it would be awesome! > > > > Since you are already working on the kernel patches (and I guess IGT?), > > I'll start working on a libdrm high level API to interact with VKMS from > > user-space on top of your patches. I'll share a link as soon as I have a > > draft PR. > > Just out of curiosity what API would that be? These should fairly > simple that they can be configured from a shell script > (mount/mkdir/rm/echo/umount). Believe should be easy enough to test stuff > with > bunch scripts like that. My plan is to add a very thin C API around mkdir/rmdir/etc. It is true that VKMS can be configure easily using a bash script; however, compositors with test suites written in C (or with bindings to libdrm) would have to write similar wrappers around the mkdir/rmdir/etc calls. I think that it could be beneficial for them to have a shared wrapper available in libdrm. > Perphas landing the I-G-T tests first (assuming we're settled > on how exactly this would work) might be of greated help to get a green lit > the kernel driver side? Skip if vkms/configfs/something else that tells > us VKMS doesn't have ConfigFS eneabled, and run it when that is on. > > The lastest iteration was shared by Jim at > https://lore.kernel.org/igt-dev/20230901092819.16924-1-marius.v...@collabora.com/ > > That way sub-sequent BAT CI would pick up issues, and can also
Re: [PATCH v6 0/7] Adds support for ConfigFS to VKMS!
On Fri, May 10, 2024 at 06:19:45PM +0200, Louis Chauvet wrote: > Le 09/05/24 - 18:18, Jim Shargo a écrit : > > Sima--thanks SO MUCH for going through with everything leaving a > > detailed review. I am excited to go through your feedback. > > > > It makes me extremely happy to see these patches get people excited. > > > > They've bounced between a few people, and I recently asked to take > > them over again from the folks who were most recently looking at them > > but haven't since had capacity to revisit them. I'd love to contribute > > more but I am currently pretty swamped and I probably couldn't > > realistically make too much headway before the middle of June. > > > > José--if you've got capacity and interest, I'd love to see this work > > get in! Thanks!! Please let me know your timeline and if you want to > > split anything up or have any questions, I'd love to help if possible. > > But most important to me is seeing the community benefit from the > > feature. > > > > And (in case it got lost in the shuffle of all these patches) the IGT > > tests really make it much easier to develop this thing. Marius has > > posted the most recent patches: > > https://lore.kernel.org/igt-dev/?q=configfs > > > > Thanks! > > -- Jim > > > > > > > > On Wed, May 8, 2024 at 2:17 PM José Expósito > > wrote: > > > > > > Hi everyone, > > > > > > I wasn't aware of these patches, but I'm really glad they are getting > > > some attention, thanks a lot for your review Sima. > > > > > > Given that it's been a while since the patches were emailed, I'm not > > > sure if the original authors of the patches could implement your > > > comments. If not, I can work on it. Please let me know. > > > > > > I'm working on a Mutter feature that'd greatly benefit from this uapi > > > and I'm sure other compositors would find it useful. > > > > > > I'll start working on a new version in a few days if nobody else is > > > already working on it. > > > > > > Best wishes, > > > José Expósito > > Hi all! > > Very nice to see other people working on this subject. As the series > seemed inactive, I started two weeks ago to rebase it on top of [1]. I > also started some work to use drmm_* helpers instead of using lists in > vkms. I currently struggle with a deadlock during rmmod. > > I need to clean my commits, but I can share a WIP version. Hi Louis, If you could share a RFC/WIP series it would be awesome! Since you are already working on the kernel patches (and I guess IGT?), I'll start working on a libdrm high level API to interact with VKMS from user-space on top of your patches. I'll share a link as soon as I have a draft PR. > Maybe we can discuss a bit the comment from Daniel (split init between > default/configfs, use or not a real platform device...) > > For the split, I think the first solution (struct vkms_config) can be > easier to understand and to implement, for two reasons: > - No need to distinguish between the "default" and the "configfs" devices > in the VKMS "core". All is managed with only one struct vkms_config. > - Most of the lifetime issue should be gone. The only thing to > synchronize is passing this vkms_config from ConfigFS to VKMS. I agree, this seems like the easiest solution. > The drawback of this is that it can become difficult to do the "runtime" > configuration (today only hotplug, but I plan to add more complex stuff > like DP emulation, EDID selection, MST support...). Those configuration > must be done "at runtime" and will require a strong synchronization with > the vkms "core". > > Maybe we can distinguish between the "creation" and the "runtime > configuration", in two different configFS directory? Once a device is > created, it is moved to the "enabled" directory and will have a different > set of attribute (connection status, current EDID...) Once the device is enabled (i.e, `echo 1 > /config/vkms/my-device/enabled`), would it make sense to use sysfs instead of another configfs directory? The advantage is that with sysfs the kernel controls the lifetime of the objects and I think it *might* simplify the code, but I'll need to write a proof of concept to see if this works. > For the platform driver part, it seems logic to me to use a "real" > platform driver and a platform device for each pipeline, but I don't have > the experience to tell if this is a good idea or not. I'm afraid I don't know which approach could work better. Trusting Sima and Maíra on this one. Jose > [1]: > https://lore.kernel.org/dri-devel/20240409-yuv-v6-0-de1c5728f...@bootlin.com/ > > Thanks, > Louis Chauvet > > -- > Louis Chauvet, Bootlin > Embedded Linux and Kernel engineering > https://bootlin.com
Re: [PATCH v6 0/7] Adds support for ConfigFS to VKMS!
Hi everyone, I wasn't aware of these patches, but I'm really glad they are getting some attention, thanks a lot for your review Sima. Given that it's been a while since the patches were emailed, I'm not sure if the original authors of the patches could implement your comments. If not, I can work on it. Please let me know. I'm working on a Mutter feature that'd greatly benefit from this uapi and I'm sure other compositors would find it useful. I'll start working on a new version in a few days if nobody else is already working on it. Best wishes, José Expósito
Re: [PATCH v2 09/13] drm/format-helper: Add conversion from XRGB8888 to 15-bit RGB555 formats
L if scanlines are stored next to each > other. > + * @src: Array of XRGB source buffer > + * @fb: DRM framebuffer > + * @clip: Clip rectangle area to copy > + * > + * This function copies parts of a framebuffer to display memory and converts > + * the color format during the process. The parameters @dst, @dst_pitch and > + * @src refer to arrays. Each array must have at least as many entries as > + * there are planes in @fb's format. Each entry stores the value for the > + * format's respective color plane at the same index. > + * > + * This function does not apply clipping on @dst (i.e. the destination is at > the > + * top-left corner). > + * > + * Drivers can use this function for ARGB1555 devices that don't support > + * XRGB natively. It sets an opaque alpha channel as part of the > conversion. > + */ > +void drm_fb_xrgb_to_argb1555(struct iosys_map *dst, const unsigned int > *dst_pitch, > + const struct iosys_map *src, const struct > drm_framebuffer *fb, > + const struct drm_rect *clip) > +{ > + static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = { > + 2, > + }; > + > + drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, > + drm_fb_xrgb_to_argb1555_line); > +} > +EXPORT_SYMBOL(drm_fb_xrgb_to_argb1555); > + > +static void drm_fb_xrgb_to_rgba5551_line(void *dbuf, const void *sbuf, > unsigned int pixels) > +{ > + u16 *dbuf16 = dbuf; > + const __le32 *sbuf32 = sbuf; > + unsigned int x; > + u16 val16; > + u32 pix; > + > + for (x = 0; x < pixels; x++) { > + pix = le32_to_cpu(sbuf32[x]); > + val16 = ((pix & 0x00f8) >> 8) | > + ((pix & 0xf800) >> 5) | > + ((pix & 0x00f8) >> 2) | > + BIT(0); /* set alpha bit */ > + dbuf16[x] = cpu_to_le16(val16); - dbuf16[x] = cpu_to_le16(val16); + dbuf16[x] = (__force u16)cpu_to_le16(val16); Reviewed-by: José Expósito > + } > +} > + > +/** > + * drm_fb_xrgb_to_rgba5551 - Convert XRGB to RGBA5551 clip buffer > + * @dst: Array of RGBA5551 destination buffers > + * @dst_pitch: Array of numbers of bytes between the start of two > consecutive scanlines > + * within @dst; can be NULL if scanlines are stored next to each > other. > + * @src: Array of XRGB source buffer > + * @fb: DRM framebuffer > + * @clip: Clip rectangle area to copy > + * > + * This function copies parts of a framebuffer to display memory and converts > + * the color format during the process. The parameters @dst, @dst_pitch and > + * @src refer to arrays. Each array must have at least as many entries as > + * there are planes in @fb's format. Each entry stores the value for the > + * format's respective color plane at the same index. > + * > + * This function does not apply clipping on @dst (i.e. the destination is at > the > + * top-left corner). > + * > + * Drivers can use this function for RGBA5551 devices that don't support > + * XRGB natively. It sets an opaque alpha channel as part of the > conversion. > + */ > +void drm_fb_xrgb_to_rgba5551(struct iosys_map *dst, const unsigned int > *dst_pitch, > + const struct iosys_map *src, const struct > drm_framebuffer *fb, > + const struct drm_rect *clip) > +{ > + static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = { > + 2, > + }; > + > + drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, > + drm_fb_xrgb_to_rgba5551_line); > +} > +EXPORT_SYMBOL(drm_fb_xrgb_to_rgba5551); > + > static void drm_fb_xrgb_to_rgb888_line(void *dbuf, const void *sbuf, > unsigned int pixels) > { > u8 *dbuf8 = dbuf; > @@ -763,6 +918,15 @@ int drm_fb_blit(struct iosys_map *dst, const unsigned > int *dst_pitch, uint32_t d > if (dst_format == DRM_FORMAT_RGB565) { > drm_fb_xrgb_to_rgb565(dst, dst_pitch, src, fb, > clip, false); > return 0; > + } else if (dst_format == DRM_FORMAT_XRGB1555) { > + drm_fb_xrgb_to_xrgb1555(dst, dst_pitch, src, fb, > clip); > + return 0; > + } else if (dst_format == DRM_FORMAT_ARGB1555) { > + drm_fb_xrgb_to_argb1555(dst, dst_pitch, src, fb, > clip); > + return 0; > + } else if (dst_format == DRM_FORMAT_RGBA5551) { > + drm_fb_xrgb_to
Re: [PATCH v2 08/13] drm/format-helper: Add conversion from XRGB8888 to ARGB2101010
On Tue, Dec 20, 2022 at 05:11:40PM +0100, Thomas Zimmermann wrote: > Add dedicated helper to convert from XRGB to ARGB2101010. Sets > all alpha bits to make pixels fully opaque. > > v2: > * set correct format in struct drm_framebuffer (Javier) > * use cpubuf_to_le32() > * type fixes > > Signed-off-by: Thomas Zimmermann > Reviewed-by: Javier Martinez Canillas Reviewed-by: José Expósito > --- > drivers/gpu/drm/drm_format_helper.c | 58 - > .../gpu/drm/tests/drm_format_helper_test.c| 63 +++ > include/drm/drm_format_helper.h | 3 + > 3 files changed, 122 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/drm_format_helper.c > b/drivers/gpu/drm/drm_format_helper.c > index 23837b202988..3767213ba97d 100644 > --- a/drivers/gpu/drm/drm_format_helper.c > +++ b/drivers/gpu/drm/drm_format_helper.c > @@ -605,6 +605,59 @@ void drm_fb_xrgb_to_xrgb2101010(struct iosys_map > *dst, const unsigned int *d > } > EXPORT_SYMBOL(drm_fb_xrgb_to_xrgb2101010); > > +static void drm_fb_xrgb_to_argb2101010_line(void *dbuf, const void > *sbuf, unsigned int pixels) > +{ > + __le32 *dbuf32 = dbuf; > + const __le32 *sbuf32 = sbuf; > + unsigned int x; > + u32 val32; > + u32 pix; > + > + for (x = 0; x < pixels; x++) { > + pix = le32_to_cpu(sbuf32[x]); > + val32 = ((pix & 0x00ff) << 2) | > + ((pix & 0xff00) << 4) | > + ((pix & 0x00ff) << 6); > + pix = GENMASK(31, 30) | /* set alpha bits */ > + val32 | ((val32 >> 8) & 0x00300c03); > + *dbuf32++ = cpu_to_le32(pix); > + } > +} > + > +/** > + * drm_fb_xrgb_to_argb2101010 - Convert XRGB to ARGB2101010 clip > buffer > + * @dst: Array of ARGB2101010 destination buffers > + * @dst_pitch: Array of numbers of bytes between the start of two > consecutive scanlines > + * within @dst; can be NULL if scanlines are stored next to each > other. > + * @src: Array of XRGB source buffers > + * @fb: DRM framebuffer > + * @clip: Clip rectangle area to copy > + * > + * This function copies parts of a framebuffer to display memory and converts > + * the color format during the process. The parameters @dst, @dst_pitch and > + * @src refer to arrays. Each array must have at least as many entries as > + * there are planes in @fb's format. Each entry stores the value for the > + * format's respective color plane at the same index. > + * > + * This function does not apply clipping on @dst (i.e. the destination is at > the > + * top-left corner). > + * > + * Drivers can use this function for ARGB2101010 devices that don't support > XRGB > + * natively. > + */ > +void drm_fb_xrgb_to_argb2101010(struct iosys_map *dst, const unsigned > int *dst_pitch, > + const struct iosys_map *src, const struct > drm_framebuffer *fb, > + const struct drm_rect *clip) > +{ > + static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = { > + 4, > + }; > + > + drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, > + drm_fb_xrgb_to_argb2101010_line); > +} > +EXPORT_SYMBOL(drm_fb_xrgb_to_argb2101010); > + > static void drm_fb_xrgb_to_gray8_line(void *dbuf, const void *sbuf, > unsigned int pixels) > { > u8 *dbuf8 = dbuf; > @@ -696,8 +749,6 @@ int drm_fb_blit(struct iosys_map *dst, const unsigned int > *dst_pitch, uint32_t d > fb_format = DRM_FORMAT_XRGB; > if (fb_format == DRM_FORMAT_ARGB2101010) > fb_format = DRM_FORMAT_XRGB2101010; > - if (dst_format == DRM_FORMAT_ARGB2101010) > - dst_format = DRM_FORMAT_XRGB2101010; > > if (fb_format == dst_format) { > drm_fb_memcpy(dst, dst_pitch, src, fb, clip); > @@ -721,6 +772,9 @@ int drm_fb_blit(struct iosys_map *dst, const unsigned int > *dst_pitch, uint32_t d > } else if (dst_format == DRM_FORMAT_XRGB2101010) { > drm_fb_xrgb_to_xrgb2101010(dst, dst_pitch, src, fb, > clip); > return 0; > + } else if (dst_format == DRM_FORMAT_ARGB2101010) { > + drm_fb_xrgb_to_argb2101010(dst, dst_pitch, src, fb, > clip); > + return 0; > } else if (dst_format == DRM_FORMAT_BGRX) { > drm_fb_swab(dst, dst_pitch, src, fb, clip, false); > return 0; >
Re: [PATCH v2 07/13] drm/format-helper: Add conversion from XRGB8888 to ARGB8888
Hi Thomas, Compiling this patch with sparse enabled (you can do it from the KUnit tests adding "--make_options C=2") throws a warning: drm_format_helper.c:614:27: warning: incorrect type in assignment (different base types) drm_format_helper.c:614:27:expected unsigned int [usertype] drm_format_helper.c:614:27:got restricted __le32 [usertype] You might want to silence the warning with... On Tue, Dec 20, 2022 at 05:11:39PM +0100, Thomas Zimmermann wrote: > Add dedicated helper to convert from XRGB to ARGB. Sets > all alpha bits to make pixels fully opaque. > > v2: > * use cpubuf_to_le32() > * type fixes > > Signed-off-by: Thomas Zimmermann > Reviewed-by: Javier Martinez Canillas > --- > drivers/gpu/drm/drm_format_helper.c | 53 +++- > .../gpu/drm/tests/drm_format_helper_test.c| 63 +++ > include/drm/drm_format_helper.h | 3 + > 3 files changed, 117 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/drm_format_helper.c > b/drivers/gpu/drm/drm_format_helper.c > index 36d2ca9d0f01..23837b202988 100644 > --- a/drivers/gpu/drm/drm_format_helper.c > +++ b/drivers/gpu/drm/drm_format_helper.c > @@ -446,6 +446,54 @@ void drm_fb_xrgb_to_rgb888(struct iosys_map *dst, > const unsigned int *dst_pi > } > EXPORT_SYMBOL(drm_fb_xrgb_to_rgb888); > > +static void drm_fb_xrgb_to_argb_line(void *dbuf, const void *sbuf, > unsigned int pixels) > +{ > + u32 *dbuf32 = dbuf; > + const __le32 *sbuf32 = sbuf; > + unsigned int x; > + u32 pix; > + > + for (x = 0; x < pixels; x++) { > + pix = le32_to_cpu(sbuf32[x]); > + pix |= GENMASK(31, 24); /* fill alpha bits */ > + dbuf32[x] = cpu_to_le32(pix); - dbuf32[x] = cpu_to_le32(pix); + dbuf32[x] = (__force u32)cpu_to_le32(pix); Other than that: Reviewed-by: José Expósito > + } > +} > + > +/** > + * drm_fb_xrgb_to_argb - Convert XRGB to ARGB clip buffer > + * @dst: Array of ARGB destination buffers > + * @dst_pitch: Array of numbers of bytes between the start of two > consecutive scanlines > + * within @dst; can be NULL if scanlines are stored next to each > other. > + * @src: Array of XRGB source buffer > + * @fb: DRM framebuffer > + * @clip: Clip rectangle area to copy > + * > + * This function copies parts of a framebuffer to display memory and > converts the > + * color format during the process. The parameters @dst, @dst_pitch and @src > refer > + * to arrays. Each array must have at least as many entries as there are > planes in > + * @fb's format. Each entry stores the value for the format's respective > color plane > + * at the same index. > + * > + * This function does not apply clipping on @dst (i.e. the destination is at > the > + * top-left corner). > + * > + * Drivers can use this function for ARGB devices that don't support > XRGB > + * natively. It sets an opaque alpha channel as part of the conversion. > + */ > +void drm_fb_xrgb_to_argb(struct iosys_map *dst, const unsigned int > *dst_pitch, > + const struct iosys_map *src, const struct > drm_framebuffer *fb, > + const struct drm_rect *clip) > +{ > + static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = { > + 4, > + }; > + > + drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, > + drm_fb_xrgb_to_argb_line); > +} > +EXPORT_SYMBOL(drm_fb_xrgb_to_argb); > + > static void drm_fb_rgb565_to_xrgb_line(void *dbuf, const void *sbuf, > unsigned int pixels) > { > __le32 *dbuf32 = dbuf; > @@ -646,8 +694,6 @@ int drm_fb_blit(struct iosys_map *dst, const unsigned int > *dst_pitch, uint32_t d > /* treat alpha channel like filler bits */ > if (fb_format == DRM_FORMAT_ARGB) > fb_format = DRM_FORMAT_XRGB; > - if (dst_format == DRM_FORMAT_ARGB) > - dst_format = DRM_FORMAT_XRGB; > if (fb_format == DRM_FORMAT_ARGB2101010) > fb_format = DRM_FORMAT_XRGB2101010; > if (dst_format == DRM_FORMAT_ARGB2101010) > @@ -669,6 +715,9 @@ int drm_fb_blit(struct iosys_map *dst, const unsigned int > *dst_pitch, uint32_t d > } else if (dst_format == DRM_FORMAT_RGB888) { > drm_fb_xrgb_to_rgb888(dst, dst_pitch, src, fb, > clip); > return 0; > + } else if (dst_format == DRM_FORMAT_ARGB) { > + drm_fb_xrgb_to_argb(dst, dst_pitch, src, fb, > clip); > +
Re: [PATCH v2 05/13] drm/format-helper: Type fixes in format-helper tests
On Tue, Dec 20, 2022 at 05:11:37PM +0100, Thomas Zimmermann wrote: > Change the source-buffer type of le32buf_to_cpu() to __le32* to > reflect endianness. Result buffers are converted to local endianness, > so instantiate them from regular u8 or u32 types. > > Signed-off-by: Thomas Zimmermann Reviewed-by: José Expósito > --- > drivers/gpu/drm/tests/drm_format_helper_test.c | 12 ++-- > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c > b/drivers/gpu/drm/tests/drm_format_helper_test.c > index 04fe373c9d97..c2411ec808a1 100644 > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c > @@ -279,7 +279,7 @@ static u16 *le16buf_to_cpu(struct kunit *test, const > __le16 *buf, size_t buf_siz > return dst; > } > > -static u32 *le32buf_to_cpu(struct kunit *test, const u32 *buf, size_t > buf_size) > +static u32 *le32buf_to_cpu(struct kunit *test, const __le32 *buf, size_t > buf_size) > { > u32 *dst = NULL; > int n; > @@ -323,7 +323,7 @@ static void drm_test_fb_xrgb_to_gray8(struct kunit > *test) > const struct convert_xrgb_case *params = test->param_value; > const struct convert_to_gray8_result *result = >gray8_result; > size_t dst_size; > - __u8 *buf = NULL; > + u8 *buf = NULL; > __le32 *xrgb = NULL; > struct iosys_map dst, src; > > @@ -353,7 +353,7 @@ static void drm_test_fb_xrgb_to_rgb332(struct kunit > *test) > const struct convert_xrgb_case *params = test->param_value; > const struct convert_to_rgb332_result *result = >rgb332_result; > size_t dst_size; > - __u8 *buf = NULL; > + u8 *buf = NULL; > __le32 *xrgb = NULL; > struct iosys_map dst, src; > > @@ -419,7 +419,7 @@ static void drm_test_fb_xrgb_to_rgb888(struct kunit > *test) > const struct convert_xrgb_case *params = test->param_value; > const struct convert_to_rgb888_result *result = >rgb888_result; > size_t dst_size; > - __u8 *buf = NULL; > + u8 *buf = NULL; > __le32 *xrgb = NULL; > struct iosys_map dst, src; > > @@ -453,7 +453,7 @@ static void drm_test_fb_xrgb_to_xrgb2101010(struct > kunit *test) > const struct convert_xrgb_case *params = test->param_value; > const struct convert_to_xrgb2101010_result *result = > >xrgb2101010_result; > size_t dst_size; > - __u32 *buf = NULL; > + u32 *buf = NULL; > __le32 *xrgb = NULL; > struct iosys_map dst, src; > > @@ -475,7 +475,7 @@ static void drm_test_fb_xrgb_to_xrgb2101010(struct > kunit *test) > iosys_map_set_vaddr(, xrgb); > > drm_fb_xrgb_to_xrgb2101010(, >dst_pitch, , , > >clip); > - buf = le32buf_to_cpu(test, buf, dst_size / sizeof(u32)); > + buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / > sizeof(u32)); > KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); > } > > -- > 2.39.0 >
Re: [PATCH v2 04/13] drm/format-helper: Store RGB565 in little-endian order
On Tue, Dec 20, 2022 at 05:11:36PM +0100, Thomas Zimmermann wrote: > Fix to-RGB565 conversion helpers to store the result in little- > endian byte order. Update test cases as well. > > Signed-off-by: Thomas Zimmermann Reviewed-by: José Expósito > --- > drivers/gpu/drm/drm_format_helper.c | 9 + > .../gpu/drm/tests/drm_format_helper_test.c| 20 ++- > 2 files changed, 24 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/drm_format_helper.c > b/drivers/gpu/drm/drm_format_helper.c > index b98bd7c5caee..f3f3b3809a3e 100644 > --- a/drivers/gpu/drm/drm_format_helper.c > +++ b/drivers/gpu/drm/drm_format_helper.c > @@ -322,7 +322,7 @@ EXPORT_SYMBOL(drm_fb_xrgb_to_rgb332); > > static void drm_fb_xrgb_to_rgb565_line(void *dbuf, const void *sbuf, > unsigned int pixels) > { > - u16 *dbuf16 = dbuf; > + __le16 *dbuf16 = dbuf; > const __le32 *sbuf32 = sbuf; > unsigned int x; > u16 val16; > @@ -333,14 +333,15 @@ static void drm_fb_xrgb_to_rgb565_line(void *dbuf, > const void *sbuf, unsigne > val16 = ((pix & 0x00F8) >> 8) | > ((pix & 0xFC00) >> 5) | > ((pix & 0x00F8) >> 3); > - dbuf16[x] = val16; > + dbuf16[x] = cpu_to_le16(val16); > } > } > > +/* TODO: implement this helper as conversion to RGB565|BIG_ENDIAN */ > static void drm_fb_xrgb_to_rgb565_swab_line(void *dbuf, const void *sbuf, > unsigned int pixels) > { > - u16 *dbuf16 = dbuf; > + __le16 *dbuf16 = dbuf; > const __le32 *sbuf32 = sbuf; > unsigned int x; > u16 val16; > @@ -351,7 +352,7 @@ static void drm_fb_xrgb_to_rgb565_swab_line(void > *dbuf, const void *sbuf, > val16 = ((pix & 0x00F8) >> 8) | > ((pix & 0xFC00) >> 5) | > ((pix & 0x00F8) >> 3); > - dbuf16[x] = swab16(val16); > + dbuf16[x] = cpu_to_le16(swab16(val16)); > } > } > > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c > b/drivers/gpu/drm/tests/drm_format_helper_test.c > index e7c49e6d3f6d..04fe373c9d97 100644 > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c > @@ -264,6 +264,21 @@ static size_t conversion_buf_size(u32 dst_format, > unsigned int dst_pitch, > return dst_pitch * drm_rect_height(clip); > } > > +static u16 *le16buf_to_cpu(struct kunit *test, const __le16 *buf, size_t > buf_size) > +{ > + u16 *dst = NULL; > + int n; > + > + dst = kunit_kzalloc(test, sizeof(*dst) * buf_size, GFP_KERNEL); > + if (!dst) > + return NULL; > + > + for (n = 0; n < buf_size; n++) > + dst[n] = le16_to_cpu(buf[n]); > + > + return dst; > +} > + > static u32 *le32buf_to_cpu(struct kunit *test, const u32 *buf, size_t > buf_size) > { > u32 *dst = NULL; > @@ -368,7 +383,7 @@ static void drm_test_fb_xrgb_to_rgb565(struct kunit > *test) > const struct convert_xrgb_case *params = test->param_value; > const struct convert_to_rgb565_result *result = >rgb565_result; > size_t dst_size; > - __u16 *buf = NULL; > + u16 *buf = NULL; > __le32 *xrgb = NULL; > struct iosys_map dst, src; > > @@ -390,9 +405,12 @@ static void drm_test_fb_xrgb_to_rgb565(struct kunit > *test) > iosys_map_set_vaddr(, xrgb); > > drm_fb_xrgb_to_rgb565(, >dst_pitch, , , > >clip, false); > + buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / > sizeof(__le16)); > KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); > > + buf = dst.vaddr; /* restore original value of buf */ > drm_fb_xrgb_to_rgb565(, >dst_pitch, , , > >clip, true); > + buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / > sizeof(__le16)); > KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0); > } > > -- > 2.39.0 >
Re: [PATCH v2 03/13] drm/format-helper: Fix test-input format conversion
On Tue, Dec 20, 2022 at 05:11:35PM +0100, Thomas Zimmermann wrote: > Convert test input for format helpers from host byte order to > little-endian order. The current code does it the other way around, > but there's no effective difference to the result. > > Signed-off-by: Thomas Zimmermann Reviewed-by: José Expósito > --- > .../gpu/drm/tests/drm_format_helper_test.c| 35 +-- > 1 file changed, 25 insertions(+), 10 deletions(-) > > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c > b/drivers/gpu/drm/tests/drm_format_helper_test.c > index cd1d7da3483c..e7c49e6d3f6d 100644 > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c > @@ -279,6 +279,21 @@ static u32 *le32buf_to_cpu(struct kunit *test, const u32 > *buf, size_t buf_size) > return dst; > } > > +static __le32 *cpubuf_to_le32(struct kunit *test, const u32 *buf, size_t > buf_size) > +{ > + __le32 *dst = NULL; > + int n; > + > + dst = kunit_kzalloc(test, sizeof(*dst) * buf_size, GFP_KERNEL); > + if (!dst) > + return NULL; > + > + for (n = 0; n < buf_size; n++) > + dst[n] = cpu_to_le32(buf[n]); > + > + return dst; > +} > + > static void convert_xrgb_case_desc(struct convert_xrgb_case *t, > char *desc) > { > @@ -294,7 +309,7 @@ static void drm_test_fb_xrgb_to_gray8(struct kunit > *test) > const struct convert_to_gray8_result *result = >gray8_result; > size_t dst_size; > __u8 *buf = NULL; > - __u32 *xrgb = NULL; > + __le32 *xrgb = NULL; > struct iosys_map dst, src; > > struct drm_framebuffer fb = { > @@ -310,7 +325,7 @@ static void drm_test_fb_xrgb_to_gray8(struct kunit > *test) > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); > iosys_map_set_vaddr(, buf); > > - xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); > + xrgb = cpubuf_to_le32(test, params->xrgb, TEST_BUF_SIZE); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); > iosys_map_set_vaddr(, xrgb); > > @@ -324,7 +339,7 @@ static void drm_test_fb_xrgb_to_rgb332(struct kunit > *test) > const struct convert_to_rgb332_result *result = >rgb332_result; > size_t dst_size; > __u8 *buf = NULL; > - __u32 *xrgb = NULL; > + __le32 *xrgb = NULL; > struct iosys_map dst, src; > > struct drm_framebuffer fb = { > @@ -340,7 +355,7 @@ static void drm_test_fb_xrgb_to_rgb332(struct kunit > *test) > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); > iosys_map_set_vaddr(, buf); > > - xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); > + xrgb = cpubuf_to_le32(test, params->xrgb, TEST_BUF_SIZE); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); > iosys_map_set_vaddr(, xrgb); > > @@ -354,7 +369,7 @@ static void drm_test_fb_xrgb_to_rgb565(struct kunit > *test) > const struct convert_to_rgb565_result *result = >rgb565_result; > size_t dst_size; > __u16 *buf = NULL; > - __u32 *xrgb = NULL; > + __le32 *xrgb = NULL; > struct iosys_map dst, src; > > struct drm_framebuffer fb = { > @@ -370,7 +385,7 @@ static void drm_test_fb_xrgb_to_rgb565(struct kunit > *test) > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); > iosys_map_set_vaddr(, buf); > > - xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); > + xrgb = cpubuf_to_le32(test, params->xrgb, TEST_BUF_SIZE); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); > iosys_map_set_vaddr(, xrgb); > > @@ -387,7 +402,7 @@ static void drm_test_fb_xrgb_to_rgb888(struct kunit > *test) > const struct convert_to_rgb888_result *result = >rgb888_result; > size_t dst_size; > __u8 *buf = NULL; > - __u32 *xrgb = NULL; > + __le32 *xrgb = NULL; > struct iosys_map dst, src; > > struct drm_framebuffer fb = { > @@ -403,7 +418,7 @@ static void drm_test_fb_xrgb_to_rgb888(struct kunit > *test) > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); > iosys_map_set_vaddr(, buf); > > - xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); > + xrgb = cpubuf_to_le32(test, params->xrgb, TEST_BUF_SIZE); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); > iosys_map_set_vaddr(, xrgb); > > @@ -421,7 +436,7 @@ static void drm_test_fb_xrgb_to_xrgb2101010(struct > kunit *test) > const st
Re: [PATCH v2 02/13] drm/format-helper: Comment on RGB888 byte order
On Tue, Dec 20, 2022 at 05:11:34PM +0100, Thomas Zimmermann wrote: > RGB888 is different than the other formats as most of its pixels are > unaligned and therefore helper functions do not use endianness conversion > helpers. Comment on this in the source code. > > Signed-off-by: Thomas Zimmermann Reviewed-by: José Expósito > --- > drivers/gpu/drm/drm_format_helper.c| 1 + > drivers/gpu/drm/tests/drm_format_helper_test.c | 4 > 2 files changed, 5 insertions(+) > > diff --git a/drivers/gpu/drm/drm_format_helper.c > b/drivers/gpu/drm/drm_format_helper.c > index 74ff33c2ddaa..b98bd7c5caee 100644 > --- a/drivers/gpu/drm/drm_format_helper.c > +++ b/drivers/gpu/drm/drm_format_helper.c > @@ -404,6 +404,7 @@ static void drm_fb_xrgb_to_rgb888_line(void *dbuf, > const void *sbuf, unsigne > > for (x = 0; x < pixels; x++) { > pix = le32_to_cpu(sbuf32[x]); > + /* write blue-green-red to output in little endianness */ > *dbuf8++ = (pix & 0x00FF) >> 0; > *dbuf8++ = (pix & 0xFF00) >> 8; > *dbuf8++ = (pix & 0x00FF) >> 16; > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c > b/drivers/gpu/drm/tests/drm_format_helper_test.c > index 2191e57f2297..cd1d7da3483c 100644 > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c > @@ -407,6 +407,10 @@ static void drm_test_fb_xrgb_to_rgb888(struct kunit > *test) > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); > iosys_map_set_vaddr(, xrgb); > > + /* > + * RGB888 expected results are already in little-endian > + * order, so there's no need to convert the test output. > + */ > drm_fb_xrgb_to_rgb888(, >dst_pitch, , , > >clip); > KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); > } > -- > 2.39.0 >
Re: [PATCH 5/9] drm/format-helper: Add conversion from XRGB8888 to 15-bit RGB555 formats
er. > + * @src: Array of XRGB source buffer > + * @fb: DRM framebuffer > + * @clip: Clip rectangle area to copy > + * > + * This function copies parts of a framebuffer to display memory and converts > + * the color format during the process. The parameters @dst, @dst_pitch and > + * @src refer to arrays. Each array must have at least as many entries as > + * there are planes in @fb's format. Each entry stores the value for the > + * format's respective color plane at the same index. > + * > + * This function does not apply clipping on @dst (i.e. the destination is at > the > + * top-left corner). > + * > + * Drivers can use this function for ARGB1555 devices that don't support > + * XRGB natively. It sets an opaque alpha channel as part of the > conversion. > + */ > +void drm_fb_xrgb_to_argb1555(struct iosys_map *dst, const unsigned int > *dst_pitch, > + const struct iosys_map *src, const struct > drm_framebuffer *fb, > + const struct drm_rect *clip) > +{ > + static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = { > + 2, > + }; > + > + drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, > + drm_fb_xrgb_to_argb1555_line); > +} > +EXPORT_SYMBOL(drm_fb_xrgb_to_argb1555); > + > +static void drm_fb_xrgb_to_rgba5551_line(void *dbuf, const void *sbuf, > unsigned int pixels) > +{ > + u16 *dbuf16 = dbuf; > + const __le32 *sbuf32 = sbuf; > + unsigned int x; > + u16 val16; > + u32 pix; > + > + for (x = 0; x < pixels; x++) { > + pix = le32_to_cpu(sbuf32[x]); > + val16 = ((pix & 0x00f8) >> 8) | > + ((pix & 0xf800) >> 5) | > + ((pix & 0x00f8) >> 2) | > + BIT(0); /* set alpha bit */ > + dbuf16[x] = cpu_to_le16(val16); And this is the last fix: - dbuf16[x] = cpu_to_le16(val16); + dbuf16[x] = val16; Other than that, this patch looks good: Reviewed-by: José Expósito Best wishes, Jose > + } > +} > + > +/** > + * drm_fb_xrgb_to_rgba5551 - Convert XRGB to RGBA5551 clip buffer > + * @dst: Array of RGBA5551 destination buffers > + * @dst_pitch: Array of numbers of bytes between the start of two > consecutive scanlines > + * within @dst; can be NULL if scanlines are stored next to each > other. > + * @src: Array of XRGB source buffer > + * @fb: DRM framebuffer > + * @clip: Clip rectangle area to copy > + * > + * This function copies parts of a framebuffer to display memory and converts > + * the color format during the process. The parameters @dst, @dst_pitch and > + * @src refer to arrays. Each array must have at least as many entries as > + * there are planes in @fb's format. Each entry stores the value for the > + * format's respective color plane at the same index. > + * > + * This function does not apply clipping on @dst (i.e. the destination is at > the > + * top-left corner). > + * > + * Drivers can use this function for RGBA5551 devices that don't support > + * XRGB natively. It sets an opaque alpha channel as part of the > conversion. > + */ > +void drm_fb_xrgb_to_rgba5551(struct iosys_map *dst, const unsigned int > *dst_pitch, > + const struct iosys_map *src, const struct > drm_framebuffer *fb, > + const struct drm_rect *clip) > +{ > + static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = { > + 2, > + }; > + > + drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, > + drm_fb_xrgb_to_rgba5551_line); > +} > +EXPORT_SYMBOL(drm_fb_xrgb_to_rgba5551); > + > static void drm_fb_xrgb_to_rgb888_line(void *dbuf, const void *sbuf, > unsigned int pixels) > { > u8 *dbuf8 = dbuf; > @@ -761,6 +916,15 @@ int drm_fb_blit(struct iosys_map *dst, const unsigned > int *dst_pitch, uint32_t d > if (dst_format == DRM_FORMAT_RGB565) { > drm_fb_xrgb_to_rgb565(dst, dst_pitch, src, fb, > clip, false); > return 0; > + } else if (dst_format == DRM_FORMAT_XRGB1555) { > + drm_fb_xrgb_to_xrgb1555(dst, dst_pitch, src, fb, > clip); > + return 0; > + } else if (dst_format == DRM_FORMAT_ARGB1555) { > + drm_fb_xrgb_to_argb1555(dst, dst_pitch, src, fb, > clip); > + return 0; > + } else if (dst_format == DRM_FORMAT_RGBA5551) { > + drm_fb_xrgb_to
Re: [bug report] Merge branch 'for-linux-next' of git://anongit.freedesktop.org/drm/drm-misc
Hi Dan, On Fri, Nov 18, 2022 at 02:17:34PM +0300, Dan Carpenter wrote: > Hello Stephen Rothwell, > > The patch 23b727d76bda: "Merge branch 'for-linux-next' of > git://anongit.freedesktop.org/drm/drm-misc" from Nov 17, 2022, leads > to the following Smatch static checker warning: > > drivers/gpu/drm/vc4/vc4_hdmi.c:351 vc4_hdmi_reset_link() > error: uninitialized symbol 'vc4_hdmi'. > > drivers/gpu/drm/vc4/vc4_hdmi.c > 346 > 347 crtc_state = crtc->state; > 348 if (!crtc_state->active) > 349 return 0; > 350 > --> 351 mutex_lock(_hdmi->mutex); >^ > This locking > > 352 > 353 vc4_hdmi = connector_to_vc4_hdmi(connector); > ^^ > needs to be done after this assignment. But this is only in linux-next > so presumably it's a temporary thing. > > 354 if (!vc4_hdmi_supports_scrambling(vc4_hdmi)) { > 355 mutex_unlock(_hdmi->mutex); > 356 return 0; > 357 } > 358 > 359 scrambling_needed = > vc4_hdmi_mode_needs_scrambling(_hdmi->saved_adjusted_mode, > 360 > vc4_hdmi->output_bpc, > > regards, > dan carpenter I think that Stephen already handled this issue as discussed here: https://lore.kernel.org/all/Y3ZvffZiR+SgtY6h@dev-arch.thelio-3990X/ Jose
[PATCH v2 1/2] drm/vc4: hdmi: Pass vc4_hdmi to vc4_hdmi_supports_scrambling()
Simplify vc4_hdmi_supports_scrambling() by changing its first parameter from struct drm_encoder to struct vc4_hdmi. Signed-off-by: José Expósito --- drivers/gpu/drm/vc4/vc4_hdmi.c | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 0d78c800ed51..a49f88e5d2b9 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -124,9 +124,8 @@ static unsigned long long vc4_hdmi_encoder_compute_mode_clock(const struct drm_display_mode *mode, unsigned int bpc, enum vc4_hdmi_output_format fmt); -static bool vc4_hdmi_supports_scrambling(struct drm_encoder *encoder) +static bool vc4_hdmi_supports_scrambling(struct vc4_hdmi *vc4_hdmi) { - struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); struct drm_display_info *display = _hdmi->connector.display_info; lockdep_assert_held(_hdmi->mutex); @@ -321,7 +320,6 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, { struct drm_device *drm = connector->dev; struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); - struct drm_encoder *encoder = _hdmi->encoder.base; struct drm_connector_state *conn_state; struct drm_crtc_state *crtc_state; struct drm_crtc *crtc; @@ -349,7 +347,7 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, if (!crtc_state->active) return 0; - if (!vc4_hdmi_supports_scrambling(encoder)) + if (!vc4_hdmi_supports_scrambling(vc4_hdmi)) return 0; scrambling_needed = vc4_hdmi_mode_needs_scrambling(_hdmi->saved_adjusted_mode, @@ -867,7 +865,7 @@ static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder) lockdep_assert_held(_hdmi->mutex); - if (!vc4_hdmi_supports_scrambling(encoder)) + if (!vc4_hdmi_supports_scrambling(vc4_hdmi)) return; if (!vc4_hdmi_mode_needs_scrambling(mode, -- 2.25.1
[PATCH v2 2/2] drm/vc4: hdmi: Fix pointer dereference before check
Commit 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") introduced the vc4_hdmi_reset_link() function. This function dereferences the "connector" pointer before checking whether it is NULL or not. Rework variable assignment to avoid this issue. Fixes: 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") Signed-off-by: José Expósito --- drivers/gpu/drm/vc4/vc4_hdmi.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index a49f88e5d2b9..6b223a5fcf6f 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -318,8 +318,8 @@ static int reset_pipe(struct drm_crtc *crtc, static int vc4_hdmi_reset_link(struct drm_connector *connector, struct drm_modeset_acquire_ctx *ctx) { - struct drm_device *drm = connector->dev; - struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); + struct drm_device *drm; + struct vc4_hdmi *vc4_hdmi; struct drm_connector_state *conn_state; struct drm_crtc_state *crtc_state; struct drm_crtc *crtc; @@ -330,6 +330,7 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, if (!connector) return 0; + drm = connector->dev; ret = drm_modeset_lock(>mode_config.connection_mutex, ctx); if (ret) return ret; @@ -347,6 +348,7 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, if (!crtc_state->active) return 0; + vc4_hdmi = connector_to_vc4_hdmi(connector); if (!vc4_hdmi_supports_scrambling(vc4_hdmi)) return 0; -- 2.25.1
[PATCH v2 0/2] drm/vc4: hdmi: Fix pointer dereference before check
v1 -> v2: As suggested by Maxime, I simplified a bit vc4_hdmi_supports_scrambling() making it receive a struct vc4_hdmi as argument instead of a struct drm_encoder. Also, variables are initialized close to where they are used in the second patch. José Expósito (2): drm/vc4: hdmi: Pass vc4_hdmi to vc4_hdmi_supports_scrambling() drm/vc4: hdmi: Fix pointer dereference before check drivers/gpu/drm/vc4/vc4_hdmi.c | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) -- 2.25.1
Re: [PATCH] drm/vc4: hdmi: Fix pointer dereference before check
Hi Maxime, Thanks a lot for looking into the patch. On Wed, Nov 02, 2022 at 10:01:53AM +0100, Maxime Ripard wrote: > Hi, > > On Sat, Oct 29, 2022 at 11:34:13AM +0200, José Expósito wrote: > > Commit 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") introduced > > the vc4_hdmi_reset_link() function. This function dereferences the > > "connector" pointer before checking whether it is NULL or not. > > > > Rework variable assignment to avoid this issue. > > > > Fixes: 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") > > Signed-off-by: José Expósito > > --- > > drivers/gpu/drm/vc4/vc4_hdmi.c | 10 +++--- > > 1 file changed, 7 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c > > index 4a73fafca51b..07d058b6afb7 100644 > > --- a/drivers/gpu/drm/vc4/vc4_hdmi.c > > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c > > @@ -319,9 +319,9 @@ static int reset_pipe(struct drm_crtc *crtc, > > static int vc4_hdmi_reset_link(struct drm_connector *connector, > >struct drm_modeset_acquire_ctx *ctx) > > { > > - struct drm_device *drm = connector->dev; > > - struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); > > - struct drm_encoder *encoder = _hdmi->encoder.base; > > + struct drm_device *drm; > > + struct vc4_hdmi *vc4_hdmi; > > + struct drm_encoder *encoder; > > struct drm_connector_state *conn_state; > > struct drm_crtc_state *crtc_state; > > struct drm_crtc *crtc; > > @@ -332,6 +332,10 @@ static int vc4_hdmi_reset_link(struct drm_connector > > *connector, > > if (!connector) > > return 0; > > > > + drm = connector->dev; > > + vc4_hdmi = connector_to_vc4_hdmi(connector); > > + encoder = _hdmi->encoder.base; > > + > > I don't think that's right. Connector shouldn't be NULL to begin with, > how did you notice this? > > Maxime This issue was reported by Coverity. At the moment this function is not invoked with a NULL connector by any code path. However, since the NULL check is present, in my opinion, it makes sense to either remove it or make it usefull just in case the preconditions change in the future. But at the moment, this is not a big deal. Thanks, Jose
[PATCH] drm/vc4: hdmi: Fix pointer dereference before check
Commit 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") introduced the vc4_hdmi_reset_link() function. This function dereferences the "connector" pointer before checking whether it is NULL or not. Rework variable assignment to avoid this issue. Fixes: 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") Signed-off-by: José Expósito --- drivers/gpu/drm/vc4/vc4_hdmi.c | 10 +++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 4a73fafca51b..07d058b6afb7 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -319,9 +319,9 @@ static int reset_pipe(struct drm_crtc *crtc, static int vc4_hdmi_reset_link(struct drm_connector *connector, struct drm_modeset_acquire_ctx *ctx) { - struct drm_device *drm = connector->dev; - struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); - struct drm_encoder *encoder = _hdmi->encoder.base; + struct drm_device *drm; + struct vc4_hdmi *vc4_hdmi; + struct drm_encoder *encoder; struct drm_connector_state *conn_state; struct drm_crtc_state *crtc_state; struct drm_crtc *crtc; @@ -332,6 +332,10 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, if (!connector) return 0; + drm = connector->dev; + vc4_hdmi = connector_to_vc4_hdmi(connector); + encoder = _hdmi->encoder.base; + ret = drm_modeset_lock(>mode_config.connection_mutex, ctx); if (ret) return ret; -- 2.25.1
Re: [PATCH] drm: tests: Fix a buffer overflow in format_helper_test
On Wed, Oct 19, 2022 at 03:32:40PM +0800, David Gow wrote: > The xrgb2101010 format conversion test (unlike for other formats) does > an endianness conversion on the results. However, it always converts > TEST_BUF_SIZE 32-bit integers, which results in reading from (and > writing to) more memory than in present in the result buffer. Instead, > use the buffer size, divided by sizeof(u32). > > The issue could be reproduced with KASAN: > ./tools/testing/kunit/kunit.py run --kunitconfig drivers/gpu/drm/tests \ > --kconfig_add CONFIG_KASAN=y --kconfig_add CONFIG_KASAN_VMALLOC=y \ > --kconfig_add CONFIG_KASAN_KUNIT_TEST=y \ > drm_format_helper_test.*xrgb2101010 > > Reported-by: Linux Kernel Functional Testing > Fixes: 453114319699 ("drm/format-helper: Add KUnit tests for > drm_fb_xrgb_to_xrgb2101010()") > Signed-off-by: David Gow > --- > > This is a fix for the issue reported here: > https://lore.kernel.org/dri-devel/CA+G9fYsuc9G+RO81E=vHMqxYStsmLURLdOB0NF26kJ1=k8p...@mail.gmail.com/ > > Note that it may conflict with the KUNIT_EXPECT_MEMEQ() series here: > https://lore.kernel.org/linux-kselftest/20221018190541.189780-1-mairaca...@riseup.net/ > > Cheers, > -- David > > --- > drivers/gpu/drm/tests/drm_format_helper_test.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c > b/drivers/gpu/drm/tests/drm_format_helper_test.c > index 8d86c250c2ec..2191e57f2297 100644 > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c > @@ -438,7 +438,7 @@ static void drm_test_fb_xrgb_to_xrgb2101010(struct > kunit *test) > iosys_map_set_vaddr(, xrgb); > > drm_fb_xrgb_to_xrgb2101010(, >dst_pitch, , , > >clip); > - buf = le32buf_to_cpu(test, buf, TEST_BUF_SIZE); > + buf = le32buf_to_cpu(test, buf, dst_size / sizeof(u32)); > KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); > } Thanks a lot for fixing this bug David, I just tested it and worked as expected. Do you think that we should update the other calls to le32buf_to_cpu() to follow a similar approach? Regardless of a possible follow up patch: Reviewed-by: José Expósito Jose > > -- > 2.38.0.413.g74048e4d9e-goog >
[PATCH v5 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()
Extend the existing test cases to test the conversion from XRGB to grayscale. Tested-by: Maíra Canal Reviewed-by: David Gow Acked-by: Maxime Ripard Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 62 +++ 1 file changed, 62 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 4a2f3c0de060..8d86c250c2ec 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -16,6 +16,11 @@ #define TEST_BUF_SIZE 50 +struct convert_to_gray8_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_to_rgb332_result { unsigned int dst_pitch; const u8 expected[TEST_BUF_SIZE]; @@ -42,6 +47,7 @@ struct convert_xrgb_case { unsigned int pitch; struct drm_rect clip; const u32 xrgb[TEST_BUF_SIZE]; + struct convert_to_gray8_result gray8_result; struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; struct convert_to_rgb888_result rgb888_result; @@ -54,6 +60,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .pitch = 1 * 4, .clip = DRM_RECT_INIT(0, 0, 1, 1), .xrgb = { 0x01FF }, + .gray8_result = { + .dst_pitch = 0, + .expected = { 0x4C }, + }, .rgb332_result = { .dst_pitch = 0, .expected = { 0xE0 }, @@ -80,6 +90,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x, 0x, 0x, 0x10FF, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { 0x4C }, + }, .rgb332_result = { .dst_pitch = 0, .expected = { 0xE0 }, @@ -113,6 +127,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x, 0x55FF, 0x66FF00FF, 0x, 0x, 0x7700, 0x8800, 0x, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0x00, + 0x4C, 0x99, + 0x19, 0x66, + 0xE5, 0xB2, + }, + }, .rgb332_result = { .dst_pitch = 0, .expected = { @@ -166,6 +189,14 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0xD16C7073, 0xA20E449C, 0xB2114D05, 0xC2A80303, 0xD26C7073, 0xA30E449C, }, + .gray8_result = { + .dst_pitch = 5, + .expected = { + 0x3C, 0x33, 0x34, 0x00, 0x00, + 0x6F, 0x3C, 0x33, 0x00, 0x00, + 0x34, 0x6F, 0x3C, 0x00, 0x00, + }, + }, .rgb332_result = { .dst_pitch = 5, .expected = { @@ -257,6 +288,36 @@ static void convert_xrgb_case_desc(struct convert_xrgb_case *t, KUNIT_ARRAY_PARAM(convert_xrgb, convert_xrgb_cases, convert_xrgb_case_desc); +static void drm_test_fb_xrgb_to_gray8(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_gray8_result *result = >gray8_result; + size_t dst_size; + __u8 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_R8, result->dst_pitch, + >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(, buf); + + xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); + iosys_map_set_vaddr(, xrgb); + + drm_fb_xrgb_to_gray8(, >dst_pitch, , , >clip); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static void drm_test_fb_xrgb_to_rgb332(struct kunit *test) { const struct convert_xrgb_case *params = test->param_value; @
[PATCH v5 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010()
Extend the existing test cases to test the conversion from XRGB to XRGB2101010. In order to be able to call drm_fb_xrgb_to_xrgb2101010() when compiling CONFIG_DRM_KMS_HELPER as a module export the symbol. Tested-by: Maíra Canal Reviewed-by: David Gow Acked-by: Maxime Ripard Signed-off-by: José Expósito --- drivers/gpu/drm/drm_format_helper.c | 1 + .../gpu/drm/tests/drm_format_helper_test.c| 63 +++ 2 files changed, 64 insertions(+) diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c index 4afc4ac27342..e2f76621453c 100644 --- a/drivers/gpu/drm/drm_format_helper.c +++ b/drivers/gpu/drm/drm_format_helper.c @@ -553,6 +553,7 @@ void drm_fb_xrgb_to_xrgb2101010(struct iosys_map *dst, const unsigned int *d drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, drm_fb_xrgb_to_xrgb2101010_line); } +EXPORT_SYMBOL(drm_fb_xrgb_to_xrgb2101010); static void drm_fb_xrgb_to_gray8_line(void *dbuf, const void *sbuf, unsigned int pixels) { diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index bc830601e7a2..4a2f3c0de060 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -32,6 +32,11 @@ struct convert_to_rgb888_result { const u8 expected[TEST_BUF_SIZE]; }; +struct convert_to_xrgb2101010_result { + unsigned int dst_pitch; + const u32 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -40,6 +45,7 @@ struct convert_xrgb_case { struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; struct convert_to_rgb888_result rgb888_result; + struct convert_to_xrgb2101010_result xrgb2101010_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -61,6 +67,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x00, 0x00, 0xFF }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { 0x3FF0 }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -83,6 +93,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x00, 0x00, 0xFF }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { 0x3FF0 }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -132,6 +146,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { + 0x3FFF, 0x, + 0x3FF0, 0x000FFC00, + 0x03FF, 0x3FF003FF, + 0x3C00, 0x000F, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -175,6 +198,14 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, }, + .xrgb2101010_result = { + .dst_pitch = 20, + .expected = { + 0x03844672, 0x0444D414, 0x2A20300C, 0x, 0x, + 0x1B1705CD, 0x03844672, 0x0444D414, 0x, 0x, + 0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 0x, + }, + }, }, }; @@ -319,10 +350,42 @@ static void drm_test_fb_xrgb_to_rgb888(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void drm_test_fb_xrgb_to_xrgb2101010(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_xrgb2101010_result *result = >xrgb2101010_result; + size_t dst_size; + __u32 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(
[PATCH v5 1/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888()
Extend the existing test cases to test the conversion from XRGB to RGB888. Tested-by: Maíra Canal Reviewed-by: David Gow Acked-by: Maxime Ripard Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 65 +++ 1 file changed, 65 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index ab49f5e8796c..bc830601e7a2 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -27,6 +27,11 @@ struct convert_to_rgb565_result { const u16 expected_swab[TEST_BUF_SIZE]; }; +struct convert_to_rgb888_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -34,6 +39,7 @@ struct convert_xrgb_case { const u32 xrgb[TEST_BUF_SIZE]; struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; + struct convert_to_rgb888_result rgb888_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -51,6 +57,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { 0x00, 0x00, 0xFF }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -69,6 +79,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { 0x00, 0x00, 0xFF }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -109,6 +123,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0xE0FF, 0xFF07, }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -141,6 +164,17 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00A8, 0x8E6B, 0x330A, 0x, 0x, }, }, + .rgb888_result = { + .dst_pitch = 15, + .expected = { + 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, 0x03, 0x03, 0xA8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x03, 0xA8, 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + }, }, }; @@ -255,9 +289,40 @@ static void drm_test_fb_xrgb_to_rgb565(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0); } +static void drm_test_fb_xrgb_to_rgb888(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_rgb888_result *result = >rgb888_result; + size_t dst_size; + __u8 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_RGB888, result->dst_pitch, + >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(, buf); + + xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); + iosys_map_set_vaddr(, xrgb); + + drm_fb_xrgb_to_rgb888(, >dst_pitch, , , >clip); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct
[PATCH v5 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale
Hello everyone, This series is a follow up on my work adding KUnit test to the XRGB conversion functions. This time RGB888, XRGB2101010 and gray8 are added. Best wishes, Jose v1 -> v2: Tested-by: Maíra Canal Reviewed-by: David Gow v2 -> v3: Export symbol drm_fb_xrgb_to_xrgb2101010() v3 -> v4: Rebased on top of Maíra's prefix renaming work: https://lore.kernel.org/dri-devel/20220911191756.203118-1-mairaca...@riseup.net/T/ v4 -> v5: Acked-by: Maxime Ripard Remove reduntant "_test" suffix Sort test alphabetically José Expósito (3): drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb888() drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_xrgb2101010() drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_gray8() drivers/gpu/drm/drm_format_helper.c | 1 + .../gpu/drm/tests/drm_format_helper_test.c| 190 ++ 2 files changed, 191 insertions(+) base-commit: 961bcdf956a4645745407a5d919be8757549b062 prerequisite-patch-id: 605f4eb1bbdb8ed39cb2ebed95768d922486099f prerequisite-patch-id: 3818f7fa7c81927c8a88607c4955a45d614ee69a prerequisite-patch-id: 634952f085f249f2e18893a3f8344a2ff27c13ad prerequisite-patch-id: fe7ea3dd385fe6c64d7c5c8d65ebe6f9c7ab047b prerequisite-patch-id: c92ac7a03faee6e1000637928628e7fd127d0159 prerequisite-patch-id: f52fbd427e8730c62b5554f68713e6fa742ffcab prerequisite-patch-id: 1a2dc68fd107316fd1d1bb91376fe19bdb039147 prerequisite-patch-id: d91c951338cfe9f06e8b8aa74856f6dc08ac8212 prerequisite-patch-id: 41a65e680affc8011670762aec58c373030ef4ea prerequisite-patch-id: bbd5bf45c2185a9f2a551447247ce13f81df7c2a prerequisite-patch-id: 9802d5e3291f150a9ceba345628bbf04be972aba prerequisite-patch-id: 0bae228d241c6c5567c0b58fa4447a3bcb35d5f2 prerequisite-patch-id: e2ed4b2c89623279d2201a81259b49ce56c5bb38 prerequisite-patch-id: 57b3203672cf7617dc1d63d3eb1373e3b2b7ca34 prerequisite-patch-id: 85c127f8e3d55e4210a00d5c84e2c4f92e2e16ad prerequisite-patch-id: cad729f2d039e636d2f3f937a9f26b1fb4455388 prerequisite-patch-id: c9e696a62ea5f2d4407914ff7a8371e285f33d55 prerequisite-patch-id: 08f30e5572d2e5a8153b563dd4d8fa0ece2cc575 prerequisite-patch-id: c7f7be4f8e90e5eb473a82c293a6b6a0f417e2ba prerequisite-patch-id: b0c636c391f5d0ebb50a07222f3e41f48cab8c76 prerequisite-patch-id: 705cc9ff7eb3e3e2873cfdb68c2d2272fde38baf prerequisite-patch-id: cfbe2b5cbfd69cf9f0b11c7c329cf8ec5a2ecff4 prerequisite-patch-id: e7df3b6bbfb6bb87efaf39e73f2e4ed1f83558af prerequisite-patch-id: 554f79bc7984201131876865f5c1765c20f84ab5 prerequisite-patch-id: 3b848305159028d4b7e1dd9013050aba60f0ca41 prerequisite-patch-id: 9e9b33181259f59bf03f1fe9b3ef1d6160ae89d9 prerequisite-patch-id: 9aefed850bf64f9015299473087fadf015d246eb prerequisite-patch-id: 3f886741cdfeff02432de1b0f5ed9d25a2847576 prerequisite-patch-id: 3e81b7138067f19ee34bd7a418c01444979ccab3 prerequisite-patch-id: 59d64b331417360de507c782fc7c33af1ac6dfc3 prerequisite-patch-id: 8b35c6be1c70eaabcd1644a38731139f5be3153a prerequisite-patch-id: d0008bddf1653ff2452f349b018eaeb3bbcae698 prerequisite-patch-id: dc45c65927286ed6da022ffae1f861cd74efe89d prerequisite-patch-id: 79665be026f637db6b4ab52cb6cebfb0406c5bb8 prerequisite-patch-id: df37cbcb0f8716cf806910c742bbca83574bee00 prerequisite-patch-id: ea87b84377d7878f9608166731cdbd5acfa0d44b prerequisite-patch-id: 0158c508dd88a47c2a241a144c73b197bc84a533 prerequisite-patch-id: efbf15a64e673484a4d3187596f2c913e726ef1a prerequisite-patch-id: 920ebf96ab5fda37dcabd5febf6d8b4123fa141b prerequisite-patch-id: 8bb836f74b1a7fdc5352ad53eedaa763815a3e04 prerequisite-patch-id: 04c88d73e6c470f9e31864c0a5cd5b3307c54417 prerequisite-patch-id: 55cf446abf46692670cf6591fb3f012e6aeb256b prerequisite-patch-id: f28093a62972e0106b15128241fd4946e0c25cd9 prerequisite-patch-id: e9c3e896c6d3d8199abca3a2d4f852ee6f8b6539 prerequisite-patch-id: 588661d6d23181fc73748ae4960fb003d3ee prerequisite-patch-id: 3edb549d3f36417d929da4be9a0da15c325c8ab7 prerequisite-patch-id: 7897a7b1e3ec3fd588dc4788bbff4bb399683b1e prerequisite-patch-id: 05f5209e92385701c23665d7825c4d00a1abfd72 prerequisite-patch-id: 634075ca9541a14809bdef5df8c9240134773117 prerequisite-patch-id: 1cfe8abd19e3b8ab5d2ba30991ff5366dedf16db prerequisite-patch-id: 831a7a6cf76aa3bd41af7764113c48749e40431d -- 2.25.1
Re: [PATCH v4 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()
On Mon, Sep 19, 2022 at 10:25:19AM +0200, Maxime Ripard wrote: > On Mon, Sep 19, 2022 at 10:18:01AM +0200, José Expósito wrote: > > Hi Maxime, > > > > Thanks for looking into the patches. > > > > On Mon, Sep 19, 2022 at 09:36:45AM +0200, Maxime Ripard wrote: > > > Hi, > > > > > > On Mon, Sep 19, 2022 at 09:15:31AM +0200, José Expósito wrote: > > > > Extend the existing test cases to test the conversion from XRGB to > > > > grayscale. > > > > > > > > Tested-by: Maíra Canal > > > > Reviewed-by: David Gow > > > > Signed-off-by: José Expósito > > > > --- > > > > .../gpu/drm/tests/drm_format_helper_test.c| 62 +++ > > > > 1 file changed, 62 insertions(+) > > > > > > > > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c > > > > b/drivers/gpu/drm/tests/drm_format_helper_test.c > > > > index 09d358b54da0..71722e828abe 100644 > > > > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c > > > > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c > > > > @@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result { > > > > const u32 expected[TEST_BUF_SIZE]; > > > > }; > > > > > > > > +struct convert_to_gray8_result { > > > > + unsigned int dst_pitch; > > > > + const u8 expected[TEST_BUF_SIZE]; > > > > +}; > > > > + > > > > > > > > [...] > > > > > > > > static struct kunit_case drm_format_helper_test_cases[] = { > > > > KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_rgb332, > > > > convert_xrgb_gen_params), > > > > KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_rgb565, > > > > convert_xrgb_gen_params), > > > > KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_rgb888_test, > > > > convert_xrgb_gen_params), > > > > KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_xrgb2101010_test, > > > > convert_xrgb_gen_params), > > > > + KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_gray8_test, > > > > convert_xrgb_gen_params), > > > > > > The trailing test feels redundant, > > > > Why do you feel like it is redundant? Under the hood, most conversion > > functions reuse the same code, but the *_line() function is unique and > > I think that it is worth testing it. > > Sure, I wasn't commenting on the code itself, but the trailing "test" in > the test name: drm_test_fb_xrgb_to_gray8_test > ^ > > Which is redundant since we already have "test" in the prefix. > > Maxime Ah! OK, I misunderstood your first sentence. Indeed, the _test sufix should be removed, added to my TODO list. Thanks!!
Re: [PATCH v4 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()
Hi Maxime, Thanks for looking into the patches. On Mon, Sep 19, 2022 at 09:36:45AM +0200, Maxime Ripard wrote: > Hi, > > On Mon, Sep 19, 2022 at 09:15:31AM +0200, José Expósito wrote: > > Extend the existing test cases to test the conversion from XRGB to > > grayscale. > > > > Tested-by: Maíra Canal > > Reviewed-by: David Gow > > Signed-off-by: José Expósito > > --- > > .../gpu/drm/tests/drm_format_helper_test.c| 62 +++ > > 1 file changed, 62 insertions(+) > > > > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c > > b/drivers/gpu/drm/tests/drm_format_helper_test.c > > index 09d358b54da0..71722e828abe 100644 > > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c > > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c > > @@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result { > > const u32 expected[TEST_BUF_SIZE]; > > }; > > > > +struct convert_to_gray8_result { > > + unsigned int dst_pitch; > > + const u8 expected[TEST_BUF_SIZE]; > > +}; > > + > > > > [...] > > > > static struct kunit_case drm_format_helper_test_cases[] = { > > KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_rgb332, > > convert_xrgb_gen_params), > > KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_rgb565, > > convert_xrgb_gen_params), > > KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_rgb888_test, > > convert_xrgb_gen_params), > > KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_xrgb2101010_test, > > convert_xrgb_gen_params), > > + KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_gray8_test, > > convert_xrgb_gen_params), > > The trailing test feels redundant, Why do you feel like it is redundant? Under the hood, most conversion functions reuse the same code, but the *_line() function is unique and I think that it is worth testing it. > and we should order them > alphabetically to avoid conflicts as much as possible. Good point, I'll sort them alphabetically. > Feel free to add my > Acked-by: Maxime Ripard > > And fix this while applying > > Maxime Thanks! Jose
[PATCH v4 1/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888()
Extend the existing test cases to test the conversion from XRGB to RGB888. Tested-by: Maíra Canal Reviewed-by: David Gow Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 65 +++ 1 file changed, 65 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index ab49f5e8796c..cc1ab672314a 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -27,6 +27,11 @@ struct convert_to_rgb565_result { const u16 expected_swab[TEST_BUF_SIZE]; }; +struct convert_to_rgb888_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -34,6 +39,7 @@ struct convert_xrgb_case { const u32 xrgb[TEST_BUF_SIZE]; struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; + struct convert_to_rgb888_result rgb888_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -51,6 +57,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { 0x00, 0x00, 0xFF }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -69,6 +79,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { 0x00, 0x00, 0xFF }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -109,6 +123,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0xE0FF, 0xFF07, }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -141,6 +164,17 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00A8, 0x8E6B, 0x330A, 0x, 0x, }, }, + .rgb888_result = { + .dst_pitch = 15, + .expected = { + 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, 0x03, 0x03, 0xA8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x03, 0xA8, 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + }, }, }; @@ -255,9 +289,40 @@ static void drm_test_fb_xrgb_to_rgb565(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0); } +static void drm_test_fb_xrgb_to_rgb888_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_rgb888_result *result = >rgb888_result; + size_t dst_size; + __u8 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_RGB888, result->dst_pitch, + >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(, buf); + + xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); + iosys_map_set_vaddr(, xrgb); + + drm_fb_xrgb_to_rgb888(, >dst_pitch, , , >clip); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_t
[PATCH v4 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010()
Extend the existing test cases to test the conversion from XRGB to XRGB2101010. In order to be able to call drm_fb_xrgb_to_xrgb2101010() when compiling CONFIG_DRM_KMS_HELPER as a module export the symbol. Tested-by: Maíra Canal Reviewed-by: David Gow Signed-off-by: José Expósito --- drivers/gpu/drm/drm_format_helper.c | 1 + .../gpu/drm/tests/drm_format_helper_test.c| 63 +++ 2 files changed, 64 insertions(+) diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c index 4afc4ac27342..e2f76621453c 100644 --- a/drivers/gpu/drm/drm_format_helper.c +++ b/drivers/gpu/drm/drm_format_helper.c @@ -553,6 +553,7 @@ void drm_fb_xrgb_to_xrgb2101010(struct iosys_map *dst, const unsigned int *d drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, drm_fb_xrgb_to_xrgb2101010_line); } +EXPORT_SYMBOL(drm_fb_xrgb_to_xrgb2101010); static void drm_fb_xrgb_to_gray8_line(void *dbuf, const void *sbuf, unsigned int pixels) { diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index cc1ab672314a..09d358b54da0 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -32,6 +32,11 @@ struct convert_to_rgb888_result { const u8 expected[TEST_BUF_SIZE]; }; +struct convert_to_xrgb2101010_result { + unsigned int dst_pitch; + const u32 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -40,6 +45,7 @@ struct convert_xrgb_case { struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; struct convert_to_rgb888_result rgb888_result; + struct convert_to_xrgb2101010_result xrgb2101010_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -61,6 +67,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x00, 0x00, 0xFF }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { 0x3FF0 }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -83,6 +93,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x00, 0x00, 0xFF }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { 0x3FF0 }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -132,6 +146,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { + 0x3FFF, 0x, + 0x3FF0, 0x000FFC00, + 0x03FF, 0x3FF003FF, + 0x3C00, 0x000F, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -175,6 +198,14 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, }, + .xrgb2101010_result = { + .dst_pitch = 20, + .expected = { + 0x03844672, 0x0444D414, 0x2A20300C, 0x, 0x, + 0x1B1705CD, 0x03844672, 0x0444D414, 0x, 0x, + 0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 0x, + }, + }, }, }; @@ -319,10 +350,42 @@ static void drm_test_fb_xrgb_to_rgb888_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void drm_test_fb_xrgb_to_xrgb2101010_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_xrgb2101010_result *result = >xrgb2101010_result; + size_t dst_size; + __u32 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(
[PATCH v4 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()
Extend the existing test cases to test the conversion from XRGB to grayscale. Tested-by: Maíra Canal Reviewed-by: David Gow Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 62 +++ 1 file changed, 62 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 09d358b54da0..71722e828abe 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result { const u32 expected[TEST_BUF_SIZE]; }; +struct convert_to_gray8_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -46,6 +51,7 @@ struct convert_xrgb_case { struct convert_to_rgb565_result rgb565_result; struct convert_to_rgb888_result rgb888_result; struct convert_to_xrgb2101010_result xrgb2101010_result; + struct convert_to_gray8_result gray8_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -71,6 +77,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x3FF0 }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { 0x4C }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -97,6 +107,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x3FF0 }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { 0x4C }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -155,6 +169,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x3C00, 0x000F, }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0x00, + 0x4C, 0x99, + 0x19, 0x66, + 0xE5, 0xB2, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -206,6 +229,14 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 0x, }, }, + .gray8_result = { + .dst_pitch = 5, + .expected = { + 0x3C, 0x33, 0x34, 0x00, 0x00, + 0x6F, 0x3C, 0x33, 0x00, 0x00, + 0x34, 0x6F, 0x3C, 0x00, 0x00, + }, + }, }, }; @@ -381,11 +412,42 @@ static void drm_test_fb_xrgb_to_xrgb2101010_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void drm_test_fb_xrgb_to_gray8_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_gray8_result *result = >gray8_result; + size_t dst_size; + __u8 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_R8, result->dst_pitch, + >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(, buf); + + xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); + iosys_map_set_vaddr(, xrgb); + + drm_fb_xrgb_to_gray8(, >dst_pitch, , , >clip); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_rgb332, convert_xrgb_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_rgb565, convert_xrgb_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_rgb888_test, convert_xrgb_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb_to_xrgb2101010_test, convert_xrgb88
[PATCH v4 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale
Hello everyone, This series is a follow up on my work adding KUnit test to the XRGB conversion functions. This time RGB888, XRGB2101010 and gray8 are added. Best wishes, Jose v1 -> v2: Tested-by: Maíra Canal Reviewed-by: David Gow v2 -> v3: Export symbol drm_fb_xrgb_to_xrgb2101010() v3 -> v4: Rebased on top of Maíra's prefix renaming work: https://lore.kernel.org/dri-devel/20220911191756.203118-1-mairaca...@riseup.net/T/ José Expósito (3): drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb888() drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_xrgb2101010() drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_gray8() drivers/gpu/drm/drm_format_helper.c | 1 + .../gpu/drm/tests/drm_format_helper_test.c| 190 ++ 2 files changed, 191 insertions(+) base-commit: 961bcdf956a4645745407a5d919be8757549b062 prerequisite-patch-id: 605f4eb1bbdb8ed39cb2ebed95768d922486099f prerequisite-patch-id: 3818f7fa7c81927c8a88607c4955a45d614ee69a prerequisite-patch-id: 634952f085f249f2e18893a3f8344a2ff27c13ad prerequisite-patch-id: fe7ea3dd385fe6c64d7c5c8d65ebe6f9c7ab047b prerequisite-patch-id: c92ac7a03faee6e1000637928628e7fd127d0159 prerequisite-patch-id: f52fbd427e8730c62b5554f68713e6fa742ffcab prerequisite-patch-id: 1a2dc68fd107316fd1d1bb91376fe19bdb039147 prerequisite-patch-id: d91c951338cfe9f06e8b8aa74856f6dc08ac8212 prerequisite-patch-id: 41a65e680affc8011670762aec58c373030ef4ea prerequisite-patch-id: bbd5bf45c2185a9f2a551447247ce13f81df7c2a prerequisite-patch-id: 9802d5e3291f150a9ceba345628bbf04be972aba prerequisite-patch-id: 0bae228d241c6c5567c0b58fa4447a3bcb35d5f2 prerequisite-patch-id: e2ed4b2c89623279d2201a81259b49ce56c5bb38 prerequisite-patch-id: 57b3203672cf7617dc1d63d3eb1373e3b2b7ca34 prerequisite-patch-id: 85c127f8e3d55e4210a00d5c84e2c4f92e2e16ad prerequisite-patch-id: cad729f2d039e636d2f3f937a9f26b1fb4455388 prerequisite-patch-id: c9e696a62ea5f2d4407914ff7a8371e285f33d55 prerequisite-patch-id: 08f30e5572d2e5a8153b563dd4d8fa0ece2cc575 prerequisite-patch-id: c7f7be4f8e90e5eb473a82c293a6b6a0f417e2ba prerequisite-patch-id: b0c636c391f5d0ebb50a07222f3e41f48cab8c76 prerequisite-patch-id: 705cc9ff7eb3e3e2873cfdb68c2d2272fde38baf prerequisite-patch-id: cfbe2b5cbfd69cf9f0b11c7c329cf8ec5a2ecff4 prerequisite-patch-id: e7df3b6bbfb6bb87efaf39e73f2e4ed1f83558af -- 2.25.1
Re: [PATCH v3 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale
On Sun, Sep 18, 2022 at 01:26:06PM -0300, Maíra Canal wrote: > Hi Jose, > > On 9/18/22 10:22, José Expósito wrote: > > Hi! > > > > On Sun, Aug 28, 2022 at 06:45:14PM +0200, José Expósito wrote: > >> Hello everyone, > >> > >> This series is a follow up on my work adding KUnit test to the XRGB > >> conversion functions. This time RGB888, XRGB2101010 and gray8 are added. > >> > >> Best wishes, > >> Jose > >> > >> v1 -> v2: > >> > >> Tested-by: Maíra Canal > >> Reviewed-by: David Gow > >> > >> v2 -> v3: > >> > >> Export symbol drm_fb_xrgb_to_xrgb2101010() > > > > This patchset is being in the mailing list for a while. Unless someone > > has a reason to not merge it, I'd like to push it next week. > > I believe this patchset doesn't apply anymore due to this patch [1], > that applied a naming convention for the DRM tests. Maybe you could send > a v3 rebasing the patchset. > > [1] > https://lore.kernel.org/dri-devel/20220911191756.203118-1-mairaca...@riseup.net/T/#mb794103c8e39cdb76734f4e22ce90806f11d99bc > > Best Regards, > - Maíra Canal Thanks for the heads up Maíra, I didn't noticed that you patches were already merged. I'll rebase on top of your work and send v4. Best wishes, Jose > > > > Thanks, > > Jose > > > >> José Expósito (3): > >> drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb888() > >> drm/format-helper: Add KUnit tests for > >> drm_fb_xrgb_to_xrgb2101010() > >> drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_gray8() > >> > >> drivers/gpu/drm/drm_format_helper.c | 1 + > >> .../gpu/drm/tests/drm_format_helper_test.c| 190 ++ > >> 2 files changed, 191 insertions(+) > >> > >> > >> base-commit: 61a9fa154d217c13eea90aa5bc635bc4b1fcb66e > >> -- > >> 2.25.1 > >>
Re: [PATCH v3 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale
Hi! On Sun, Aug 28, 2022 at 06:45:14PM +0200, José Expósito wrote: > Hello everyone, > > This series is a follow up on my work adding KUnit test to the XRGB > conversion functions. This time RGB888, XRGB2101010 and gray8 are added. > > Best wishes, > Jose > > v1 -> v2: > > Tested-by: Maíra Canal > Reviewed-by: David Gow > > v2 -> v3: > > Export symbol drm_fb_xrgb_to_xrgb2101010() This patchset is being in the mailing list for a while. Unless someone has a reason to not merge it, I'd like to push it next week. Thanks, Jose > José Expósito (3): > drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb888() > drm/format-helper: Add KUnit tests for > drm_fb_xrgb_to_xrgb2101010() > drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_gray8() > > drivers/gpu/drm/drm_format_helper.c | 1 + > .../gpu/drm/tests/drm_format_helper_test.c| 190 ++ > 2 files changed, 191 insertions(+) > > > base-commit: 61a9fa154d217c13eea90aa5bc635bc4b1fcb66e > -- > 2.25.1 >
Re: [PATCH] drm/doc: Custom Kconfig for KUnit is no longer needed
Hi Michał, On Mon, Sep 05, 2022 at 08:47:11PM +0200, Michał Winiarski wrote: > When built for UML, KUnit provides virtio/PCI, which means that the > DMA/IOMEM UML emulation needed by DRM is already present and does not > need to be manually added with --kconfig_add. > > References: commit 6fc3a8636a7b ("kunit: tool: Enable virtio/PCI by default > on UML") > Signed-off-by: Michał Winiarski > --- > Documentation/gpu/drm-internals.rst | 7 +-- > 1 file changed, 1 insertion(+), 6 deletions(-) > > diff --git a/Documentation/gpu/drm-internals.rst > b/Documentation/gpu/drm-internals.rst > index 5fd20a306718..c264a9587d21 100644 > --- a/Documentation/gpu/drm-internals.rst > +++ b/Documentation/gpu/drm-internals.rst > @@ -228,16 +228,11 @@ follows: > > .. code-block:: bash > > - $ ./tools/testing/kunit/kunit.py run > --kunitconfig=drivers/gpu/drm/tests \ > - --kconfig_add CONFIG_VIRTIO_UML=y \ > - --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y > + $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/tests > > .. note:: > The configuration included in ``.kunitconfig`` should be as generic as > possible. > - ``CONFIG_VIRTIO_UML`` and ``CONFIG_UML_PCI_OVER_VIRTIO`` are not > - included in it because they are only required for User Mode Linux. > - > > Legacy Support Code > === > -- > 2.37.3 > Thanks for the patch. This was in my ToDo list and I was waiting until 6fc3a8636a7b was merged in the DRM tree, but since you already fixed it I can mark it as done. Thanks!
[PATCH v3 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010()
Extend the existing test cases to test the conversion from XRGB to XRGB2101010. In order to be able to call drm_fb_xrgb_to_xrgb2101010() when compiling CONFIG_DRM_KMS_HELPER as a module export the symbol. Tested-by: Maíra Canal Reviewed-by: David Gow Signed-off-by: José Expósito --- drivers/gpu/drm/drm_format_helper.c | 1 + .../gpu/drm/tests/drm_format_helper_test.c| 63 +++ 2 files changed, 64 insertions(+) diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c index 56642816fdff..b9a9fea0f6f1 100644 --- a/drivers/gpu/drm/drm_format_helper.c +++ b/drivers/gpu/drm/drm_format_helper.c @@ -553,6 +553,7 @@ void drm_fb_xrgb_to_xrgb2101010(struct iosys_map *dst, const unsigned int *d drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, drm_fb_xrgb_to_xrgb2101010_line); } +EXPORT_SYMBOL(drm_fb_xrgb_to_xrgb2101010); static void drm_fb_xrgb_to_gray8_line(void *dbuf, const void *sbuf, unsigned int pixels) { diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 08d08e7ab19a..d8536db4de1e 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -32,6 +32,11 @@ struct convert_to_rgb888_result { const u8 expected[TEST_BUF_SIZE]; }; +struct convert_to_xrgb2101010_result { + unsigned int dst_pitch; + const u32 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -40,6 +45,7 @@ struct convert_xrgb_case { struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; struct convert_to_rgb888_result rgb888_result; + struct convert_to_xrgb2101010_result xrgb2101010_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -61,6 +67,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x00, 0x00, 0xFF }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { 0x3FF0 }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -83,6 +93,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x00, 0x00, 0xFF }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { 0x3FF0 }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -132,6 +146,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { + 0x3FFF, 0x, + 0x3FF0, 0x000FFC00, + 0x03FF, 0x3FF003FF, + 0x3C00, 0x000F, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -175,6 +198,14 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, }, + .xrgb2101010_result = { + .dst_pitch = 20, + .expected = { + 0x03844672, 0x0444D414, 0x2A20300C, 0x, 0x, + 0x1B1705CD, 0x03844672, 0x0444D414, 0x, 0x, + 0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 0x, + }, + }, }, }; @@ -319,10 +350,42 @@ static void xrgb_to_rgb888_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void xrgb_to_xrgb2101010_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_xrgb2101010_result *result = >xrgb2101010_result; + size_t dst_size; + __u32 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_XRGB2101010, + re
[PATCH v3 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()
Extend the existing test cases to test the conversion from XRGB to grayscale. Tested-by: Maíra Canal Reviewed-by: David Gow Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 62 +++ 1 file changed, 62 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index d8536db4de1e..2f548aa51a30 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result { const u32 expected[TEST_BUF_SIZE]; }; +struct convert_to_gray8_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -46,6 +51,7 @@ struct convert_xrgb_case { struct convert_to_rgb565_result rgb565_result; struct convert_to_rgb888_result rgb888_result; struct convert_to_xrgb2101010_result xrgb2101010_result; + struct convert_to_gray8_result gray8_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -71,6 +77,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x3FF0 }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { 0x4C }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -97,6 +107,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x3FF0 }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { 0x4C }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -155,6 +169,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x3C00, 0x000F, }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0x00, + 0x4C, 0x99, + 0x19, 0x66, + 0xE5, 0xB2, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -206,6 +229,14 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 0x, }, }, + .gray8_result = { + .dst_pitch = 5, + .expected = { + 0x3C, 0x33, 0x34, 0x00, 0x00, + 0x6F, 0x3C, 0x33, 0x00, 0x00, + 0x34, 0x6F, 0x3C, 0x00, 0x00, + }, + }, }, }; @@ -381,11 +412,42 @@ static void xrgb_to_xrgb2101010_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void xrgb_to_gray8_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_gray8_result *result = >gray8_result; + size_t dst_size; + __u8 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_R8, result->dst_pitch, + >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(, buf); + + xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); + iosys_map_set_vaddr(, xrgb); + + drm_fb_xrgb_to_gray8(, >dst_pitch, , , >clip); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(xrgb_to_rgb332_test, convert_xrgb_gen_params), KUNIT_CASE_PARAM(xrgb_to_rgb565_test, convert_xrgb_gen_params), KUNIT_CASE_PARAM(xrgb_to_rgb888_test, convert_xrgb_gen_params), KUNIT_CASE_PARAM(xrgb_to_xrgb2101010_test, convert_xrgb_gen_params), + KUNIT_CASE_PARAM(xrgb_to
[PATCH v3 1/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888()
Extend the existing test cases to test the conversion from XRGB to RGB888. Tested-by: Maíra Canal Reviewed-by: David Gow Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 65 +++ 1 file changed, 65 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 828487071796..08d08e7ab19a 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -27,6 +27,11 @@ struct convert_to_rgb565_result { const u16 expected_swab[TEST_BUF_SIZE]; }; +struct convert_to_rgb888_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -34,6 +39,7 @@ struct convert_xrgb_case { const u32 xrgb[TEST_BUF_SIZE]; struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; + struct convert_to_rgb888_result rgb888_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -51,6 +57,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { 0x00, 0x00, 0xFF }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -69,6 +79,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { 0x00, 0x00, 0xFF }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -109,6 +123,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0xE0FF, 0xFF07, }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -141,6 +164,17 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00A8, 0x8E6B, 0x330A, 0x, 0x, }, }, + .rgb888_result = { + .dst_pitch = 15, + .expected = { + 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, 0x03, 0x03, 0xA8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x03, 0xA8, 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + }, }, }; @@ -255,9 +289,40 @@ static void xrgb_to_rgb565_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0); } +static void xrgb_to_rgb888_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_rgb888_result *result = >rgb888_result; + size_t dst_size; + __u8 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_RGB888, result->dst_pitch, + >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(, buf); + + xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); + iosys_map_set_vaddr(, xrgb); + + drm_fb_xrgb_to_rgb888(, >dst_pitch, , , >clip); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_t
[PATCH v3 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale
Hello everyone, This series is a follow up on my work adding KUnit test to the XRGB conversion functions. This time RGB888, XRGB2101010 and gray8 are added. Best wishes, Jose v1 -> v2: Tested-by: Maíra Canal Reviewed-by: David Gow v2 -> v3: Export symbol drm_fb_xrgb_to_xrgb2101010() José Expósito (3): drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb888() drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_xrgb2101010() drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_gray8() drivers/gpu/drm/drm_format_helper.c | 1 + .../gpu/drm/tests/drm_format_helper_test.c| 190 ++ 2 files changed, 191 insertions(+) base-commit: 61a9fa154d217c13eea90aa5bc635bc4b1fcb66e -- 2.25.1
[PATCH v2 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()
Extend the existing test cases to test the conversion from XRGB to grayscale. Tested-by: Maíra Canal Reviewed-by: David Gow Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 62 +++ 1 file changed, 62 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index d8536db4de1e..2f548aa51a30 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result { const u32 expected[TEST_BUF_SIZE]; }; +struct convert_to_gray8_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -46,6 +51,7 @@ struct convert_xrgb_case { struct convert_to_rgb565_result rgb565_result; struct convert_to_rgb888_result rgb888_result; struct convert_to_xrgb2101010_result xrgb2101010_result; + struct convert_to_gray8_result gray8_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -71,6 +77,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x3FF0 }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { 0x4C }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -97,6 +107,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x3FF0 }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { 0x4C }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -155,6 +169,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x3C00, 0x000F, }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0x00, + 0x4C, 0x99, + 0x19, 0x66, + 0xE5, 0xB2, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -206,6 +229,14 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 0x, }, }, + .gray8_result = { + .dst_pitch = 5, + .expected = { + 0x3C, 0x33, 0x34, 0x00, 0x00, + 0x6F, 0x3C, 0x33, 0x00, 0x00, + 0x34, 0x6F, 0x3C, 0x00, 0x00, + }, + }, }, }; @@ -381,11 +412,42 @@ static void xrgb_to_xrgb2101010_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void xrgb_to_gray8_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_gray8_result *result = >gray8_result; + size_t dst_size; + __u8 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_R8, result->dst_pitch, + >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(, buf); + + xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); + iosys_map_set_vaddr(, xrgb); + + drm_fb_xrgb_to_gray8(, >dst_pitch, , , >clip); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(xrgb_to_rgb332_test, convert_xrgb_gen_params), KUNIT_CASE_PARAM(xrgb_to_rgb565_test, convert_xrgb_gen_params), KUNIT_CASE_PARAM(xrgb_to_rgb888_test, convert_xrgb_gen_params), KUNIT_CASE_PARAM(xrgb_to_xrgb2101010_test, convert_xrgb_gen_params), + KUNIT_CASE_PARAM(xrgb_to
[PATCH v2 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010()
Extend the existing test cases to test the conversion from XRGB to XRGB2101010. Tested-by: Maíra Canal Reviewed-by: David Gow Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 63 +++ 1 file changed, 63 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 08d08e7ab19a..d8536db4de1e 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -32,6 +32,11 @@ struct convert_to_rgb888_result { const u8 expected[TEST_BUF_SIZE]; }; +struct convert_to_xrgb2101010_result { + unsigned int dst_pitch; + const u32 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -40,6 +45,7 @@ struct convert_xrgb_case { struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; struct convert_to_rgb888_result rgb888_result; + struct convert_to_xrgb2101010_result xrgb2101010_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -61,6 +67,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x00, 0x00, 0xFF }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { 0x3FF0 }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -83,6 +93,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x00, 0x00, 0xFF }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { 0x3FF0 }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -132,6 +146,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { + 0x3FFF, 0x, + 0x3FF0, 0x000FFC00, + 0x03FF, 0x3FF003FF, + 0x3C00, 0x000F, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -175,6 +198,14 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, }, + .xrgb2101010_result = { + .dst_pitch = 20, + .expected = { + 0x03844672, 0x0444D414, 0x2A20300C, 0x, 0x, + 0x1B1705CD, 0x03844672, 0x0444D414, 0x, 0x, + 0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 0x, + }, + }, }, }; @@ -319,10 +350,42 @@ static void xrgb_to_rgb888_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void xrgb_to_xrgb2101010_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_xrgb2101010_result *result = >xrgb2101010_result; + size_t dst_size; + __u32 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_XRGB2101010, + result->dst_pitch, >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(, buf); + + xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); + iosys_map_set_vaddr(, xrgb); + + drm_fb_xrgb_to_xrgb2101010(, >dst_pitch, , , >clip); + buf = le32buf_to_cpu(test, buf, TEST_BUF_SIZE); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(xrgb_to_rgb332_test, convert_xrgb_gen_params),
[PATCH v2 1/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888()
Extend the existing test cases to test the conversion from XRGB to RGB888. Tested-by: Maíra Canal Reviewed-by: David Gow Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 65 +++ 1 file changed, 65 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 828487071796..08d08e7ab19a 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -27,6 +27,11 @@ struct convert_to_rgb565_result { const u16 expected_swab[TEST_BUF_SIZE]; }; +struct convert_to_rgb888_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -34,6 +39,7 @@ struct convert_xrgb_case { const u32 xrgb[TEST_BUF_SIZE]; struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; + struct convert_to_rgb888_result rgb888_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -51,6 +57,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { 0x00, 0x00, 0xFF }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -69,6 +79,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { 0x00, 0x00, 0xFF }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -109,6 +123,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0xE0FF, 0xFF07, }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -141,6 +164,17 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00A8, 0x8E6B, 0x330A, 0x, 0x, }, }, + .rgb888_result = { + .dst_pitch = 15, + .expected = { + 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, 0x03, 0x03, 0xA8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x03, 0xA8, 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + }, }, }; @@ -255,9 +289,40 @@ static void xrgb_to_rgb565_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0); } +static void xrgb_to_rgb888_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_rgb888_result *result = >rgb888_result; + size_t dst_size; + __u8 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_RGB888, result->dst_pitch, + >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(, buf); + + xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); + iosys_map_set_vaddr(, xrgb); + + drm_fb_xrgb_to_rgb888(, >dst_pitch, , , >clip); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_t
[PATCH v2 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale
Hello everyone, This series is a follow up on my work adding KUnit test to the XRGB conversion functions. This time RGB888, XRGB2101010 and gray8 are added. Best wishes, Jose v1 -> v2: Tested-by: Maíra Canal Reviewed-by: David Gow José Expósito (3): drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb888() drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_xrgb2101010() drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_gray8() .../gpu/drm/tests/drm_format_helper_test.c| 190 ++ 1 file changed, 190 insertions(+) base-commit: 61a9fa154d217c13eea90aa5bc635bc4b1fcb66e -- 2.25.1
Re: [PATCH 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale
On Tue, Aug 16, 2022 at 10:37:49AM -0300, Maíra Canal wrote: > Hi José, > > Tested the whole series on UML, x86, i386 and PPC. All looks fine! > > Tested-by: Maíra Canal > > Best Regards, > - Maíra Canal > > On 8/16/22 07:29, José Expósito wrote: > > Hello everyone, > > > > This series is a follow up on my work adding KUnit test to the XRGB > > conversion functions. This time RGB888, XRGB2101010 and gray8 are added. > > > > Best wishes, > > Jose > > > > José Expósito (3): > >drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb888() > >drm/format-helper: Add KUnit tests for > > drm_fb_xrgb_to_xrgb2101010() > >drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_gray8() > > > > .../gpu/drm/tests/drm_format_helper_test.c| 190 ++ > > 1 file changed, 190 insertions(+) > > Thanks a lot for testing the series Maíra and for the code review David. I added a note to my ToDo list to use KUNIT_EXPECT_MEMEQ once it gets merged. For the moment, I'll send v2 :) Best wishes, Jose
[PATCH 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010()
Extend the existing test cases to test the conversion from XRGB to XRGB2101010. Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 63 +++ 1 file changed, 63 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 08d08e7ab19a..d8536db4de1e 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -32,6 +32,11 @@ struct convert_to_rgb888_result { const u8 expected[TEST_BUF_SIZE]; }; +struct convert_to_xrgb2101010_result { + unsigned int dst_pitch; + const u32 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -40,6 +45,7 @@ struct convert_xrgb_case { struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; struct convert_to_rgb888_result rgb888_result; + struct convert_to_xrgb2101010_result xrgb2101010_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -61,6 +67,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x00, 0x00, 0xFF }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { 0x3FF0 }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -83,6 +93,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x00, 0x00, 0xFF }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { 0x3FF0 }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -132,6 +146,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, }, }, + .xrgb2101010_result = { + .dst_pitch = 0, + .expected = { + 0x3FFF, 0x, + 0x3FF0, 0x000FFC00, + 0x03FF, 0x3FF003FF, + 0x3C00, 0x000F, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -175,6 +198,14 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, }, + .xrgb2101010_result = { + .dst_pitch = 20, + .expected = { + 0x03844672, 0x0444D414, 0x2A20300C, 0x, 0x, + 0x1B1705CD, 0x03844672, 0x0444D414, 0x, 0x, + 0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 0x, + }, + }, }, }; @@ -319,10 +350,42 @@ static void xrgb_to_rgb888_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void xrgb_to_xrgb2101010_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_xrgb2101010_result *result = >xrgb2101010_result; + size_t dst_size; + __u32 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_XRGB2101010, + result->dst_pitch, >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(, buf); + + xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); + iosys_map_set_vaddr(, xrgb); + + drm_fb_xrgb_to_xrgb2101010(, >dst_pitch, , , >clip); + buf = le32buf_to_cpu(test, buf, TEST_BUF_SIZE); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(xrgb_to_rgb332_test, convert_xrgb_gen_params), KUNIT_CASE_PARAM(xrgb_to_rgb565_test, convert_xrgb88
[PATCH 1/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888()
Extend the existing test cases to test the conversion from XRGB to RGB888. Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 65 +++ 1 file changed, 65 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 828487071796..08d08e7ab19a 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -27,6 +27,11 @@ struct convert_to_rgb565_result { const u16 expected_swab[TEST_BUF_SIZE]; }; +struct convert_to_rgb888_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -34,6 +39,7 @@ struct convert_xrgb_case { const u32 xrgb[TEST_BUF_SIZE]; struct convert_to_rgb332_result rgb332_result; struct convert_to_rgb565_result rgb565_result; + struct convert_to_rgb888_result rgb888_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -51,6 +57,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { 0x00, 0x00, 0xFF }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -69,6 +79,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { 0x00, 0x00, 0xFF }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -109,6 +123,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0xE0FF, 0xFF07, }, }, + .rgb888_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -141,6 +164,17 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x00A8, 0x8E6B, 0x330A, 0x, 0x, }, }, + .rgb888_result = { + .dst_pitch = 15, + .expected = { + 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, 0x03, 0x03, 0xA8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x03, 0xA8, 0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + }, }, }; @@ -255,9 +289,40 @@ static void xrgb_to_rgb565_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0); } +static void xrgb_to_rgb888_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_rgb888_result *result = >rgb888_result; + size_t dst_size; + __u8 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_RGB888, result->dst_pitch, + >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(, buf); + + xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); + iosys_map_set_vaddr(, xrgb); + + drm_fb_xrgb_to_rgb888(, >dst_pitch, , , >clip); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(xrgb_to_
[PATCH 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()
Extend the existing test cases to test the conversion from XRGB to grayscale. Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 62 +++ 1 file changed, 62 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index d8536db4de1e..2f548aa51a30 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result { const u32 expected[TEST_BUF_SIZE]; }; +struct convert_to_gray8_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; @@ -46,6 +51,7 @@ struct convert_xrgb_case { struct convert_to_rgb565_result rgb565_result; struct convert_to_rgb888_result rgb888_result; struct convert_to_xrgb2101010_result xrgb2101010_result; + struct convert_to_gray8_result gray8_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -71,6 +77,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x3FF0 }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { 0x4C }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -97,6 +107,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0x3FF0 }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { 0x4C }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -155,6 +169,15 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x3C00, 0x000F, }, }, + .gray8_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0x00, + 0x4C, 0x99, + 0x19, 0x66, + 0xE5, 0xB2, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -206,6 +229,14 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 0x, }, }, + .gray8_result = { + .dst_pitch = 5, + .expected = { + 0x3C, 0x33, 0x34, 0x00, 0x00, + 0x6F, 0x3C, 0x33, 0x00, 0x00, + 0x34, 0x6F, 0x3C, 0x00, 0x00, + }, + }, }, }; @@ -381,11 +412,42 @@ static void xrgb_to_xrgb2101010_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); } +static void xrgb_to_gray8_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_gray8_result *result = >gray8_result; + size_t dst_size; + __u8 *buf = NULL; + __u32 *xrgb = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_R8, result->dst_pitch, + >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(, buf); + + xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb); + iosys_map_set_vaddr(, xrgb); + + drm_fb_xrgb_to_gray8(, >dst_pitch, , , >clip); + KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); +} + static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(xrgb_to_rgb332_test, convert_xrgb_gen_params), KUNIT_CASE_PARAM(xrgb_to_rgb565_test, convert_xrgb_gen_params), KUNIT_CASE_PARAM(xrgb_to_rgb888_test, convert_xrgb_gen_params), KUNIT_CASE_PARAM(xrgb_to_xrgb2101010_test, convert_xrgb_gen_params), + KUNIT_CASE_PARAM(xrgb_to_gray8_test, convert_xrgb_gen_params), {} }; -- 2.25.1
[PATCH 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale
Hello everyone, This series is a follow up on my work adding KUnit test to the XRGB conversion functions. This time RGB888, XRGB2101010 and gray8 are added. Best wishes, Jose José Expósito (3): drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb888() drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_xrgb2101010() drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_gray8() .../gpu/drm/tests/drm_format_helper_test.c| 190 ++ 1 file changed, 190 insertions(+) -- 2.25.1
Re: [PATCH v2 4/4] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb565()
On Wed, Aug 10, 2022 at 09:41:18AM -0700, Daniel Latypov wrote: > On Sun, Jul 17, 2022 at 10:01 AM José Expósito > wrote: > > > > José Expósito wrote: > > > I already fixed the warning and added the reviewed by tags, however, I > > > noticed that rebasing the series on the latest drm-misc-next show this > > > error: > > > [...] > > > > Sorry for the extra email. I forgot to mention that the error is only > > present in UML. Running in other architectures works as expected. > > Tested on x86_64 and PowerPC. > > Can you take a look at the raw output? > > It would be .kunit/test.log (or replace .kunit with w/e --build_dir > you're using). > You could also run the test with --raw_output to have kunit.py print > that out instead. > We might want to compare the output on UML vs x86 and see what looks > suspicious. > > These errors > [ERROR] Test: xrgb_to_rgb332_test: missing subtest result line! > means that kunit.py can't parse the KTAP output. > > It could be that the output is mangled for some reason. > I recall running into a UML-specific issue with output mangling on an > old kernel fork. I doubt it's related to this one, but it shows that > it's possible there could be something going on. > > -Daniel Hi! Sorry for not clarifying the error in this thread. I fixed it in v3 (already merged). The issue was in my implementation. I was overwriting a few bytes of memory due to an out of bounds bug. Thanks to the crash I mentioned, I detected it before the code got merged. Thanks a lot for the pointers Daniel, the next time I'll check .kunit/test.log for usefull information. Jose
Re: [PATCH 05/12] drm/format-helper: Rework XRGB8888-to-RGBG565 conversion
Hi Thomas, On Wed, Jul 27, 2022 at 01:33:05PM +0200, Thomas Zimmermann wrote: > Update XRGB-to-RGB565 conversion to support struct iosys_map > and convert all users. Although these are single-plane color formats, > the new interface supports multi-plane formats for consistency with > drm_fb_blit(). > > Signed-off-by: Thomas Zimmermann Tested-by: José Expósito Reviewed-by: José Expósito In order to continue working on the missing tests for drm_format_helper I rebased your series on top of drm-misc-next and fixed the conflicts in the tests [1]. It is an easy fix, but feel free to copy & paste the code if you want to save a couple of minutes. FWIW, I ran the existing test for RGB565 on little and big endian archs and they are working as expected. Jose [1] https://github.com/JoseExposito/linux/commit/175af3a6b6b9b8013e9925c06b4951fffbbce15b > --- > drivers/gpu/drm/drm_format_helper.c | 59 +++-- > drivers/gpu/drm/drm_mipi_dbi.c | 4 +- > drivers/gpu/drm/gud/gud_pipe.c | 3 +- > drivers/gpu/drm/tiny/cirrus.c | 3 +- > include/drm/drm_format_helper.h | 9 ++--- > 5 files changed, 30 insertions(+), 48 deletions(-) > > diff --git a/drivers/gpu/drm/drm_format_helper.c > b/drivers/gpu/drm/drm_format_helper.c > index 2b5c3746ff4a..8bf5655f5ce0 100644 > --- a/drivers/gpu/drm/drm_format_helper.c > +++ b/drivers/gpu/drm/drm_format_helper.c > @@ -330,9 +330,9 @@ static void drm_fb_xrgb_to_rgb565_swab_line(void > *dbuf, const void *sbuf, > > /** > * drm_fb_xrgb_to_rgb565 - Convert XRGB to RGB565 clip buffer > - * @dst: RGB565 destination buffer > - * @dst_pitch: Number of bytes between two consecutive scanlines within dst > - * @vaddr: XRGB source buffer > + * @dst: Array of RGB565 destination buffers > + * @dst_pitch: Array of numbers of bytes between two consecutive scanlines > within dst > + * @vmap: Array of XRGB source buffer > * @fb: DRM framebuffer > * @clip: Clip rectangle area to copy > * @swab: Swap bytes > @@ -340,43 +340,31 @@ static void drm_fb_xrgb_to_rgb565_swab_line(void > *dbuf, const void *sbuf, > * Drivers can use this function for RGB565 devices that don't natively > * support XRGB. > */ > -void drm_fb_xrgb_to_rgb565(void *dst, unsigned int dst_pitch, const void > *vaddr, > -const struct drm_framebuffer *fb, const struct > drm_rect *clip, > -bool swab) > +void drm_fb_xrgb_to_rgb565(struct iosys_map *dst, const unsigned int > *dst_pitch, > +const struct iosys_map *vmap, const struct > drm_framebuffer *fb, > +const struct drm_rect *clip, bool swab) > { > + static const unsigned int default_dst_pitch[DRM_FORMAT_MAX_PLANES] = { > + 0, 0, 0, 0 > + }; > + void (*xfrm_line)(void *dbuf, const void *sbuf, unsigned int npixels); > + > if (swab) > - drm_fb_xfrm(dst, dst_pitch, 2, vaddr, fb, clip, false, > - drm_fb_xrgb_to_rgb565_swab_line); > + xfrm_line = drm_fb_xrgb_to_rgb565_swab_line; > else > - drm_fb_xfrm(dst, dst_pitch, 2, vaddr, fb, clip, false, > - drm_fb_xrgb_to_rgb565_line); > -} > -EXPORT_SYMBOL(drm_fb_xrgb_to_rgb565); > + xfrm_line = drm_fb_xrgb_to_rgb565_line; > > -/** > - * drm_fb_xrgb_to_rgb565_toio - Convert XRGB to RGB565 clip buffer > - * @dst: RGB565 destination buffer (iomem) > - * @dst_pitch: Number of bytes between two consecutive scanlines within dst > - * @vaddr: XRGB source buffer > - * @fb: DRM framebuffer > - * @clip: Clip rectangle area to copy > - * @swab: Swap bytes > - * > - * Drivers can use this function for RGB565 devices that don't natively > - * support XRGB. > - */ > -void drm_fb_xrgb_to_rgb565_toio(void __iomem *dst, unsigned int > dst_pitch, > - const void *vaddr, const struct > drm_framebuffer *fb, > - const struct drm_rect *clip, bool swab) > -{ > - if (swab) > - drm_fb_xfrm_toio(dst, dst_pitch, 2, vaddr, fb, clip, false, > - drm_fb_xrgb_to_rgb565_swab_line); > + if (!dst_pitch) > + dst_pitch = default_dst_pitch; > + > + if (dst[0].is_iomem) > + drm_fb_xfrm_toio(dst[0].vaddr_iomem, dst_pitch[0], 2, > vmap[0].vaddr, fb, clip, > + false, xfrm_line); > else > - drm_fb_xfrm_toio(dst, dst_pitch, 2, vaddr, fb, clip, false, > - drm_fb_xrgb_to_rgb565_line);
Re: [PATCH 12/12] drm/format-helper: Move destination-buffer handling into internal helper
On Thu, Jul 28, 2022 at 09:45:27AM +0200, Thomas Zimmermann wrote: > Hi > > Am 28.07.22 um 09:26 schrieb José Expósito: > > Hi! > > > > On Wed, Jul 27, 2022 at 01:33:12PM +0200, Thomas Zimmermann wrote: > > > The format-convertion helpers handle several cases for different > > > values of destination buffer and pitch. Move that code into the > > > internal helper drm_fb_xfrm() and avoid quite a bit of duplucation. > > > > > > Signed-off-by: Thomas Zimmermann > > > --- > > > drivers/gpu/drm/drm_format_helper.c | 169 +++- > > > 1 file changed, 64 insertions(+), 105 deletions(-) > > > > > > diff --git a/drivers/gpu/drm/drm_format_helper.c > > > b/drivers/gpu/drm/drm_format_helper.c > > > index d296d181659d..35aebdb90165 100644 > > > --- a/drivers/gpu/drm/drm_format_helper.c > > > +++ b/drivers/gpu/drm/drm_format_helper.c > > > @@ -41,11 +41,11 @@ unsigned int drm_fb_clip_offset(unsigned int pitch, > > > const struct drm_format_info > > > } > > > EXPORT_SYMBOL(drm_fb_clip_offset); > > > -/* TODO: Make this functon work with multi-plane formats. */ > > > -static int drm_fb_xfrm(void *dst, unsigned long dst_pitch, unsigned long > > > dst_pixsize, > > > -const void *vaddr, const struct drm_framebuffer *fb, > > > -const struct drm_rect *clip, bool vaddr_cached_hint, > > > -void (*xfrm_line)(void *dbuf, const void *sbuf, unsigned > > > int npixels)) > > > +/* TODO: Make this function work with multi-plane formats. */ > > > +static int __drm_fb_xfrm(void *dst, unsigned long dst_pitch, unsigned > > > long dst_pixsize, > > > + const void *vaddr, const struct drm_framebuffer *fb, > > > + const struct drm_rect *clip, bool vaddr_cached_hint, > > > + void (*xfrm_line)(void *dbuf, const void *sbuf, > > > unsigned int npixels)) > > > { > > > unsigned long linepixels = drm_rect_width(clip); > > > unsigned long lines = drm_rect_height(clip); > > > @@ -84,11 +84,11 @@ static int drm_fb_xfrm(void *dst, unsigned long > > > dst_pitch, unsigned long dst_pix > > > return 0; > > > } > > > -/* TODO: Make this functon work with multi-plane formats. */ > > > -static int drm_fb_xfrm_toio(void __iomem *dst, unsigned long dst_pitch, > > > unsigned long dst_pixsize, > > > - const void *vaddr, const struct drm_framebuffer *fb, > > > - const struct drm_rect *clip, bool vaddr_cached_hint, > > > - void (*xfrm_line)(void *dbuf, const void *sbuf, > > > unsigned int npixels)) > > > +/* TODO: Make this function work with multi-plane formats. */ > > > +static int __drm_fb_xfrm_toio(void __iomem *dst, unsigned long > > > dst_pitch, unsigned long dst_pixsize, > > > + const void *vaddr, const struct drm_framebuffer > > > *fb, > > > + const struct drm_rect *clip, bool > > > vaddr_cached_hint, > > > + void (*xfrm_line)(void *dbuf, const void *sbuf, > > > unsigned int npixels)) > > > { > > > unsigned long linepixels = drm_rect_width(clip); > > > unsigned long lines = drm_rect_height(clip); > > > @@ -129,6 +129,29 @@ static int drm_fb_xfrm_toio(void __iomem *dst, > > > unsigned long dst_pitch, unsigned > > > return 0; > > > } > > > +/* TODO: Make this function work with multi-plane formats. */ > > > +static int drm_fb_xfrm(struct iosys_map *dst, > > > +const unsigned int *dst_pitch, const u8 *dst_pixsize, > > > +const struct iosys_map *vmap, const struct > > > drm_framebuffer *fb, > > > +const struct drm_rect *clip, bool vaddr_cached_hint, > > > +void (*xfrm_line)(void *dbuf, const void *sbuf, unsigned > > > int npixels)) > > > +{ > > > + static const unsigned int default_dst_pitch[DRM_FORMAT_MAX_PLANES] = { > > > + 0, 0, 0, 0 > > > + }; > > > + > > > + if (!dst_pitch) > > > + dst_pitch = default_dst_pitch; > > > + > > > + if (dst[0].is_iomem) > > > + return __drm_fb_xfrm_toio(dst[0].vaddr_iomem, dst_pitch[0], > > > dst_pixsize[0], > > > +
Re: [PATCH v3 0/4] KUnit tests for RGB565 conversion
On Wed, Jul 27, 2022 at 01:09:12AM +0200, José Expósito wrote: > Hello everyone, > > This series is a follow up of the XRGB to RGB332 conversion KUnit > tests. > > As I mentioned in v2 [1] I suspected that the inconsistency handling > the endian might need to be fixed. > Fortunately, Geert Uytterhoeven fixed it in commit 4d9db10576ff > ("drm/format-helper: Fix endianness in drm_fb_*_to_*() conversion > helpers"), so I updated the tests to reflect his change. > > Changes since v1: > > - Fix a bug reported by David Gow in the XRGB to RGB332 tests > - Simplify the test structure as suggested by David Gow > - Add Tested-by Tales L. Aparecida and Acked-by Thomas Zimmermann > - Fix link in the last patch (Thomas Zimmermann) > > Changes since v2: > > - Test endian as fixed in commit 4d9db10576ff ("drm/format-helper: Fix >endianness in drm_fb_*_to_*() conversion helpers") > - Fix Sparse warning reported by David Gow > - Add Reviewed-by David Gow > > [1] > https://lore.kernel.org/dri-devel/20220709115837.560877-1-jose.exposit...@gmail.com/ > > José Expósito (4): > drm/format-helper: Fix test on big endian architectures > drm/format-helper: Rename test cases to make them more generic > drm/format-helper: Support multiple target formats results > drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb565() > > .../gpu/drm/tests/drm_format_helper_test.c| 169 ++ > 1 file changed, 139 insertions(+), 30 deletions(-) > > -- > 2.25.1 > As suggested by Thomas [1] I pushed the series to drm-misc-next. I've found some conflicts in drm-tip in unreleated files I'm trying to figure out on IRC though :( Jose [1] https://lore.kernel.org/dri-devel/4ba57f80-5025-c3a0-5f65-ec52643f0...@suse.de/
Re: [PATCH 04/12] drm/format-helper: Rework XRGB8888-to-RGBG332 conversion
On Thu, Jul 28, 2022 at 09:27:52AM +0200, Thomas Zimmermann wrote: > Hi > > Am 28.07.22 um 09:13 schrieb José Expósito: > > Hi Thomas, > > > > On Wed, Jul 27, 2022 at 01:33:04PM +0200, Thomas Zimmermann wrote: > > > Update XRGB-to-RGB332 conversion to support struct iosys_map > > > and convert all users. Although these are single-plane color formats, > > > the new interface supports multi-plane formats for consistency with > > > drm_fb_blit(). > > > > > > Signed-off-by: Thomas Zimmermann > > > > Tested-by: José Expósito > > Reviewed-by: José Expósito > > > > I just ran the tests in x86_64 and UML and they work as expected. > > I need to find some time to review all patches, but this one LGTM. > > Thanks a lot. > > > > > This series will cause conflicts with [1]. Depending on which patchset > > gets merged earlier, we will have to resolve the conflicts in one > > series or the other. > > I've seen this. Go ahead and commit your patches if they are ready. I can > easily rebase on top. > > Best reards > Thomas OK, I just merged the series in drm-misc-next... With some conflicts in drm-tip in unreleated files I'm trying to figure out on IRC. But I think you should be able to rebase your series if you want to. Jose > > > > Best wishes, > > Jose > > > > [1] https://patchwork.kernel.org/project/dri-devel/list/?series=663266 > > > > > --- > > > drivers/gpu/drm/drm_format_helper.c | 25 ++- > > > drivers/gpu/drm/gud/gud_pipe.c| 2 +- > > > .../gpu/drm/tests/drm_format_helper_test.c| 14 ++- > > > include/drm/drm_format_helper.h | 5 ++-- > > > 4 files changed, 31 insertions(+), 15 deletions(-) > > > > > > diff --git a/drivers/gpu/drm/drm_format_helper.c > > > b/drivers/gpu/drm/drm_format_helper.c > > > index fa22d3cb11e8..2b5c3746ff4a 100644 > > > --- a/drivers/gpu/drm/drm_format_helper.c > > > +++ b/drivers/gpu/drm/drm_format_helper.c > > > @@ -265,18 +265,31 @@ static void drm_fb_xrgb_to_rgb332_line(void > > > *dbuf, const void *sbuf, unsigne > > > /** > > >* drm_fb_xrgb_to_rgb332 - Convert XRGB to RGB332 clip buffer > > > - * @dst: RGB332 destination buffer > > > - * @dst_pitch: Number of bytes between two consecutive scanlines within > > > dst > > > - * @src: XRGB source buffer > > > + * @dst: Array of RGB332 destination buffers > > > + * @dst_pitch: Array of numbers of bytes between two consecutive > > > scanlines within dst > > > + * @vmap: Array of XRGB source buffers > > >* @fb: DRM framebuffer > > >* @clip: Clip rectangle area to copy > > >* > > >* Drivers can use this function for RGB332 devices that don't natively > > > support XRGB. > > >*/ > > > -void drm_fb_xrgb_to_rgb332(void *dst, unsigned int dst_pitch, const > > > void *src, > > > -const struct drm_framebuffer *fb, const struct > > > drm_rect *clip) > > > +void drm_fb_xrgb_to_rgb332(struct iosys_map *dst, const unsigned int > > > *dst_pitch, > > > +const struct iosys_map *vmap, const struct > > > drm_framebuffer *fb, > > > +const struct drm_rect *clip) > > > { > > > - drm_fb_xfrm(dst, dst_pitch, 1, src, fb, clip, false, > > > drm_fb_xrgb_to_rgb332_line); > > > + static const unsigned int default_dst_pitch[DRM_FORMAT_MAX_PLANES] = { > > > + 0, 0, 0, 0 > > > + }; > > > + > > > + if (!dst_pitch) > > > + dst_pitch = default_dst_pitch; > > > + > > > + if (dst[0].is_iomem) > > > + drm_fb_xfrm_toio(dst[0].vaddr_iomem, dst_pitch[0], 1, > > > vmap[0].vaddr, fb, clip, > > > + false, drm_fb_xrgb_to_rgb332_line); > > > + else > > > + drm_fb_xfrm(dst[0].vaddr, dst_pitch[0], 1, vmap[0].vaddr, fb, > > > clip, > > > + false, drm_fb_xrgb_to_rgb332_line); > > > } > > > EXPORT_SYMBOL(drm_fb_xrgb_to_rgb332); > > > diff --git a/drivers/gpu/drm/gud/gud_pipe.c > > > b/drivers/gpu/drm/gud/gud_pipe.c > > > index a15cda9ba058..426a3ae6cc50 100644 > > > --- a/drivers/gpu/drm/gud/gud_pipe.c > > > +++ b/drivers/gpu/drm/gud/gud_pipe.c > > > @@ -196,7 +19
Re: [PATCH 12/12] drm/format-helper: Move destination-buffer handling into internal helper
Hi! On Wed, Jul 27, 2022 at 01:33:12PM +0200, Thomas Zimmermann wrote: > The format-convertion helpers handle several cases for different > values of destination buffer and pitch. Move that code into the > internal helper drm_fb_xfrm() and avoid quite a bit of duplucation. > > Signed-off-by: Thomas Zimmermann > --- > drivers/gpu/drm/drm_format_helper.c | 169 +++- > 1 file changed, 64 insertions(+), 105 deletions(-) > > diff --git a/drivers/gpu/drm/drm_format_helper.c > b/drivers/gpu/drm/drm_format_helper.c > index d296d181659d..35aebdb90165 100644 > --- a/drivers/gpu/drm/drm_format_helper.c > +++ b/drivers/gpu/drm/drm_format_helper.c > @@ -41,11 +41,11 @@ unsigned int drm_fb_clip_offset(unsigned int pitch, const > struct drm_format_info > } > EXPORT_SYMBOL(drm_fb_clip_offset); > > -/* TODO: Make this functon work with multi-plane formats. */ > -static int drm_fb_xfrm(void *dst, unsigned long dst_pitch, unsigned long > dst_pixsize, > -const void *vaddr, const struct drm_framebuffer *fb, > -const struct drm_rect *clip, bool vaddr_cached_hint, > -void (*xfrm_line)(void *dbuf, const void *sbuf, unsigned > int npixels)) > +/* TODO: Make this function work with multi-plane formats. */ > +static int __drm_fb_xfrm(void *dst, unsigned long dst_pitch, unsigned long > dst_pixsize, > + const void *vaddr, const struct drm_framebuffer *fb, > + const struct drm_rect *clip, bool vaddr_cached_hint, > + void (*xfrm_line)(void *dbuf, const void *sbuf, > unsigned int npixels)) > { > unsigned long linepixels = drm_rect_width(clip); > unsigned long lines = drm_rect_height(clip); > @@ -84,11 +84,11 @@ static int drm_fb_xfrm(void *dst, unsigned long > dst_pitch, unsigned long dst_pix > return 0; > } > > -/* TODO: Make this functon work with multi-plane formats. */ > -static int drm_fb_xfrm_toio(void __iomem *dst, unsigned long dst_pitch, > unsigned long dst_pixsize, > - const void *vaddr, const struct drm_framebuffer *fb, > - const struct drm_rect *clip, bool vaddr_cached_hint, > - void (*xfrm_line)(void *dbuf, const void *sbuf, > unsigned int npixels)) > +/* TODO: Make this function work with multi-plane formats. */ > +static int __drm_fb_xfrm_toio(void __iomem *dst, unsigned long dst_pitch, > unsigned long dst_pixsize, > + const void *vaddr, const struct drm_framebuffer > *fb, > + const struct drm_rect *clip, bool > vaddr_cached_hint, > + void (*xfrm_line)(void *dbuf, const void *sbuf, > unsigned int npixels)) > { > unsigned long linepixels = drm_rect_width(clip); > unsigned long lines = drm_rect_height(clip); > @@ -129,6 +129,29 @@ static int drm_fb_xfrm_toio(void __iomem *dst, unsigned > long dst_pitch, unsigned > return 0; > } > > +/* TODO: Make this function work with multi-plane formats. */ > +static int drm_fb_xfrm(struct iosys_map *dst, > +const unsigned int *dst_pitch, const u8 *dst_pixsize, > +const struct iosys_map *vmap, const struct > drm_framebuffer *fb, > +const struct drm_rect *clip, bool vaddr_cached_hint, > +void (*xfrm_line)(void *dbuf, const void *sbuf, unsigned > int npixels)) > +{ > + static const unsigned int default_dst_pitch[DRM_FORMAT_MAX_PLANES] = { > + 0, 0, 0, 0 > + }; > + > + if (!dst_pitch) > + dst_pitch = default_dst_pitch; > + > + if (dst[0].is_iomem) > + return __drm_fb_xfrm_toio(dst[0].vaddr_iomem, dst_pitch[0], > dst_pixsize[0], > + vmap[0].vaddr, fb, clip, false, > xfrm_line); > + else > + return __drm_fb_xfrm(dst[0].vaddr, dst_pitch[0], dst_pixsize[0], > + vmap[0].vaddr, fb, clip, false, xfrm_line); > +} > + > + Nit: Extra blank line > /** > * drm_fb_memcpy - Copy clip buffer > * @dst: Array of destination buffers > @@ -213,14 +236,10 @@ void drm_fb_swab(struct iosys_map *dst, const unsigned > int *dst_pitch, >const struct iosys_map *vmap, const struct drm_framebuffer *fb, >const struct drm_rect *clip, bool cached) > { > - static const unsigned int default_dst_pitch[DRM_FORMAT_MAX_PLANES] = { > - 0, 0, 0, 0 > - }; > const struct drm_format_info *format = fb->format; > - u8 cpp = format->cpp[0]; > void (*swab_line)(void *dbuf, const void *sbuf, unsigned int npixels); > > - switch (cpp) { > + switch (format->cpp[0]) { > case 4: > swab_line = drm_fb_swab32_line; > break; > @@ -230,21 +249,10 @@ void drm_fb_swab(struct iosys_map *dst, const unsigned > int *dst_pitch, > default: >
Re: [PATCH 04/12] drm/format-helper: Rework XRGB8888-to-RGBG332 conversion
Hi Thomas, On Wed, Jul 27, 2022 at 01:33:04PM +0200, Thomas Zimmermann wrote: > Update XRGB-to-RGB332 conversion to support struct iosys_map > and convert all users. Although these are single-plane color formats, > the new interface supports multi-plane formats for consistency with > drm_fb_blit(). > > Signed-off-by: Thomas Zimmermann Tested-by: José Expósito Reviewed-by: José Expósito I just ran the tests in x86_64 and UML and they work as expected. I need to find some time to review all patches, but this one LGTM. This series will cause conflicts with [1]. Depending on which patchset gets merged earlier, we will have to resolve the conflicts in one series or the other. Best wishes, Jose [1] https://patchwork.kernel.org/project/dri-devel/list/?series=663266 > --- > drivers/gpu/drm/drm_format_helper.c | 25 ++- > drivers/gpu/drm/gud/gud_pipe.c| 2 +- > .../gpu/drm/tests/drm_format_helper_test.c| 14 ++- > include/drm/drm_format_helper.h | 5 ++-- > 4 files changed, 31 insertions(+), 15 deletions(-) > > diff --git a/drivers/gpu/drm/drm_format_helper.c > b/drivers/gpu/drm/drm_format_helper.c > index fa22d3cb11e8..2b5c3746ff4a 100644 > --- a/drivers/gpu/drm/drm_format_helper.c > +++ b/drivers/gpu/drm/drm_format_helper.c > @@ -265,18 +265,31 @@ static void drm_fb_xrgb_to_rgb332_line(void *dbuf, > const void *sbuf, unsigne > > /** > * drm_fb_xrgb_to_rgb332 - Convert XRGB to RGB332 clip buffer > - * @dst: RGB332 destination buffer > - * @dst_pitch: Number of bytes between two consecutive scanlines within dst > - * @src: XRGB source buffer > + * @dst: Array of RGB332 destination buffers > + * @dst_pitch: Array of numbers of bytes between two consecutive scanlines > within dst > + * @vmap: Array of XRGB source buffers > * @fb: DRM framebuffer > * @clip: Clip rectangle area to copy > * > * Drivers can use this function for RGB332 devices that don't natively > support XRGB. > */ > -void drm_fb_xrgb_to_rgb332(void *dst, unsigned int dst_pitch, const void > *src, > -const struct drm_framebuffer *fb, const struct > drm_rect *clip) > +void drm_fb_xrgb_to_rgb332(struct iosys_map *dst, const unsigned int > *dst_pitch, > +const struct iosys_map *vmap, const struct > drm_framebuffer *fb, > +const struct drm_rect *clip) > { > - drm_fb_xfrm(dst, dst_pitch, 1, src, fb, clip, false, > drm_fb_xrgb_to_rgb332_line); > + static const unsigned int default_dst_pitch[DRM_FORMAT_MAX_PLANES] = { > + 0, 0, 0, 0 > + }; > + > + if (!dst_pitch) > + dst_pitch = default_dst_pitch; > + > + if (dst[0].is_iomem) > + drm_fb_xfrm_toio(dst[0].vaddr_iomem, dst_pitch[0], 1, > vmap[0].vaddr, fb, clip, > + false, drm_fb_xrgb_to_rgb332_line); > + else > + drm_fb_xfrm(dst[0].vaddr, dst_pitch[0], 1, vmap[0].vaddr, fb, > clip, > + false, drm_fb_xrgb_to_rgb332_line); > } > EXPORT_SYMBOL(drm_fb_xrgb_to_rgb332); > > diff --git a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c > index a15cda9ba058..426a3ae6cc50 100644 > --- a/drivers/gpu/drm/gud/gud_pipe.c > +++ b/drivers/gpu/drm/gud/gud_pipe.c > @@ -196,7 +196,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct > drm_framebuffer *fb, > } else if (format->format == DRM_FORMAT_R8) { > drm_fb_xrgb_to_gray8(buf, 0, vaddr, fb, rect); > } else if (format->format == DRM_FORMAT_RGB332) { > - drm_fb_xrgb_to_rgb332(buf, 0, vaddr, fb, rect); > + drm_fb_xrgb_to_rgb332(, NULL, map_data, fb, > rect); > } else if (format->format == DRM_FORMAT_RGB565) { > drm_fb_xrgb_to_rgb565(buf, 0, vaddr, fb, rect, > gud_is_big_endian()); > } else if (format->format == DRM_FORMAT_RGB888) { > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c > b/drivers/gpu/drm/tests/drm_format_helper_test.c > index 98583bf56044..b74dba06f704 100644 > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c > @@ -124,7 +124,8 @@ static void xrgb_to_rgb332_test(struct kunit *test) > { > const struct xrgb_to_rgb332_case *params = test->param_value; > size_t dst_size; > - __u8 *dst = NULL; > + struct iosys_map dst, xrgb; > + __u8 *buf = NULL; > > struct drm_framebuffer fb = { > .format =
[PATCH v3 4/4] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb565()
Extend the existing test cases to test the conversion from XRGB to RGB565. The documentation and the color picker available on [1] are useful resources to understand this patch and validate the values returned by the conversion function. Tested-by: Tales L. Aparecida Acked-by: Thomas Zimmermann Reviewed-by: David Gow Signed-off-by: José Expósito Link: http://www.barth-dev.de/online/rgb565-color-picker/ # [1] --- .../gpu/drm/tests/drm_format_helper_test.c| 78 +++ 1 file changed, 78 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index bbe9e9f57e2b..26ecf3b4b137 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -21,12 +21,19 @@ struct convert_to_rgb332_result { const u8 expected[TEST_BUF_SIZE]; }; +struct convert_to_rgb565_result { + unsigned int dst_pitch; + const u16 expected[TEST_BUF_SIZE]; + const u16 expected_swab[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; struct drm_rect clip; const u32 xrgb[TEST_BUF_SIZE]; struct convert_to_rgb332_result rgb332_result; + struct convert_to_rgb565_result rgb565_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -39,6 +46,11 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0xE0 }, }, + .rgb565_result = { + .dst_pitch = 0, + .expected = { 0xF800 }, + .expected_swab = { 0x00F8 }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -52,6 +64,11 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0xE0 }, }, + .rgb565_result = { + .dst_pitch = 0, + .expected = { 0xF800 }, + .expected_swab = { 0x00F8 }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -77,6 +94,21 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0xFC, 0x1F, }, }, + .rgb565_result = { + .dst_pitch = 0, + .expected = { + 0x, 0x, + 0xF800, 0x07E0, + 0x001F, 0xF81F, + 0xFFE0, 0x07FF, + }, + .expected_swab = { + 0x, 0x, + 0x00F8, 0xE007, + 0x1F00, 0x1FF8, + 0xE0FF, 0xFF07, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -96,6 +128,19 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0xA0, 0x6D, 0x0A, 0x00, 0x00, }, }, + .rgb565_result = { + .dst_pitch = 10, + .expected = { + 0x0A33, 0x1260, 0xA800, 0x, 0x, + 0x6B8E, 0x0A33, 0x1260, 0x, 0x, + 0xA800, 0x6B8E, 0x0A33, 0x, 0x, + }, + .expected_swab = { + 0x330A, 0x6012, 0x00A8, 0x, 0x, + 0x8E6B, 0x330A, 0x6012, 0x, 0x, + 0x00A8, 0x8E6B, 0x330A, 0x, 0x, + }, + }, }, }; @@ -175,8 +220,41 @@ static void xrgb_to_rgb332_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(dst, result->expected, dst_size), 0); } +static void xrgb_to_rgb565_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_rgb565_result *result = >rgb565_result; + size_t dst_size; + __u16 *dst = NULL; + __u32 *src = NULL; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_RGB565, result->dst_pitch, + >clip); + KUNIT_ASSERT_GT(test, dst_size, 0); + + dst = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSE
[PATCH v3 3/4] drm/format-helper: Support multiple target formats results
In order to support multiple destination format conversions, store the destination pitch and the expected result in its own structure. Tested-by: Tales L. Aparecida Acked-by: Thomas Zimmermann Reviewed-by: David Gow Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 53 --- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 97fccd0a948b..bbe9e9f57e2b 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -16,34 +16,42 @@ #define TEST_BUF_SIZE 50 +struct convert_to_rgb332_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; - unsigned int dst_pitch; struct drm_rect clip; const u32 xrgb[TEST_BUF_SIZE]; - const u8 expected[4 * TEST_BUF_SIZE]; + struct convert_to_rgb332_result rgb332_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { { .name = "single_pixel_source_buffer", .pitch = 1 * 4, - .dst_pitch = 0, .clip = DRM_RECT_INIT(0, 0, 1, 1), .xrgb = { 0x01FF }, - .expected = { 0xE0 }, + .rgb332_result = { + .dst_pitch = 0, + .expected = { 0xE0 }, + }, }, { .name = "single_pixel_clip_rectangle", .pitch = 2 * 4, - .dst_pitch = 0, .clip = DRM_RECT_INIT(1, 1, 1, 1), .xrgb = { 0x, 0x, 0x, 0x10FF, }, - .expected = { 0xE0 }, + .rgb332_result = { + .dst_pitch = 0, + .expected = { 0xE0 }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -52,7 +60,6 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { */ .name = "well_known_colors", .pitch = 4 * 4, - .dst_pitch = 0, .clip = DRM_RECT_INIT(1, 1, 2, 4), .xrgb = { 0x, 0x, 0x, 0x, @@ -61,28 +68,33 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x, 0x55FF, 0x66FF00FF, 0x, 0x, 0x7700, 0x8800, 0x, }, - .expected = { - 0xFF, 0x00, - 0xE0, 0x1C, - 0x03, 0xE3, - 0xFC, 0x1F, + .rgb332_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0x00, + 0xE0, 0x1C, + 0x03, 0xE3, + 0xFC, 0x1F, + }, }, }, { /* Randomly picked colors. Full buffer within the clip area. */ .name = "destination_pitch", .pitch = 3 * 4, - .dst_pitch = 5, .clip = DRM_RECT_INIT(0, 0, 3, 3), .xrgb = { 0xA10E449C, 0xB1114D05, 0xC1A80303, 0xD16C7073, 0xA20E449C, 0xB2114D05, 0xC2A80303, 0xD26C7073, 0xA30E449C, }, - .expected = { - 0x0A, 0x08, 0xA0, 0x00, 0x00, - 0x6D, 0x0A, 0x08, 0x00, 0x00, - 0xA0, 0x6D, 0x0A, 0x00, 0x00, + .rgb332_result = { + .dst_pitch = 5, + .expected = { + 0x0A, 0x08, 0xA0, 0x00, 0x00, + 0x6D, 0x0A, 0x08, 0x00, 0x00, + 0xA0, 0x6D, 0x0A, 0x00, 0x00, + }, }, }, }; @@ -138,6 +150,7 @@ KUNIT_ARRAY_PARAM(convert_xrgb, convert_xrgb_cases, static void xrgb_to_rgb332_test(struct kunit *test) { const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_rgb332_result *result = >rgb332_result; size_t dst_size; __u8 *dst = NULL; __u32 *src = NULL; @@ -147,7 +160,7 @@ static void xrgb_to_rgb332_test(struct kunit *test) .pitches = { params->pitch, 0, 0 }, }; - dst_size = conversion_buf_size(DRM_FORMAT_RGB332, params->dst_pitch, + dst_
[PATCH v3 1/4] drm/format-helper: Fix test on big endian architectures
The tests fail on big endian architectures, like PowerPC: $ ./tools/testing/kunit/kunit.py run \ --kunitconfig=drivers/gpu/drm/tests \ --arch=powerpc --cross_compile=powerpc64-linux-gnu- Transform the XRGB buffer from little endian to the CPU endian before calling the conversion function to avoid this error. Fixes: 8f456104915f ("drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb332()") Reported-by: David Gow Reviewed-by: David Gow Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 23 +-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 98583bf56044..eefaba3aaea2 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -111,6 +111,21 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch, return dst_pitch * drm_rect_height(clip); } +static u32 *le32buf_to_cpu(struct kunit *test, const u32 *buf, size_t buf_size) +{ + u32 *dst = NULL; + int n; + + dst = kunit_kzalloc(test, sizeof(*dst) * buf_size, GFP_KERNEL); + if (!dst) + return NULL; + + for (n = 0; n < buf_size; n++) + dst[n] = le32_to_cpu((__force __le32)buf[n]); + + return dst; +} + static void xrgb_to_rgb332_case_desc(struct xrgb_to_rgb332_case *t, char *desc) { @@ -125,6 +140,7 @@ static void xrgb_to_rgb332_test(struct kunit *test) const struct xrgb_to_rgb332_case *params = test->param_value; size_t dst_size; __u8 *dst = NULL; + __u32 *src = NULL; struct drm_framebuffer fb = { .format = drm_format_info(DRM_FORMAT_XRGB), @@ -138,8 +154,11 @@ static void xrgb_to_rgb332_test(struct kunit *test) dst = kunit_kzalloc(test, dst_size, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dst); - drm_fb_xrgb_to_rgb332(dst, params->dst_pitch, params->xrgb, - , >clip); + src = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, src); + + drm_fb_xrgb_to_rgb332(dst, params->dst_pitch, src, , + >clip); KUNIT_EXPECT_EQ(test, memcmp(dst, params->expected, dst_size), 0); } -- 2.25.1
[PATCH v3 2/4] drm/format-helper: Rename test cases to make them more generic
The tests available at the moment only check the conversion from XRGB to RGB332. However, more conversions will be tested in the future. In order to make the struct and functions present in the tests more generic, rename xrgb_to_rgb332_* to convert_xrgb_*. Tested-by: Tales L. Aparecida Acked-by: Thomas Zimmermann Reviewed-by: David Gow Signed-off-by: José Expósito --- drivers/gpu/drm/tests/drm_format_helper_test.c | 17 - 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index eefaba3aaea2..97fccd0a948b 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -16,7 +16,7 @@ #define TEST_BUF_SIZE 50 -struct xrgb_to_rgb332_case { +struct convert_xrgb_case { const char *name; unsigned int pitch; unsigned int dst_pitch; @@ -25,7 +25,7 @@ struct xrgb_to_rgb332_case { const u8 expected[4 * TEST_BUF_SIZE]; }; -static struct xrgb_to_rgb332_case xrgb_to_rgb332_cases[] = { +static struct convert_xrgb_case convert_xrgb_cases[] = { { .name = "single_pixel_source_buffer", .pitch = 1 * 4, @@ -126,18 +126,18 @@ static u32 *le32buf_to_cpu(struct kunit *test, const u32 *buf, size_t buf_size) return dst; } -static void xrgb_to_rgb332_case_desc(struct xrgb_to_rgb332_case *t, -char *desc) +static void convert_xrgb_case_desc(struct convert_xrgb_case *t, + char *desc) { strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); } -KUNIT_ARRAY_PARAM(xrgb_to_rgb332, xrgb_to_rgb332_cases, - xrgb_to_rgb332_case_desc); +KUNIT_ARRAY_PARAM(convert_xrgb, convert_xrgb_cases, + convert_xrgb_case_desc); static void xrgb_to_rgb332_test(struct kunit *test) { - const struct xrgb_to_rgb332_case *params = test->param_value; + const struct convert_xrgb_case *params = test->param_value; size_t dst_size; __u8 *dst = NULL; __u32 *src = NULL; @@ -163,8 +163,7 @@ static void xrgb_to_rgb332_test(struct kunit *test) } static struct kunit_case drm_format_helper_test_cases[] = { - KUNIT_CASE_PARAM(xrgb_to_rgb332_test, -xrgb_to_rgb332_gen_params), + KUNIT_CASE_PARAM(xrgb_to_rgb332_test, convert_xrgb_gen_params), {} }; -- 2.25.1
[PATCH v3 0/4] KUnit tests for RGB565 conversion
Hello everyone, This series is a follow up of the XRGB to RGB332 conversion KUnit tests. As I mentioned in v2 [1] I suspected that the inconsistency handling the endian might need to be fixed. Fortunately, Geert Uytterhoeven fixed it in commit 4d9db10576ff ("drm/format-helper: Fix endianness in drm_fb_*_to_*() conversion helpers"), so I updated the tests to reflect his change. Changes since v1: - Fix a bug reported by David Gow in the XRGB to RGB332 tests - Simplify the test structure as suggested by David Gow - Add Tested-by Tales L. Aparecida and Acked-by Thomas Zimmermann - Fix link in the last patch (Thomas Zimmermann) Changes since v2: - Test endian as fixed in commit 4d9db10576ff ("drm/format-helper: Fix endianness in drm_fb_*_to_*() conversion helpers") - Fix Sparse warning reported by David Gow - Add Reviewed-by David Gow [1] https://lore.kernel.org/dri-devel/20220709115837.560877-1-jose.exposit...@gmail.com/ José Expósito (4): drm/format-helper: Fix test on big endian architectures drm/format-helper: Rename test cases to make them more generic drm/format-helper: Support multiple target formats results drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb565() .../gpu/drm/tests/drm_format_helper_test.c| 169 ++ 1 file changed, 139 insertions(+), 30 deletions(-) -- 2.25.1
Re: [PATCH v2 4/4] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb565()
José Expósito wrote: > I already fixed the warning and added the reviewed by tags, however, I > noticed that rebasing the series on the latest drm-misc-next show this > error: > [...] Sorry for the extra email. I forgot to mention that the error is only present in UML. Running in other architectures works as expected. Tested on x86_64 and PowerPC. Jose
Re: [PATCH v2 4/4] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb565()
Hi David, On Sat, Jul 16, 2022 at 05:32:51PM +0800, David Gow wrote: > On Sat, Jul 9, 2022 at 7:58 PM José Expósito > wrote: > > > > Extend the existing test cases to test the conversion from XRGB to > > RGB565. > > > > The documentation and the color picker available on [1] are useful > > resources to understand this patch and validate the values returned by > > the conversion function. > > > > Tested-by: Tales L. Aparecida > > Acked-by: Thomas Zimmermann > > Signed-off-by: José Expósito > > Link: http://www.barth-dev.de/online/rgb565-color-picker/ # [1] > > --- > > Looks good and passes here. > > Reviewed-by: David Gow > > Thanks, > -- David Thanks a lot for reviewing the series and for pointing out the Sparse warning. I already fixed the warning and added the reviewed by tags, however, I noticed that rebasing the series on the latest drm-misc-next show this error: [18:49:32] [18:49:33] === drm_format_helper_test (2 subtests) [18:49:33] = xrgb_to_rgb332_test == [18:49:33] [ERROR] Test: xrgb_to_rgb332_test: missing subtest result line! [18:49:33] [ERROR] Test: xrgb_to_rgb332_test: 0 tests run! [18:49:33] == [NO TESTS RUN] xrgb_to_rgb332_test == [18:49:33] [ERROR] Test: drm_format_helper_test: missing expected subtest! [18:49:33] [CRASHED] [18:49:33] [ERROR] Test: drm_format_helper_test: missing subtest result line! [18:49:33] # Subtest: drm_format_helper_test [18:49:33] 1..2 [18:49:33] = [CRASHED] drm_format_helper_test = [18:49:33] [ERROR] Test: main: missing expected subtest! [18:49:33] [CRASHED] [18:49:33] [ERROR] Test: main: missing expected subtest! [18:49:33] [CRASHED] [18:49:33] [ERROR] Test: main: missing expected subtest! [18:49:33] [CRASHED] [18:49:33] [ERROR] Test: main: missing expected subtest! [18:49:33] [CRASHED] [18:49:33] [ERROR] Test: main: missing expected subtest! [18:49:33] [CRASHED] [18:49:33] [ERROR] Test: main: missing expected subtest! [18:49:33] [CRASHED] [18:49:33] [ERROR] Test: main: missing expected subtest! [18:49:33] [CRASHED] [18:49:33] [ERROR] Test: main: missing expected subtest! [18:49:33] [CRASHED] [18:49:33] [ERROR] Test: main: missing expected subtest! [18:49:33] [CRASHED] [18:49:33] [18:49:33] Testing complete. Ran 10 tests: crashed: 10, errors: 13 I bisected drm-misc-next to find out that the first bad commit is: e23a5e14aa278858c2e3d81ec34e83aa9a4177c5 Not very usefull, because that commit merges v5.19-rc6 into misc. I tested on the latest kselftest-master branch and the error is not present. Are you aware of any change that could cause this issue? Jose > > .../gpu/drm/tests/drm_format_helper_test.c| 76 ++- > > 1 file changed, 75 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c > > b/drivers/gpu/drm/tests/drm_format_helper_test.c > > index 0a490ad4fd32..c0592c1235cf 100644 > > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c > > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c > > @@ -21,12 +21,19 @@ struct convert_to_rgb332_result { > > const u8 expected[TEST_BUF_SIZE]; > > }; > > > > +struct convert_to_rgb565_result { > > + unsigned int dst_pitch; > > + const u16 expected[TEST_BUF_SIZE]; > > + const u16 expected_swab[TEST_BUF_SIZE]; > > +}; > > + > > struct convert_xrgb_case { > > const char *name; > > unsigned int pitch; > > struct drm_rect clip; > > const u32 xrgb[TEST_BUF_SIZE]; > > struct convert_to_rgb332_result rgb332_result; > > + struct convert_to_rgb565_result rgb565_result; > > }; > > > > static struct convert_xrgb_case convert_xrgb_cases[] = { > > @@ -39,6 +46,11 @@ static struct convert_xrgb_case > > convert_xrgb_cases[] = { > > .dst_pitch = 0, > > .expected = { 0xE0 }, > > }, > > + .rgb565_result = { > > + .dst_pitch = 0, > > + .expected = { 0xF800 }, > > + .expected_swab = { 0x00F8 }, > > + }, > > }, > > { > > .name = "single_pixel_clip_rectangle", > > @@ -52,6 +64,11 @@ static s
[PATCH v2 4/4] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb565()
Extend the existing test cases to test the conversion from XRGB to RGB565. The documentation and the color picker available on [1] are useful resources to understand this patch and validate the values returned by the conversion function. Tested-by: Tales L. Aparecida Acked-by: Thomas Zimmermann Signed-off-by: José Expósito Link: http://www.barth-dev.de/online/rgb565-color-picker/ # [1] --- .../gpu/drm/tests/drm_format_helper_test.c| 76 ++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 0a490ad4fd32..c0592c1235cf 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -21,12 +21,19 @@ struct convert_to_rgb332_result { const u8 expected[TEST_BUF_SIZE]; }; +struct convert_to_rgb565_result { + unsigned int dst_pitch; + const u16 expected[TEST_BUF_SIZE]; + const u16 expected_swab[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; struct drm_rect clip; const u32 xrgb[TEST_BUF_SIZE]; struct convert_to_rgb332_result rgb332_result; + struct convert_to_rgb565_result rgb565_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -39,6 +46,11 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0xE0 }, }, + .rgb565_result = { + .dst_pitch = 0, + .expected = { 0xF800 }, + .expected_swab = { 0x00F8 }, + }, }, { .name = "single_pixel_clip_rectangle", @@ -52,6 +64,11 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0xE0 }, }, + .rgb565_result = { + .dst_pitch = 0, + .expected = { 0xF800 }, + .expected_swab = { 0x00F8 }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -77,6 +94,21 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0xFC, 0x1F, }, }, + .rgb565_result = { + .dst_pitch = 0, + .expected = { + 0x, 0x, + 0xF800, 0x07E0, + 0x001F, 0xF81F, + 0xFFE0, 0x07FF, + }, + .expected_swab = { + 0x, 0x, + 0x00F8, 0xE007, + 0x1F00, 0x1FF8, + 0xE0FF, 0xFF07, + }, + }, }, { /* Randomly picked colors. Full buffer within the clip area. */ @@ -96,6 +128,19 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0xA0, 0x6D, 0x0A, 0x00, 0x00, }, }, + .rgb565_result = { + .dst_pitch = 10, + .expected = { + 0x0A33, 0x1260, 0xA800, 0x, 0x, + 0x6B8E, 0x0A33, 0x1260, 0x, 0x, + 0xA800, 0x6B8E, 0x0A33, 0x, 0x, + }, + .expected_swab = { + 0x330A, 0x6012, 0x00A8, 0x, 0x, + 0x8E6B, 0x330A, 0x6012, 0x, 0x, + 0x00A8, 0x8E6B, 0x330A, 0x, 0x, + }, + }, }, }; @@ -120,7 +165,7 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch, if (!dst_pitch) dst_pitch = drm_rect_width(clip) * dst_fi->cpp[0]; - return dst_pitch * drm_rect_height(clip); + return (dst_pitch * drm_rect_height(clip)) / (dst_fi->depth / 8); } static u32 *le32buf_to_cpu(struct kunit *test, const u32 *buf, size_t buf_size) @@ -175,8 +220,37 @@ static void xrgb_to_rgb332_test(struct kunit *test) KUNIT_EXPECT_EQ(test, memcmp(dst, result->expected, dst_size), 0); } +static void xrgb_to_rgb565_test(struct kunit *test) +{ + const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_rgb565_result *result = >rgb565_result; + size_t dst_size; + __u16 *dst = NULL; + + struct drm_framebuffer fb = { +
[PATCH v2 1/4] drm/format-helper: Fix test on big endian architectures
The tests fail on big endian architectures, like PowerPC: $ ./tools/testing/kunit/kunit.py run \ --kunitconfig=drivers/gpu/drm/tests \ --arch=powerpc --cross_compile=powerpc64-linux-gnu- Transform the XRGB buffer from little endian to the CPU endian before calling the conversion function to avoid this error. Fixes: 8f456104915f ("drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb332()") Reported-by: David Gow Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 23 +-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 98583bf56044..4d074c2e48bf 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -111,6 +111,21 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch, return dst_pitch * drm_rect_height(clip); } +static u32 *le32buf_to_cpu(struct kunit *test, const u32 *buf, size_t buf_size) +{ + u32 *dst = NULL; + int n; + + dst = kunit_kzalloc(test, buf_size, GFP_KERNEL); + if (!dst) + return NULL; + + for (n = 0; n < buf_size; n++) + dst[n] = le32_to_cpu(buf[n]); + + return dst; +} + static void xrgb_to_rgb332_case_desc(struct xrgb_to_rgb332_case *t, char *desc) { @@ -125,6 +140,7 @@ static void xrgb_to_rgb332_test(struct kunit *test) const struct xrgb_to_rgb332_case *params = test->param_value; size_t dst_size; __u8 *dst = NULL; + __u32 *src = NULL; struct drm_framebuffer fb = { .format = drm_format_info(DRM_FORMAT_XRGB), @@ -138,8 +154,11 @@ static void xrgb_to_rgb332_test(struct kunit *test) dst = kunit_kzalloc(test, dst_size, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dst); - drm_fb_xrgb_to_rgb332(dst, params->dst_pitch, params->xrgb, - , >clip); + src = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, src); + + drm_fb_xrgb_to_rgb332(dst, params->dst_pitch, src, , + >clip); KUNIT_EXPECT_EQ(test, memcmp(dst, params->expected, dst_size), 0); } -- 2.25.1
[PATCH v2 3/4] drm/format-helper: Support multiple target formats results
In order to support multiple destination format conversions, store the destination pitch and the expected result in its own structure. Tested-by: Tales L. Aparecida Acked-by: Thomas Zimmermann Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 53 --- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index f66aaa0e52c9..0a490ad4fd32 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -16,34 +16,42 @@ #define TEST_BUF_SIZE 50 +struct convert_to_rgb332_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; - unsigned int dst_pitch; struct drm_rect clip; const u32 xrgb[TEST_BUF_SIZE]; - const u8 expected[4 * TEST_BUF_SIZE]; + struct convert_to_rgb332_result rgb332_result; }; static struct convert_xrgb_case convert_xrgb_cases[] = { { .name = "single_pixel_source_buffer", .pitch = 1 * 4, - .dst_pitch = 0, .clip = DRM_RECT_INIT(0, 0, 1, 1), .xrgb = { 0x01FF }, - .expected = { 0xE0 }, + .rgb332_result = { + .dst_pitch = 0, + .expected = { 0xE0 }, + }, }, { .name = "single_pixel_clip_rectangle", .pitch = 2 * 4, - .dst_pitch = 0, .clip = DRM_RECT_INIT(1, 1, 1, 1), .xrgb = { 0x, 0x, 0x, 0x10FF, }, - .expected = { 0xE0 }, + .rgb332_result = { + .dst_pitch = 0, + .expected = { 0xE0 }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -52,7 +60,6 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { */ .name = "well_known_colors", .pitch = 4 * 4, - .dst_pitch = 0, .clip = DRM_RECT_INIT(1, 1, 2, 4), .xrgb = { 0x, 0x, 0x, 0x, @@ -61,28 +68,33 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x, 0x55FF, 0x66FF00FF, 0x, 0x, 0x7700, 0x8800, 0x, }, - .expected = { - 0xFF, 0x00, - 0xE0, 0x1C, - 0x03, 0xE3, - 0xFC, 0x1F, + .rgb332_result = { + .dst_pitch = 0, + .expected = { + 0xFF, 0x00, + 0xE0, 0x1C, + 0x03, 0xE3, + 0xFC, 0x1F, + }, }, }, { /* Randomly picked colors. Full buffer within the clip area. */ .name = "destination_pitch", .pitch = 3 * 4, - .dst_pitch = 5, .clip = DRM_RECT_INIT(0, 0, 3, 3), .xrgb = { 0xA10E449C, 0xB1114D05, 0xC1A80303, 0xD16C7073, 0xA20E449C, 0xB2114D05, 0xC2A80303, 0xD26C7073, 0xA30E449C, }, - .expected = { - 0x0A, 0x08, 0xA0, 0x00, 0x00, - 0x6D, 0x0A, 0x08, 0x00, 0x00, - 0xA0, 0x6D, 0x0A, 0x00, 0x00, + .rgb332_result = { + .dst_pitch = 5, + .expected = { + 0x0A, 0x08, 0xA0, 0x00, 0x00, + 0x6D, 0x0A, 0x08, 0x00, 0x00, + 0xA0, 0x6D, 0x0A, 0x00, 0x00, + }, }, }, }; @@ -138,6 +150,7 @@ KUNIT_ARRAY_PARAM(convert_xrgb, convert_xrgb_cases, static void xrgb_to_rgb332_test(struct kunit *test) { const struct convert_xrgb_case *params = test->param_value; + const struct convert_to_rgb332_result *result = >rgb332_result; size_t dst_size; __u8 *dst = NULL; __u32 *src = NULL; @@ -147,7 +160,7 @@ static void xrgb_to_rgb332_test(struct kunit *test) .pitches = { params->pitch, 0, 0 }, }; - dst_size = conversion_buf_size(DRM_FORMAT_RGB332, params->dst_pitch, + dst_size = conv
[PATCH v2 2/4] drm/format-helper: Rename test cases to make them more generic
The tests available at the moment only check the conversion from XRGB to RGB332. However, more conversions will be tested in the future. In order to make the struct and functions present in the tests more generic, rename xrgb_to_rgb332_* to convert_xrgb_*. Tested-by: Tales L. Aparecida Acked-by: Thomas Zimmermann Signed-off-by: José Expósito --- drivers/gpu/drm/tests/drm_format_helper_test.c | 17 - 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 4d074c2e48bf..f66aaa0e52c9 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -16,7 +16,7 @@ #define TEST_BUF_SIZE 50 -struct xrgb_to_rgb332_case { +struct convert_xrgb_case { const char *name; unsigned int pitch; unsigned int dst_pitch; @@ -25,7 +25,7 @@ struct xrgb_to_rgb332_case { const u8 expected[4 * TEST_BUF_SIZE]; }; -static struct xrgb_to_rgb332_case xrgb_to_rgb332_cases[] = { +static struct convert_xrgb_case convert_xrgb_cases[] = { { .name = "single_pixel_source_buffer", .pitch = 1 * 4, @@ -126,18 +126,18 @@ static u32 *le32buf_to_cpu(struct kunit *test, const u32 *buf, size_t buf_size) return dst; } -static void xrgb_to_rgb332_case_desc(struct xrgb_to_rgb332_case *t, -char *desc) +static void convert_xrgb_case_desc(struct convert_xrgb_case *t, + char *desc) { strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); } -KUNIT_ARRAY_PARAM(xrgb_to_rgb332, xrgb_to_rgb332_cases, - xrgb_to_rgb332_case_desc); +KUNIT_ARRAY_PARAM(convert_xrgb, convert_xrgb_cases, + convert_xrgb_case_desc); static void xrgb_to_rgb332_test(struct kunit *test) { - const struct xrgb_to_rgb332_case *params = test->param_value; + const struct convert_xrgb_case *params = test->param_value; size_t dst_size; __u8 *dst = NULL; __u32 *src = NULL; @@ -163,8 +163,7 @@ static void xrgb_to_rgb332_test(struct kunit *test) } static struct kunit_case drm_format_helper_test_cases[] = { - KUNIT_CASE_PARAM(xrgb_to_rgb332_test, -xrgb_to_rgb332_gen_params), + KUNIT_CASE_PARAM(xrgb_to_rgb332_test, convert_xrgb_gen_params), {} }; -- 2.25.1
[PATCH v2 0/4] KUnit tests for RGB565 conversion
Hello everyone, This series is a follow up of the XRGB to RGB332 conversion KUnit tests. The first patch fixes a bug reported by David Gow in the XRGB to RGB332 tests. Note that the fix is required for this format because internally, the drm_fb_xrgb_to_rgb332_line() function, calls le32_to_cpu(). The other *_line() functiones don't change the endian. That's why the RGB565 tests don't need to make any endian conversions. I'm not sure whether this inconsistency handling the endian could be considered a bug or not, but at list it is confusing. It'd be interesting to hear the opinion of the maintainers on this topic. Patches 2 and 3 make the test generic and the last one tests drm_fb_xrgb_to_rgb565(). Best wishes, José Expósito Changes since v1: - Fix a bug reported by David Gow in the XRGB to RGB332 tests - Simplify the test structure as suggested by David Gow - Add Tested-by Tales L. Aparecida and Acked-by Thomas Zimmermann - Fix link in the last patch (Thomas Zimmermann) José Expósito (4): drm/format-helper: Fix test on big endian architectures drm/format-helper: Rename test cases to make them more generic drm/format-helper: Support multiple target formats results drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb565() .../gpu/drm/tests/drm_format_helper_test.c| 167 ++ 1 file changed, 136 insertions(+), 31 deletions(-) base-commit: 6fde8eec71796f3534f0c274066862829813b21f prerequisite-patch-id: 8a16f4c8004d6161035eaea275c8eafaa0ac927e prerequisite-patch-id: 53fded2a49e6212b546db76ec52563a683752e65 prerequisite-patch-id: 294b0ca27a6ee57096c8f097c0572336b8a2d583 prerequisite-patch-id: 5e05bfc5287d16c207bfc616b2776ad72eb4ab29 prerequisite-patch-id: e94560be85dffb62a5b3cf58d1f0fc3d278ad806 prerequisite-patch-id: a471df39c7b32c69dd2b138a7d0af015ea42e00a prerequisite-patch-id: 04e8b96dd1319088e45d4b4dc4beb29889b30941 prerequisite-patch-id: bda9f93309910ca6d9528c9c560a3ccb7c388bfa prerequisite-patch-id: f45a301abf3874302b47751378d1cb4da01a1e2a prerequisite-patch-id: 7e8d74a4769f5bc8f2a1ced1de64aa13ea7b9d6c prerequisite-patch-id: cfa9be5a3b48cada74c681ebe967ef2a3ac572a0 prerequisite-patch-id: f4d0b5ba40437486248a6df6ab022a3428898273 prerequisite-patch-id: f6380c88b6640cd57b867a59ed42a2fc754fa9e4 prerequisite-patch-id: 112685a3c337b3bc8ff9507ab832c6322a77a2cc prerequisite-patch-id: 3f69109f64a8b7ac85a0332d177c8b2216cc747c prerequisite-patch-id: 7f0a3edb0b94bd54681d67c50a23008ccdb18c00 prerequisite-patch-id: bfb6024a0e542cdc89f1f2a98cc249a2c071c68f prerequisite-patch-id: b569ec32d7a4a9c7be317e8a8f0177ad4f696a10 prerequisite-patch-id: f1f7adf96de1501469c223a50d6405dc4b378982 prerequisite-patch-id: ce194443e4d40ded9bcec371717566398333e1db prerequisite-patch-id: 253ba111d18eea436c45fc43216b7d3ddba41388 prerequisite-patch-id: fac3f1b822c5154bc16eae9eb97b95fa19c178ad prerequisite-patch-id: 7eeca32e531b0d97d67285c106c1e721158da931 prerequisite-patch-id: 2b1b9ce615e8856f7e236f5fbaf7dfcd625da2ea prerequisite-patch-id: 6e45198758680c3ed23f58ee049d93f63d316d88 prerequisite-patch-id: 58c3a87ebf0a31d65a3a787121a066013e1da82e prerequisite-patch-id: e62f9ef9e892d075778094ee5b4e4e9d9cc76c86 prerequisite-patch-id: 3a7abafa7b011cbeca304f8af85b88aefc55cf64 prerequisite-patch-id: 1146b840a8ff43a4fdc8382c6c4d133aae6ec2fa prerequisite-patch-id: 1455f1117f208d983759d89b750440d349a880c2 prerequisite-patch-id: 92d0eb8a4e06da97b18a5cf28a81fc90158c444d prerequisite-patch-id: 2ab38ae9cea6d979bff04345550a1a848b55a091 prerequisite-patch-id: 25b591d59400b972ed1b709d932feaba0d5f642e prerequisite-patch-id: 003dca01353bba78d1a05baa5852acb1b313a154 prerequisite-patch-id: f7beda6d5b2aa56ecd5ce610f36db704d1fbd653 prerequisite-patch-id: f641abe09200a8b9507124949bab294a05529175 prerequisite-patch-id: 1fa4294e769b40dca3b89fa160c4ae1ff9eff8b7 prerequisite-patch-id: 9d04c01b752031e874286e121a64844891008a14 prerequisite-patch-id: f34a698723d7df6b6a4d17686395af8b694186e2 prerequisite-patch-id: 488ab7cec987c0a6c8c032fc74ad79a40bf546f9 prerequisite-patch-id: a5a4c847fb9b55f53eaef99b353749f61dd1f72f prerequisite-patch-id: 443d79ee1834963cb1f2a4e0007d02e419a2f5ff prerequisite-patch-id: 15add4faa533058e2ef962aeb7563835c6cbd82a prerequisite-patch-id: 6afb078b02085c4b24136bff54941a11090ea738 prerequisite-patch-id: da36728d198481270fb9695c7d86d210111353c2 prerequisite-patch-id: eb412a9ebab86d80a96f3c32690e5a96ed5a9ebc prerequisite-patch-id: e33a4314f9bb9caf819f5e350c50b5b571d68e37 prerequisite-patch-id: 10ec9def77f602a29e20ac1b4193bbc7e932a7f5 prerequisite-patch-id: 970edbb64a43f50ac7e80f2f0258767a08b8294c prerequisite-patch-id: f089485485d6e374fca925da2b904867c8e60a74 prerequisite-patch-id: b60e812dbb263d1b9c27f46bf487f4f73568a9d0 prerequisite-patch-id: 6344323c6242f0fa4402003f63cac9bc63fc7752 prerequisite-patch-id: b4d1a179227563da227593d7588306c9e676c6af prerequisite-patch-id: 48dbb90b0dbd77ad1e6ae8101804d23bb855645f prerequisite-patch-id: f104eb773c8c0b0ead12b8576ce0052c646cf598
Re: [PATCH 0/4] KUnit tests for RGB565 conversion
Hi David, Sorry for not getting back to you sooner, I've been swamped with work this week. On Wed, Jun 29, 2022 at 03:27:44PM +0800, David Gow wrote: > These look pretty good overall to me, but there is one big issue > (which is actually with the previous series -- oops!), and a few small > stylistic thoughts. > > For the big issue: these tests don't work on big-endian systems. The > 'swab' bit in this series reminded me to check, and sure enough, all > of the tests fail (including the rgb332 ones). > > I tested it on PowerPC with: > ./tools/testing/kunit/kunit.py run > --kunitconfig=drivers/gpu/drm/tests --arch=powerpc > --cross_compile=powerpc64-linux-gnu- > > So that's something which needs to be fixed. Oops, yes, definitely something that I need to fix! I'll include an extra patch at the beginning of v2 fixing this bug. > The smaller stylistic thoughts basically all revolve around the > complexity of convert_xrgb_cases: there are arrays of structs with > arrays of unions of structs (with function pointers in them). This > isn't a problem: it's actually a lot more readable than that > description implies, but there are other ways it could be tackled > (which have their own tradeoffs, of course). > > One possibility would be to split up the test into a separate test per > destination format. They could reuse the convert_xrgb_cases array, > and just each access a different result. You could make things even > clearer (IMO) by replacing the results[] array with a separate, named, > member (since you don't need to iterate over them any more), and > remove the need to have the function pointer and swab union/members by > just hardcoding those in the separate test functions. It'd also make > the results a bit clearer, as each destination format would get its > own separate set of results. > > Of course, that's just an idea: I don't actually have a problem with > the existing design either (other than the endianness issue, of > course). I like from your approach that the output of the tests would be easier to understand. At the moment, if a test fails, there is not enough context to know which target format failed. I'll explore this approach and see how it looks like. Thanks, Jose > Cheers, > -- David
[PATCH 2/4] drm/format-helper: Transform tests to be agnostic of target format
In order to support multiple destination format conversions, store the target format, conversion function, parameters and expected result in its own structure. Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 88 ++- 1 file changed, 64 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index de8cf525109e..732d945e7f4e 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -16,34 +16,55 @@ #define TEST_BUF_SIZE 50 +struct convert_xrgb_result { + u32 dst_format; + void (*conv_func)(void *dst, unsigned int dst_pitch, + const void *src, + const struct drm_framebuffer *fb, + const struct drm_rect *clip); + unsigned int dst_pitch; + const u8 expected[4 * TEST_BUF_SIZE]; +}; + struct convert_xrgb_case { const char *name; unsigned int pitch; - unsigned int dst_pitch; struct drm_rect clip; const u32 xrgb[TEST_BUF_SIZE]; - const u8 expected[4 * TEST_BUF_SIZE]; + struct convert_xrgb_result results[1]; }; static struct convert_xrgb_case convert_xrgb_cases[] = { { .name = "single_pixel_source_buffer", .pitch = 1 * 4, - .dst_pitch = 0, .clip = DRM_RECT_INIT(0, 0, 1, 1), .xrgb = { 0x01FF }, - .expected = { 0xE0 }, + .results = { + { + .dst_format = DRM_FORMAT_RGB332, + .conv_func = drm_fb_xrgb_to_rgb332, + .dst_pitch = 0, + .expected = { 0xE0 }, + }, + }, }, { .name = "single_pixel_clip_rectangle", .pitch = 2 * 4, - .dst_pitch = 0, .clip = DRM_RECT_INIT(1, 1, 1, 1), .xrgb = { 0x, 0x, 0x, 0x10FF, }, - .expected = { 0xE0 }, + .results = { + { + .dst_format = DRM_FORMAT_RGB332, + .conv_func = drm_fb_xrgb_to_rgb332, + .dst_pitch = 0, + .expected = { 0xE0 }, + }, + }, }, { /* Well known colors: White, black, red, green, blue, magenta, @@ -52,7 +73,6 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { */ .name = "well_known_colors", .pitch = 4 * 4, - .dst_pitch = 0, .clip = DRM_RECT_INIT(1, 1, 2, 4), .xrgb = { 0x, 0x, 0x, 0x, @@ -61,28 +81,41 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0x, 0x55FF, 0x66FF00FF, 0x, 0x, 0x7700, 0x8800, 0x, }, - .expected = { - 0xFF, 0x00, - 0xE0, 0x1C, - 0x03, 0xE3, - 0xFC, 0x1F, + .results = { + { + .dst_format = DRM_FORMAT_RGB332, + .conv_func = drm_fb_xrgb_to_rgb332, + .dst_pitch = 0, + .expected = { + 0xFF, 0x00, + 0xE0, 0x1C, + 0x03, 0xE3, + 0xFC, 0x1F, + }, + }, }, }, { /* Randomly picked colors. Full buffer within the clip area. */ .name = "destination_pitch", .pitch = 3 * 4, - .dst_pitch = 5, .clip = DRM_RECT_INIT(0, 0, 3, 3), .xrgb = { 0xA10E449C, 0xB1114D05, 0xC1A80303, 0xD16C7073, 0xA20E449C, 0xB2114D05, 0xC2A80303, 0xD26C7073, 0xA30E449C, }, - .expected = { - 0x0A, 0x08, 0xA0, 0x00, 0x00, - 0x6D, 0x0A, 0x08, 0x00, 0x00, - 0xA0, 0x6D, 0x0A, 0x00, 0x00, + .results = { + { + .dst_format = DRM_FORMAT_RGB332, +
[PATCH 4/4] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb565()
Extend the existing test cases to test the conversion from XRGB to RGB565. The documentation and the color picker available on [1] are useful resources to understand this patch and validate the values returned by the conversion function. [1] http://www.barth-dev.de/online/rgb565-color-picker/ Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 100 +- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 52dc41cc7c60..3fbe8026bccc 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -48,7 +48,7 @@ struct convert_xrgb_case { unsigned int pitch; struct drm_rect clip; const u32 xrgb[TEST_BUF_SIZE]; - struct convert_xrgb_result results[1]; + struct convert_xrgb_result results[3]; }; static struct convert_xrgb_case convert_xrgb_cases[] = { @@ -64,6 +64,26 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0xE0 }, }, + { + .dst_format = DRM_FORMAT_RGB565, + .has_swab = true, + .conv_swab = { + .func = drm_fb_xrgb_to_rgb565, + .swab = false, + }, + .dst_pitch = 0, + .expected = { 0x00, 0xF8 }, + }, + { + .dst_format = DRM_FORMAT_RGB565, + .has_swab = true, + .conv_swab = { + .func = drm_fb_xrgb_to_rgb565, + .swab = true, + }, + .dst_pitch = 0, + .expected = { 0xF8, 0x00 }, + }, }, }, { @@ -81,6 +101,26 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .dst_pitch = 0, .expected = { 0xE0 }, }, + { + .dst_format = DRM_FORMAT_RGB565, + .has_swab = true, + .conv_swab = { + .func = drm_fb_xrgb_to_rgb565, + .swab = false, + }, + .dst_pitch = 0, + .expected = { 0x00, 0xF8 }, + }, + { + .dst_format = DRM_FORMAT_RGB565, + .has_swab = true, + .conv_swab = { + .func = drm_fb_xrgb_to_rgb565, + .swab = true, + }, + .dst_pitch = 0, + .expected = { 0xF8, 0x00 }, + }, }, }, { @@ -110,6 +150,36 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { 0xFC, 0x1F, }, }, + { + .dst_format = DRM_FORMAT_RGB565, + .has_swab = true, + .conv_swab = { + .func = drm_fb_xrgb_to_rgb565, + .swab = false, + }, + .dst_pitch = 0, + .expected = { + 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0xF8, 0xE0, 0x07, + 0x1F, 0x00, 0x1F, 0xF8, + 0xE0, 0xFF, 0xFF, 0x07, + }, + }, + { + .dst_format = DRM_FORMAT_RGB565, + .has_swab = true, + .conv_swab = { + .func = drm_fb_xrgb_to_rgb565, + .swab = true, + }, + .dst_pitch = 0, + .expected = { + 0xFF, 0xFF, 0x00, 0x00
[PATCH 3/4] drm/format-helper: Add support for conversion functions with swab
The RGB565 conversion functions take an extra parameter ("swab") indicating whether the bytes should be swapped into the clip buffer or not. Create a union in the "convert_xrgb_result" structure holding the value of the "swab" parameter as well as the conversion function pointer. Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 44 ++- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 732d945e7f4e..52dc41cc7c60 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -16,12 +16,29 @@ #define TEST_BUF_SIZE 50 +struct convert_xrgb_func { + void (*func)(void *dst, unsigned int dst_pitch, +const void *src, +const struct drm_framebuffer *fb, +const struct drm_rect *clip); +}; + +struct convert_xrgb_func_swab { + void (*func)(void *dst, unsigned int dst_pitch, +const void *src, +const struct drm_framebuffer *fb, +const struct drm_rect *clip, +bool swab); + bool swab; +}; + struct convert_xrgb_result { u32 dst_format; - void (*conv_func)(void *dst, unsigned int dst_pitch, - const void *src, - const struct drm_framebuffer *fb, - const struct drm_rect *clip); + bool has_swab; + union { + struct convert_xrgb_func conv; + struct convert_xrgb_func_swab conv_swab; + }; unsigned int dst_pitch; const u8 expected[4 * TEST_BUF_SIZE]; }; @@ -43,7 +60,7 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .results = { { .dst_format = DRM_FORMAT_RGB332, - .conv_func = drm_fb_xrgb_to_rgb332, + .conv = { .func = drm_fb_xrgb_to_rgb332 }, .dst_pitch = 0, .expected = { 0xE0 }, }, @@ -60,7 +77,7 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .results = { { .dst_format = DRM_FORMAT_RGB332, - .conv_func = drm_fb_xrgb_to_rgb332, + .conv = { .func = drm_fb_xrgb_to_rgb332 }, .dst_pitch = 0, .expected = { 0xE0 }, }, @@ -84,7 +101,7 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .results = { { .dst_format = DRM_FORMAT_RGB332, - .conv_func = drm_fb_xrgb_to_rgb332, + .conv = { .func = drm_fb_xrgb_to_rgb332 }, .dst_pitch = 0, .expected = { 0xFF, 0x00, @@ -108,7 +125,7 @@ static struct convert_xrgb_case convert_xrgb_cases[] = { .results = { { .dst_format = DRM_FORMAT_RGB332, - .conv_func = drm_fb_xrgb_to_rgb332, + .conv = { .func = drm_fb_xrgb_to_rgb332 }, .dst_pitch = 5, .expected = { 0x0A, 0x08, 0xA0, 0x00, 0x00, @@ -177,8 +194,15 @@ static void convert_xrgb_test(struct kunit *test) dst = kunit_kzalloc(test, dst_size, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dst); - result->conv_func(dst, result->dst_pitch, params->xrgb, - , >clip); + if (result->has_swab) { + result->conv_swab.func(dst, result->dst_pitch, + params->xrgb, , + >clip, + result->conv_swab.swab); + } else { + result->conv.func(dst, result->dst_pitch, + params->xrgb, , >clip); + } KUNIT_EXPECT_EQ(test, memcmp(dst, result->expected, dst_size), 0); } } -- 2.25.1
[PATCH 1/4] drm/format-helper: Rename test cases to make them more generic
The tests available at the moment only check the conversion from XRGB to RGB332. However, more conversion will be tested in the future. In order to make the struct and functions present in the tests more generic, rename xrgb_to_rgb332_* to convert_xrgb_*. Signed-off-by: José Expósito --- .../gpu/drm/tests/drm_format_helper_test.c| 19 +-- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 98583bf56044..de8cf525109e 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -16,7 +16,7 @@ #define TEST_BUF_SIZE 50 -struct xrgb_to_rgb332_case { +struct convert_xrgb_case { const char *name; unsigned int pitch; unsigned int dst_pitch; @@ -25,7 +25,7 @@ struct xrgb_to_rgb332_case { const u8 expected[4 * TEST_BUF_SIZE]; }; -static struct xrgb_to_rgb332_case xrgb_to_rgb332_cases[] = { +static struct convert_xrgb_case convert_xrgb_cases[] = { { .name = "single_pixel_source_buffer", .pitch = 1 * 4, @@ -111,18 +111,18 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch, return dst_pitch * drm_rect_height(clip); } -static void xrgb_to_rgb332_case_desc(struct xrgb_to_rgb332_case *t, -char *desc) +static void convert_xrgb_case_desc(struct convert_xrgb_case *t, + char *desc) { strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); } -KUNIT_ARRAY_PARAM(xrgb_to_rgb332, xrgb_to_rgb332_cases, - xrgb_to_rgb332_case_desc); +KUNIT_ARRAY_PARAM(convert_xrgb, convert_xrgb_cases, + convert_xrgb_case_desc); -static void xrgb_to_rgb332_test(struct kunit *test) +static void convert_xrgb_test(struct kunit *test) { - const struct xrgb_to_rgb332_case *params = test->param_value; + const struct convert_xrgb_case *params = test->param_value; size_t dst_size; __u8 *dst = NULL; @@ -144,8 +144,7 @@ static void xrgb_to_rgb332_test(struct kunit *test) } static struct kunit_case drm_format_helper_test_cases[] = { - KUNIT_CASE_PARAM(xrgb_to_rgb332_test, -xrgb_to_rgb332_gen_params), + KUNIT_CASE_PARAM(convert_xrgb_test, convert_xrgb_gen_params), {} }; -- 2.25.1
[PATCH 0/4] KUnit tests for RGB565 conversion
Hello everyone, This series is a follow up of the XRGB to RGB332 conversion KUnit tests. The first 3 patches refactor the existing test to make them agnostic of the target format and add support for "swab". The last patch adds the RGB565 conversion values, and shows how more formats will be easily added in the future. Thank you very much in advance for your feedback, José Expósito José Expósito (4): drm/format-helper: Rename test cases to make them more generic drm/format-helper: Transform tests to be agnostic of target format drm/format-helper: Add support for conversion functions with swab drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb565() .../gpu/drm/tests/drm_format_helper_test.c| 231 +++--- 1 file changed, 196 insertions(+), 35 deletions(-) base-commit: 6fde8eec71796f3534f0c274066862829813b21f prerequisite-patch-id: 8a16f4c8004d6161035eaea275c8eafaa0ac927e prerequisite-patch-id: 53fded2a49e6212b546db76ec52563a683752e65 prerequisite-patch-id: 294b0ca27a6ee57096c8f097c0572336b8a2d583 prerequisite-patch-id: 5e05bfc5287d16c207bfc616b2776ad72eb4ab29 prerequisite-patch-id: e94560be85dffb62a5b3cf58d1f0fc3d278ad806 prerequisite-patch-id: a471df39c7b32c69dd2b138a7d0af015ea42e00a -- 2.25.1
Re: [PATCH v3 3/3] drm/doc: Add KUnit documentation
Hi Javier, Daniel, On Fri, Jun 24, 2022 at 11:18:40PM +0200, Javier Martinez Canillas wrote: > Hello Daniel, > > On 6/24/22 23:01, Daniel Vetter wrote: > > > > [...] > > > > Hey so since you have a bunch of patches merged into drm already but seem > > to lack drm-misc commit rights to push these yourself I think it's time to > > get those: > > > > https://drm.pages.freedesktop.org/maintainer-tools/commit-access.html#drm-misc > > > > And I guess Javier can help you with any questions you might have and make > > sure the request gets through by poking folks on #dri-devel irc? > > > > Yes, he already requested commit access and got the acks, so I think is > just a matter of time until he has this sorted out. > > José, please don't hesitate to ask if you need any help or clarification > once you have a setup to push your patches. The dim documentation [0] is > superb but I know that it can be somewhat stressful the first time :) Thanks for creating my ssh account :D The tool is really well documented, setting it up was a piece of cake. I pushed the patches to drm-misc-next. The output didn't show any errors or warnings, hopefully meaning that I didn't mess up. Jose > [0]: https://drm.pages.freedesktop.org/maintainer-tools/dim.html > -- > Best regards, > > Javier Martinez Canillas > Linux Engineering > Red Hat >
Re:[PATCH] drm/vc4: perfmon: Fix variable dereferenced before check
Maxime Ripard wrote: > Commit 30f8c74ca9b7 ("drm/vc4: Warn if some v3d code is run on BCM2711") > introduced a check in vc4_perfmon_get() that dereferences a pointer before > we checked whether that pointer is valid or not. > > Let's rework that function a bit to do things in the proper order. > > Reported-by: kernel test robot > Reported-by: Dan Carpenter > Fixes: 30f8c74ca9b7 ("drm/vc4: Warn if some v3d code is run on BCM2711") > Signed-off-by: Maxime Ripard Reviewed-by: José Expósito I was about to send the same patch because Coverity reported this issue today, but you already found and fixed it :D Best wishes, José Expósito
Re: [PATCH v4 3/3] drm/doc: Add KUnit documentation
Hi David, On Tue, Jun 21, 2022 at 05:38:38PM +0800, David Gow wrote: > On Tue, Jun 21, 2022 at 12:06 AM José Expósito > wrote: > > > > Explain how to run the KUnit tests present in the DRM subsystem and > > clarify why the UML-only options were not added to the configuration > > file present in drivers/gpu/drm/.kunitconfig [1] [2]. > > > > [1] > > https://lore.kernel.org/dri-devel/CABVgOSn8i=lo5p7830h2xu1jgg0krn0qtnxkomhf1otgxja...@mail.gmail.com/ > > [2] > > https://lore.kernel.org/dri-devel/CAGS_qxqpiCim_sy1LDK7PLwVgWf-LKW+uNFTGM=t7ydk-dy...@mail.gmail.com/ > > > > Reviewed-by: Maxime Ripard > > Reviewed-by: Javier Martinez Canillas > > Acked-by: Thomas Zimmermann > > Signed-off-by: José Expósito > > --- > > This looks good (and doesn't seem to introduce any 'make htmldocs' > build issues on my machine). > > You could also mention that using --arch=x86_64 (or similar) instead > of the UML options is another, equally viable option for running the > tests. That'd make it more obvious how to run on different > architectures: UML, while a good default, is quite different to other > architectures in not having any PCI support out-of-the-box. > > (Maybe we should make the --arch=um default config include these > options? Or have um-pci as another architecture. We did decide not to > bother with SMP and x86, though...) Javier suggested the same: https://lore.kernel.org/dri-devel/20220614180952.GA7067@elementary/ I prefer to keep the docs as simple as possible and link the KUnit docs for more information. However, you both have way more experience than me and agree on the topic, so I'll be happy to include it in v5 if you think it is a good idea. > Regardless, this is > Reviewed-by: David Gow Thanks for reviewing and building the docs, appreciate it. Jose > Cheers, > -- David
Re: [PATCH v4 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()
Hi David, On Tue, Jun 21, 2022 at 05:38:33PM +0800, David Gow wrote: > On Tue, Jun 21, 2022 at 12:06 AM José Expósito > wrote: > > > > Test the conversion from XRGB to RGB332. > > > > What is tested? > > > > - Different values for the X in XRGB to make sure it is ignored > > - Different clip values: Single pixel and full and partial buffer > > - Well known colors: White, black, red, green, blue, magenta, yellow > >and cyan > > - Other colors: Randomly picked > > - Destination pitch > > > > How to run the tests? > > > > $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/tests \ > > --kconfig_add CONFIG_VIRTIO_UML=y \ > > --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y > > > > Suggested-by: Javier Martinez Canillas > > Reviewed-by: Javier Martinez Canillas > > Acked-by: Thomas Zimmermann > > Signed-off-by: José Expósito > > --- > > These tests all pass properly on my system, and look good to me from a > KUnit point of view. Thanks very much. > > A couple of small notes below, which you can take or leave as you > wish: they mostly focus on potential future tests. > > Regardless, > Reviewed-by: David Gow Thanks a lot for your review :) > Cheers, > -- David > > > drivers/gpu/drm/Kconfig | 16 ++ > > drivers/gpu/drm/Makefile | 1 + > > drivers/gpu/drm/tests/.kunitconfig| 3 + > > drivers/gpu/drm/tests/Makefile| 3 + > > .../gpu/drm/tests/drm_format_helper_test.c| 161 ++ > > 5 files changed, 184 insertions(+) > > create mode 100644 drivers/gpu/drm/tests/.kunitconfig > > create mode 100644 drivers/gpu/drm/tests/Makefile > > create mode 100644 drivers/gpu/drm/tests/drm_format_helper_test.c > > > > diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig > > index 22e7fa48d693..6c2256e8474b 100644 > > --- a/drivers/gpu/drm/Kconfig > > +++ b/drivers/gpu/drm/Kconfig > > @@ -70,6 +70,22 @@ config DRM_DEBUG_SELFTEST > > > > If in doubt, say "N". > > > > +config DRM_KUNIT_TEST > > + tristate "KUnit tests for DRM" if !KUNIT_ALL_TESTS > > + depends on DRM && KUNIT=y > > + select DRM_KMS_HELPER > > + default KUNIT_ALL_TESTS > > + help > > + This builds unit tests for DRM. This option is not useful for > > + distributions or general kernels, but only for kernel > > + developers working on DRM and associated drivers. > > + > > + For more information on KUnit and unit tests in general, > > + please refer to the KUnit documentation in > > + Documentation/dev-tools/kunit/. > > + > > + If in doubt, say "N". > > + > > config DRM_KMS_HELPER > > tristate > > depends on DRM > > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile > > index 13ef240b3d2b..db8ffcf4e048 100644 > > --- a/drivers/gpu/drm/Makefile > > +++ b/drivers/gpu/drm/Makefile > > @@ -76,6 +76,7 @@ obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o > > # > > > > obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/ > > +obj-$(CONFIG_DRM_KUNIT_TEST) += tests/ > > > > obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o > > obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o > > diff --git a/drivers/gpu/drm/tests/.kunitconfig > > b/drivers/gpu/drm/tests/.kunitconfig > > new file mode 100644 > > index ..6ec04b4c979d > > --- /dev/null > > +++ b/drivers/gpu/drm/tests/.kunitconfig > > @@ -0,0 +1,3 @@ > > +CONFIG_KUNIT=y > > +CONFIG_DRM=y > > +CONFIG_DRM_KUNIT_TEST=y > > diff --git a/drivers/gpu/drm/tests/Makefile b/drivers/gpu/drm/tests/Makefile > > new file mode 100644 > > index ..2c8273796d9d > > --- /dev/null > > +++ b/drivers/gpu/drm/tests/Makefile > > @@ -0,0 +1,3 @@ > > +# SPDX-License-Identifier: GPL-2.0 > > + > > +obj-$(CONFIG_DRM_KUNIT_TEST) += drm_format_helper_test.o > > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c > > b/drivers/gpu/drm/tests/drm_format_helper_test.c > > new file mode 100644 > > index ..98583bf56044 > > --- /dev/null > > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c > > @@ -0,0 +1,161 @@ > > +// SPDX-License-Identifier: GPL-2.0+ > > + > > +#include > > + > > +#include > > +#include > > +#include > > +#in
[PATCH v4 3/3] drm/doc: Add KUnit documentation
Explain how to run the KUnit tests present in the DRM subsystem and clarify why the UML-only options were not added to the configuration file present in drivers/gpu/drm/.kunitconfig [1] [2]. [1] https://lore.kernel.org/dri-devel/CABVgOSn8i=lo5p7830h2xu1jgg0krn0qtnxkomhf1otgxja...@mail.gmail.com/ [2] https://lore.kernel.org/dri-devel/CAGS_qxqpiCim_sy1LDK7PLwVgWf-LKW+uNFTGM=t7ydk-dy...@mail.gmail.com/ Reviewed-by: Maxime Ripard Reviewed-by: Javier Martinez Canillas Acked-by: Thomas Zimmermann Signed-off-by: José Expósito --- Documentation/gpu/drm-internals.rst | 32 + 1 file changed, 32 insertions(+) diff --git a/Documentation/gpu/drm-internals.rst b/Documentation/gpu/drm-internals.rst index 38afed24a75c..5fd20a306718 100644 --- a/Documentation/gpu/drm-internals.rst +++ b/Documentation/gpu/drm-internals.rst @@ -207,6 +207,38 @@ Utilities :internal: +Unit testing + + +KUnit +- + +KUnit (Kernel unit testing framework) provides a common framework for unit tests +within the Linux kernel. + +This section covers the specifics for the DRM subsystem. For general information +about KUnit, please refer to Documentation/dev-tools/kunit/start.rst. + +How to run the tests? +~ + +In order to facilitate running the test suite, a configuration file is present +in ``drivers/gpu/drm/tests/.kunitconfig``. It can be used by ``kunit.py`` as +follows: + +.. code-block:: bash + + $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/tests \ + --kconfig_add CONFIG_VIRTIO_UML=y \ + --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y + +.. note:: + The configuration included in ``.kunitconfig`` should be as generic as + possible. + ``CONFIG_VIRTIO_UML`` and ``CONFIG_UML_PCI_OVER_VIRTIO`` are not + included in it because they are only required for User Mode Linux. + + Legacy Support Code === -- 2.25.1
[PATCH v4 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()
Test the conversion from XRGB to RGB332. What is tested? - Different values for the X in XRGB to make sure it is ignored - Different clip values: Single pixel and full and partial buffer - Well known colors: White, black, red, green, blue, magenta, yellow and cyan - Other colors: Randomly picked - Destination pitch How to run the tests? $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/tests \ --kconfig_add CONFIG_VIRTIO_UML=y \ --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y Suggested-by: Javier Martinez Canillas Reviewed-by: Javier Martinez Canillas Acked-by: Thomas Zimmermann Signed-off-by: José Expósito --- drivers/gpu/drm/Kconfig | 16 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/tests/.kunitconfig| 3 + drivers/gpu/drm/tests/Makefile| 3 + .../gpu/drm/tests/drm_format_helper_test.c| 161 ++ 5 files changed, 184 insertions(+) create mode 100644 drivers/gpu/drm/tests/.kunitconfig create mode 100644 drivers/gpu/drm/tests/Makefile create mode 100644 drivers/gpu/drm/tests/drm_format_helper_test.c diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 22e7fa48d693..6c2256e8474b 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -70,6 +70,22 @@ config DRM_DEBUG_SELFTEST If in doubt, say "N". +config DRM_KUNIT_TEST + tristate "KUnit tests for DRM" if !KUNIT_ALL_TESTS + depends on DRM && KUNIT=y + select DRM_KMS_HELPER + default KUNIT_ALL_TESTS + help + This builds unit tests for DRM. This option is not useful for + distributions or general kernels, but only for kernel + developers working on DRM and associated drivers. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N". + config DRM_KMS_HELPER tristate depends on DRM diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 13ef240b3d2b..db8ffcf4e048 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -76,6 +76,7 @@ obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o # obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/ +obj-$(CONFIG_DRM_KUNIT_TEST) += tests/ obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o diff --git a/drivers/gpu/drm/tests/.kunitconfig b/drivers/gpu/drm/tests/.kunitconfig new file mode 100644 index ..6ec04b4c979d --- /dev/null +++ b/drivers/gpu/drm/tests/.kunitconfig @@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_KUNIT_TEST=y diff --git a/drivers/gpu/drm/tests/Makefile b/drivers/gpu/drm/tests/Makefile new file mode 100644 index ..2c8273796d9d --- /dev/null +++ b/drivers/gpu/drm/tests/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_DRM_KUNIT_TEST) += drm_format_helper_test.o diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c new file mode 100644 index ..98583bf56044 --- /dev/null +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -0,0 +1,161 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../drm_crtc_internal.h" + +#define TEST_BUF_SIZE 50 + +struct xrgb_to_rgb332_case { + const char *name; + unsigned int pitch; + unsigned int dst_pitch; + struct drm_rect clip; + const u32 xrgb[TEST_BUF_SIZE]; + const u8 expected[4 * TEST_BUF_SIZE]; +}; + +static struct xrgb_to_rgb332_case xrgb_to_rgb332_cases[] = { + { + .name = "single_pixel_source_buffer", + .pitch = 1 * 4, + .dst_pitch = 0, + .clip = DRM_RECT_INIT(0, 0, 1, 1), + .xrgb = { 0x01FF }, + .expected = { 0xE0 }, + }, + { + .name = "single_pixel_clip_rectangle", + .pitch = 2 * 4, + .dst_pitch = 0, + .clip = DRM_RECT_INIT(1, 1, 1, 1), + .xrgb = { + 0x, 0x, + 0x, 0x10FF, + }, + .expected = { 0xE0 }, + }, + { + /* Well known colors: White, black, red, green, blue, magenta, +* yellow and cyan. Different values for the X in XRGB to +* make sure it is ignored. Partial clip area. +*/ + .name = "well_known_colors", + .pitch = 4 * 4, + .dst_pitch = 0, + .clip = DRM_RECT_INIT(1, 1, 2, 4), + .xrgb8
[PATCH v4 1/3] drm/rect: Add DRM_RECT_INIT() macro
Add a helper macro to initialize a rectangle from x, y, width and height information. Reviewed-by: Jani Nikula Acked-by: Thomas Zimmermann Signed-off-by: José Expósito --- include/drm/drm_rect.h | 16 1 file changed, 16 insertions(+) diff --git a/include/drm/drm_rect.h b/include/drm/drm_rect.h index 6f6e19bd4dac..e8d94fca2703 100644 --- a/include/drm/drm_rect.h +++ b/include/drm/drm_rect.h @@ -47,6 +47,22 @@ struct drm_rect { int x1, y1, x2, y2; }; +/** + * DRM_RECT_INIT - initialize a rectangle from x/y/w/h + * @x: x coordinate + * @y: y coordinate + * @w: width + * @h: height + * + * RETURNS: + * A new rectangle of the specified size. + */ +#define DRM_RECT_INIT(x, y, w, h) ((struct drm_rect){ \ + .x1 = (x), \ + .y1 = (y), \ + .x2 = (x) + (w), \ + .y2 = (y) + (h) }) + /** * DRM_RECT_FMT - printf string for drm_rect */ -- 2.25.1
[PATCH v4 0/3] KUnit tests for drm_format_helper
Hello everyone, Following the style used in the selftest to KUnit series [1] and the AMD series [2], the tests were moved to the "tests" folder. In addition, to be consistent naming functions, I renamed the kunit_suite and the test cases to use underscores as suggested in [3]. It is not clear yet whether we want to have one or multiple Kconfig symbols and select which test should be built. However, refactoring from one approach to the other is quite simple, so I think we should be fine choosing the simpler option now and refactoring if required. Thanks a lot, José Expósito [1] https://lore.kernel.org/dri-devel/20220615135824.15522-1-maira.ca...@usp.br/T/ [2] https://lore.kernel.org/dri-devel/20220608010709.272962-1-maira.ca...@usp.br/ [3] https://www.kernel.org/doc/html/latest/dev-tools/kunit/style.html RFC -> v1: https://lore.kernel.org/dri-devel/20220530102017.471865-1-jose.exposit...@gmail.com/T/ - Add .kunitconfig (Maxime Ripard) - Fix memory leak (Daniel Latypov) - Make config option generic (Javier Martinez Canillas): DRM_FORMAR_HELPER_TEST -> DRM_KUNIT_TEST - Remove DISABLE_STRUCTLEAK_PLUGIN (Daniel Latypov) v1 -> v2: https://lore.kernel.org/dri-devel/20220606095516.938934-1-jose.exposit...@gmail.com/T/ Thomas Zimmermann: - Add DRM_RECT_INIT() macro - Move tests to drivers/gpu/drm/kunit - Improve test documentation v2 -> v3: https://lore.kernel.org/dri-devel/20220612161248.271590-1-jose.exposit...@gmail.com/T/ - Use designated initializer in DRM_RECT_INIT (Jani Nikula) - Simplify the "conversion_buf_size" helper v3 -> v4: https://lore.kernel.org/dri-devel/20220616183852.GA12343@elementary/T/ - Move the source to the "tests" folder - Use "_" in kunit_suite and cases: https://www.kernel.org/doc/html/latest/dev-tools/kunit/style.html - Reviewed-by and Acked-by tags José Expósito (3): drm/rect: Add DRM_RECT_INIT() macro drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb332() drm/doc: Add KUnit documentation Documentation/gpu/drm-internals.rst | 32 drivers/gpu/drm/Kconfig | 16 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/tests/.kunitconfig| 3 + drivers/gpu/drm/tests/Makefile| 3 + .../gpu/drm/tests/drm_format_helper_test.c| 161 ++ include/drm/drm_rect.h| 16 ++ 7 files changed, 232 insertions(+) create mode 100644 drivers/gpu/drm/tests/.kunitconfig create mode 100644 drivers/gpu/drm/tests/Makefile create mode 100644 drivers/gpu/drm/tests/drm_format_helper_test.c -- 2.25.1
Re: [PATCH v3 0/3] KUnit tests for drm_format_helper
Hi! Javier Martinez Canillas wrote: > Before merging this, could you please reach the folks working on [0] ? > I think that would be good to have some consistency with regard to KUnit > tests from the start to avoid future refactorings. For instance, you are > adding the tests under a `kunit` sub-directory while they are doing it > in a `tests` sub-dir. > > Also there may be other things that could be made more consistent, like > the naming conventions for the tests, suites, etc. > > [0]: https://lore.kernel.org/all/20220608010709.272962-4-maira.ca...@usp.br/T/ David Gow wrote: > [+Maíra, Isabella, Tales, Magali for other drm,amdgpu,KUnit work.] > > These seem pretty good to me, but I'd echo Javier's comments about > consistency with other DRM tests. I agree, I'd need to look with more detail into the selftest conversion and the AMD series, but it'd be nice to avoid unnecessary refactors. > In particular, we now have three concurrently developed DRM-related > test suites, each doing things slightly differently: > - This series is putting tests in drm/kunit, and providing a > .kunitconfig in that directory, > > - The selftest ports here[1] are putting tests in drm/tests, and > provide a separate Kconfig file, as well as a .kunitconfig Now that "selftests/" is going to be removed, "tests/" is a good name for the folder, I'll rename it in v4. > - And the AMDGPU tests[2] are doing something totally different, with > their own tests in drm/amd/display/amdgpu_dm/tests, which get compiled > directly into the amdgpu module (and, at present, can't be run at all > via kunit_tool) > > Certainly the general DRM tests should be in the same place, and use > the same Kconfig entries, etc. A mix of the separate Kconfig file from > [1] (if there's enough benefit to having the ability to turn on and > off suites individually, which seems plausible) and the documentation > from this series seems good to me. I agree about having the DRM-core tests in drm/tests/ and driver tests in drm/driver/tests/. About allowing turning on or off test suites, it was agreed to use a generic symbol to group them (DRM_KUNIT_TEST) [1]. I won't have time merge all patches toghether and run them until next week, but if it takes too long to run them or you find it beneficial to split the symbols, I'll change my patch. [1] https://lore.kernel.org/dri-devel/e26de140-afb7-7b1b-4826-6ac4f3a4f...@redhat.com/ > There's some basic guidelines around test nomenclature in > Documentation/dev-tools/kunit/style.rst[3], though all of these > patches seem pretty consistent with that. Either 'kunit' or 'tests' > would work as a directory name: given the AMDGPU patches are using > 'tests', maybe that's easier to stick with. I'll have to rename my kunit_suite to use underscores, as well as the test cases, that at the moment are using English sentences. Maíra: We'd also need to agree on the file names used, the documentation [2] suggest to use *_test.c, it'd need to be changed in the selftest to KUnit series. Best wishes, Jose [2] https://www.kernel.org/doc/html/latest/dev-tools/kunit/style.html#test-file-and-module-names > Cheers, > -- David > > [1]: > https://lore.kernel.org/linux-kselftest/20220615135824.15522-1-maira.ca...@usp.br/ > [2]: > https://lore.kernel.org/dri-devel/20220608010709.272962-1-maira.ca...@usp.br/ > [3]: https://www.kernel.org/doc/html/latest/dev-tools/kunit/style.html
Re: [PATCH v3 3/3] drm/doc: Add KUnit documentation
Hi Javier, On Tue, Jun 14, 2022 at 02:58:29PM +0200, Javier Martinez Canillas wrote: > Hello José, > > On 6/13/22 19:17, José Expósito wrote: > > [snip] > > > +KUnit (Kernel unit testing framework) provides a common framework for unit > > tests > > +within the Linux kernel. > > + > > I think that it will be useful to have a reference to the KUnit kernel doc > here, > something like the following: > > `KUnit <https://docs.kernel.org/dev-tools/kunit/index.html>`_ (Kernel Unit... There is a link in the next paragraph. Once the documentation is generated the path "Documentation/dev-tools/kunit/start.rst" is transformed into a link. > > +This section covers the specifics for the DRM subsystem. For general > > information > > +about KUnit, please refer to Documentation/dev-tools/kunit/start.rst. > > + > > +How to run the tests? > > +~ > > + > > +In order to facilitate running the test suite, a configuration file is > > present > > +in ``drivers/gpu/drm/kunit/.kunitconfig``. It can be used by ``kunit.py`` > > as > > +follows: > > + > > +.. code-block:: bash > > + > > + $ ./tools/testing/kunit/kunit.py run > > --kunitconfig=drivers/gpu/drm/kunit \ > > + --kconfig_add CONFIG_VIRTIO_UML=y \ > > + --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y > > + > > +.. note:: > > + The configuration included in ``.kunitconfig`` should be as generic as > > + possible. > > + ``CONFIG_VIRTIO_UML`` and ``CONFIG_UML_PCI_OVER_VIRTIO`` are not > > + included in it because they are only required for User Mode Linux. > > + > > + > > Maybe also add something like this ? > > For example, the following command can be used to run the test for x86_64: > > $ ./tools/testing/kunit/kunit.py run > --kunitconfig=drivers/gpu/drm/kunit \ > --arch=x86_64 I didn't want to go into much detail because the KUnit docs are a very good resource and already explain how to run the tests in your favorite architecture. Since running the test on x86_64 should not change the results, I'd prefer to keep it simple and trust the KUnit docs for the "advanced" options. > Regardless, the patch looks good to me: > > Reviewed-by: Javier Martinez Canillas Thanks a lot for taking the time to review it. I'll add the tag if a v4 is required after chatting with the guys working on the AMDGPU tests. Jose > -- > Best regards, > > Javier Martinez Canillas > Linux Engineering > Red Hat >
Re: [PATCH] drm/bridge: anx7625: Zero error variable when panel bridge not present
On Mon, Jun 13, 2022 at 12:37:05PM -0400, Nícolas F. R. A. Prado wrote: > While parsing the DT, the anx7625 driver checks for the presence of a > panel bridge on endpoint 1. If it is missing, pdata->panel_bridge stores > the error pointer and the function returns successfully without first > cleaning that variable. This is an issue since other functions later > check for the presence of a panel bridge by testing the trueness of that > variable. > > In order to ensure proper behavior, zero out pdata->panel_bridge before > returning when no panel bridge is found. > > Fixes: 9e82ea0fb1df ("drm/bridge: anx7625: switch to devm_drm_of_get_bridge") > Signed-off-by: Nícolas F. R. A. Prado > > --- > > drivers/gpu/drm/bridge/analogix/anx7625.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c > b/drivers/gpu/drm/bridge/analogix/anx7625.c > index 53a5da6c49dd..3aed4de16690 100644 > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c > @@ -1657,8 +1657,10 @@ static int anx7625_parse_dt(struct device *dev, > > pdata->panel_bridge = devm_drm_of_get_bridge(dev, np, 1, 0); > if (IS_ERR(pdata->panel_bridge)) { > - if (PTR_ERR(pdata->panel_bridge) == -ENODEV) > + if (PTR_ERR(pdata->panel_bridge) == -ENODEV) { > + pdata->panel_bridge = NULL; > return 0; > + } > > return PTR_ERR(pdata->panel_bridge); > } > -- > 2.36.1 > Thanks for spotting this error Nícolas. As you mentioned, prior to 9e82ea0fb1df the "pdata->panel_bridge" pointer was not modified (i.e. left to NULL) on the ENODEV error branch. I missed it during the refactor, sorry about that.
Re: [PATCH v2 1/3] drm/rect: Add DRM_RECT_INIT() macro
On Mon, Jun 13, 2022 at 10:53:57AM +0300, Jani Nikula wrote: > On Sun, 12 Jun 2022, José Expósito wrote: > > Add a helper macro to initialize a rectangle from x, y, width and > > height information. > > > > Signed-off-by: José Expósito > > --- > > include/drm/drm_rect.h | 12 > > 1 file changed, 12 insertions(+) > > > > diff --git a/include/drm/drm_rect.h b/include/drm/drm_rect.h > > index 6f6e19bd4dac..945696323c69 100644 > > --- a/include/drm/drm_rect.h > > +++ b/include/drm/drm_rect.h > > @@ -47,6 +47,18 @@ struct drm_rect { > > int x1, y1, x2, y2; > > }; > > > > +/** > > + * DRM_RECT_INIT - initialize a rectangle from x/y/w/h > > + * @x: x coordinate > > + * @y: y coordinate > > + * @w: width > > + * @h: height > > + * > > + * RETURNS: > > + * A new rectangle of the specified size. > > + */ > > +#define DRM_RECT_INIT(x, y, w, h) { (x), (y), (x) + (w), (y) + (h) } > > Please use designated initializers. > > It might help type safety if it also contained a (struct drm_rect) cast. Thanks a lot for your review Jani, just emailed v3 with your suggested changes. Jose > BR, > Jani. > > > > + > > /** > > * DRM_RECT_FMT - printf string for drm_rect > > */ > > -- > Jani Nikula, Intel Open Source Graphics Center
[PATCH v3 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()
Test the conversion from XRGB to RGB332. What is tested? - Different values for the X in XRGB to make sure it is ignored - Different clip values: Single pixel and full and partial buffer - Well known colors: White, black, red, green, blue, magenta, yellow and cyan - Other colors: Randomly picked - Destination pitch How to run the tests? $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/kunit \ --kconfig_add CONFIG_VIRTIO_UML=y \ --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y Suggested-by: Javier Martinez Canillas Reviewed-by: Javier Martinez Canillas Signed-off-by: José Expósito --- drivers/gpu/drm/Kconfig | 16 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/kunit/.kunitconfig| 3 + drivers/gpu/drm/kunit/Makefile| 3 + .../gpu/drm/kunit/drm_format_helper_test.c| 160 ++ 5 files changed, 183 insertions(+) create mode 100644 drivers/gpu/drm/kunit/.kunitconfig create mode 100644 drivers/gpu/drm/kunit/Makefile create mode 100644 drivers/gpu/drm/kunit/drm_format_helper_test.c diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 22e7fa48d693..6c2256e8474b 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -70,6 +70,22 @@ config DRM_DEBUG_SELFTEST If in doubt, say "N". +config DRM_KUNIT_TEST + tristate "KUnit tests for DRM" if !KUNIT_ALL_TESTS + depends on DRM && KUNIT=y + select DRM_KMS_HELPER + default KUNIT_ALL_TESTS + help + This builds unit tests for DRM. This option is not useful for + distributions or general kernels, but only for kernel + developers working on DRM and associated drivers. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N". + config DRM_KMS_HELPER tristate depends on DRM diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 13ef240b3d2b..3171437d74f8 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -76,6 +76,7 @@ obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o # obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/ +obj-$(CONFIG_DRM_KUNIT_TEST) += kunit/ obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o diff --git a/drivers/gpu/drm/kunit/.kunitconfig b/drivers/gpu/drm/kunit/.kunitconfig new file mode 100644 index ..6ec04b4c979d --- /dev/null +++ b/drivers/gpu/drm/kunit/.kunitconfig @@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_KUNIT_TEST=y diff --git a/drivers/gpu/drm/kunit/Makefile b/drivers/gpu/drm/kunit/Makefile new file mode 100644 index ..2c8273796d9d --- /dev/null +++ b/drivers/gpu/drm/kunit/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_DRM_KUNIT_TEST) += drm_format_helper_test.o diff --git a/drivers/gpu/drm/kunit/drm_format_helper_test.c b/drivers/gpu/drm/kunit/drm_format_helper_test.c new file mode 100644 index ..f8f2351f3449 --- /dev/null +++ b/drivers/gpu/drm/kunit/drm_format_helper_test.c @@ -0,0 +1,160 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../drm_crtc_internal.h" + +#define TEST_BUF_SIZE 50 + +struct xrgb_to_rgb332_case { + const char *name; + unsigned int pitch; + unsigned int dst_pitch; + struct drm_rect clip; + const u32 xrgb[TEST_BUF_SIZE]; + const u8 expected[4 * TEST_BUF_SIZE]; +}; + +static struct xrgb_to_rgb332_case xrgb_to_rgb332_cases[] = { + { + .name = "Single pixel source buffer", + .pitch = 1 * 4, + .dst_pitch = 0, + .clip = DRM_RECT_INIT(0, 0, 1, 1), + .xrgb = { 0x01FF }, + .expected = { 0xE0 }, + }, + { + .name = "Single pixel clip rectangle", + .pitch = 2 * 4, + .dst_pitch = 0, + .clip = DRM_RECT_INIT(1, 1, 1, 1), + .xrgb = { + 0x, 0x, + 0x, 0x10FF, + }, + .expected = { 0xE0 }, + }, + { + /* Well known colors, different values for the X in XRGB to +* make sure it is ignored. Partial clip area. +*/ + .name = "White, black, red, green, blue, magenta, yellow, cyan", + .pitch = 4 * 4, + .dst_pitch = 0, + .clip = DRM_RECT_INIT(1, 1, 2, 4), + .xrgb = { + 0x, 0x, 0x, 0x00
[PATCH v3 1/3] drm/rect: Add DRM_RECT_INIT() macro
Add a helper macro to initialize a rectangle from x, y, width and height information. Signed-off-by: José Expósito --- include/drm/drm_rect.h | 16 1 file changed, 16 insertions(+) diff --git a/include/drm/drm_rect.h b/include/drm/drm_rect.h index 6f6e19bd4dac..e8d94fca2703 100644 --- a/include/drm/drm_rect.h +++ b/include/drm/drm_rect.h @@ -47,6 +47,22 @@ struct drm_rect { int x1, y1, x2, y2; }; +/** + * DRM_RECT_INIT - initialize a rectangle from x/y/w/h + * @x: x coordinate + * @y: y coordinate + * @w: width + * @h: height + * + * RETURNS: + * A new rectangle of the specified size. + */ +#define DRM_RECT_INIT(x, y, w, h) ((struct drm_rect){ \ + .x1 = (x), \ + .y1 = (y), \ + .x2 = (x) + (w), \ + .y2 = (y) + (h) }) + /** * DRM_RECT_FMT - printf string for drm_rect */ -- 2.25.1
[PATCH v3 3/3] drm/doc: Add KUnit documentation
Explain how to run the KUnit tests present in the DRM subsystem and clarify why the UML-only options were not added to the configuration file present in drivers/gpu/drm/.kunitconfig [1] [2]. [1] https://lore.kernel.org/dri-devel/CABVgOSn8i=lo5p7830h2xu1jgg0krn0qtnxkomhf1otgxja...@mail.gmail.com/ [2] https://lore.kernel.org/dri-devel/CAGS_qxqpiCim_sy1LDK7PLwVgWf-LKW+uNFTGM=t7ydk-dy...@mail.gmail.com/ Reviewed-by: Maxime Ripard Signed-off-by: José Expósito --- Documentation/gpu/drm-internals.rst | 32 + 1 file changed, 32 insertions(+) diff --git a/Documentation/gpu/drm-internals.rst b/Documentation/gpu/drm-internals.rst index 38afed24a75c..f1d97e80ca29 100644 --- a/Documentation/gpu/drm-internals.rst +++ b/Documentation/gpu/drm-internals.rst @@ -207,6 +207,38 @@ Utilities :internal: +Unit testing + + +KUnit +- + +KUnit (Kernel unit testing framework) provides a common framework for unit tests +within the Linux kernel. + +This section covers the specifics for the DRM subsystem. For general information +about KUnit, please refer to Documentation/dev-tools/kunit/start.rst. + +How to run the tests? +~ + +In order to facilitate running the test suite, a configuration file is present +in ``drivers/gpu/drm/kunit/.kunitconfig``. It can be used by ``kunit.py`` as +follows: + +.. code-block:: bash + + $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/kunit \ + --kconfig_add CONFIG_VIRTIO_UML=y \ + --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y + +.. note:: + The configuration included in ``.kunitconfig`` should be as generic as + possible. + ``CONFIG_VIRTIO_UML`` and ``CONFIG_UML_PCI_OVER_VIRTIO`` are not + included in it because they are only required for User Mode Linux. + + Legacy Support Code === -- 2.25.1
[PATCH v3 0/3] KUnit tests for drm_format_helper
Hello everyone, Here is the v3 of the series, including the documentation, previously sent as a standalone patch [1], and changes suggested during review. Thanks a lot, José Expósito RFC -> v1: https://lore.kernel.org/dri-devel/20220530102017.471865-1-jose.exposit...@gmail.com/T/ - Add .kunitconfig (Maxime Ripard) - Fix memory leak (Daniel Latypov) - Make config option generic (Javier Martinez Canillas): DRM_FORMAR_HELPER_TEST -> DRM_KUNIT_TEST - Remove DISABLE_STRUCTLEAK_PLUGIN (Daniel Latypov) v1 -> v2: https://lore.kernel.org/dri-devel/20220606095516.938934-1-jose.exposit...@gmail.com/T/ Thomas Zimmermann: - Add DRM_RECT_INIT() macro - Move tests to drivers/gpu/drm/kunit - Improve test documentation v2 -> v3: https://lore.kernel.org/dri-devel/20220612161248.271590-1-jose.exposit...@gmail.com/T/ - Use designated initializer in DRM_RECT_INIT (Jani Nikula) - Simplify the "conversion_buf_size" helper [1] https://lore.kernel.org/dri-devel/20220606180940.43371-1-jose.exposit...@gmail.com/T/ José Expósito (3): drm/rect: Add DRM_RECT_INIT() macro drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb332() drm/doc: Add KUnit documentation Documentation/gpu/drm-internals.rst | 32 drivers/gpu/drm/Kconfig | 16 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/kunit/.kunitconfig| 3 + drivers/gpu/drm/kunit/Makefile| 3 + .../gpu/drm/kunit/drm_format_helper_test.c| 160 ++ include/drm/drm_rect.h| 16 ++ 7 files changed, 231 insertions(+) create mode 100644 drivers/gpu/drm/kunit/.kunitconfig create mode 100644 drivers/gpu/drm/kunit/Makefile create mode 100644 drivers/gpu/drm/kunit/drm_format_helper_test.c -- 2.25.1
[PATCH v2 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()
Test the conversion from XRGB to RGB332. What is tested? - Different values for the X in XRGB to make sure it is ignored - Different clip values: Single pixel and full and partial buffer - Well known colors: White, black, red, green, blue, magenta, yellow and cyan - Other colors: Randomly picked - Destination pitch How to run the tests? $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/kunit \ --kconfig_add CONFIG_VIRTIO_UML=y \ --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y Suggested-by: Javier Martinez Canillas Reviewed-by: Javier Martinez Canillas Signed-off-by: José Expósito --- drivers/gpu/drm/Kconfig | 16 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/kunit/.kunitconfig| 3 + drivers/gpu/drm/kunit/Makefile| 3 + .../gpu/drm/kunit/drm_format_helper_test.c| 169 ++ 5 files changed, 192 insertions(+) create mode 100644 drivers/gpu/drm/kunit/.kunitconfig create mode 100644 drivers/gpu/drm/kunit/Makefile create mode 100644 drivers/gpu/drm/kunit/drm_format_helper_test.c diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 22e7fa48d693..6c2256e8474b 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -70,6 +70,22 @@ config DRM_DEBUG_SELFTEST If in doubt, say "N". +config DRM_KUNIT_TEST + tristate "KUnit tests for DRM" if !KUNIT_ALL_TESTS + depends on DRM && KUNIT=y + select DRM_KMS_HELPER + default KUNIT_ALL_TESTS + help + This builds unit tests for DRM. This option is not useful for + distributions or general kernels, but only for kernel + developers working on DRM and associated drivers. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N". + config DRM_KMS_HELPER tristate depends on DRM diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 13ef240b3d2b..3171437d74f8 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -76,6 +76,7 @@ obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o # obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/ +obj-$(CONFIG_DRM_KUNIT_TEST) += kunit/ obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o diff --git a/drivers/gpu/drm/kunit/.kunitconfig b/drivers/gpu/drm/kunit/.kunitconfig new file mode 100644 index ..6ec04b4c979d --- /dev/null +++ b/drivers/gpu/drm/kunit/.kunitconfig @@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_KUNIT_TEST=y diff --git a/drivers/gpu/drm/kunit/Makefile b/drivers/gpu/drm/kunit/Makefile new file mode 100644 index ..2c8273796d9d --- /dev/null +++ b/drivers/gpu/drm/kunit/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_DRM_KUNIT_TEST) += drm_format_helper_test.o diff --git a/drivers/gpu/drm/kunit/drm_format_helper_test.c b/drivers/gpu/drm/kunit/drm_format_helper_test.c new file mode 100644 index ..c87e7ab69184 --- /dev/null +++ b/drivers/gpu/drm/kunit/drm_format_helper_test.c @@ -0,0 +1,169 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../drm_crtc_internal.h" + +#define TEST_BUF_SIZE 50 + +struct xrgb_to_rgb332_case { + const char *name; + unsigned int pitch; + unsigned int dst_pitch; + struct drm_rect clip; + const u32 xrgb[TEST_BUF_SIZE]; + const u8 expected[4 * TEST_BUF_SIZE]; +}; + +static struct xrgb_to_rgb332_case xrgb_to_rgb332_cases[] = { + { + .name = "Single pixel source buffer", + .pitch = 1 * 4, + .dst_pitch = 0, + .clip = DRM_RECT_INIT(0, 0, 1, 1), + .xrgb = { 0x01FF }, + .expected = { 0xE0 }, + }, + { + .name = "Single pixel clip rectangle", + .pitch = 2 * 4, + .dst_pitch = 0, + .clip = DRM_RECT_INIT(1, 1, 1, 1), + .xrgb = { + 0x, 0x, + 0x, 0x10FF, + }, + .expected = { 0xE0 }, + }, + { + /* Well known colors, different values for the X in XRGB to +* make sure it is ignored. Partial clip area. +*/ + .name = "White, black, red, green, blue, magenta, yellow, cyan", + .pitch = 4 * 4, + .dst_pitch = 0, + .clip = DRM_RECT_INIT(1, 1, 2, 4), + .xrgb = { + 0x, 0x, 0x, 0x00
[PATCH v2 3/3] drm/doc: Add KUnit documentation
Explain how to run the KUnit tests present in the DRM subsystem and clarify why the UML-only options were not added to the configuration file present in drivers/gpu/drm/.kunitconfig [1] [2]. [1] https://lore.kernel.org/dri-devel/CABVgOSn8i=lo5p7830h2xu1jgg0krn0qtnxkomhf1otgxja...@mail.gmail.com/ [2] https://lore.kernel.org/dri-devel/CAGS_qxqpiCim_sy1LDK7PLwVgWf-LKW+uNFTGM=t7ydk-dy...@mail.gmail.com/ Reviewed-by: Maxime Ripard Signed-off-by: José Expósito --- Documentation/gpu/drm-internals.rst | 32 + 1 file changed, 32 insertions(+) diff --git a/Documentation/gpu/drm-internals.rst b/Documentation/gpu/drm-internals.rst index 38afed24a75c..f1d97e80ca29 100644 --- a/Documentation/gpu/drm-internals.rst +++ b/Documentation/gpu/drm-internals.rst @@ -207,6 +207,38 @@ Utilities :internal: +Unit testing + + +KUnit +- + +KUnit (Kernel unit testing framework) provides a common framework for unit tests +within the Linux kernel. + +This section covers the specifics for the DRM subsystem. For general information +about KUnit, please refer to Documentation/dev-tools/kunit/start.rst. + +How to run the tests? +~ + +In order to facilitate running the test suite, a configuration file is present +in ``drivers/gpu/drm/kunit/.kunitconfig``. It can be used by ``kunit.py`` as +follows: + +.. code-block:: bash + + $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/kunit \ + --kconfig_add CONFIG_VIRTIO_UML=y \ + --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y + +.. note:: + The configuration included in ``.kunitconfig`` should be as generic as + possible. + ``CONFIG_VIRTIO_UML`` and ``CONFIG_UML_PCI_OVER_VIRTIO`` are not + included in it because they are only required for User Mode Linux. + + Legacy Support Code === -- 2.25.1
[PATCH v2 1/3] drm/rect: Add DRM_RECT_INIT() macro
Add a helper macro to initialize a rectangle from x, y, width and height information. Signed-off-by: José Expósito --- include/drm/drm_rect.h | 12 1 file changed, 12 insertions(+) diff --git a/include/drm/drm_rect.h b/include/drm/drm_rect.h index 6f6e19bd4dac..945696323c69 100644 --- a/include/drm/drm_rect.h +++ b/include/drm/drm_rect.h @@ -47,6 +47,18 @@ struct drm_rect { int x1, y1, x2, y2; }; +/** + * DRM_RECT_INIT - initialize a rectangle from x/y/w/h + * @x: x coordinate + * @y: y coordinate + * @w: width + * @h: height + * + * RETURNS: + * A new rectangle of the specified size. + */ +#define DRM_RECT_INIT(x, y, w, h) { (x), (y), (x) + (w), (y) + (h) } + /** * DRM_RECT_FMT - printf string for drm_rect */ -- 2.25.1
[PATCH v2 0/3] KUnit tests for drm_format_helper
Hello everyone, Here is the v2 of the series, including the documentation, previously sent as a standalone patch [1], and changes suggested during review. Thanks a lot, José Expósito RFC -> v1: https://lore.kernel.org/dri-devel/20220530102017.471865-1-jose.exposit...@gmail.com/T/ - Add .kunitconfig (Maxime Ripard) - Fix memory leak (Daniel Latypov) - Make config option generic (Javier Martinez Canillas): DRM_FORMAR_HELPER_TEST -> DRM_KUNIT_TEST - Remove DISABLE_STRUCTLEAK_PLUGIN (Daniel Latypov) v1 -> v2: https://lore.kernel.org/dri-devel/20220606095516.938934-1-jose.exposit...@gmail.com/T/ Thomas Zimmermann: - Add DRM_RECT_INIT() macro - Move tests to drivers/gpu/drm/kunit - Improve test documentation [1] https://lore.kernel.org/dri-devel/20220606180940.43371-1-jose.exposit...@gmail.com/T/ José Expósito (3): drm/rect: Add DRM_RECT_INIT() macro drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb332() drm/doc: Add KUnit documentation Documentation/gpu/drm-internals.rst | 32 drivers/gpu/drm/Kconfig | 16 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/kunit/.kunitconfig| 3 + drivers/gpu/drm/kunit/Makefile| 3 + .../gpu/drm/kunit/drm_format_helper_test.c| 169 ++ include/drm/drm_rect.h| 12 ++ 7 files changed, 236 insertions(+) create mode 100644 drivers/gpu/drm/kunit/.kunitconfig create mode 100644 drivers/gpu/drm/kunit/Makefile create mode 100644 drivers/gpu/drm/kunit/drm_format_helper_test.c -- 2.25.1
Re: [PATCH 1/1] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()
Hi Thomas, Thanks a lot for your review. On Tue, Jun 07, 2022 at 09:22:38AM +0200, Thomas Zimmermann wrote: > Hi, > > ading Kunit tests for the conversion helpers is pretty cool. Thanks for > doing that. > > Am 06.06.22 um 11:55 schrieb José Expósito: > > Test the conversion from XRGB to RGB332. > > > > What is tested? > > > > - Different values for the X in XRGB to make sure it is ignored > > - Different clip values: Single pixel and full and partial buffer > > - Well known colors: White, black, red, green, blue, magenta, yellow > > and cyan > > - Other colors: Randomly picked > > - Destination pitch > > > > How to run the tests? > > > > $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm \ > > --kconfig_add CONFIG_VIRTIO_UML=y \ > > --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y > > > > Suggested-by: Javier Martinez Canillas > > Signed-off-by: José Expósito > > > > --- > > > > RFC -> v1: > > https://lore.kernel.org/dri-devel/20220530102017.471865-1-jose.exposit...@gmail.com/T/ > > > > - Add .kunitconfig (Maxime Ripard) > > - Fix memory leak (Daniel Latypov) > > - Make config option generic (Javier Martinez Canillas): > > DRM_FORMAR_HELPER_TEST -> DRM_KUNIT_TEST > > - Remove DISABLE_STRUCTLEAK_PLUGIN (Daniel Latypov) > > --- > > drivers/gpu/drm/.kunitconfig | 3 + > > drivers/gpu/drm/Kconfig | 16 +++ > > drivers/gpu/drm/Makefile | 2 + > > drivers/gpu/drm/drm_format_helper_test.c | 166 +++ > > 4 files changed, 187 insertions(+) > > create mode 100644 drivers/gpu/drm/.kunitconfig > > create mode 100644 drivers/gpu/drm/drm_format_helper_test.c > > > > diff --git a/drivers/gpu/drm/.kunitconfig b/drivers/gpu/drm/.kunitconfig > > new file mode 100644 > > index ..6ec04b4c979d > > --- /dev/null > > +++ b/drivers/gpu/drm/.kunitconfig > > @@ -0,0 +1,3 @@ > > +CONFIG_KUNIT=y > > +CONFIG_DRM=y > > +CONFIG_DRM_KUNIT_TEST=y > > diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig > > index e88c497fa010..3c0b1faba439 100644 > > --- a/drivers/gpu/drm/Kconfig > > +++ b/drivers/gpu/drm/Kconfig > > @@ -70,6 +70,22 @@ config DRM_DEBUG_SELFTEST > > If in doubt, say "N". > > +config DRM_KUNIT_TEST > > + tristate "KUnit tests for DRM" if !KUNIT_ALL_TESTS > > + depends on DRM && KUNIT=y > > + select DRM_KMS_HELPER > > + default KUNIT_ALL_TESTS > > + help > > + This builds unit tests for DRM. This option is not useful for > > + distributions or general kernels, but only for kernel > > + developers working on DRM and associated drivers. > > + > > + For more information on KUnit and unit tests in general, > > + please refer to the KUnit documentation in > > + Documentation/dev-tools/kunit/. > > + > > + If in doubt, say "N". > > + > > config DRM_KMS_HELPER > > tristate > > depends on DRM > > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile > > index 15fe3163f822..6549471f09c7 100644 > > --- a/drivers/gpu/drm/Makefile > > +++ b/drivers/gpu/drm/Makefile > > @@ -76,6 +76,8 @@ obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o > > # > > obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/ > > +obj-$(CONFIG_DRM_KUNIT_TEST) += drm_kms_helper.o \ > > You already selected DRM_KMS_HELPER in Kconfig. Why do you need to list the > module here? Actually, it is not required. I'll remove it in v2. > > + drm_format_helper_test.o > > One comment about source-code organization: > > There is potentially a long list of test files that will contain unit tests. > I would prefer to put the unit tests into their own subdirectory (e.g., > kunit). It makes sense, and it'd also be more consistent with selftest tests. > > obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o > > obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o > > diff --git a/drivers/gpu/drm/drm_format_helper_test.c > > b/drivers/gpu/drm/drm_format_helper_test.c > > new file mode 100644 > > index ..e9302219f3f9 > > --- /dev/null > > +++ b/drivers/gpu/drm/drm_format_helper_test.c > > @@ -0,0 +1,166 @@ > > +// SPDX-License-Identifier: GPL-2.0+ > > + > > +#include > > + > > +#include > > +#include > > +#include > > +#include >
[PATCH] drm/doc: Add KUnit documentation
Explain how to run the KUnit tests present in the DRM subsystem and clarify why the UML-only options were not added to the configuration file present in drivers/gpu/drm/.kunitconfig [1] [2]. [1] https://lore.kernel.org/dri-devel/CABVgOSn8i=lo5p7830h2xu1jgg0krn0qtnxkomhf1otgxja...@mail.gmail.com/ [2] https://lore.kernel.org/dri-devel/CAGS_qxqpiCim_sy1LDK7PLwVgWf-LKW+uNFTGM=t7ydk-dy...@mail.gmail.com/ Signed-off-by: José Expósito --- Documentation/gpu/drm-internals.rst | 31 + 1 file changed, 31 insertions(+) diff --git a/Documentation/gpu/drm-internals.rst b/Documentation/gpu/drm-internals.rst index 38afed24a75c..08f115417381 100644 --- a/Documentation/gpu/drm-internals.rst +++ b/Documentation/gpu/drm-internals.rst @@ -207,6 +207,37 @@ Utilities :internal: +Unit testing + + +KUnit +- + +KUnit (Kernel unit testing framework) provides a common framework for unit tests +within the Linux kernel. + +This section covers the specifics for the DRM subsystem. For general information +about KUnit, please refer to Documentation/dev-tools/kunit/start.rst. + +How to run the tests? +~ + +In order to facilitate running the test suite, a configuration file is present +in ``drivers/gpu/drm/.kunitconfig``. It can be used by ``kunit.py`` as follows: + +.. code-block:: bash + + $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm \ + --kconfig_add CONFIG_VIRTIO_UML=y \ + --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y + +.. note:: + The configuration included in ``.kunitconfig`` should be as generic as + possible. + ``CONFIG_VIRTIO_UML`` and ``CONFIG_UML_PCI_OVER_VIRTIO`` are not + included in it because they are only required for User Mode Linux. + + Legacy Support Code === -- 2.25.1
Re: [PATCH 1/1] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()
Hi! Javier Martinez Canillas wrote: > Hello José, > > On 6/6/22 11:55, José Expósito wrote: > > Test the conversion from XRGB to RGB332. > > > > What is tested? > > > > - Different values for the X in XRGB to make sure it is ignored > > - Different clip values: Single pixel and full and partial buffer > > - Well known colors: White, black, red, green, blue, magenta, yellow > >and cyan > > - Other colors: Randomly picked > > - Destination pitch > > > > How to run the tests? > > > > $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm \ > > --kconfig_add CONFIG_VIRTIO_UML=y \ > > --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y > > > > Suggested-by: Javier Martinez Canillas > > Signed-off-by: José Expósito > > > > --- > > Thanks for addressing the issues pointed out. Patch looks good to me now. > > Reviewed-by: Javier Martinez Canillas Thanks for the quick review Javier :) Javier Martinez Canillas wrote: > By the way, I think you should request an account [0], so that you can push > patches to drm-misc directly. Specially since AFAIU the plan is to add more > KUnit tests in future patch series. > > [0]: https://www.freedesktop.org/wiki/AccountRequests/ I'll request one, thanks for the tip. --- Maxime Ripard wrote: > > > The following works correctly but it won't use User Mode Linux: > > > > > > ./tools/testing/kunit/kunit.py run > > > --kunitconfig=drivers/gpu/drm/.kunitconfig --arch=x86_64 > > > > > > But then, can't we add them to .kunitconfig? > > > > > > > That's what I asked in the previous RFC too. Daniel mentioned that it > > shouldn't > > go there because is platform specific (AFAIU, one might want to test it on > > x86, > > aarch64, etc) but then I asked why we couldn't have a arch/um/.kunitconfig. > > > > The answer was that's not that simple and some agreement on how to do it is > > needed: > > > > https://lists.freedesktop.org/archives/dri-devel/2022-June/357617.html > > We should probably just document it somewhere in KMS then? It doesn't > have to be in this patch series, but I have the feeling that we will end > up with that discussion a lot from people frustrated to have spent too > much time figuring it out :) My understanding from Daniel's comment [1] is also that at the moment it is not easy to support this use case, so yes, at least copy and pasting the command in the docs should help everyone figure out how to run the tests. Documentation/gpu/drm-internals.rst seems like a good place to add some information about how to run and add tests. I'll send a patch with the docs ASAP. Jose [1] https://lore.kernel.org/dri-devel/CAGS_qxqpiCim_sy1LDK7PLwVgWf-LKW+uNFTGM=t7ydk-dy...@mail.gmail.com/
[PATCH 1/1] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()
Test the conversion from XRGB to RGB332. What is tested? - Different values for the X in XRGB to make sure it is ignored - Different clip values: Single pixel and full and partial buffer - Well known colors: White, black, red, green, blue, magenta, yellow and cyan - Other colors: Randomly picked - Destination pitch How to run the tests? $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm \ --kconfig_add CONFIG_VIRTIO_UML=y \ --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y Suggested-by: Javier Martinez Canillas Signed-off-by: José Expósito --- RFC -> v1: https://lore.kernel.org/dri-devel/20220530102017.471865-1-jose.exposit...@gmail.com/T/ - Add .kunitconfig (Maxime Ripard) - Fix memory leak (Daniel Latypov) - Make config option generic (Javier Martinez Canillas): DRM_FORMAR_HELPER_TEST -> DRM_KUNIT_TEST - Remove DISABLE_STRUCTLEAK_PLUGIN (Daniel Latypov) --- drivers/gpu/drm/.kunitconfig | 3 + drivers/gpu/drm/Kconfig | 16 +++ drivers/gpu/drm/Makefile | 2 + drivers/gpu/drm/drm_format_helper_test.c | 166 +++ 4 files changed, 187 insertions(+) create mode 100644 drivers/gpu/drm/.kunitconfig create mode 100644 drivers/gpu/drm/drm_format_helper_test.c diff --git a/drivers/gpu/drm/.kunitconfig b/drivers/gpu/drm/.kunitconfig new file mode 100644 index ..6ec04b4c979d --- /dev/null +++ b/drivers/gpu/drm/.kunitconfig @@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_KUNIT_TEST=y diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index e88c497fa010..3c0b1faba439 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -70,6 +70,22 @@ config DRM_DEBUG_SELFTEST If in doubt, say "N". +config DRM_KUNIT_TEST + tristate "KUnit tests for DRM" if !KUNIT_ALL_TESTS + depends on DRM && KUNIT=y + select DRM_KMS_HELPER + default KUNIT_ALL_TESTS + help + This builds unit tests for DRM. This option is not useful for + distributions or general kernels, but only for kernel + developers working on DRM and associated drivers. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N". + config DRM_KMS_HELPER tristate depends on DRM diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 15fe3163f822..6549471f09c7 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -76,6 +76,8 @@ obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o # obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/ +obj-$(CONFIG_DRM_KUNIT_TEST) += drm_kms_helper.o \ + drm_format_helper_test.o obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o diff --git a/drivers/gpu/drm/drm_format_helper_test.c b/drivers/gpu/drm/drm_format_helper_test.c new file mode 100644 index ..e9302219f3f9 --- /dev/null +++ b/drivers/gpu/drm/drm_format_helper_test.c @@ -0,0 +1,166 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "drm_crtc_internal.h" + +#define TEST_BUF_SIZE 50 +#define CLIP(x, y, w, h) { (x), (y), (x) + (w), (y) + (h) } + +struct xrgb_to_rgb332_case { + const char *name; + unsigned int pitch; + unsigned int dst_pitch; + struct drm_rect clip; + const u32 xrgb[TEST_BUF_SIZE]; + const u8 expected[4 * TEST_BUF_SIZE]; +}; + +static struct xrgb_to_rgb332_case xrgb_to_rgb332_cases[] = { + { + .name = "Single pixel source", + .pitch = 1 * 4, + .dst_pitch = 0, + .clip = CLIP(0, 0, 1, 1), + .xrgb = { 0x01FF }, + .expected = { 0xE0 }, + }, + { + .name = "Single pixel clip", + .pitch = 2 * 4, + .dst_pitch = 0, + .clip = CLIP(1, 1, 1, 1), + .xrgb = { + 0x, 0x, + 0x, 0x10FF, + }, + .expected = { 0xE0 }, + }, + { + .name = "White, black, red, green, blue, magenta, yellow, cyan", + .pitch = 4 * 4, + .dst_pitch = 0, + .clip = CLIP(1, 1, 2, 4), + .xrgb = { + 0x, 0x, 0x, 0x, + 0x, 0x11FF, 0x2200, 0x, + 0x, 0x33FF, 0x4400FF00, 0x, + 0x, 0x55FF, 0x66FF00FF, 0x, + 0x00
[PATCH 0/1] KUnit tests for drm_format_helper
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 includes the changes suggested in the RFC version [2]. Best wishes, José Expósito [1] https://cgit.freedesktop.org/drm/drm-misc/commit/?id=596c35b1440e [2] https://lore.kernel.org/dri-devel/20220530102017.471865-1-jose.exposit...@gmail.com/T/ José Expósito (1): drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb332() drivers/gpu/drm/.kunitconfig | 3 + drivers/gpu/drm/Kconfig | 16 +++ drivers/gpu/drm/Makefile | 2 + drivers/gpu/drm/drm_format_helper_test.c | 166 +++ 4 files changed, 187 insertions(+) create mode 100644 drivers/gpu/drm/.kunitconfig create mode 100644 drivers/gpu/drm/drm_format_helper_test.c -- 2.25.1
Re: [RFC PATCH 1/1] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()
Hello everyone, On Thu, Jun 02, 2022 at 07:21:28PM +0200, Javier Martinez Canillas wrote: > Hello David, > > On 6/2/22 19:07, David Gow wrote: > > On Thu, Jun 2, 2022 at 9:27 AM Javier Martinez Canillas > > [snip] > > >> > >> And doing that will also allow you to get rid of this, since just selecting > >> CONFIG_DRM_KUNIT_TEST=y would be enough for the tests built and run by > >> KUnit. > >> > > > > This is definitely something other KUnit tests (apparmor, elf, etc) > > are doing, and it's generally fine. You do lose the ability to build > > the tests as a separate module, though. (This is not usually a big > > problem, but there are some cases where it's useful.) > > > > That being said, I don't think 'select' is enough of a problem that > > you should feel the need to refactor in this way just to avoid it. > > Oh, yes I didn't want to imply that this was the main reason but just > pointed out that wouldn't even be needed if done that way. And it is > something that we want to do anyway IMO, since as mentioned it would > allow to test the static functions, which are the majority the format > helpers in that file. Conversion functions alway call drm_fb_xfrm()/drm_fb_xfrm_toio() and their *_line function. For example, drm_fb_xrgb_to_rgb332() calls drm_fb_xfrm() and drm_fb_xrgb_to_rgb332_line(). The current tests already check that the *_line() function works as expected. I'd like to test the high-level functions first and, if required, go into more detail in the future. The refactor is pretty easy, so I'd prefer to keep it as it is for the moment. About the other changes suggested, I applied all of them over the weekend. I'll send v1 of the patch to the mailing list including them so we have an up to date code to comment on. Thanks a lot for all of your comments and help, José Expósito
Re: [RFC PATCH 1/1] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()
Hi Daniel, Thanks for looking into the patch and for your comments. On Mon, May 30, 2022 at 03:57:56PM -0700, Daniel Latypov wrote: > A few initial notes: > a) normally, `select`ing other kconfigs is discouraged. It's not > explicitly called out in > https://www.kernel.org/doc/html/latest/dev-tools/kunit/style.html#test-kconfig-entries > but this was the conclusion after some debate on the mailing lists > earlier. > > b) I see `dst` is allocated with kzalloc but not freed. Should we use > `kunit_kzalloc()` instead so it does get automatically freed? Ooops yes, it was in my "I'll handle that once it works" list, but I forgot to fix it, thanks for pointing it out > > > > --- > > > > 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 > > > > > > > > diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig > > > > index e88c497fa010..d92be6faef15 100644 > > > > --- a/drivers/gpu/drm/Kconfig > > > > +++ b/drivers/gpu/drm/Kconfig > > > > @@ -76,6 +76,18 @@ config DRM_KMS_HELPER > > > > help > > > > CRTC helpers for KMS drivers. > > > > > > > > +config DRM_FORMAR_HELPER_TEST > > > > + bool "drm_format_helper tests" if !KUNIT_ALL_TESTS > > > > + depends on DRM && KUNIT=y > > > > + select DRM_KMS_HELPER > > From above, a) > Specifically here, it'd be encouraged to instead do > depends on DRM && KUNIT=y && DRM_KMS_HELPER My first attempt was to go with: depends on KUNIT=y && DRM && DRM_KMS_HELPER However, when I try to run the tests I get this error: $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm --arch=x86_64 Regenerating .config ... Populating config with: $ make ARCH=x86_64 olddefconfig O=.kunit ERROR:root:Not all Kconfig options selected in kunitconfig were in the generated .config. This is probably due to unsatisfied dependencies. Missing: CONFIG_DRM_KMS_HELPER=y, CONFIG_DRM_FORMAR_HELPER_TEST=y I wasn't able to figure out why that was happening, so I decided to use "select", which seems to solve the problem. Do you know why this could be happening? > Ideally, using a .kunitconfig file would make it so having to select > DRM_KMS_HELPER manually isn't that annoying. > > > > AFAIK, kunit test cases are supposed to have a .kunitconfig too to > > > enable the kunit tests easily. > > > > > > Maxime > > > > A .kuniconfig example is present in the cover letter. My understanding > > from the docs: > > > > https://docs.kernel.org/dev-tools/kunit/run_wrapper.html#create-a-kunitconfig-file > > The bit of the documentation you're looking for is > https://www.kernel.org/doc/html/latest/dev-tools/kunit/running_tips.html#defining-a-set-of-tests > You can create a drivers/gpu/drm/.kunitconfig file and run with > $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm > --arch=x86_86 > > The contents of that file would be just like > CONFIG_KUNIT=y > CONFIG_DRM=y > CONFIG_DRM_KMS_HELPER=y # if no `select` > CONFIG_DRM_FORMAR_HELPER_TEST=y Noted, thanks a lot, I'll include it in the final version of the patch. By the way, I also included it in an unrelated patch, just in case you are wondering why I emailed you a random patch: https://lore.kernel.org/linux-input/20220531181246.190729-1-jose.exposit...@gmail.com/T/ Thanks a lot for your help, José Expósito > Re "kunit test cases are supposed to have a .kunitconfig too" > As I noted in the docs: > This is a relatively new feature (5.12+) so we don’t have any > conventions yet about on what files should be checked in versus just > kept around locally. It’s up to you and your maintainer to decide if a > config is useful enough to submit (and therefore have to maintain). > > So it's up to whatever people think works best/is worth it. > I think in this case, it makes sense to add the file. > > > Is that, like the .config file, the .kunitconfig file is not meant to > > be included in git, but I'm sure someone else will clarify this point. > > That bit of the docs needs to be rewritten. > You're recommended to check in a drivers/gpu/drm/.kunitconfig file into git. > > Context: `kunit.py` used to use the "/.kunitconfig" file. > Anytime you wanted to run more tests, you'd append to that file. > So we agreed that no one should check in that file specifically. > > Now kunit.py > * uses "/.kunitconfig", by default: ".kunit/.kunitconfig" > * has the --kunitconfig flag so you can use different files > so it's no longer as relevant. > > Hope that helps, > Daniel
Re: [RFC PATCH 1/1] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()
Hi Maxime, On Mon, May 30, 2022 at 03:11:58PM +0200, Maxime Ripard wrote: > > Hi, > > On Mon, May 30, 2022 at 12:20:17PM +0200, José Expósito wrote: > > Test the conversion from XRGB to RGB332. > > > > What is tested? > > > > - Different values for the X in XRGB 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 > > > > Suggested-by: Javier Martinez Canillas > > Signed-off-by: José Expósito > > It looks mostly good to me, but I think we should Cc > kunit-...@googlegroups.com to have their feedback. Thanks a lot for the quick feedback. I just cc'ed kunit-...@googlegroups.com. For anyone joining the conversation, here is the link to the patch and the cover letter with some questions: https://lore.kernel.org/dri-devel/20220530102017.471865-1-jose.exposit...@gmail.com/T/ > > > --- > > 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 > > > > diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig > > index e88c497fa010..d92be6faef15 100644 > > --- a/drivers/gpu/drm/Kconfig > > +++ b/drivers/gpu/drm/Kconfig > > @@ -76,6 +76,18 @@ config DRM_KMS_HELPER > > help > > CRTC helpers for KMS drivers. > > > > +config DRM_FORMAR_HELPER_TEST > > + bool "drm_format_helper tests" if !KUNIT_ALL_TESTS > > + depends on DRM && KUNIT=y > > + select DRM_KMS_HELPER > > + default KUNIT_ALL_TESTS > > + help > > + KUnit tests for the drm_format_helper APIs. 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". > > + > > AFAIK, kunit test cases are supposed to have a .kunitconfig too to > enable the kunit tests easily. > > Maxime A .kuniconfig example is present in the cover letter. My understanding from the docs: https://docs.kernel.org/dev-tools/kunit/run_wrapper.html#create-a-kunitconfig-file Is that, like the .config file, the .kunitconfig file is not meant to be included in git, but I'm sure someone else will clarify this point. Thanks again, José Expósito
[RFC PATCH 1/1] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()
Test the conversion from XRGB to RGB332. What is tested? - Different values for the X in XRGB 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 Suggested-by: Javier Martinez Canillas Signed-off-by: José Expósito --- 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 diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index e88c497fa010..d92be6faef15 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -76,6 +76,18 @@ config DRM_KMS_HELPER help CRTC helpers for KMS drivers. +config DRM_FORMAR_HELPER_TEST + bool "drm_format_helper tests" if !KUNIT_ALL_TESTS + depends on DRM && KUNIT=y + select DRM_KMS_HELPER + default KUNIT_ALL_TESTS + help + KUnit tests for the drm_format_helper APIs. 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_DEBUG_DP_MST_TOPOLOGY_REFS bool "Enable refcount backtrace history in the DP MST helpers" depends on STACKTRACE_SUPPORT diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 15fe3163f822..6a7d7655d38c 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -76,6 +76,9 @@ obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o # obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/ +obj-$(CONFIG_DRM_FORMAR_HELPER_TEST) += drm_kms_helper.o \ + drm_format_helper_test.o +CFLAGS_drm_format_helper_test.o += $(DISABLE_STRUCTLEAK_PLUGIN) obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o diff --git a/drivers/gpu/drm/drm_format_helper_test.c b/drivers/gpu/drm/drm_format_helper_test.c new file mode 100644 index ..9c8a3007346c --- /dev/null +++ b/drivers/gpu/drm/drm_format_helper_test.c @@ -0,0 +1,166 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "drm_crtc_internal.h" + +#define TEST_BUF_SIZE 50 +#define CLIP(x, y, w, h) { (x), (y), (x) + (w), (y) + (h) } + +struct xrgb_to_rgb332_case { + const char *name; + unsigned int pitch; + unsigned int dst_pitch; + struct drm_rect clip; + const u32 xrgb[TEST_BUF_SIZE]; + const u8 expected[4 * TEST_BUF_SIZE]; +}; + +static struct xrgb_to_rgb332_case xrgb_to_rgb332_cases[] = { + { + .name = "Single pixel source", + .pitch = 1 * 4, + .dst_pitch = 0, + .clip = CLIP(0, 0, 1, 1), + .xrgb = { 0x01FF }, + .expected = { 0xE0 }, + }, + { + .name = "Single pixel clip", + .pitch = 2 * 4, + .dst_pitch = 0, + .clip = CLIP(1, 1, 1, 1), + .xrgb = { + 0x, 0x, + 0x, 0x10FF, + }, + .expected = { 0xE0 }, + }, + { + .name = "White, black, red, green, blue, magenta, yellow, cyan", + .pitch = 4 * 4, + .dst_pitch = 0, + .clip = CLIP(1, 1, 2, 4), + .xrgb = { + 0x, 0x, 0x, 0x, + 0x, 0x11FF, 0x2200, 0x, + 0x, 0x33FF, 0x4400FF00, 0x, + 0x, 0x55FF, 0x66FF00FF, 0x, + 0x, 0x7700, 0x8800, 0x, + }, + .expected = { + 0xFF, 0x00, + 0xE0, 0x1C, + 0x03, 0xE3, + 0xFC, 0x1F, + }, + }, + { + .name = "Destination pitch", + .pitch = 3 * 4, + .dst_pitch = 5, + .clip = CLIP(0, 0, 3, 3), + .xrgb = { + 0xA10E449C, 0xB1114D05, 0xC1A80303, + 0xD16C7073, 0xA20E449C, 0xB2114D05, + 0xC2A80303, 0xD26C7073, 0xA30E449C, + }, + .expected = { + 0x0A, 0x08, 0xA0, 0x00, 0x00, + 0x6D, 0x0A, 0x08, 0x00, 0x00, + 0xA0, 0x6D, 0x0A, 0x00, 0x00, +
[RFC PATCH 0/1] KUnit tests for drm_format_helper
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_xrgb_to_rgb332". Since the conversion functions present in "drm_format_helper" convert from XRGB to another format, my plan is to create a set of XRGB 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), .xrgb = { 0x01FF }, .expected = { 0xE0 }, } In a follow up patch, should look like: { .name = "Single pixel source", .pitch = 1 * 4, .clip = CLIP(0, 0, 1, 1), .xrgb = { 0x01FF }, .expected = { { .dst_format = DRM_FORMAT_RGB332, .dst_pitch = 0, .conv_func = drm_fb_xrgb_to_rgb332, .result = { 0xE0 }, }, { ... }, }, } What is tested? - Different values for the X in XRGB 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_xrgb_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 -- 2.25.1
[PATCH 4/5] drm/sti/sti_hdmi: Replace drm_detect_hdmi_monitor() with is_hdmi
Once EDID is parsed, the monitor HDMI support information is available through drm_display_info.is_hdmi. This driver calls drm_detect_hdmi_monitor() to receive the same information and stores its own cached value, which is less efficient. Avoid calling drm_detect_hdmi_monitor() and use drm_display_info.is_hdmi instead and also remove sti_hdmi.hdmi_monitor as it is no longer necessary. Signed-off-by: José Expósito --- drivers/gpu/drm/sti/sti_hdmi.c | 7 --- drivers/gpu/drm/sti/sti_hdmi.h | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/sti/sti_hdmi.c b/drivers/gpu/drm/sti/sti_hdmi.c index f3ace11209dd..93841ba907a8 100644 --- a/drivers/gpu/drm/sti/sti_hdmi.c +++ b/drivers/gpu/drm/sti/sti_hdmi.c @@ -266,6 +266,7 @@ static void hdmi_active_area(struct sti_hdmi *hdmi) static void hdmi_config(struct sti_hdmi *hdmi) { u32 conf; + struct drm_display_info *display = >drm_connector->display_info; DRM_DEBUG_DRIVER("\n"); @@ -274,7 +275,7 @@ static void hdmi_config(struct sti_hdmi *hdmi) /* Select encryption type and the framing mode */ conf |= HDMI_CFG_ESS_NOT_OESS; - if (hdmi->hdmi_monitor) + if (display->is_hdmi) conf |= HDMI_CFG_HDMI_NOT_DVI; /* Set Hsync polarity */ @@ -984,9 +985,9 @@ static int sti_hdmi_connector_get_modes(struct drm_connector *connector) if (!edid) goto fail; - hdmi->hdmi_monitor = drm_detect_hdmi_monitor(edid); DRM_DEBUG_KMS("%s : %dx%d cm\n", - (hdmi->hdmi_monitor ? "hdmi monitor" : "dvi monitor"), + (connector->display_info.is_hdmi ? "hdmi monitor" : +"dvi monitor"), edid->width_cm, edid->height_cm); cec_notifier_set_phys_addr_from_edid(hdmi->notifier, edid); diff --git a/drivers/gpu/drm/sti/sti_hdmi.h b/drivers/gpu/drm/sti/sti_hdmi.h index 05b2f3d0d48d..6d4c3f57bc46 100644 --- a/drivers/gpu/drm/sti/sti_hdmi.h +++ b/drivers/gpu/drm/sti/sti_hdmi.h @@ -57,7 +57,6 @@ struct hdmi_audio_params { * @reset: reset control of the hdmi phy * @ddc_adapt: i2c ddc adapter * @colorspace: current colorspace selected - * @hdmi_monitor: true if HDMI monitor detected else DVI monitor assumed * @audio_pdev: ASoC hdmi-codec platform device * @audio: hdmi audio parameters. * @drm_connector: hdmi connector @@ -83,7 +82,6 @@ struct sti_hdmi { struct reset_control *reset; struct i2c_adapter *ddc_adapt; enum hdmi_colorspace colorspace; - bool hdmi_monitor; struct platform_device *audio_pdev; struct hdmi_audio_params audio; struct drm_connector *drm_connector; -- 2.25.1