Message ID | 20230721182316.560649-7-arthurgrillo@riseup.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Increase code coverage on drm_format_helper.c | expand |
Hi Arthur, kernel test robot noticed the following build warnings: [auto build test WARNING on drm-misc/drm-misc-next] [also build test WARNING on drm/drm-next drm-exynos/exynos-drm-next drm-intel/for-linux-next drm-intel/for-linux-next-fixes drm-tip/drm-tip linus/master v6.5-rc3 next-20230725] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Arthur-Grillo/drm-format-helper-Test-default-pitch-fallback/20230722-022649 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20230721182316.560649-7-arthurgrillo%40riseup.net patch subject: [PATCH 6/6] drm/format-helper: Add KUnit tests for drm_fb_memcpy() config: nios2-randconfig-r093-20230723 (https://download.01.org/0day-ci/archive/20230725/202307252148.wr2nafKj-lkp@intel.com/config) compiler: nios2-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230725/202307252148.wr2nafKj-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202307252148.wr2nafKj-lkp@intel.com/ sparse warnings: (new ones prefixed by >>) drivers/gpu/drm/tests/drm_format_helper_test.c:856:36: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected restricted __le32 const [usertype] *buf @@ got unsigned int [usertype] *[assigned] buf @@ drivers/gpu/drm/tests/drm_format_helper_test.c:856:36: sparse: expected restricted __le32 const [usertype] *buf drivers/gpu/drm/tests/drm_format_helper_test.c:856:36: sparse: got unsigned int [usertype] *[assigned] buf drivers/gpu/drm/tests/drm_format_helper_test.c:1058:34: sparse: sparse: symbol 'fb_build_fourcc_list_cases' was not declared. Should it be static? >> drivers/gpu/drm/tests/drm_format_helper_test.c:1566:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [usertype] * @@ got restricted __le32 [usertype] * @@ drivers/gpu/drm/tests/drm_format_helper_test.c:1566:27: sparse: expected unsigned int [usertype] * drivers/gpu/drm/tests/drm_format_helper_test.c:1566:27: sparse: got restricted __le32 [usertype] * drivers/gpu/drm/tests/drm_format_helper_test.c:1576:29: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [usertype] * @@ got restricted __le32 [usertype] * @@ drivers/gpu/drm/tests/drm_format_helper_test.c:1576:29: sparse: expected unsigned int [usertype] * drivers/gpu/drm/tests/drm_format_helper_test.c:1576:29: sparse: got restricted __le32 [usertype] * vim +1566 drivers/gpu/drm/tests/drm_format_helper_test.c 1539 1540 static void drm_test_fb_memcpy(struct kunit *test) 1541 { 1542 const struct multi_plane_op_case *params = test->param_value; 1543 const struct fb_memcpy_result *result = ¶ms->memcpy_result; 1544 size_t dst_size[DRM_FORMAT_MAX_PLANES] = { 0 }; 1545 u32 *buf[DRM_FORMAT_MAX_PLANES] = { 0 }; 1546 u32 *src_cp[DRM_FORMAT_MAX_PLANES] = { 0 }; 1547 u32 *expected[DRM_FORMAT_MAX_PLANES] = { 0 }; 1548 struct iosys_map dst[DRM_FORMAT_MAX_PLANES]; 1549 struct iosys_map src[DRM_FORMAT_MAX_PLANES]; 1550 1551 struct drm_framebuffer fb = { 1552 .format = drm_format_info(params->format), 1553 }; 1554 1555 memcpy(fb.pitches, params->src_pitches, DRM_FORMAT_MAX_PLANES * sizeof(int)); 1556 1557 for (size_t i = 0; i < fb.format->num_planes; i++) { 1558 dst_size[i] = conversion_buf_size(params->format, result->dst_pitches[i], 1559 ¶ms->clip, i); 1560 KUNIT_ASSERT_GT(test, dst_size[i], 0); 1561 1562 buf[i] = kunit_kzalloc(test, dst_size[i], GFP_KERNEL); 1563 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf[i]); 1564 iosys_map_set_vaddr(&dst[i], buf[i]); 1565 > 1566 src_cp[i] = cpubuf_to_le32(test, params->src[i], TEST_BUF_SIZE); 1567 iosys_map_set_vaddr(&src[i], src_cp[i]); 1568 } 1569 1570 if (result->dst_pitches[0] == TEST_USE_DEFAULT_PITCH) 1571 drm_fb_memcpy(dst, NULL, src, &fb, ¶ms->clip); 1572 else 1573 drm_fb_memcpy(dst, result->dst_pitches, src, &fb, ¶ms->clip); 1574 1575 for (size_t i = 0; i < fb.format->num_planes; i++) { 1576 expected[i] = cpubuf_to_le32(test, result->expected[i], TEST_BUF_SIZE); 1577 KUNIT_EXPECT_MEMEQ_MSG(test, buf[i], expected[i], dst_size[i], 1578 "Failed expectation on plane %zu", i); 1579 } 1580 } 1581
On 7/21/23 15:23, Arthur Grillo wrote: > Insert parameterized test for the drm_fb_memcpy() to ensure correctness > and prevent future regressions. The test case can accept different > formats. > > Signed-off-by: Arthur Grillo <arthurgrillo@riseup.net> > --- > .../gpu/drm/tests/drm_format_helper_test.c | 391 ++++++++++++++++++ > 1 file changed, 391 insertions(+) > > diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c > index 6ecd92898e8e..3db4b95f3a98 100644 > --- a/drivers/gpu/drm/tests/drm_format_helper_test.c > +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c > @@ -1189,6 +1189,396 @@ static void drm_test_fb_build_fourcc_list(struct kunit *test) > KUNIT_EXPECT_MEMEQ(test, fourccs_out, params->expected, TEST_BUF_SIZE); > } > > +struct fb_memcpy_result { > + unsigned int dst_pitches[DRM_FORMAT_MAX_PLANES]; > + const u32 expected[DRM_FORMAT_MAX_PLANES][TEST_BUF_SIZE]; > +}; > + > +struct multi_plane_op_case { > + const char *name; > + u32 format; > + struct drm_rect clip; > + unsigned int src_pitches[DRM_FORMAT_MAX_PLANES]; > + const u32 src[DRM_FORMAT_MAX_PLANES][TEST_BUF_SIZE]; > + struct fb_memcpy_result memcpy_result; > +}; > + > +/* The `src` and `expected` buffers are u32 arrays. To deal with planes that > + * have a cpp != 4 the values are stored together on the same u32 number in a > + * way so the order in memory is correct in a little-endian machine. > + * > + * Because of that, on some occasions, parts of a u32 will not be part of the > + * test, to make this explicit the 0xFF byte is used on those parts. > + */ > + > +static struct multi_plane_op_case multi_plane_op_cases[] = { > + { > + .name = "single_pixel_source_buffer", > + .format = DRM_FORMAT_XRGB8888, > + .clip = DRM_RECT_INIT(0, 0, 1, 1), > + .src_pitches = { 1 * 4 }, > + .src = {{ 0x01020304 }}, > + .memcpy_result = { > + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, > + .expected = {{ 0x01020304 }}, > + } > + }, > + { > + .name = "single_pixel_source_buffer", > + .format = DRM_FORMAT_XRGB8888_A8, > + .clip = DRM_RECT_INIT(0, 0, 1, 1), > + .src_pitches = { 1 * 4, 1 }, > + .src = { > + { 0x01020304 }, > + { 0xFFFFFF01 }, > + }, > + .memcpy_result = { > + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, > + .expected = { > + { 0x01020304 }, > + { 0x00000001 }, > + }, > + }, > + }, Some tests have the same description name. Could you distinct them with different names? Best Regards, - Maíra > + { > + .name = "single_pixel_source_buffer", > + .format = DRM_FORMAT_YUV444, > + .clip = DRM_RECT_INIT(0, 0, 1, 1), > + .src_pitches = { 1, 1, 1 }, > + .src = { > + { 0xFFFFFF01 }, > + { 0xFFFFFF01 }, > + { 0xFFFFFF01 }, > + }, > + .memcpy_result = { > + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, > + .expected = { > + { 0x00000001 }, > + { 0x00000001 }, > + { 0x00000001 }, > + }, > + }, > + }, > + { > + .name = "single_pixel_clip_rectangle", > + .format = DRM_FORMAT_XBGR8888, > + .clip = DRM_RECT_INIT(1, 1, 1, 1), > + .src_pitches = { 2 * 4 }, > + .src = { > + { > + 0x00000000, 0x00000000, > + 0x00000000, 0x01020304, > + }, > + }, > + .memcpy_result = { > + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, > + .expected = { > + { 0x01020304 }, > + }, > + }, > + }, > + { > + .name = "single_pixel_clip_rectangle", > + .format = DRM_FORMAT_XRGB8888_A8, > + .clip = DRM_RECT_INIT(1, 1, 1, 1), > + .src_pitches = { 2 * 4, 2 * 1 }, > + .src = { > + { > + 0x00000000, 0x00000000, > + 0x00000000, 0x01020304, > + }, > + { 0x01000000 }, > + }, > + .memcpy_result = { > + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, > + .expected = { > + { 0x01020304 }, > + { 0x00000001 }, > + }, > + }, > + }, > + { > + .name = "single_pixel_clip_rectangle", > + .format = DRM_FORMAT_YUV444, > + .clip = DRM_RECT_INIT(1, 1, 1, 1), > + .src_pitches = { 2 * 1, 2 * 1, 2 * 1 }, > + .src = { > + { 0x01000000 }, > + { 0x01000000 }, > + { 0x01000000 }, > + }, > + .memcpy_result = { > + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, > + .expected = { > + { 0x00000001 }, > + { 0x00000001 }, > + { 0x00000001 }, > + }, > + }, > + }, > + { > + .name = "well_known_colors", > + .format = DRM_FORMAT_XBGR8888, > + .clip = DRM_RECT_INIT(1, 1, 2, 4), > + .src_pitches = { 4 * 4 }, > + .src = { > + { > + 0x00000000, 0x00000000, 0x00000000, 0x00000000, > + 0x00000000, 0x11FFFFFF, 0x22000000, 0x00000000, > + 0x00000000, 0x33FF0000, 0x4400FF00, 0x00000000, > + 0x00000000, 0x550000FF, 0x66FF00FF, 0x00000000, > + 0x00000000, 0x77FFFF00, 0x8800FFFF, 0x00000000, > + }, > + }, > + .memcpy_result = { > + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, > + .expected = { > + { > + 0x11FFFFFF, 0x22000000, > + 0x33FF0000, 0x4400FF00, > + 0x550000FF, 0x66FF00FF, > + 0x77FFFF00, 0x8800FFFF, > + }, > + }, > + }, > + }, > + { > + .name = "well_known_colors", > + .format = DRM_FORMAT_XRGB8888_A8, > + .clip = DRM_RECT_INIT(1, 1, 2, 4), > + .src_pitches = { 4 * 4, 4 * 1 }, > + .src = { > + { > + 0x00000000, 0x00000000, 0x00000000, 0x00000000, > + 0x00000000, 0xFFFFFFFF, 0xFF000000, 0x00000000, > + 0x00000000, 0xFFFF0000, 0xFF00FF00, 0x00000000, > + 0x00000000, 0xFF0000FF, 0xFFFF00FF, 0x00000000, > + 0x00000000, 0xFFFFFF00, 0xFF00FFFF, 0x00000000, > + }, > + { > + 0x00000000, > + 0x00221100, > + 0x00443300, > + 0x00665500, > + 0x00887700, > + }, > + }, > + .memcpy_result = { > + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, > + .expected = { > + { > + 0xFFFFFFFF, 0xFF000000, > + 0xFFFF0000, 0xFF00FF00, > + 0xFF0000FF, 0xFFFF00FF, > + 0xFFFFFF00, 0xFF00FFFF, > + }, > + { > + 0x44332211, > + 0x88776655, > + }, > + }, > + }, > + }, > + { > + .name = "well_known_colors", > + .format = DRM_FORMAT_YUV444, > + .clip = DRM_RECT_INIT(1, 1, 2, 4), > + .src_pitches = { 4 * 1, 4 * 1, 4 * 1 }, > + .src = { > + { > + 0x00000000, > + 0x0000FF00, > + 0x00954C00, > + 0x00691D00, > + 0x00B2E100, > + }, > + { > + 0x00000000, > + 0x00000000, > + 0x00BEDE00, > + 0x00436500, > + 0x00229B00, > + }, > + { > + 0x00000000, > + 0x00000000, > + 0x007E9C00, > + 0x0083E700, > + 0x00641A00, > + }, > + }, > + .memcpy_result = { > + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, > + .expected = { > + { > + 0x954C00FF, > + 0xB2E1691D, > + }, > + { > + 0xBEDE0000, > + 0x229B4365, > + }, > + { > + 0x7E9C0000, > + 0x641A83E7, > + }, > + }, > + }, > + }, > + { > + .name = "destination_pitch", > + .format = DRM_FORMAT_XBGR8888, > + .clip = DRM_RECT_INIT(0, 0, 3, 3), > + .src_pitches = { 3 * 4 }, > + .src = { > + { > + 0xA10E449C, 0xB1114D05, 0xC1A8F303, > + 0xD16CF073, 0xA20E449C, 0xB2114D05, > + 0xC2A80303, 0xD26CF073, 0xA30E449C, > + }, > + }, > + .memcpy_result = { > + .dst_pitches = { 5 * 4 }, > + .expected = { > + { > + 0xA10E449C, 0xB1114D05, 0xC1A8F303, 0x00000000, 0x00000000, > + 0xD16CF073, 0xA20E449C, 0xB2114D05, 0x00000000, 0x00000000, > + 0xC2A80303, 0xD26CF073, 0xA30E449C, 0x00000000, 0x00000000, > + }, > + }, > + }, > + }, > + { > + .name = "destination_pitch", > + .format = DRM_FORMAT_XRGB8888_A8, > + .clip = DRM_RECT_INIT(0, 0, 3, 3), > + .src_pitches = { 3 * 4, 3 * 1 }, > + .src = { > + { > + 0xFF0E449C, 0xFF114D05, 0xFFA8F303, > + 0xFF6CF073, 0xFF0E449C, 0xFF114D05, > + 0xFFA80303, 0xFF6CF073, 0xFF0E449C, > + }, > + { > + 0xB2C1B1A1, > + 0xD2A3D1A2, > + 0xFFFFFFC2, > + }, > + }, > + .memcpy_result = { > + .dst_pitches = { 5 * 4, 5 * 1 }, > + .expected = { > + { > + 0xFF0E449C, 0xFF114D05, 0xFFA8F303, 0x00000000, 0x00000000, > + 0xFF6CF073, 0xFF0E449C, 0xFF114D05, 0x00000000, 0x00000000, > + 0xFFA80303, 0xFF6CF073, 0xFF0E449C, 0x00000000, 0x00000000, > + }, > + { > + 0x00C1B1A1, > + 0xD1A2B200, > + 0xD2A30000, > + 0xFF0000C2, > + }, > + }, > + }, > + }, > + { > + .name = "destination_pitch", > + .format = DRM_FORMAT_YUV444, > + .clip = DRM_RECT_INIT(0, 0, 3, 3), > + .src_pitches = { 3 * 1, 3 * 1, 3 * 1 }, > + .src = { > + { > + 0xBAC1323D, > + 0xBA34323D, > + 0xFFFFFF3D, > + }, > + { > + 0xE1ABEC2A, > + 0xE1EAEC2A, > + 0xFFFFFF2A, > + }, > + { > + 0xBCEBE4D7, > + 0xBC65E4D7, > + 0xFFFFFFD7, > + }, > + }, > + .memcpy_result = { > + .dst_pitches = { 5 * 1, 5 * 1, 5 * 1 }, > + .expected = { > + { > + 0x00C1323D, > + 0x323DBA00, > + 0xBA340000, > + 0xFF00003D, > + }, > + { > + 0x00ABEC2A, > + 0xEC2AE100, > + 0xE1EA0000, > + 0xFF00002A, > + }, > + { > + 0x00EBE4D7, > + 0xE4D7BC00, > + 0xBC650000, > + 0xFF0000D7, > + }, > + }, > + }, > + }, > +}; > + > +static void multi_plane_op_case_desc(struct multi_plane_op_case *t, char *desc) > +{ > + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s: %p4cc", t->name, &t->format); > +} > + > +KUNIT_ARRAY_PARAM(multi_plane_op, multi_plane_op_cases, multi_plane_op_case_desc); > + > +static void drm_test_fb_memcpy(struct kunit *test) > +{ > + const struct multi_plane_op_case *params = test->param_value; > + const struct fb_memcpy_result *result = ¶ms->memcpy_result; > + size_t dst_size[DRM_FORMAT_MAX_PLANES] = { 0 }; > + u32 *buf[DRM_FORMAT_MAX_PLANES] = { 0 }; > + u32 *src_cp[DRM_FORMAT_MAX_PLANES] = { 0 }; > + u32 *expected[DRM_FORMAT_MAX_PLANES] = { 0 }; > + struct iosys_map dst[DRM_FORMAT_MAX_PLANES]; > + struct iosys_map src[DRM_FORMAT_MAX_PLANES]; > + > + struct drm_framebuffer fb = { > + .format = drm_format_info(params->format), > + }; > + > + memcpy(fb.pitches, params->src_pitches, DRM_FORMAT_MAX_PLANES * sizeof(int)); > + > + for (size_t i = 0; i < fb.format->num_planes; i++) { > + dst_size[i] = conversion_buf_size(params->format, result->dst_pitches[i], > + ¶ms->clip, i); > + KUNIT_ASSERT_GT(test, dst_size[i], 0); > + > + buf[i] = kunit_kzalloc(test, dst_size[i], GFP_KERNEL); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf[i]); > + iosys_map_set_vaddr(&dst[i], buf[i]); > + > + src_cp[i] = cpubuf_to_le32(test, params->src[i], TEST_BUF_SIZE); > + iosys_map_set_vaddr(&src[i], src_cp[i]); > + } > + > + if (result->dst_pitches[0] == TEST_USE_DEFAULT_PITCH) > + drm_fb_memcpy(dst, NULL, src, &fb, ¶ms->clip); > + else > + drm_fb_memcpy(dst, result->dst_pitches, src, &fb, ¶ms->clip); > + > + for (size_t i = 0; i < fb.format->num_planes; i++) { > + expected[i] = cpubuf_to_le32(test, result->expected[i], TEST_BUF_SIZE); > + KUNIT_EXPECT_MEMEQ_MSG(test, buf[i], expected[i], dst_size[i], > + "Failed expectation on plane %zu", i); > + } > +} > + > static struct kunit_case drm_format_helper_test_cases[] = { > KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_gray8, convert_xrgb8888_gen_params), > KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params), > @@ -1204,6 +1594,7 @@ static struct kunit_case drm_format_helper_test_cases[] = { > KUNIT_CASE_PARAM(drm_test_fb_swab, convert_xrgb8888_gen_params), > KUNIT_CASE_PARAM(drm_test_fb_clip_offset, clip_offset_gen_params), > KUNIT_CASE_PARAM(drm_test_fb_build_fourcc_list, fb_build_fourcc_list_gen_params), > + KUNIT_CASE_PARAM(drm_test_fb_memcpy, multi_plane_op_gen_params), > {} > }; >
On 05/08/23 10:26, Maira Canal wrote: > On 7/21/23 15:23, Arthur Grillo wrote: >> Insert parameterized test for the drm_fb_memcpy() to ensure correctness >> and prevent future regressions. The test case can accept different >> formats. >> >> Signed-off-by: Arthur Grillo <arthurgrillo@riseup.net> >> --- >> .../gpu/drm/tests/drm_format_helper_test.c | 391 ++++++++++++++++++ >> 1 file changed, 391 insertions(+) >> >> diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c >> index 6ecd92898e8e..3db4b95f3a98 100644 >> --- a/drivers/gpu/drm/tests/drm_format_helper_test.c >> +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c >> @@ -1189,6 +1189,396 @@ static void drm_test_fb_build_fourcc_list(struct kunit *test) >> KUNIT_EXPECT_MEMEQ(test, fourccs_out, params->expected, TEST_BUF_SIZE); >> } >> +struct fb_memcpy_result { >> + unsigned int dst_pitches[DRM_FORMAT_MAX_PLANES]; >> + const u32 expected[DRM_FORMAT_MAX_PLANES][TEST_BUF_SIZE]; >> +}; >> + >> +struct multi_plane_op_case { >> + const char *name; >> + u32 format; >> + struct drm_rect clip; >> + unsigned int src_pitches[DRM_FORMAT_MAX_PLANES]; >> + const u32 src[DRM_FORMAT_MAX_PLANES][TEST_BUF_SIZE]; >> + struct fb_memcpy_result memcpy_result; >> +}; >> + >> +/* The `src` and `expected` buffers are u32 arrays. To deal with planes that >> + * have a cpp != 4 the values are stored together on the same u32 number in a >> + * way so the order in memory is correct in a little-endian machine. >> + * >> + * Because of that, on some occasions, parts of a u32 will not be part of the >> + * test, to make this explicit the 0xFF byte is used on those parts. >> + */ >> + >> +static struct multi_plane_op_case multi_plane_op_cases[] = { >> + { >> + .name = "single_pixel_source_buffer", >> + .format = DRM_FORMAT_XRGB8888, >> + .clip = DRM_RECT_INIT(0, 0, 1, 1), >> + .src_pitches = { 1 * 4 }, >> + .src = {{ 0x01020304 }}, >> + .memcpy_result = { >> + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, >> + .expected = {{ 0x01020304 }}, >> + } >> + }, >> + { >> + .name = "single_pixel_source_buffer", >> + .format = DRM_FORMAT_XRGB8888_A8, >> + .clip = DRM_RECT_INIT(0, 0, 1, 1), >> + .src_pitches = { 1 * 4, 1 }, >> + .src = { >> + { 0x01020304 }, >> + { 0xFFFFFF01 }, >> + }, >> + .memcpy_result = { >> + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, >> + .expected = { >> + { 0x01020304 }, >> + { 0x00000001 }, >> + }, >> + }, >> + }, > > Some tests have the same description name. Could you distinct them with > different names? The test description is formed not only by the `.name` attribute but also by the string representation of the `.format` attribute, so two test descriptions are distinct if they have the same `.name` but different `.format`. Best Regards, ~Arthur Grillo > > Best Regards, > - Maíra > >> + { >> + .name = "single_pixel_source_buffer", >> + .format = DRM_FORMAT_YUV444, >> + .clip = DRM_RECT_INIT(0, 0, 1, 1), >> + .src_pitches = { 1, 1, 1 }, >> + .src = { >> + { 0xFFFFFF01 }, >> + { 0xFFFFFF01 }, >> + { 0xFFFFFF01 }, >> + }, >> + .memcpy_result = { >> + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, >> + .expected = { >> + { 0x00000001 }, >> + { 0x00000001 }, >> + { 0x00000001 }, >> + }, >> + }, >> + }, >> + { >> + .name = "single_pixel_clip_rectangle", >> + .format = DRM_FORMAT_XBGR8888, >> + .clip = DRM_RECT_INIT(1, 1, 1, 1), >> + .src_pitches = { 2 * 4 }, >> + .src = { >> + { >> + 0x00000000, 0x00000000, >> + 0x00000000, 0x01020304, >> + }, >> + }, >> + .memcpy_result = { >> + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, >> + .expected = { >> + { 0x01020304 }, >> + }, >> + }, >> + }, >> + { >> + .name = "single_pixel_clip_rectangle", >> + .format = DRM_FORMAT_XRGB8888_A8, >> + .clip = DRM_RECT_INIT(1, 1, 1, 1), >> + .src_pitches = { 2 * 4, 2 * 1 }, >> + .src = { >> + { >> + 0x00000000, 0x00000000, >> + 0x00000000, 0x01020304, >> + }, >> + { 0x01000000 }, >> + }, >> + .memcpy_result = { >> + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, >> + .expected = { >> + { 0x01020304 }, >> + { 0x00000001 }, >> + }, >> + }, >> + }, >> + { >> + .name = "single_pixel_clip_rectangle", >> + .format = DRM_FORMAT_YUV444, >> + .clip = DRM_RECT_INIT(1, 1, 1, 1), >> + .src_pitches = { 2 * 1, 2 * 1, 2 * 1 }, >> + .src = { >> + { 0x01000000 }, >> + { 0x01000000 }, >> + { 0x01000000 }, >> + }, >> + .memcpy_result = { >> + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, >> + .expected = { >> + { 0x00000001 }, >> + { 0x00000001 }, >> + { 0x00000001 }, >> + }, >> + }, >> + }, >> + { >> + .name = "well_known_colors", >> + .format = DRM_FORMAT_XBGR8888, >> + .clip = DRM_RECT_INIT(1, 1, 2, 4), >> + .src_pitches = { 4 * 4 }, >> + .src = { >> + { >> + 0x00000000, 0x00000000, 0x00000000, 0x00000000, >> + 0x00000000, 0x11FFFFFF, 0x22000000, 0x00000000, >> + 0x00000000, 0x33FF0000, 0x4400FF00, 0x00000000, >> + 0x00000000, 0x550000FF, 0x66FF00FF, 0x00000000, >> + 0x00000000, 0x77FFFF00, 0x8800FFFF, 0x00000000, >> + }, >> + }, >> + .memcpy_result = { >> + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, >> + .expected = { >> + { >> + 0x11FFFFFF, 0x22000000, >> + 0x33FF0000, 0x4400FF00, >> + 0x550000FF, 0x66FF00FF, >> + 0x77FFFF00, 0x8800FFFF, >> + }, >> + }, >> + }, >> + }, >> + { >> + .name = "well_known_colors", >> + .format = DRM_FORMAT_XRGB8888_A8, >> + .clip = DRM_RECT_INIT(1, 1, 2, 4), >> + .src_pitches = { 4 * 4, 4 * 1 }, >> + .src = { >> + { >> + 0x00000000, 0x00000000, 0x00000000, 0x00000000, >> + 0x00000000, 0xFFFFFFFF, 0xFF000000, 0x00000000, >> + 0x00000000, 0xFFFF0000, 0xFF00FF00, 0x00000000, >> + 0x00000000, 0xFF0000FF, 0xFFFF00FF, 0x00000000, >> + 0x00000000, 0xFFFFFF00, 0xFF00FFFF, 0x00000000, >> + }, >> + { >> + 0x00000000, >> + 0x00221100, >> + 0x00443300, >> + 0x00665500, >> + 0x00887700, >> + }, >> + }, >> + .memcpy_result = { >> + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, >> + .expected = { >> + { >> + 0xFFFFFFFF, 0xFF000000, >> + 0xFFFF0000, 0xFF00FF00, >> + 0xFF0000FF, 0xFFFF00FF, >> + 0xFFFFFF00, 0xFF00FFFF, >> + }, >> + { >> + 0x44332211, >> + 0x88776655, >> + }, >> + }, >> + }, >> + }, >> + { >> + .name = "well_known_colors", >> + .format = DRM_FORMAT_YUV444, >> + .clip = DRM_RECT_INIT(1, 1, 2, 4), >> + .src_pitches = { 4 * 1, 4 * 1, 4 * 1 }, >> + .src = { >> + { >> + 0x00000000, >> + 0x0000FF00, >> + 0x00954C00, >> + 0x00691D00, >> + 0x00B2E100, >> + }, >> + { >> + 0x00000000, >> + 0x00000000, >> + 0x00BEDE00, >> + 0x00436500, >> + 0x00229B00, >> + }, >> + { >> + 0x00000000, >> + 0x00000000, >> + 0x007E9C00, >> + 0x0083E700, >> + 0x00641A00, >> + }, >> + }, >> + .memcpy_result = { >> + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, >> + .expected = { >> + { >> + 0x954C00FF, >> + 0xB2E1691D, >> + }, >> + { >> + 0xBEDE0000, >> + 0x229B4365, >> + }, >> + { >> + 0x7E9C0000, >> + 0x641A83E7, >> + }, >> + }, >> + }, >> + }, >> + { >> + .name = "destination_pitch", >> + .format = DRM_FORMAT_XBGR8888, >> + .clip = DRM_RECT_INIT(0, 0, 3, 3), >> + .src_pitches = { 3 * 4 }, >> + .src = { >> + { >> + 0xA10E449C, 0xB1114D05, 0xC1A8F303, >> + 0xD16CF073, 0xA20E449C, 0xB2114D05, >> + 0xC2A80303, 0xD26CF073, 0xA30E449C, >> + }, >> + }, >> + .memcpy_result = { >> + .dst_pitches = { 5 * 4 }, >> + .expected = { >> + { >> + 0xA10E449C, 0xB1114D05, 0xC1A8F303, 0x00000000, 0x00000000, >> + 0xD16CF073, 0xA20E449C, 0xB2114D05, 0x00000000, 0x00000000, >> + 0xC2A80303, 0xD26CF073, 0xA30E449C, 0x00000000, 0x00000000, >> + }, >> + }, >> + }, >> + }, >> + { >> + .name = "destination_pitch", >> + .format = DRM_FORMAT_XRGB8888_A8, >> + .clip = DRM_RECT_INIT(0, 0, 3, 3), >> + .src_pitches = { 3 * 4, 3 * 1 }, >> + .src = { >> + { >> + 0xFF0E449C, 0xFF114D05, 0xFFA8F303, >> + 0xFF6CF073, 0xFF0E449C, 0xFF114D05, >> + 0xFFA80303, 0xFF6CF073, 0xFF0E449C, >> + }, >> + { >> + 0xB2C1B1A1, >> + 0xD2A3D1A2, >> + 0xFFFFFFC2, >> + }, >> + }, >> + .memcpy_result = { >> + .dst_pitches = { 5 * 4, 5 * 1 }, >> + .expected = { >> + { >> + 0xFF0E449C, 0xFF114D05, 0xFFA8F303, 0x00000000, 0x00000000, >> + 0xFF6CF073, 0xFF0E449C, 0xFF114D05, 0x00000000, 0x00000000, >> + 0xFFA80303, 0xFF6CF073, 0xFF0E449C, 0x00000000, 0x00000000, >> + }, >> + { >> + 0x00C1B1A1, >> + 0xD1A2B200, >> + 0xD2A30000, >> + 0xFF0000C2, >> + }, >> + }, >> + }, >> + }, >> + { >> + .name = "destination_pitch", >> + .format = DRM_FORMAT_YUV444, >> + .clip = DRM_RECT_INIT(0, 0, 3, 3), >> + .src_pitches = { 3 * 1, 3 * 1, 3 * 1 }, >> + .src = { >> + { >> + 0xBAC1323D, >> + 0xBA34323D, >> + 0xFFFFFF3D, >> + }, >> + { >> + 0xE1ABEC2A, >> + 0xE1EAEC2A, >> + 0xFFFFFF2A, >> + }, >> + { >> + 0xBCEBE4D7, >> + 0xBC65E4D7, >> + 0xFFFFFFD7, >> + }, >> + }, >> + .memcpy_result = { >> + .dst_pitches = { 5 * 1, 5 * 1, 5 * 1 }, >> + .expected = { >> + { >> + 0x00C1323D, >> + 0x323DBA00, >> + 0xBA340000, >> + 0xFF00003D, >> + }, >> + { >> + 0x00ABEC2A, >> + 0xEC2AE100, >> + 0xE1EA0000, >> + 0xFF00002A, >> + }, >> + { >> + 0x00EBE4D7, >> + 0xE4D7BC00, >> + 0xBC650000, >> + 0xFF0000D7, >> + }, >> + }, >> + }, >> + }, >> +}; >> + >> +static void multi_plane_op_case_desc(struct multi_plane_op_case *t, char *desc) >> +{ >> + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s: %p4cc", t->name, &t->format); >> +} >> + >> +KUNIT_ARRAY_PARAM(multi_plane_op, multi_plane_op_cases, multi_plane_op_case_desc); >> + >> +static void drm_test_fb_memcpy(struct kunit *test) >> +{ >> + const struct multi_plane_op_case *params = test->param_value; >> + const struct fb_memcpy_result *result = ¶ms->memcpy_result; >> + size_t dst_size[DRM_FORMAT_MAX_PLANES] = { 0 }; >> + u32 *buf[DRM_FORMAT_MAX_PLANES] = { 0 }; >> + u32 *src_cp[DRM_FORMAT_MAX_PLANES] = { 0 }; >> + u32 *expected[DRM_FORMAT_MAX_PLANES] = { 0 }; >> + struct iosys_map dst[DRM_FORMAT_MAX_PLANES]; >> + struct iosys_map src[DRM_FORMAT_MAX_PLANES]; >> + >> + struct drm_framebuffer fb = { >> + .format = drm_format_info(params->format), >> + }; >> + >> + memcpy(fb.pitches, params->src_pitches, DRM_FORMAT_MAX_PLANES * sizeof(int)); >> + >> + for (size_t i = 0; i < fb.format->num_planes; i++) { >> + dst_size[i] = conversion_buf_size(params->format, result->dst_pitches[i], >> + ¶ms->clip, i); >> + KUNIT_ASSERT_GT(test, dst_size[i], 0); >> + >> + buf[i] = kunit_kzalloc(test, dst_size[i], GFP_KERNEL); >> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf[i]); >> + iosys_map_set_vaddr(&dst[i], buf[i]); >> + >> + src_cp[i] = cpubuf_to_le32(test, params->src[i], TEST_BUF_SIZE); >> + iosys_map_set_vaddr(&src[i], src_cp[i]); >> + } >> + >> + if (result->dst_pitches[0] == TEST_USE_DEFAULT_PITCH) >> + drm_fb_memcpy(dst, NULL, src, &fb, ¶ms->clip); >> + else >> + drm_fb_memcpy(dst, result->dst_pitches, src, &fb, ¶ms->clip); >> + >> + for (size_t i = 0; i < fb.format->num_planes; i++) { >> + expected[i] = cpubuf_to_le32(test, result->expected[i], TEST_BUF_SIZE); >> + KUNIT_EXPECT_MEMEQ_MSG(test, buf[i], expected[i], dst_size[i], >> + "Failed expectation on plane %zu", i); >> + } >> +} >> + >> static struct kunit_case drm_format_helper_test_cases[] = { >> KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_gray8, convert_xrgb8888_gen_params), >> KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params), >> @@ -1204,6 +1594,7 @@ static struct kunit_case drm_format_helper_test_cases[] = { >> KUNIT_CASE_PARAM(drm_test_fb_swab, convert_xrgb8888_gen_params), >> KUNIT_CASE_PARAM(drm_test_fb_clip_offset, clip_offset_gen_params), >> KUNIT_CASE_PARAM(drm_test_fb_build_fourcc_list, fb_build_fourcc_list_gen_params), >> + KUNIT_CASE_PARAM(drm_test_fb_memcpy, multi_plane_op_gen_params), >> {} >> }; >>
diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 6ecd92898e8e..3db4b95f3a98 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -1189,6 +1189,396 @@ static void drm_test_fb_build_fourcc_list(struct kunit *test) KUNIT_EXPECT_MEMEQ(test, fourccs_out, params->expected, TEST_BUF_SIZE); } +struct fb_memcpy_result { + unsigned int dst_pitches[DRM_FORMAT_MAX_PLANES]; + const u32 expected[DRM_FORMAT_MAX_PLANES][TEST_BUF_SIZE]; +}; + +struct multi_plane_op_case { + const char *name; + u32 format; + struct drm_rect clip; + unsigned int src_pitches[DRM_FORMAT_MAX_PLANES]; + const u32 src[DRM_FORMAT_MAX_PLANES][TEST_BUF_SIZE]; + struct fb_memcpy_result memcpy_result; +}; + +/* The `src` and `expected` buffers are u32 arrays. To deal with planes that + * have a cpp != 4 the values are stored together on the same u32 number in a + * way so the order in memory is correct in a little-endian machine. + * + * Because of that, on some occasions, parts of a u32 will not be part of the + * test, to make this explicit the 0xFF byte is used on those parts. + */ + +static struct multi_plane_op_case multi_plane_op_cases[] = { + { + .name = "single_pixel_source_buffer", + .format = DRM_FORMAT_XRGB8888, + .clip = DRM_RECT_INIT(0, 0, 1, 1), + .src_pitches = { 1 * 4 }, + .src = {{ 0x01020304 }}, + .memcpy_result = { + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, + .expected = {{ 0x01020304 }}, + } + }, + { + .name = "single_pixel_source_buffer", + .format = DRM_FORMAT_XRGB8888_A8, + .clip = DRM_RECT_INIT(0, 0, 1, 1), + .src_pitches = { 1 * 4, 1 }, + .src = { + { 0x01020304 }, + { 0xFFFFFF01 }, + }, + .memcpy_result = { + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, + .expected = { + { 0x01020304 }, + { 0x00000001 }, + }, + }, + }, + { + .name = "single_pixel_source_buffer", + .format = DRM_FORMAT_YUV444, + .clip = DRM_RECT_INIT(0, 0, 1, 1), + .src_pitches = { 1, 1, 1 }, + .src = { + { 0xFFFFFF01 }, + { 0xFFFFFF01 }, + { 0xFFFFFF01 }, + }, + .memcpy_result = { + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, + .expected = { + { 0x00000001 }, + { 0x00000001 }, + { 0x00000001 }, + }, + }, + }, + { + .name = "single_pixel_clip_rectangle", + .format = DRM_FORMAT_XBGR8888, + .clip = DRM_RECT_INIT(1, 1, 1, 1), + .src_pitches = { 2 * 4 }, + .src = { + { + 0x00000000, 0x00000000, + 0x00000000, 0x01020304, + }, + }, + .memcpy_result = { + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, + .expected = { + { 0x01020304 }, + }, + }, + }, + { + .name = "single_pixel_clip_rectangle", + .format = DRM_FORMAT_XRGB8888_A8, + .clip = DRM_RECT_INIT(1, 1, 1, 1), + .src_pitches = { 2 * 4, 2 * 1 }, + .src = { + { + 0x00000000, 0x00000000, + 0x00000000, 0x01020304, + }, + { 0x01000000 }, + }, + .memcpy_result = { + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, + .expected = { + { 0x01020304 }, + { 0x00000001 }, + }, + }, + }, + { + .name = "single_pixel_clip_rectangle", + .format = DRM_FORMAT_YUV444, + .clip = DRM_RECT_INIT(1, 1, 1, 1), + .src_pitches = { 2 * 1, 2 * 1, 2 * 1 }, + .src = { + { 0x01000000 }, + { 0x01000000 }, + { 0x01000000 }, + }, + .memcpy_result = { + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, + .expected = { + { 0x00000001 }, + { 0x00000001 }, + { 0x00000001 }, + }, + }, + }, + { + .name = "well_known_colors", + .format = DRM_FORMAT_XBGR8888, + .clip = DRM_RECT_INIT(1, 1, 2, 4), + .src_pitches = { 4 * 4 }, + .src = { + { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x11FFFFFF, 0x22000000, 0x00000000, + 0x00000000, 0x33FF0000, 0x4400FF00, 0x00000000, + 0x00000000, 0x550000FF, 0x66FF00FF, 0x00000000, + 0x00000000, 0x77FFFF00, 0x8800FFFF, 0x00000000, + }, + }, + .memcpy_result = { + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, + .expected = { + { + 0x11FFFFFF, 0x22000000, + 0x33FF0000, 0x4400FF00, + 0x550000FF, 0x66FF00FF, + 0x77FFFF00, 0x8800FFFF, + }, + }, + }, + }, + { + .name = "well_known_colors", + .format = DRM_FORMAT_XRGB8888_A8, + .clip = DRM_RECT_INIT(1, 1, 2, 4), + .src_pitches = { 4 * 4, 4 * 1 }, + .src = { + { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0xFFFFFFFF, 0xFF000000, 0x00000000, + 0x00000000, 0xFFFF0000, 0xFF00FF00, 0x00000000, + 0x00000000, 0xFF0000FF, 0xFFFF00FF, 0x00000000, + 0x00000000, 0xFFFFFF00, 0xFF00FFFF, 0x00000000, + }, + { + 0x00000000, + 0x00221100, + 0x00443300, + 0x00665500, + 0x00887700, + }, + }, + .memcpy_result = { + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, + .expected = { + { + 0xFFFFFFFF, 0xFF000000, + 0xFFFF0000, 0xFF00FF00, + 0xFF0000FF, 0xFFFF00FF, + 0xFFFFFF00, 0xFF00FFFF, + }, + { + 0x44332211, + 0x88776655, + }, + }, + }, + }, + { + .name = "well_known_colors", + .format = DRM_FORMAT_YUV444, + .clip = DRM_RECT_INIT(1, 1, 2, 4), + .src_pitches = { 4 * 1, 4 * 1, 4 * 1 }, + .src = { + { + 0x00000000, + 0x0000FF00, + 0x00954C00, + 0x00691D00, + 0x00B2E100, + }, + { + 0x00000000, + 0x00000000, + 0x00BEDE00, + 0x00436500, + 0x00229B00, + }, + { + 0x00000000, + 0x00000000, + 0x007E9C00, + 0x0083E700, + 0x00641A00, + }, + }, + .memcpy_result = { + .dst_pitches = { TEST_USE_DEFAULT_PITCH }, + .expected = { + { + 0x954C00FF, + 0xB2E1691D, + }, + { + 0xBEDE0000, + 0x229B4365, + }, + { + 0x7E9C0000, + 0x641A83E7, + }, + }, + }, + }, + { + .name = "destination_pitch", + .format = DRM_FORMAT_XBGR8888, + .clip = DRM_RECT_INIT(0, 0, 3, 3), + .src_pitches = { 3 * 4 }, + .src = { + { + 0xA10E449C, 0xB1114D05, 0xC1A8F303, + 0xD16CF073, 0xA20E449C, 0xB2114D05, + 0xC2A80303, 0xD26CF073, 0xA30E449C, + }, + }, + .memcpy_result = { + .dst_pitches = { 5 * 4 }, + .expected = { + { + 0xA10E449C, 0xB1114D05, 0xC1A8F303, 0x00000000, 0x00000000, + 0xD16CF073, 0xA20E449C, 0xB2114D05, 0x00000000, 0x00000000, + 0xC2A80303, 0xD26CF073, 0xA30E449C, 0x00000000, 0x00000000, + }, + }, + }, + }, + { + .name = "destination_pitch", + .format = DRM_FORMAT_XRGB8888_A8, + .clip = DRM_RECT_INIT(0, 0, 3, 3), + .src_pitches = { 3 * 4, 3 * 1 }, + .src = { + { + 0xFF0E449C, 0xFF114D05, 0xFFA8F303, + 0xFF6CF073, 0xFF0E449C, 0xFF114D05, + 0xFFA80303, 0xFF6CF073, 0xFF0E449C, + }, + { + 0xB2C1B1A1, + 0xD2A3D1A2, + 0xFFFFFFC2, + }, + }, + .memcpy_result = { + .dst_pitches = { 5 * 4, 5 * 1 }, + .expected = { + { + 0xFF0E449C, 0xFF114D05, 0xFFA8F303, 0x00000000, 0x00000000, + 0xFF6CF073, 0xFF0E449C, 0xFF114D05, 0x00000000, 0x00000000, + 0xFFA80303, 0xFF6CF073, 0xFF0E449C, 0x00000000, 0x00000000, + }, + { + 0x00C1B1A1, + 0xD1A2B200, + 0xD2A30000, + 0xFF0000C2, + }, + }, + }, + }, + { + .name = "destination_pitch", + .format = DRM_FORMAT_YUV444, + .clip = DRM_RECT_INIT(0, 0, 3, 3), + .src_pitches = { 3 * 1, 3 * 1, 3 * 1 }, + .src = { + { + 0xBAC1323D, + 0xBA34323D, + 0xFFFFFF3D, + }, + { + 0xE1ABEC2A, + 0xE1EAEC2A, + 0xFFFFFF2A, + }, + { + 0xBCEBE4D7, + 0xBC65E4D7, + 0xFFFFFFD7, + }, + }, + .memcpy_result = { + .dst_pitches = { 5 * 1, 5 * 1, 5 * 1 }, + .expected = { + { + 0x00C1323D, + 0x323DBA00, + 0xBA340000, + 0xFF00003D, + }, + { + 0x00ABEC2A, + 0xEC2AE100, + 0xE1EA0000, + 0xFF00002A, + }, + { + 0x00EBE4D7, + 0xE4D7BC00, + 0xBC650000, + 0xFF0000D7, + }, + }, + }, + }, +}; + +static void multi_plane_op_case_desc(struct multi_plane_op_case *t, char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s: %p4cc", t->name, &t->format); +} + +KUNIT_ARRAY_PARAM(multi_plane_op, multi_plane_op_cases, multi_plane_op_case_desc); + +static void drm_test_fb_memcpy(struct kunit *test) +{ + const struct multi_plane_op_case *params = test->param_value; + const struct fb_memcpy_result *result = ¶ms->memcpy_result; + size_t dst_size[DRM_FORMAT_MAX_PLANES] = { 0 }; + u32 *buf[DRM_FORMAT_MAX_PLANES] = { 0 }; + u32 *src_cp[DRM_FORMAT_MAX_PLANES] = { 0 }; + u32 *expected[DRM_FORMAT_MAX_PLANES] = { 0 }; + struct iosys_map dst[DRM_FORMAT_MAX_PLANES]; + struct iosys_map src[DRM_FORMAT_MAX_PLANES]; + + struct drm_framebuffer fb = { + .format = drm_format_info(params->format), + }; + + memcpy(fb.pitches, params->src_pitches, DRM_FORMAT_MAX_PLANES * sizeof(int)); + + for (size_t i = 0; i < fb.format->num_planes; i++) { + dst_size[i] = conversion_buf_size(params->format, result->dst_pitches[i], + ¶ms->clip, i); + KUNIT_ASSERT_GT(test, dst_size[i], 0); + + buf[i] = kunit_kzalloc(test, dst_size[i], GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf[i]); + iosys_map_set_vaddr(&dst[i], buf[i]); + + src_cp[i] = cpubuf_to_le32(test, params->src[i], TEST_BUF_SIZE); + iosys_map_set_vaddr(&src[i], src_cp[i]); + } + + if (result->dst_pitches[0] == TEST_USE_DEFAULT_PITCH) + drm_fb_memcpy(dst, NULL, src, &fb, ¶ms->clip); + else + drm_fb_memcpy(dst, result->dst_pitches, src, &fb, ¶ms->clip); + + for (size_t i = 0; i < fb.format->num_planes; i++) { + expected[i] = cpubuf_to_le32(test, result->expected[i], TEST_BUF_SIZE); + KUNIT_EXPECT_MEMEQ_MSG(test, buf[i], expected[i], dst_size[i], + "Failed expectation on plane %zu", i); + } +} + static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_gray8, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb332, convert_xrgb8888_gen_params), @@ -1204,6 +1594,7 @@ static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(drm_test_fb_swab, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_clip_offset, clip_offset_gen_params), KUNIT_CASE_PARAM(drm_test_fb_build_fourcc_list, fb_build_fourcc_list_gen_params), + KUNIT_CASE_PARAM(drm_test_fb_memcpy, multi_plane_op_gen_params), {} };
Insert parameterized test for the drm_fb_memcpy() to ensure correctness and prevent future regressions. The test case can accept different formats. Signed-off-by: Arthur Grillo <arthurgrillo@riseup.net> --- .../gpu/drm/tests/drm_format_helper_test.c | 391 ++++++++++++++++++ 1 file changed, 391 insertions(+)