1 // SPDX-License-Identifier: GPL-2.0+
3 #include <kunit/test.h>
5 #include <drm/drm_device.h>
6 #include <drm/drm_file.h>
7 #include <drm/drm_format_helper.h>
8 #include <drm/drm_fourcc.h>
9 #include <drm/drm_framebuffer.h>
10 #include <drm/drm_gem_framebuffer_helper.h>
11 #include <drm/drm_mode.h>
12 #include <drm/drm_print.h>
13 #include <drm/drm_rect.h>
15 #include "../drm_crtc_internal.h"
17 #define TEST_BUF_SIZE 50
19 struct convert_to_gray8_result {
20 unsigned int dst_pitch;
21 const u8 expected[TEST_BUF_SIZE];
24 struct convert_to_rgb332_result {
25 unsigned int dst_pitch;
26 const u8 expected[TEST_BUF_SIZE];
29 struct convert_to_rgb565_result {
30 unsigned int dst_pitch;
31 const u16 expected[TEST_BUF_SIZE];
32 const u16 expected_swab[TEST_BUF_SIZE];
35 struct convert_to_xrgb1555_result {
36 unsigned int dst_pitch;
37 const u16 expected[TEST_BUF_SIZE];
40 struct convert_to_argb1555_result {
41 unsigned int dst_pitch;
42 const u16 expected[TEST_BUF_SIZE];
45 struct convert_to_rgba5551_result {
46 unsigned int dst_pitch;
47 const u16 expected[TEST_BUF_SIZE];
50 struct convert_to_rgb888_result {
51 unsigned int dst_pitch;
52 const u8 expected[TEST_BUF_SIZE];
55 struct convert_to_argb8888_result {
56 unsigned int dst_pitch;
57 const u32 expected[TEST_BUF_SIZE];
60 struct convert_to_xrgb2101010_result {
61 unsigned int dst_pitch;
62 const u32 expected[TEST_BUF_SIZE];
65 struct convert_to_argb2101010_result {
66 unsigned int dst_pitch;
67 const u32 expected[TEST_BUF_SIZE];
70 struct convert_to_mono_result {
71 unsigned int dst_pitch;
72 const u8 expected[TEST_BUF_SIZE];
75 struct convert_xrgb8888_case {
79 const u32 xrgb8888[TEST_BUF_SIZE];
80 struct convert_to_gray8_result gray8_result;
81 struct convert_to_rgb332_result rgb332_result;
82 struct convert_to_rgb565_result rgb565_result;
83 struct convert_to_xrgb1555_result xrgb1555_result;
84 struct convert_to_argb1555_result argb1555_result;
85 struct convert_to_rgba5551_result rgba5551_result;
86 struct convert_to_rgb888_result rgb888_result;
87 struct convert_to_argb8888_result argb8888_result;
88 struct convert_to_xrgb2101010_result xrgb2101010_result;
89 struct convert_to_argb2101010_result argb2101010_result;
90 struct convert_to_mono_result mono_result;
93 static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
95 .name = "single_pixel_source_buffer",
97 .clip = DRM_RECT_INIT(0, 0, 1, 1),
98 .xrgb8888 = { 0x01FF0000 },
101 .expected = { 0x4C },
105 .expected = { 0xE0 },
109 .expected = { 0xF800 },
110 .expected_swab = { 0x00F8 },
114 .expected = { 0x7C00 },
118 .expected = { 0xFC00 },
122 .expected = { 0xF801 },
126 .expected = { 0x00, 0x00, 0xFF },
130 .expected = { 0xFFFF0000 },
132 .xrgb2101010_result = {
134 .expected = { 0x3FF00000 },
136 .argb2101010_result = {
138 .expected = { 0xFFF00000 },
146 .name = "single_pixel_clip_rectangle",
148 .clip = DRM_RECT_INIT(1, 1, 1, 1),
150 0x00000000, 0x00000000,
151 0x00000000, 0x10FF0000,
155 .expected = { 0x4C },
159 .expected = { 0xE0 },
163 .expected = { 0xF800 },
164 .expected_swab = { 0x00F8 },
168 .expected = { 0x7C00 },
172 .expected = { 0xFC00 },
176 .expected = { 0xF801 },
180 .expected = { 0x00, 0x00, 0xFF },
184 .expected = { 0xFFFF0000 },
186 .xrgb2101010_result = {
188 .expected = { 0x3FF00000 },
190 .argb2101010_result = {
192 .expected = { 0xFFF00000 },
200 /* Well known colors: White, black, red, green, blue, magenta,
201 * yellow and cyan. Different values for the X in XRGB8888 to
202 * make sure it is ignored. Partial clip area.
204 .name = "well_known_colors",
206 .clip = DRM_RECT_INIT(1, 1, 2, 4),
208 0x00000000, 0x00000000, 0x00000000, 0x00000000,
209 0x00000000, 0x11FFFFFF, 0x22000000, 0x00000000,
210 0x00000000, 0x33FF0000, 0x4400FF00, 0x00000000,
211 0x00000000, 0x550000FF, 0x66FF00FF, 0x00000000,
212 0x00000000, 0x77FFFF00, 0x8800FFFF, 0x00000000,
277 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
278 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00,
279 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF,
280 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
286 0xFFFFFFFF, 0xFF000000,
287 0xFFFF0000, 0xFF00FF00,
288 0xFF0000FF, 0xFFFF00FF,
289 0xFFFFFF00, 0xFF00FFFF,
292 .xrgb2101010_result = {
295 0x3FFFFFFF, 0x00000000,
296 0x3FF00000, 0x000FFC00,
297 0x000003FF, 0x3FF003FF,
298 0x3FFFFC00, 0x000FFFFF,
301 .argb2101010_result = {
304 0xFFFFFFFF, 0xC0000000,
305 0xFFF00000, 0xC00FFC00,
306 0xC00003FF, 0xFFF003FF,
307 0xFFFFFC00, 0xC00FFFFF,
321 /* Randomly picked colors. Full buffer within the clip area. */
322 .name = "destination_pitch",
324 .clip = DRM_RECT_INIT(0, 0, 3, 3),
326 0xA10E449C, 0xB1114D05, 0xC1A8F303,
327 0xD16CF073, 0xA20E449C, 0xB2114D05,
328 0xC2A80303, 0xD26CF073, 0xA30E449C,
333 0x3C, 0x33, 0xC4, 0x00, 0x00,
334 0xBB, 0x3C, 0x33, 0x00, 0x00,
335 0x34, 0xBB, 0x3C, 0x00, 0x00,
341 0x0A, 0x08, 0xBC, 0x00, 0x00,
342 0x7D, 0x0A, 0x08, 0x00, 0x00,
343 0xA0, 0x7D, 0x0A, 0x00, 0x00,
349 0x0A33, 0x1260, 0xAF80, 0x0000, 0x0000,
350 0x6F8E, 0x0A33, 0x1260, 0x0000, 0x0000,
351 0xA800, 0x6F8E, 0x0A33, 0x0000, 0x0000,
354 0x330A, 0x6012, 0x80AF, 0x0000, 0x0000,
355 0x8E6F, 0x330A, 0x6012, 0x0000, 0x0000,
356 0x00A8, 0x8E6F, 0x330A, 0x0000, 0x0000,
362 0x0513, 0x0920, 0x57C0, 0x0000, 0x0000,
363 0x37CE, 0x0513, 0x0920, 0x0000, 0x0000,
364 0x5400, 0x37CE, 0x0513, 0x0000, 0x0000,
370 0x8513, 0x8920, 0xD7C0, 0x0000, 0x0000,
371 0xB7CE, 0x8513, 0x8920, 0x0000, 0x0000,
372 0xD400, 0xB7CE, 0x8513, 0x0000, 0x0000,
378 0x0A27, 0x1241, 0xAF81, 0x0000, 0x0000,
379 0x6F9D, 0x0A27, 0x1241, 0x0000, 0x0000,
380 0xA801, 0x6F9D, 0x0A27, 0x0000, 0x0000,
386 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, 0x03, 0xF3, 0xA8,
387 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
388 0x73, 0xF0, 0x6C, 0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11,
389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
390 0x03, 0x03, 0xA8, 0x73, 0xF0, 0x6C, 0x9C, 0x44, 0x0E,
391 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
397 0xFF0E449C, 0xFF114D05, 0xFFA8F303, 0x00000000, 0x00000000,
398 0xFF6CF073, 0xFF0E449C, 0xFF114D05, 0x00000000, 0x00000000,
399 0xFFA80303, 0xFF6CF073, 0xFF0E449C, 0x00000000, 0x00000000,
402 .xrgb2101010_result = {
405 0x03844672, 0x0444D414, 0x2A2F3C0C, 0x00000000, 0x00000000,
406 0x1B1F0DCD, 0x03844672, 0x0444D414, 0x00000000, 0x00000000,
407 0x2A20300C, 0x1B1F0DCD, 0x03844672, 0x00000000, 0x00000000,
410 .argb2101010_result = {
413 0xC3844672, 0xC444D414, 0xEA2F3C0C, 0x00000000, 0x00000000,
414 0xDB1F0DCD, 0xC3844672, 0xC444D414, 0x00000000, 0x00000000,
415 0xEA20300C, 0xDB1F0DCD, 0xC3844672, 0x00000000, 0x00000000,
430 * conversion_buf_size - Return the destination buffer size required to convert
432 * @dst_format: destination buffer pixel format (DRM_FORMAT_*)
433 * @dst_pitch: Number of bytes between two consecutive scanlines within dst
434 * @clip: Clip rectangle area to convert
437 * The size of the destination buffer or negative value on error.
439 static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch,
440 const struct drm_rect *clip)
442 const struct drm_format_info *dst_fi = drm_format_info(dst_format);
448 dst_pitch = drm_format_info_min_pitch(dst_fi, 0, drm_rect_width(clip));
450 return dst_pitch * drm_rect_height(clip);
453 static u16 *le16buf_to_cpu(struct kunit *test, const __le16 *buf, size_t buf_size)
458 dst = kunit_kzalloc(test, sizeof(*dst) * buf_size, GFP_KERNEL);
462 for (n = 0; n < buf_size; n++)
463 dst[n] = le16_to_cpu(buf[n]);
468 static u32 *le32buf_to_cpu(struct kunit *test, const __le32 *buf, size_t buf_size)
473 dst = kunit_kzalloc(test, sizeof(*dst) * buf_size, GFP_KERNEL);
477 for (n = 0; n < buf_size; n++)
478 dst[n] = le32_to_cpu((__force __le32)buf[n]);
483 static __le32 *cpubuf_to_le32(struct kunit *test, const u32 *buf, size_t buf_size)
488 dst = kunit_kzalloc(test, sizeof(*dst) * buf_size, GFP_KERNEL);
492 for (n = 0; n < buf_size; n++)
493 dst[n] = cpu_to_le32(buf[n]);
498 static void convert_xrgb8888_case_desc(struct convert_xrgb8888_case *t,
501 strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
504 KUNIT_ARRAY_PARAM(convert_xrgb8888, convert_xrgb8888_cases,
505 convert_xrgb8888_case_desc);
507 static void drm_test_fb_xrgb8888_to_gray8(struct kunit *test)
509 const struct convert_xrgb8888_case *params = test->param_value;
510 const struct convert_to_gray8_result *result = ¶ms->gray8_result;
513 __le32 *xrgb8888 = NULL;
514 struct iosys_map dst, src;
516 struct drm_framebuffer fb = {
517 .format = drm_format_info(DRM_FORMAT_XRGB8888),
518 .pitches = { params->pitch, 0, 0 },
521 dst_size = conversion_buf_size(DRM_FORMAT_R8, result->dst_pitch,
523 KUNIT_ASSERT_GT(test, dst_size, 0);
525 buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
526 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
527 iosys_map_set_vaddr(&dst, buf);
529 xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
530 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
531 iosys_map_set_vaddr(&src, xrgb8888);
533 drm_fb_xrgb8888_to_gray8(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);
534 KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
537 static void drm_test_fb_xrgb8888_to_rgb332(struct kunit *test)
539 const struct convert_xrgb8888_case *params = test->param_value;
540 const struct convert_to_rgb332_result *result = ¶ms->rgb332_result;
543 __le32 *xrgb8888 = NULL;
544 struct iosys_map dst, src;
546 struct drm_framebuffer fb = {
547 .format = drm_format_info(DRM_FORMAT_XRGB8888),
548 .pitches = { params->pitch, 0, 0 },
551 dst_size = conversion_buf_size(DRM_FORMAT_RGB332, result->dst_pitch,
553 KUNIT_ASSERT_GT(test, dst_size, 0);
555 buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
556 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
557 iosys_map_set_vaddr(&dst, buf);
559 xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
560 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
561 iosys_map_set_vaddr(&src, xrgb8888);
563 drm_fb_xrgb8888_to_rgb332(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);
564 KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
567 static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test)
569 const struct convert_xrgb8888_case *params = test->param_value;
570 const struct convert_to_rgb565_result *result = ¶ms->rgb565_result;
573 __le32 *xrgb8888 = NULL;
574 struct iosys_map dst, src;
576 struct drm_framebuffer fb = {
577 .format = drm_format_info(DRM_FORMAT_XRGB8888),
578 .pitches = { params->pitch, 0, 0 },
581 dst_size = conversion_buf_size(DRM_FORMAT_RGB565, result->dst_pitch,
583 KUNIT_ASSERT_GT(test, dst_size, 0);
585 buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
586 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
587 iosys_map_set_vaddr(&dst, buf);
589 xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
590 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
591 iosys_map_set_vaddr(&src, xrgb8888);
593 drm_fb_xrgb8888_to_rgb565(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, false);
594 buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
595 KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
597 buf = dst.vaddr; /* restore original value of buf */
598 drm_fb_xrgb8888_to_rgb565(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, true);
599 buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
600 KUNIT_EXPECT_MEMEQ(test, buf, result->expected_swab, dst_size);
603 static void drm_test_fb_xrgb8888_to_xrgb1555(struct kunit *test)
605 const struct convert_xrgb8888_case *params = test->param_value;
606 const struct convert_to_xrgb1555_result *result = ¶ms->xrgb1555_result;
609 __le32 *xrgb8888 = NULL;
610 struct iosys_map dst, src;
612 struct drm_framebuffer fb = {
613 .format = drm_format_info(DRM_FORMAT_XRGB8888),
614 .pitches = { params->pitch, 0, 0 },
617 dst_size = conversion_buf_size(DRM_FORMAT_XRGB1555, result->dst_pitch,
619 KUNIT_ASSERT_GT(test, dst_size, 0);
621 buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
622 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
623 iosys_map_set_vaddr(&dst, buf);
625 xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
626 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
627 iosys_map_set_vaddr(&src, xrgb8888);
629 drm_fb_xrgb8888_to_xrgb1555(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);
630 buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
631 KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
634 static void drm_test_fb_xrgb8888_to_argb1555(struct kunit *test)
636 const struct convert_xrgb8888_case *params = test->param_value;
637 const struct convert_to_argb1555_result *result = ¶ms->argb1555_result;
640 __le32 *xrgb8888 = NULL;
641 struct iosys_map dst, src;
643 struct drm_framebuffer fb = {
644 .format = drm_format_info(DRM_FORMAT_XRGB8888),
645 .pitches = { params->pitch, 0, 0 },
648 dst_size = conversion_buf_size(DRM_FORMAT_ARGB1555, result->dst_pitch,
650 KUNIT_ASSERT_GT(test, dst_size, 0);
652 buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
653 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
654 iosys_map_set_vaddr(&dst, buf);
656 xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
657 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
658 iosys_map_set_vaddr(&src, xrgb8888);
660 drm_fb_xrgb8888_to_argb1555(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);
661 buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
662 KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
665 static void drm_test_fb_xrgb8888_to_rgba5551(struct kunit *test)
667 const struct convert_xrgb8888_case *params = test->param_value;
668 const struct convert_to_rgba5551_result *result = ¶ms->rgba5551_result;
671 __le32 *xrgb8888 = NULL;
672 struct iosys_map dst, src;
674 struct drm_framebuffer fb = {
675 .format = drm_format_info(DRM_FORMAT_XRGB8888),
676 .pitches = { params->pitch, 0, 0 },
679 dst_size = conversion_buf_size(DRM_FORMAT_RGBA5551, result->dst_pitch,
681 KUNIT_ASSERT_GT(test, dst_size, 0);
683 buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
684 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
685 iosys_map_set_vaddr(&dst, buf);
687 xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
688 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
689 iosys_map_set_vaddr(&src, xrgb8888);
691 drm_fb_xrgb8888_to_rgba5551(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);
692 buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
693 KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
696 static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test)
698 const struct convert_xrgb8888_case *params = test->param_value;
699 const struct convert_to_rgb888_result *result = ¶ms->rgb888_result;
702 __le32 *xrgb8888 = NULL;
703 struct iosys_map dst, src;
705 struct drm_framebuffer fb = {
706 .format = drm_format_info(DRM_FORMAT_XRGB8888),
707 .pitches = { params->pitch, 0, 0 },
710 dst_size = conversion_buf_size(DRM_FORMAT_RGB888, result->dst_pitch,
712 KUNIT_ASSERT_GT(test, dst_size, 0);
714 buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
715 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
716 iosys_map_set_vaddr(&dst, buf);
718 xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
719 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
720 iosys_map_set_vaddr(&src, xrgb8888);
723 * RGB888 expected results are already in little-endian
724 * order, so there's no need to convert the test output.
726 drm_fb_xrgb8888_to_rgb888(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);
727 KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
730 static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test)
732 const struct convert_xrgb8888_case *params = test->param_value;
733 const struct convert_to_argb8888_result *result = ¶ms->argb8888_result;
736 __le32 *xrgb8888 = NULL;
737 struct iosys_map dst, src;
739 struct drm_framebuffer fb = {
740 .format = drm_format_info(DRM_FORMAT_XRGB8888),
741 .pitches = { params->pitch, 0, 0 },
744 dst_size = conversion_buf_size(DRM_FORMAT_ARGB8888,
745 result->dst_pitch, ¶ms->clip);
746 KUNIT_ASSERT_GT(test, dst_size, 0);
748 buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
749 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
750 iosys_map_set_vaddr(&dst, buf);
752 xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
753 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
754 iosys_map_set_vaddr(&src, xrgb8888);
756 drm_fb_xrgb8888_to_argb8888(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);
757 buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
758 KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
761 static void drm_test_fb_xrgb8888_to_xrgb2101010(struct kunit *test)
763 const struct convert_xrgb8888_case *params = test->param_value;
764 const struct convert_to_xrgb2101010_result *result = ¶ms->xrgb2101010_result;
767 __le32 *xrgb8888 = NULL;
768 struct iosys_map dst, src;
770 struct drm_framebuffer fb = {
771 .format = drm_format_info(DRM_FORMAT_XRGB8888),
772 .pitches = { params->pitch, 0, 0 },
775 dst_size = conversion_buf_size(DRM_FORMAT_XRGB2101010,
776 result->dst_pitch, ¶ms->clip);
777 KUNIT_ASSERT_GT(test, dst_size, 0);
779 buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
780 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
781 iosys_map_set_vaddr(&dst, buf);
783 xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
784 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
785 iosys_map_set_vaddr(&src, xrgb8888);
787 drm_fb_xrgb8888_to_xrgb2101010(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);
788 buf = le32buf_to_cpu(test, buf, dst_size / sizeof(u32));
789 KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
792 static void drm_test_fb_xrgb8888_to_argb2101010(struct kunit *test)
794 const struct convert_xrgb8888_case *params = test->param_value;
795 const struct convert_to_argb2101010_result *result = ¶ms->argb2101010_result;
798 __le32 *xrgb8888 = NULL;
799 struct iosys_map dst, src;
801 struct drm_framebuffer fb = {
802 .format = drm_format_info(DRM_FORMAT_XRGB8888),
803 .pitches = { params->pitch, 0, 0 },
806 dst_size = conversion_buf_size(DRM_FORMAT_ARGB2101010,
807 result->dst_pitch, ¶ms->clip);
808 KUNIT_ASSERT_GT(test, dst_size, 0);
810 buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
811 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
812 iosys_map_set_vaddr(&dst, buf);
814 xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
815 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
816 iosys_map_set_vaddr(&src, xrgb8888);
818 drm_fb_xrgb8888_to_argb2101010(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);
819 buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
820 KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
823 static void drm_test_fb_xrgb8888_to_mono(struct kunit *test)
825 const struct convert_xrgb8888_case *params = test->param_value;
826 const struct convert_to_mono_result *result = ¶ms->mono_result;
829 __le32 *xrgb8888 = NULL;
830 struct iosys_map dst, src;
832 struct drm_framebuffer fb = {
833 .format = drm_format_info(DRM_FORMAT_XRGB8888),
834 .pitches = { params->pitch, 0, 0 },
837 dst_size = conversion_buf_size(DRM_FORMAT_C1, result->dst_pitch, ¶ms->clip);
839 KUNIT_ASSERT_GT(test, dst_size, 0);
841 buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
842 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
843 iosys_map_set_vaddr(&dst, buf);
845 xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
846 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
847 iosys_map_set_vaddr(&src, xrgb8888);
849 drm_fb_xrgb8888_to_mono(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);
850 KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
853 static struct kunit_case drm_format_helper_test_cases[] = {
854 KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_gray8, convert_xrgb8888_gen_params),
855 KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params),
856 KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb565, convert_xrgb8888_gen_params),
857 KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb1555, convert_xrgb8888_gen_params),
858 KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb1555, convert_xrgb8888_gen_params),
859 KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgba5551, convert_xrgb8888_gen_params),
860 KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888, convert_xrgb8888_gen_params),
861 KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb8888, convert_xrgb8888_gen_params),
862 KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010, convert_xrgb8888_gen_params),
863 KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb2101010, convert_xrgb8888_gen_params),
864 KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_mono, convert_xrgb8888_gen_params),
868 static struct kunit_suite drm_format_helper_test_suite = {
869 .name = "drm_format_helper_test",
870 .test_cases = drm_format_helper_test_cases,
873 kunit_test_suite(drm_format_helper_test_suite);
875 MODULE_DESCRIPTION("KUnit tests for the drm_format_helper APIs");
876 MODULE_LICENSE("GPL");