Increase code coverage on drm_format_helper.c
Subsystems (2)
cover Increase code coverage on drm_format_helper.c
The following series include improvements and new KUnit tests to some functions on drm_format_helper.c.
The first patch improves existing conversion tests to assure that the default pitch is used when NULL is used on the dst_pitch argument.
Patches 2, 3, 4, and 6 add the new parametrized tests to the following functions:
- drm_fb_swab()
- drm_fb_clip_offset()
- drm_fb_build_fourcc_list()
- drm_fb_memcpy()
The 5th patch is a change to the conversion_buf_size() helper used on the tests, this change was needed to make the patch 6.
a coverage report for the file can be found below:
https://grillo-0.github.io/coverage-reports/gsoc-drm-format-test/drivers/gpu/drm/drm_format_helper.c.gcov.html
Arthur Grillo (6):
drm/format-helper: Test default pitch fallback drm/format-helper: Add KUnit tests for drm_fb_swab() drm/format-helper: Add KUnit tests for drm_fb_clip_offset() drm/format-helper: Add KUnit tests for drm_fb_build_fourcc_list() drm/format-helper-test: Add multi-plane support to
conversion_buf_size()
drm/format-helper: Add KUnit tests for drm_fb_memcpy()
.../gpu/drm/tests/drm_format_helper_test.c | 849 ++++++++++++++++-- 1 file changed, 791 insertions(+), 58 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/6 drm/format-helper: Test default pitch fallback
Test the default pitch fallback when NULL is passed as the dst_pitch on the conversion procedures.
--- .../gpu/drm/tests/drm_format_helper_test.c | 132 ++++++++++++------ 1 file changed, 87 insertions(+), 45 deletions(-)
drivers/gpu/drm/tests/drm_format_helper_test.c +87 -45
@@ -16,6 +16,8 @@#define TEST_BUF_SIZE 50 +#define TEST_USE_DEFAULT_PITCH 0 +struct convert_to_gray8_result {unsigned int dst_pitch;const u8 expected[TEST_BUF_SIZE ];
@@ -97,48 +99,48 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .clip = DRM_RECT_INIT(0, 0, 1, 1), .xrgb8888 = { 0x01FF0000 }, .gray8_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0x4C }, }, .rgb332_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0xE0 }, }, .rgb565_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, .xrgb1555_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0x7C00 }, }, .argb1555_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0xFC00 }, }, .rgba5551_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0xF801 }, }, .rgb888_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0x00, 0x00, 0xFF }, }, .argb8888_result = { - .dst_pitch =0 , + .dst_pitch =TEST_USE_DEFAULT_PITCH , .expected = { 0xFFFF0000 }, }, .xrgb2101010_result = { - .dst_pitch =0 , + .dst_pitch =TEST_USE_DEFAULT_PITCH , .expected = { 0x3FF00000 }, }, .argb2101010_result = { - .dst_pitch =0 , + .dst_pitch =TEST_USE_DEFAULT_PITCH , .expected = { 0xFFF00000 }, }, .mono_result = { - .dst_pitch =0 , + .dst_pitch =TEST_USE_DEFAULT_PITCH , .expected = { 0b0 }, }, },
@@ -151,48 +153,48 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0x00000000, 0x10FF0000, }, .gray8_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0x4C }, }, .rgb332_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0xE0 }, }, .rgb565_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0xF800 }, .expected_swab = { 0x00F8 }, }, .xrgb1555_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0x7C00 }, }, .argb1555_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0xFC00 }, }, .rgba5551_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0xF801 }, }, .rgb888_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0x00, 0x00, 0xFF }, }, .argb8888_result = { - .dst_pitch =0 , + .dst_pitch =TEST_USE_DEFAULT_PITCH , .expected = { 0xFFFF0000 }, }, .xrgb2101010_result = { - .dst_pitch =0 , + .dst_pitch =TEST_USE_DEFAULT_PITCH , .expected = { 0x3FF00000 }, }, .argb2101010_result = { - .dst_pitch =0 , + .dst_pitch =TEST_USE_DEFAULT_PITCH , .expected = { 0xFFF00000 }, }, .mono_result = { - .dst_pitch =0 , + .dst_pitch =TEST_USE_DEFAULT_PITCH , .expected = { 0b0 }, }, },
@@ -212,7 +214,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0x00000000, 0x77FFFF00, 0x8800FFFF, 0x00000000, }, .gray8_result = { - .dst_pitch =0 , + .dst_pitch =TEST_USE_DEFAULT_PITCH , .expected = {0xFF ,0x00 , 0x4C, 0x99,
@@ -221,7 +223,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { }, }, .rgb332_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = {0xFF ,0x00 , 0xE0, 0x1C,
@@ -230,7 +232,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { }, }, .rgb565_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = {0xFFFF ,0x0000 , 0xF800, 0x07E0,
@@ -245,7 +247,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { }, }, .xrgb1555_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = {0x7FFF ,0x0000 , 0x7C00, 0x03E0,
@@ -254,7 +256,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { }, }, .argb1555_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = {0xFFFF ,0x8000 , 0xFC00, 0x83E0,
@@ -263,7 +265,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { }, }, .rgba5551_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = {0xFFFF ,0x0001 , 0xF801, 0x07C1,
@@ -272,7 +274,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { }, }, .rgb888_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = {0xFF ,0xFF ,0xFF ,0x00 ,0x00 ,0x00 , 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00,
@@ -281,7 +283,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { }, }, .argb8888_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = {0xFFFFFFFF ,0xFF000000 , 0xFFFF0000, 0xFF00FF00,
@@ -290,7 +292,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { }, }, .xrgb2101010_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = {0x3FFFFFFF ,0x00000000 , 0x3FF00000, 0x000FFC00,
@@ -299,7 +301,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { }, }, .argb2101010_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = {0xFFFFFFFF ,0xC0000000 , 0xFFF00000, 0xC00FFC00,
@@ -308,7 +310,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { }, }, .mono_result = { - .dst_pitch = 0, + .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = {0b01 , 0b10,
@@ -530,7 +532,10 @@ static void drm_test_fb_xrgb8888_to_gray8(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_gray8 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_gray8 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_gray8 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }
@@ -560,7 +565,10 @@ static void drm_test_fb_xrgb8888_to_rgb332(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_rgb332 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_rgb332 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_rgb332 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }
@@ -590,12 +598,19 @@ static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_rgb565 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, false); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_rgb565 (&dst,NULL , &src, &fb, ¶ms->clip, false); +else +drm_fb_xrgb8888_to_rgb565 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, + false); buf =le16buf_to_cpu (test, (__force const __le16 *)buf, dst_size /sizeof (__le16));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); buf = dst.vaddr;/* restore original value of buf */ -drm_fb_xrgb8888_to_rgb565 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, true); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_rgb565 (&dst,NULL , &src, &fb, ¶ms->clip, true); +else +drm_fb_xrgb8888_to_rgb565 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, true); buf =le16buf_to_cpu (test, (__force const __le16 *)buf, dst_size /sizeof (__le16));KUNIT_EXPECT_MEMEQ (test, buf, result->expected_swab, dst_size); }
@@ -626,7 +641,10 @@ static void drm_test_fb_xrgb8888_to_xrgb1555(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_xrgb1555 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_xrgb1555 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_xrgb1555 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); buf =le16buf_to_cpu (test, (__force const __le16 *)buf, dst_size /sizeof (__le16));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }
@@ -657,7 +675,10 @@ static void drm_test_fb_xrgb8888_to_argb1555(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_argb1555 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_argb1555 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_argb1555 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); buf =le16buf_to_cpu (test, (__force const __le16 *)buf, dst_size /sizeof (__le16));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }
@@ -688,7 +709,10 @@ static void drm_test_fb_xrgb8888_to_rgba5551(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_rgba5551 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_rgba5551 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_rgba5551 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); buf =le16buf_to_cpu (test, (__force const __le16 *)buf, dst_size /sizeof (__le16));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }
@@ -723,7 +747,11 @@ static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test)* RGB888 expected results are already in little-endian * order, so there's no need to convert the test output. */ -drm_fb_xrgb8888_to_rgb888 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_rgb888 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_rgb888 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }
@@ -753,7 +781,11 @@ static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_argb8888 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_argb8888 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_argb8888 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); + buf =le32buf_to_cpu (test, (__force const __le32 *)buf, dst_size /sizeof (u32));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }
@@ -784,7 +816,10 @@ static void drm_test_fb_xrgb8888_to_xrgb2101010(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_xrgb2101010 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_xrgb2101010 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_xrgb2101010 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); buf =le32buf_to_cpu (test, buf, dst_size /sizeof (u32));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }
@@ -815,7 +850,11 @@ static void drm_test_fb_xrgb8888_to_argb2101010(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_argb2101010 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_argb2101010 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_argb2101010 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); + buf =le32buf_to_cpu (test, (__force const __le32 *)buf, dst_size /sizeof (u32));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }
@@ -846,7 +885,10 @@ static void drm_test_fb_xrgb8888_to_mono(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_mono (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_mono (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_mono (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }
Signature · 1 line
2.41.0
Re: [PATCH 1/6] drm/format-helper: Test default pitch fallback
Hi Arthur,
Just nitpicking, but...
Quoted 8 lines · Arthur Grillo
Test the default pitch fallback when NULL is passed as the
dst_pitchon the conversion procedures.Signed-off-by Arthur Grillo <[email protected]>--- .../gpu/drm/tests/drm_format_helper_test.c | 132 ++++++++++++------ 1 file changed, 87 insertions(+), 45 deletions(-)
[...]
drivers/gpu/drm/tests/drm_format_helper_test.c static void drm_test_fb_xrgb8888_to_gray8(struct kunit *test) · line 538
Quoted 9 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +4
-1@@ -530,7 +532,10 @@ static void drm_test_fb_xrgb8888_to_gray8(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_gray8 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_gray8 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_gray8 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);
Couldn't we do something like:
unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH)
? NULL : &result->dst_pitch;
[...]
drm_fb_xrgb8888_to_gray8(&dst, dst_pitch, &src, &fb, ¶ms->clip);
I believe the code would be cleaner.
Best Regards,
- Maíra
Quoted 136 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +48
-11KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }@@ -560,7 +565,10 @@ static void drm_test_fb_xrgb8888_to_rgb332(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_rgb332 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_rgb332 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_rgb332 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }@@ -590,12 +598,19 @@ static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_rgb565 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, false); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_rgb565 (&dst,NULL , &src, &fb, ¶ms->clip, false); +else +drm_fb_xrgb8888_to_rgb565 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, + false); buf =le16buf_to_cpu (test, (__force const __le16 *)buf, dst_size /sizeof (__le16));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); buf = dst.vaddr;/* restore original value of buf */ -drm_fb_xrgb8888_to_rgb565 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, true); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_rgb565 (&dst,NULL , &src, &fb, ¶ms->clip, true); +else +drm_fb_xrgb8888_to_rgb565 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, true); buf =le16buf_to_cpu (test, (__force const __le16 *)buf, dst_size /sizeof (__le16));KUNIT_EXPECT_MEMEQ (test, buf, result->expected_swab, dst_size); }@@ -626,7 +641,10 @@ static void drm_test_fb_xrgb8888_to_xrgb1555(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_xrgb1555 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_xrgb1555 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_xrgb1555 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); buf =le16buf_to_cpu (test, (__force const __le16 *)buf, dst_size /sizeof (__le16));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }@@ -657,7 +675,10 @@ static void drm_test_fb_xrgb8888_to_argb1555(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_argb1555 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_argb1555 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_argb1555 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); buf =le16buf_to_cpu (test, (__force const __le16 *)buf, dst_size /sizeof (__le16));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }@@ -688,7 +709,10 @@ static void drm_test_fb_xrgb8888_to_rgba5551(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_rgba5551 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_rgba5551 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_rgba5551 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); buf =le16buf_to_cpu (test, (__force const __le16 *)buf, dst_size /sizeof (__le16));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }@@ -723,7 +747,11 @@ static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test)* RGB888 expected results are already in little-endian * order, so there's no need to convert the test output. */ -drm_fb_xrgb8888_to_rgb888 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_rgb888 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_rgb888 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }@@ -753,7 +781,11 @@ static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_argb8888 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_argb8888 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_argb8888 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); + buf =le32buf_to_cpu (test, (__force const __le32 *)buf, dst_size /sizeof (u32));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }@@ -784,7 +816,10 @@ static void drm_test_fb_xrgb8888_to_xrgb2101010(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_xrgb2101010 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_xrgb2101010 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_xrgb2101010 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); buf =le32buf_to_cpu (test, buf, dst_size /sizeof (u32));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }@@ -815,7 +850,11 @@ static void drm_test_fb_xrgb8888_to_argb2101010(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_argb2101010 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_argb2101010 (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_argb2101010 (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); + buf =le32buf_to_cpu (test, (__force const __le32 *)buf, dst_size /sizeof (u32));KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }@@ -846,7 +885,10 @@ static void drm_test_fb_xrgb8888_to_mono(struct kunit *test)KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888);iosys_map_set_vaddr (&src, xrgb8888); -drm_fb_xrgb8888_to_mono (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip); +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_xrgb8888_to_mono (&dst,NULL , &src, &fb, ¶ms->clip); +else +drm_fb_xrgb8888_to_mono (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip);KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); }
Re: [PATCH 1/6] drm/format-helper: Test default pitch fallback
In reply to Arthur GrilloHi,
Em 21/07/2023 15:23, Arthur Grillo escreveu:
Quoted 5 lines
Test the default pitch fallback when NULL is passed as the
dst_pitchon the conversion procedures.Signed-off-by Arthur Grillo <[email protected]>---
With Maíra's comment about the duplicated drm_fb_xrgb8888_to_rgb565() addressed:
PATCH 2/6 drm/format-helper: Add KUnit tests for drm_fb_swab()
In reply to Arthur GrilloInsert parameterized test for the drm_fb_swab() to ensure correctness and prevent future regressions.
--- .../gpu/drm/tests/drm_format_helper_test.c | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+)
drivers/gpu/drm/tests/drm_format_helper_test.c +66 -0
@@ -74,6 +74,11 @@ struct convert_to_mono_result {const u8 expected[TEST_BUF_SIZE ]; }; +struct fb_swab_result { +unsigned int dst_pitch; +const u32 expected[TEST_BUF_SIZE ]; +}; +struct convert_xrgb8888_case {const char *name;unsigned int pitch;
@@ -90,6 +95,7 @@ struct convert_xrgb8888_case {struct convert_to_xrgb2101010_result xrgb2101010_result;struct convert_to_argb2101010_result argb2101010_result;struct convert_to_mono_result mono_result; +struct fb_swab_result swab_result; };static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
@@ -143,6 +149,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0b0 }, }, + .swab_result = { + .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { 0x0000FF01 }, + }, }, { .name = "single_pixel_clip_rectangle",
@@ -197,6 +207,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0b0 }, }, + .swab_result = { + .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { 0x0000FF10 }, + }, }, {/* Well known colors: White, black, red, green, blue, magenta,
@@ -318,6 +332,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0b11, }, }, + .swab_result = { + .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { +0xFFFFFF11 ,0x00000022 , +0x0000FF33 ,0x00FF0044 , +0xFF000055 ,0xFF00FF66 , + 0x00FFFF77, 0xFFFF0088, + }, + }, }, {/* Randomly picked colors. Full buffer within the clip area. */
@@ -425,6 +448,14 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0b010, 0b000, }, }, + .swab_result = { + .dst_pitch = 20, + .expected = { +0x9C440EA1 ,0x054D11B1 ,0x03F3A8C1 ,0x00000000 ,0x00000000 , +0x73F06CD1 ,0x9C440EA2 ,0x054D11B2 ,0x00000000 ,0x00000000 , + 0x0303A8C2, 0x73F06CD2, 0x9C440EA3, 0x00000000, 0x00000000, + }, + }, }, };
@@ -892,6 +923,40 @@ static void drm_test_fb_xrgb8888_to_mono(struct kunit *test)KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); } +static void drm_test_fb_swab (struct kunit *test) +{ +const struct convert_xrgb8888_case *params = test->param_value; +const struct fb_swab_result *result = ¶ms->swab_result; +size_t dst_size; +u32 *buf =NULL ; +__le32 *xrgb8888 =NULL ; +struct iosys_map dst, src; + +struct drm_framebuffer fb = { + .format =drm_format_info (DRM_FORMAT_XRGB8888 ), + .pitches = { params->pitch,0 ,0 }, + }; + + dst_size =conversion_buf_size (DRM_FORMAT_XRGB8888 , result->dst_pitch, ¶ms->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 (&dst, buf); + + xrgb8888 =cpubuf_to_le32 (test, params->xrgb8888,TEST_BUF_SIZE ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888); +iosys_map_set_vaddr (&src, xrgb8888); + +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_swab (&dst,NULL , &src, &fb, ¶ms->clip, false); +else +drm_fb_swab (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, false); + buf =le32buf_to_cpu (test, (__force const __le32 *)buf, dst_size /sizeof (u32)); +KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); +} +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),
@@ -904,6 +969,7 @@ static struct kunit_case drm_format_helper_test_cases[] = {KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_xrgb2101010, convert_xrgb8888_gen_params),KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_argb2101010, convert_xrgb8888_gen_params),KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_mono, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(drm_test_fb_swab, convert_xrgb8888_gen_params), {} };
Signature · 1 line
2.41.0
Re: [PATCH 2/6] drm/format-helper: Add KUnit tests for drm_fb_swab()
Quoted 4 lines · Arthur Grillo
Insert parameterized test for the
drm_fb_swab()to ensure correctness and prevent future regressions.Signed-off-by Arthur Grillo <[email protected]>
With the nit I pointed in patch #1 addressed,
Best Regards,
- Maíra
Quoted 130 lines
--- .../gpu/drm/tests/drm_format_helper_test.c | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+)drivers/gpu/drm/tests/drm_format_helper_test.c +66
-0@@ -74,6 +74,11 @@ struct convert_to_mono_result {const u8 expected[TEST_BUF_SIZE ]; }; +struct fb_swab_result { +unsigned int dst_pitch; +const u32 expected[TEST_BUF_SIZE ]; +}; +struct convert_xrgb8888_case {const char *name;unsigned int pitch;@@ -90,6 +95,7 @@ struct convert_xrgb8888_case {struct convert_to_xrgb2101010_result xrgb2101010_result;struct convert_to_argb2101010_result argb2101010_result;struct convert_to_mono_result mono_result; +struct fb_swab_result swab_result; };static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {@@ -143,6 +149,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0b0 }, }, + .swab_result = { + .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { 0x0000FF01 }, + }, }, { .name = "single_pixel_clip_rectangle",@@ -197,6 +207,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0b0 }, }, + .swab_result = { + .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { 0x0000FF10 }, + }, }, {/* Well known colors: White, black, red, green, blue, magenta, @@ -318,6 +332,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0b11, }, }, + .swab_result = { + .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { +0xFFFFFF11 ,0x00000022 , +0x0000FF33 ,0x00FF0044 , +0xFF000055 ,0xFF00FF66 , + 0x00FFFF77, 0xFFFF0088, + }, + }, }, {/* Randomly picked colors. Full buffer within the clip area. */ @@ -425,6 +448,14 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0b010, 0b000, }, }, + .swab_result = { + .dst_pitch = 20, + .expected = { +0x9C440EA1 ,0x054D11B1 ,0x03F3A8C1 ,0x00000000 ,0x00000000 , +0x73F06CD1 ,0x9C440EA2 ,0x054D11B2 ,0x00000000 ,0x00000000 , + 0x0303A8C2, 0x73F06CD2, 0x9C440EA3, 0x00000000, 0x00000000, + }, + }, }, };@@ -892,6 +923,40 @@ static void drm_test_fb_xrgb8888_to_mono(struct kunit *test)KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); } +static void drm_test_fb_swab (struct kunit *test) +{ +const struct convert_xrgb8888_case *params = test->param_value; +const struct fb_swab_result *result = ¶ms->swab_result; +size_t dst_size; +u32 *buf =NULL ; +__le32 *xrgb8888 =NULL ; +struct iosys_map dst, src; + +struct drm_framebuffer fb = { + .format =drm_format_info (DRM_FORMAT_XRGB8888 ), + .pitches = { params->pitch,0 ,0 }, + }; + + dst_size =conversion_buf_size (DRM_FORMAT_XRGB8888 , result->dst_pitch, ¶ms->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 (&dst, buf); + + xrgb8888 =cpubuf_to_le32 (test, params->xrgb8888,TEST_BUF_SIZE ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, xrgb8888); +iosys_map_set_vaddr (&src, xrgb8888); + +if (result->dst_pitch ==TEST_USE_DEFAULT_PITCH ) +drm_fb_swab (&dst,NULL , &src, &fb, ¶ms->clip, false); +else +drm_fb_swab (&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, false); + buf =le32buf_to_cpu (test, (__force const __le32 *)buf, dst_size /sizeof (u32)); +KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); +} +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),@@ -904,6 +969,7 @@ static struct kunit_case drm_format_helper_test_cases[] = {KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_xrgb2101010, convert_xrgb8888_gen_params),KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_argb2101010, convert_xrgb8888_gen_params),KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_mono, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(drm_test_fb_swab, convert_xrgb8888_gen_params), {} };
Re: [PATCH 2/6] drm/format-helper: Add KUnit tests for drm_fb_swab()
In reply to Arthur GrilloEm 21/07/2023 15:23, Arthur Grillo escreveu:
Quoted 5 lines
Insert parameterized test for the
drm_fb_swab()to ensure correctness and prevent future regressions.Signed-off-by Arthur Grillo <[email protected]>---
[...]
Quoted 12 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +8
-0+ .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { +0xFFFFFF11 ,0x00000022 , +0x0000FF33 ,0x00FF0044 , +0xFF000055 ,0xFF00FF66 , + 0x00FFFF77, 0xFFFF0088, + }, + }, }, {/* Randomly picked colors. Full buffer within the clip area. */
drivers/gpu/drm/tests/drm_format_helper_test.c static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { · line 456
Quoted 9 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +6
-0@@ -425,6 +448,14 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {0b010 ,0b000 , }, }, + .swab_result = { + .dst_pitch =20 , + .expected = { +0x9C440EA1 ,0x054D11B1 ,0x03F3A8C1 ,0x00000000 ,0x00000000 , +0x73F06CD1 ,0x9C440EA2 ,0x054D11B2 ,0x00000000 ,0x00000000 , + 0x0303A8C2, 0x73F06CD2, 0x9C440EA3, 0x00000000, 0x00000000,
I would appreciated to have some information about those numbers in the commit message.
PATCH 3/6 drm/format-helper: Add KUnit tests for drm_fb_clip_offset()
In reply to Arthur GrilloInsert parameterized test for the drm_fb_clip_offset() to ensure correctness and prevent future regressions.
--- .../gpu/drm/tests/drm_format_helper_test.c | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+)
drivers/gpu/drm/tests/drm_format_helper_test.c +91 -0
@@ -957,6 +957,96 @@ static void drm_test_fb_swab(struct kunit *test)KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); } +struct clip_offset_case { +const char *name; +unsigned int pitch; +u32 format; +struct drm_rect clip; +unsigned int expected_offset; +}; + +static struct clip_offset_case clip_offset_cases[] = { + { + .name ="pass through" , + .pitch =TEST_USE_DEFAULT_PITCH , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (0 ,0 ,3 ,3 ), + .expected_offset =0 + }, + { + .name ="horizontal offset" , + .pitch =TEST_USE_DEFAULT_PITCH , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (1 ,0 ,3 ,3 ), + .expected_offset =4 , + }, + { + .name ="vertical offset" , + .pitch =TEST_USE_DEFAULT_PITCH , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (0 ,1 ,3 ,3 ), + .expected_offset =12 , + }, + { + .name ="horizontal and vertical offset" , + .pitch =TEST_USE_DEFAULT_PITCH , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (1 ,1 ,3 ,3 ), + .expected_offset =16 , + }, + { + .name ="horizontal offset (custom pitch)" , + .pitch =20 , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (1 ,0 ,3 ,3 ), + .expected_offset =4 , + }, + { + .name ="vertical offset (custom pitch)" , + .pitch =20 , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (0 ,1 ,3 ,3 ), + .expected_offset =20 , + }, + { + .name ="horizontal and vertical offset (custom pitch)" , + .pitch =20 , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (1 ,1 ,3 ,3 ), + .expected_offset =24 , + }, +}; + +static void clip_offset_case_desc (struct clip_offset_case *t,char *desc) +{ +strscpy (desc, t->name,KUNIT_PARAM_DESC_SIZE ); +} + +KUNIT_ARRAY_PARAM (clip_offset, clip_offset_cases, clip_offset_case_desc); + +static void drm_test_fb_clip_offset (struct kunit *test) +{ +const struct clip_offset_case *params = test->param_value; +const struct drm_format_info *format_info =drm_format_info (params->format); + +unsigned int offset =-1 ; + +unsigned int pitch = params->pitch; + +if (pitch ==TEST_USE_DEFAULT_PITCH ) + pitch =drm_format_info_min_pitch (format_info,0 , +drm_rect_width (¶ms->clip)); + +/* Assure that the pitch is not zero, because this will inevitable cause the +* wrong expected result +*/ +KUNIT_ASSERT_NE (test, pitch,0 ); + + offset =drm_fb_clip_offset (pitch, format_info, ¶ms->clip); + +KUNIT_EXPECT_EQ (test, offset, params->expected_offset); +} +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),
@@ -970,6 +1060,7 @@ static struct kunit_case drm_format_helper_test_cases[] = {KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_argb2101010, convert_xrgb8888_gen_params),KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_mono, convert_xrgb8888_gen_params),KUNIT_CASE_PARAM (drm_test_fb_swab, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(drm_test_fb_clip_offset, clip_offset_gen_params), {} };
Signature · 1 line
2.41.0
Re: [PATCH 3/6] drm/format-helper: Add KUnit tests for drm_fb_clip_offset()
Quoted 4 lines · Arthur Grillo
Insert parameterized test for the
drm_fb_clip_offset()to ensure correctness and prevent future regressions.Signed-off-by Arthur Grillo <[email protected]>
Could you please use the prefix drm/tests in the commit message for all patches? Besides that:
Best Regards,
- Maíra
Quoted 113 lines
--- .../gpu/drm/tests/drm_format_helper_test.c | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+)drivers/gpu/drm/tests/drm_format_helper_test.c +91
-0@@ -957,6 +957,96 @@ static void drm_test_fb_swab(struct kunit *test)KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); } +struct clip_offset_case { +const char *name; +unsigned int pitch; +u32 format; +struct drm_rect clip; +unsigned int expected_offset; +}; + +static struct clip_offset_case clip_offset_cases[] = { + { + .name ="pass through" , + .pitch =TEST_USE_DEFAULT_PITCH , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (0 ,0 ,3 ,3 ), + .expected_offset =0 + }, + { + .name ="horizontal offset" , + .pitch =TEST_USE_DEFAULT_PITCH , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (1 ,0 ,3 ,3 ), + .expected_offset =4 , + }, + { + .name ="vertical offset" , + .pitch =TEST_USE_DEFAULT_PITCH , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (0 ,1 ,3 ,3 ), + .expected_offset =12 , + }, + { + .name ="horizontal and vertical offset" , + .pitch =TEST_USE_DEFAULT_PITCH , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (1 ,1 ,3 ,3 ), + .expected_offset =16 , + }, + { + .name ="horizontal offset (custom pitch)" , + .pitch =20 , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (1 ,0 ,3 ,3 ), + .expected_offset =4 , + }, + { + .name ="vertical offset (custom pitch)" , + .pitch =20 , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (0 ,1 ,3 ,3 ), + .expected_offset =20 , + }, + { + .name ="horizontal and vertical offset (custom pitch)" , + .pitch =20 , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (1 ,1 ,3 ,3 ), + .expected_offset =24 , + }, +}; + +static void clip_offset_case_desc (struct clip_offset_case *t,char *desc) +{ +strscpy (desc, t->name,KUNIT_PARAM_DESC_SIZE ); +} + +KUNIT_ARRAY_PARAM (clip_offset, clip_offset_cases, clip_offset_case_desc); + +static void drm_test_fb_clip_offset (struct kunit *test) +{ +const struct clip_offset_case *params = test->param_value; +const struct drm_format_info *format_info =drm_format_info (params->format); + +unsigned int offset =-1 ; + +unsigned int pitch = params->pitch; + +if (pitch ==TEST_USE_DEFAULT_PITCH ) + pitch =drm_format_info_min_pitch (format_info,0 , +drm_rect_width (¶ms->clip)); + +/* Assure that the pitch is not zero, because this will inevitable cause the +* wrong expected result +*/ +KUNIT_ASSERT_NE (test, pitch,0 ); + + offset =drm_fb_clip_offset (pitch, format_info, ¶ms->clip); + +KUNIT_EXPECT_EQ (test, offset, params->expected_offset); +} +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),@@ -970,6 +1060,7 @@ static struct kunit_case drm_format_helper_test_cases[] = {KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_argb2101010, convert_xrgb8888_gen_params),KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_mono, convert_xrgb8888_gen_params),KUNIT_CASE_PARAM (drm_test_fb_swab, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(drm_test_fb_clip_offset, clip_offset_gen_params), {} };
Re: [PATCH 3/6] drm/format-helper: Add KUnit tests for drm_fb_clip_offset()
In reply to Arthur GrilloEm 21/07/2023 15:23, Arthur Grillo escreveu:
Quoted 79 lines
Insert parameterized test for the
drm_fb_clip_offset()to ensure correctness and prevent future regressions.Signed-off-by Arthur Grillo <[email protected]>--- .../gpu/drm/tests/drm_format_helper_test.c | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+)drivers/gpu/drm/tests/drm_format_helper_test.c +63
-0@@ -957,6 +957,96 @@ static void drm_test_fb_swab(struct kunit *test)KUNIT_EXPECT_MEMEQ (test, buf, result->expected, dst_size); } +struct clip_offset_case { +const char *name; +unsigned int pitch; +u32 format; +struct drm_rect clip; +unsigned int expected_offset; +}; + +static struct clip_offset_case clip_offset_cases[] = { + { + .name ="pass through" , + .pitch =TEST_USE_DEFAULT_PITCH , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (0 ,0 ,3 ,3 ), + .expected_offset =0 + }, + { + .name ="horizontal offset" , + .pitch =TEST_USE_DEFAULT_PITCH , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (1 ,0 ,3 ,3 ), + .expected_offset =4 , + }, + { + .name ="vertical offset" , + .pitch =TEST_USE_DEFAULT_PITCH , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (0 ,1 ,3 ,3 ), + .expected_offset =12 , + }, + { + .name ="horizontal and vertical offset" , + .pitch =TEST_USE_DEFAULT_PITCH , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (1 ,1 ,3 ,3 ), + .expected_offset =16 , + }, + { + .name ="horizontal offset (custom pitch)" , + .pitch =20 , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (1 ,0 ,3 ,3 ), + .expected_offset =4 , + }, + { + .name ="vertical offset (custom pitch)" , + .pitch =20 , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (0 ,1 ,3 ,3 ), + .expected_offset =20 , + }, + { + .name ="horizontal and vertical offset (custom pitch)" , + .pitch =20 , + .format =DRM_FORMAT_XRGB8888 , + .clip =DRM_RECT_INIT (1 ,1 ,3 ,3 ), + .expected_offset =24 , + }, +}; + +static void clip_offset_case_desc (struct clip_offset_case *t,char *desc) +{ +strscpy (desc, t->name,KUNIT_PARAM_DESC_SIZE );
drivers/gpu/drm/tests/drm_format_helper_test.c static void drm_test_fb_swab(struct kunit *test) · line 1032
Quoted 10 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +10
-0+} + +KUNIT_ARRAY_PARAM (clip_offset, clip_offset_cases, clip_offset_case_desc); + +static void drm_test_fb_clip_offset (struct kunit *test) +{ +const struct clip_offset_case *params = test->param_value; +const struct drm_format_info *format_info =drm_format_info (params->format); + +unsigned int offset =-1 ;
why?
drivers/gpu/drm/tests/drm_format_helper_test.c static void drm_test_fb_swab(struct kunit *test) · line 1042
Quoted 10 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +10
-0+ +unsigned int pitch = params->pitch; + +if (pitch ==TEST_USE_DEFAULT_PITCH ) + pitch =drm_format_info_min_pitch (format_info,0 , +drm_rect_width (¶ms->clip)); + +/* Assure that the pitch is not zero, because this will inevitable cause the +* wrong expected result +*/
Multiline comments should be like this:
/*
* Assure that...
*/
Quoted 18 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +8
-0+KUNIT_ASSERT_NE (test, pitch,0 ); + + offset =drm_fb_clip_offset (pitch, format_info, ¶ms->clip); + +KUNIT_EXPECT_EQ (test, offset, params->expected_offset); +} +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),@@ -970,6 +1060,7 @@ static struct kunit_case drm_format_helper_test_cases[] = {KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_argb2101010, convert_xrgb8888_gen_params),KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_mono, convert_xrgb8888_gen_params),KUNIT_CASE_PARAM (drm_test_fb_swab, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(drm_test_fb_clip_offset, clip_offset_gen_params), {} };
PATCH 4/6 drm/format-helper: Add KUnit tests for drm_fb_build_fourcc_list()
In reply to Arthur GrilloInsert parameterized test for the drm_fb_build_fourcc_list() to ensure correctness and prevent future regressions.
--- .../gpu/drm/tests/drm_format_helper_test.c | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+)
drivers/gpu/drm/tests/drm_format_helper_test.c +143 -0
@@ -3,6 +3,7 @@#include <kunit/test.h> #include <drm/drm_device.h> +#include <drm/drm_drv.h> #include <drm/drm_file.h> #include <drm/drm_format_helper.h> #include <drm/drm_fourcc.h>
@@ -11,6 +12,7 @@#include <drm/drm_mode.h> #include <drm/drm_print.h> #include <drm/drm_rect.h> +#include <drm/drm_kunit_helpers.h> #include "../drm_crtc_internal.h"
@@ -1047,6 +1049,146 @@ static void drm_test_fb_clip_offset(struct kunit *test)KUNIT_EXPECT_EQ (test, offset, params->expected_offset); } +struct fb_build_fourcc_list_case { +const char *name; +u32 native_fourccs[TEST_BUF_SIZE ]; +u32 expected[TEST_BUF_SIZE ]; +}; + +struct fb_build_fourcc_list_case fb_build_fourcc_list_cases[] = { + { + .name ="no native formats" , + .native_fourccs = { }, + .expected = {DRM_FORMAT_XRGB8888 }, + }, + { + .name ="XRGB8888 as native format" , + .native_fourccs = {DRM_FORMAT_XRGB8888 }, + .expected = {DRM_FORMAT_XRGB8888 }, + }, + { + .name ="remove duplicates" , + .native_fourccs = { +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_RGB565 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB565 , +DRM_FORMAT_RGB565 , +DRM_FORMAT_XRGB8888 , + }, + .expected = { +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_RGB565 , + }, + }, + { + .name ="convert alpha formats" , + .native_fourccs = { +DRM_FORMAT_ARGB1555 , +DRM_FORMAT_ABGR1555 , +DRM_FORMAT_RGBA5551 , +DRM_FORMAT_BGRA5551 , +DRM_FORMAT_ARGB8888 , +DRM_FORMAT_ABGR8888 , +DRM_FORMAT_RGBA8888 , +DRM_FORMAT_BGRA8888 , +DRM_FORMAT_ARGB2101010 , +DRM_FORMAT_ABGR2101010 , +DRM_FORMAT_RGBA1010102 , +DRM_FORMAT_BGRA1010102 , + }, + .expected = { +DRM_FORMAT_XRGB1555 , +DRM_FORMAT_XBGR1555 , +DRM_FORMAT_RGBX5551 , +DRM_FORMAT_BGRX5551 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_XBGR8888 , +DRM_FORMAT_RGBX8888 , +DRM_FORMAT_BGRX8888 , +DRM_FORMAT_XRGB2101010 , +DRM_FORMAT_XBGR2101010 , +DRM_FORMAT_RGBX1010102 , +DRM_FORMAT_BGRX1010102 , + }, + }, + { + .name ="random formats" , + .native_fourccs = { +DRM_FORMAT_Y212 , +DRM_FORMAT_ARGB1555 , +DRM_FORMAT_ABGR16161616F , +DRM_FORMAT_C8 , +DRM_FORMAT_BGR888 , +DRM_FORMAT_XRGB1555 , +DRM_FORMAT_RGBA5551 , +DRM_FORMAT_BGR565_A8 , +DRM_FORMAT_R10 , +DRM_FORMAT_XYUV8888 , + }, + .expected = { +DRM_FORMAT_Y212 , +DRM_FORMAT_XRGB1555 , +DRM_FORMAT_ABGR16161616F , +DRM_FORMAT_C8 , +DRM_FORMAT_BGR888 , +DRM_FORMAT_RGBX5551 , +DRM_FORMAT_BGR565_A8 , +DRM_FORMAT_R10 , +DRM_FORMAT_XYUV8888 , +DRM_FORMAT_XRGB8888 , + }, + }, +}; + +static void fb_build_fourcc_list_case_desc (struct fb_build_fourcc_list_case *t,char *desc) +{ +strscpy (desc, t->name,KUNIT_PARAM_DESC_SIZE ); +} + +KUNIT_ARRAY_PARAM (fb_build_fourcc_list, fb_build_fourcc_list_cases, fb_build_fourcc_list_case_desc); + +static size_t get_nfourccs (const u32 *fourccs) +{ +size_t i; + +for (i =0 ; i <TEST_BUF_SIZE && fourccs[i]; ++i) + ; + +return i; +} + +static void drm_test_fb_build_fourcc_list (struct kunit *test) +{ +const struct fb_build_fourcc_list_case *params = test->param_value; +u32 fourccs_out[TEST_BUF_SIZE ]; +size_t nfourccs_out; +struct drm_device *drm; +struct device *dev; + + dev =drm_kunit_helper_alloc_device (test); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, dev); + + drm =__drm_kunit_helper_alloc_drm_device (test, dev,sizeof (*drm),0 ,DRIVER_MODESET ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, drm); + + nfourccs_out =drm_fb_build_fourcc_list (drm, params->native_fourccs, +get_nfourccs (params->native_fourccs), + fourccs_out,TEST_BUF_SIZE ); + +drm_kunit_helper_free_device (test, dev); +KUNIT_EXPECT_EQ (test, nfourccs_out,get_nfourccs (params->expected)); +KUNIT_EXPECT_MEMEQ (test, fourccs_out, params->expected,TEST_BUF_SIZE ); +} +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),
@@ -1061,6 +1203,7 @@ static struct kunit_case drm_format_helper_test_cases[] = {KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_mono, convert_xrgb8888_gen_params),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), {} };
Signature · 1 line
2.41.0
Re: [PATCH 4/6] drm/format-helper: Add KUnit tests for drm_fb_build_fourcc_list()
On 7/21/23 15:23, Arthur Grillo wrote:> Insert parameterized test for the drm_fb_build_fourcc_list() to ensure
Quoted 157 lines
correctness and prevent future regressions.
Signed-off-by Arthur Grillo <[email protected]>--- .../gpu/drm/tests/drm_format_helper_test.c | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+)drivers/gpu/drm/tests/drm_format_helper_test.c +128
-0@@ -3,6 +3,7 @@#include <kunit/test.h> #include <drm/drm_device.h> +#include <drm/drm_drv.h> #include <drm/drm_file.h> #include <drm/drm_format_helper.h> #include <drm/drm_fourcc.h> @@ -11,6 +12,7 @@#include <drm/drm_mode.h> #include <drm/drm_print.h> #include <drm/drm_rect.h> +#include <drm/drm_kunit_helpers.h> #include "../drm_crtc_internal.h" @@ -1047,6 +1049,146 @@ static void drm_test_fb_clip_offset(struct kunit *test)KUNIT_EXPECT_EQ (test, offset, params->expected_offset); } +struct fb_build_fourcc_list_case { +const char *name; +u32 native_fourccs[TEST_BUF_SIZE ]; +u32 expected[TEST_BUF_SIZE ]; +}; + +struct fb_build_fourcc_list_case fb_build_fourcc_list_cases[] = { + { + .name ="no native formats" , + .native_fourccs = { }, + .expected = {DRM_FORMAT_XRGB8888 }, + }, + { + .name ="XRGB8888 as native format" , + .native_fourccs = {DRM_FORMAT_XRGB8888 }, + .expected = {DRM_FORMAT_XRGB8888 }, + }, + { + .name ="remove duplicates" , + .native_fourccs = { +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_RGB565 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB565 , +DRM_FORMAT_RGB565 , +DRM_FORMAT_XRGB8888 , + }, + .expected = { +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_RGB565 , + }, + }, + { + .name ="convert alpha formats" , + .native_fourccs = { +DRM_FORMAT_ARGB1555 , +DRM_FORMAT_ABGR1555 , +DRM_FORMAT_RGBA5551 , +DRM_FORMAT_BGRA5551 , +DRM_FORMAT_ARGB8888 , +DRM_FORMAT_ABGR8888 , +DRM_FORMAT_RGBA8888 , +DRM_FORMAT_BGRA8888 , +DRM_FORMAT_ARGB2101010 , +DRM_FORMAT_ABGR2101010 , +DRM_FORMAT_RGBA1010102 , +DRM_FORMAT_BGRA1010102 , + }, + .expected = { +DRM_FORMAT_XRGB1555 , +DRM_FORMAT_XBGR1555 , +DRM_FORMAT_RGBX5551 , +DRM_FORMAT_BGRX5551 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_XBGR8888 , +DRM_FORMAT_RGBX8888 , +DRM_FORMAT_BGRX8888 , +DRM_FORMAT_XRGB2101010 , +DRM_FORMAT_XBGR2101010 , +DRM_FORMAT_RGBX1010102 , +DRM_FORMAT_BGRX1010102 , + }, + }, + { + .name ="random formats" , + .native_fourccs = { +DRM_FORMAT_Y212 , +DRM_FORMAT_ARGB1555 , +DRM_FORMAT_ABGR16161616F , +DRM_FORMAT_C8 , +DRM_FORMAT_BGR888 , +DRM_FORMAT_XRGB1555 , +DRM_FORMAT_RGBA5551 , +DRM_FORMAT_BGR565_A8 , +DRM_FORMAT_R10 , +DRM_FORMAT_XYUV8888 , + }, + .expected = { +DRM_FORMAT_Y212 , +DRM_FORMAT_XRGB1555 , +DRM_FORMAT_ABGR16161616F , +DRM_FORMAT_C8 , +DRM_FORMAT_BGR888 , +DRM_FORMAT_RGBX5551 , +DRM_FORMAT_BGR565_A8 , +DRM_FORMAT_R10 , +DRM_FORMAT_XYUV8888 , +DRM_FORMAT_XRGB8888 , + }, + }, +}; + +static void fb_build_fourcc_list_case_desc (struct fb_build_fourcc_list_case *t,char *desc) +{ +strscpy (desc, t->name,KUNIT_PARAM_DESC_SIZE ); +} + +KUNIT_ARRAY_PARAM (fb_build_fourcc_list, fb_build_fourcc_list_cases, fb_build_fourcc_list_case_desc); + +static size_t get_nfourccs (const u32 *fourccs) +{ +size_t i; + +for (i =0 ; i <TEST_BUF_SIZE && fourccs[i]; ++i) + ; + +return i; +} + +static void drm_test_fb_build_fourcc_list (struct kunit *test) +{ +const struct fb_build_fourcc_list_case *params = test->param_value; +u32 fourccs_out[TEST_BUF_SIZE ]; +size_t nfourccs_out; +struct drm_device *drm; +struct device *dev; + + dev =drm_kunit_helper_alloc_device (test);
drivers/gpu/drm/tests/drm_format_helper_test.c static void drm_test_fb_clip_offset(struct kunit *test) · line 1187
Quoted 10 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +10
-0+KUNIT_ASSERT_NOT_ERR_OR_NULL (test, dev); + + drm =__drm_kunit_helper_alloc_drm_device (test, dev,sizeof (*drm),0 ,DRIVER_MODESET ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, drm); + + nfourccs_out =drm_fb_build_fourcc_list (drm, params->native_fourccs, +get_nfourccs (params->native_fourccs), + fourccs_out,TEST_BUF_SIZE ); + +drm_kunit_helper_free_device (test, dev);
I believe that this function is no longer needed after Maxime's patches.
drivers/gpu/drm/tests/drm_format_helper_test.c static void drm_test_fb_clip_offset(struct kunit *test) · line 1188
Quoted 1 line
drivers/gpu/drm/tests/drm_format_helper_test.c +1
-0+KUNIT_EXPECT_EQ (test, nfourccs_out,get_nfourccs (params->expected));
Instead of using this get_fourccs() functions, wouldn't it be better to hardcode the number of expected fourccs in the cases?
Best Regards,
- Maíra
Quoted 14 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +4
-0+KUNIT_EXPECT_MEMEQ (test, fourccs_out, params->expected,TEST_BUF_SIZE ); +} +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),@@ -1061,6 +1203,7 @@ static struct kunit_case drm_format_helper_test_cases[] = {KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_mono, convert_xrgb8888_gen_params),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), {} };
Re: [PATCH 4/6] drm/format-helper: Add KUnit tests for drm_fb_build_fourcc_list()
In reply to Arthur GrilloEm 21/07/2023 15:23, Arthur Grillo escreveu:
Quoted 21 lines
Insert parameterized test for the
drm_fb_build_fourcc_list()to ensure correctness and prevent future regressions.Signed-off-by Arthur Grillo <[email protected]>--- .../gpu/drm/tests/drm_format_helper_test.c | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+)drivers/gpu/drm/tests/drm_format_helper_test.c +1
-0@@ -3,6 +3,7 @@#include <kunit/test.h> #include <drm/drm_device.h> +#include <drm/drm_drv.h> #include <drm/drm_file.h> #include <drm/drm_format_helper.h> #include <drm/drm_fourcc.h>
drivers/gpu/drm/tests/drm_format_helper_test.c line 15
Quoted 4 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +1
-0@@ -11,6 +12,7 @@#include <drm/drm_mode.h> #include <drm/drm_print.h> #include <drm/drm_rect.h> +#include <drm/drm_kunit_helpers.h>
Keep the includes sorted please
Quoted 113 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +106
-0#include "../drm_crtc_internal.h" @@ -1047,6 +1049,146 @@ static void drm_test_fb_clip_offset(struct kunit *test)KUNIT_EXPECT_EQ (test, offset, params->expected_offset); } +struct fb_build_fourcc_list_case { +const char *name; +u32 native_fourccs[TEST_BUF_SIZE ]; +u32 expected[TEST_BUF_SIZE ]; +}; + +struct fb_build_fourcc_list_case fb_build_fourcc_list_cases[] = { + { + .name ="no native formats" , + .native_fourccs = { }, + .expected = {DRM_FORMAT_XRGB8888 }, + }, + { + .name ="XRGB8888 as native format" , + .native_fourccs = {DRM_FORMAT_XRGB8888 }, + .expected = {DRM_FORMAT_XRGB8888 }, + }, + { + .name ="remove duplicates" , + .native_fourccs = { +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_RGB565 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB565 , +DRM_FORMAT_RGB565 , +DRM_FORMAT_XRGB8888 , + }, + .expected = { +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB888 , +DRM_FORMAT_RGB565 , + }, + }, + { + .name ="convert alpha formats" , + .native_fourccs = { +DRM_FORMAT_ARGB1555 , +DRM_FORMAT_ABGR1555 , +DRM_FORMAT_RGBA5551 , +DRM_FORMAT_BGRA5551 , +DRM_FORMAT_ARGB8888 , +DRM_FORMAT_ABGR8888 , +DRM_FORMAT_RGBA8888 , +DRM_FORMAT_BGRA8888 , +DRM_FORMAT_ARGB2101010 , +DRM_FORMAT_ABGR2101010 , +DRM_FORMAT_RGBA1010102 , +DRM_FORMAT_BGRA1010102 , + }, + .expected = { +DRM_FORMAT_XRGB1555 , +DRM_FORMAT_XBGR1555 , +DRM_FORMAT_RGBX5551 , +DRM_FORMAT_BGRX5551 , +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_XBGR8888 , +DRM_FORMAT_RGBX8888 , +DRM_FORMAT_BGRX8888 , +DRM_FORMAT_XRGB2101010 , +DRM_FORMAT_XBGR2101010 , +DRM_FORMAT_RGBX1010102 , +DRM_FORMAT_BGRX1010102 , + }, + }, + { + .name ="random formats" , + .native_fourccs = { +DRM_FORMAT_Y212 , +DRM_FORMAT_ARGB1555 , +DRM_FORMAT_ABGR16161616F , +DRM_FORMAT_C8 , +DRM_FORMAT_BGR888 , +DRM_FORMAT_XRGB1555 , +DRM_FORMAT_RGBA5551 , +DRM_FORMAT_BGR565_A8 , +DRM_FORMAT_R10 , +DRM_FORMAT_XYUV8888 , + }, + .expected = { +DRM_FORMAT_Y212 , +DRM_FORMAT_XRGB1555 , +DRM_FORMAT_ABGR16161616F , +DRM_FORMAT_C8 , +DRM_FORMAT_BGR888 , +DRM_FORMAT_RGBX5551 , +DRM_FORMAT_BGR565_A8 , +DRM_FORMAT_R10 , +DRM_FORMAT_XYUV8888 , +DRM_FORMAT_XRGB8888 , + }, + }, +}; + +static void fb_build_fourcc_list_case_desc (struct fb_build_fourcc_list_case *t,char *desc) +{ +strscpy (desc, t->name,KUNIT_PARAM_DESC_SIZE ); +} + +KUNIT_ARRAY_PARAM (fb_build_fourcc_list, fb_build_fourcc_list_cases, fb_build_fourcc_list_case_desc);
drivers/gpu/drm/tests/drm_format_helper_test.c static void drm_test_fb_clip_offset(struct kunit *test) · line 1167
Quoted 10 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +10
-0+ +static size_t get_nfourccs (const u32 *fourccs) +{ +size_t i; + +for (i =0 ; i <TEST_BUF_SIZE && fourccs[i]; ++i) + ; + +return i; +}
I agree with Maira here, maybe a .fourccs_size struct member would be better
Quoted 35 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +25
-0+ +static void drm_test_fb_build_fourcc_list (struct kunit *test) +{ +const struct fb_build_fourcc_list_case *params = test->param_value; +u32 fourccs_out[TEST_BUF_SIZE ]; +size_t nfourccs_out; +struct drm_device *drm; +struct device *dev; + + dev =drm_kunit_helper_alloc_device (test); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, dev); + + drm =__drm_kunit_helper_alloc_drm_device (test, dev,sizeof (*drm),0 ,DRIVER_MODESET ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, drm); + + nfourccs_out =drm_fb_build_fourcc_list (drm, params->native_fourccs, +get_nfourccs (params->native_fourccs), + fourccs_out,TEST_BUF_SIZE ); + +drm_kunit_helper_free_device (test, dev); +KUNIT_EXPECT_EQ (test, nfourccs_out,get_nfourccs (params->expected)); +KUNIT_EXPECT_MEMEQ (test, fourccs_out, params->expected,TEST_BUF_SIZE ); +} +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),@@ -1061,6 +1203,7 @@ static struct kunit_case drm_format_helper_test_cases[] = {KUNIT_CASE_PARAM (drm_test_fb_xrgb8888_to_mono, convert_xrgb8888_gen_params),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), {} };
PATCH 5/6 drm/format-helper-test: Add multi-plane support to conversion_buf_size()
In reply to Arthur GrilloThe drm_fb_memcpy() supports multi-plane formats. To fully test it in the future, add multi-plane support to the conversion_buf_size() helper.
--- .../gpu/drm/tests/drm_format_helper_test.c | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/tests/drm_format_helper_test.c +14 -14
@@ -472,7 +472,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {* The size of the destination buffer or negative value on error. */ static size_t conversion_buf_size (u32 dst_format,unsigned int dst_pitch, -const struct drm_rect *clip) +const struct drm_rect *clip,int plane) {const struct drm_format_info *dst_fi =drm_format_info (dst_format);
@@ -480,7 +480,7 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch,return -EINVAL ;if (!dst_pitch) - dst_pitch =drm_format_info_min_pitch (dst_fi,0 ,drm_rect_width (clip)); + dst_pitch =drm_format_info_min_pitch (dst_fi, plane,drm_rect_width (clip));return dst_pitch *drm_rect_height (clip); }
@@ -554,7 +554,7 @@ static void drm_test_fb_xrgb8888_to_gray8(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_R8 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );
@@ -587,7 +587,7 @@ static void drm_test_fb_xrgb8888_to_rgb332(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_RGB332 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );
@@ -620,7 +620,7 @@ static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_RGB565 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );
@@ -663,7 +663,7 @@ static void drm_test_fb_xrgb8888_to_xrgb1555(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_XRGB1555 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );
@@ -697,7 +697,7 @@ static void drm_test_fb_xrgb8888_to_argb1555(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_ARGB1555 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );
@@ -731,7 +731,7 @@ static void drm_test_fb_xrgb8888_to_rgba5551(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_RGBA5551 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );
@@ -765,7 +765,7 @@ static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_RGB888 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );
@@ -803,7 +803,7 @@ static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_ARGB8888 , - result->dst_pitch, ¶ms->clip); + result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );
@@ -838,7 +838,7 @@ static void drm_test_fb_xrgb8888_to_xrgb2101010(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_XRGB2101010 , - result->dst_pitch, ¶ms->clip); + result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );
@@ -872,7 +872,7 @@ static void drm_test_fb_xrgb8888_to_argb2101010(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_ARGB2101010 , - result->dst_pitch, ¶ms->clip); + result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );
@@ -906,7 +906,7 @@ static void drm_test_fb_xrgb8888_to_mono(struct kunit *test) .pitches = { params->pitch, 0, 0 }, }; - dst_size =conversion_buf_size (DRM_FORMAT_C1 , result->dst_pitch, ¶ms->clip); + dst_size =conversion_buf_size (DRM_FORMAT_C1 , result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 );
@@ -939,7 +939,7 @@ static void drm_test_fb_swab(struct kunit *test) .pitches = { params->pitch, 0, 0 }, }; - dst_size =conversion_buf_size (DRM_FORMAT_XRGB8888 , result->dst_pitch, ¶ms->clip); + dst_size =conversion_buf_size (DRM_FORMAT_XRGB8888 , result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 );
Signature · 1 line
2.41.0
Re: [PATCH 5/6] drm/format-helper-test: Add multi-plane support to conversion_buf_size()
Quoted 4 lines · Arthur Grillo
The
drm_fb_memcpy()supports multi-plane formats. To fully test it in the future, add multi-plane support to theconversion_buf_size()helper.Signed-off-by Arthur Grillo <[email protected]>
Best Regards,
- Maíra
Quoted 134 lines
--- .../gpu/drm/tests/drm_format_helper_test.c | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-)drivers/gpu/drm/tests/drm_format_helper_test.c +14
-14@@ -472,7 +472,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {* The size of the destination buffer or negative value on error. */ static size_t conversion_buf_size (u32 dst_format,unsigned int dst_pitch, -const struct drm_rect *clip) +const struct drm_rect *clip,int plane) {const struct drm_format_info *dst_fi =drm_format_info (dst_format);@@ -480,7 +480,7 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch,return -EINVAL ;if (!dst_pitch) - dst_pitch =drm_format_info_min_pitch (dst_fi,0 ,drm_rect_width (clip)); + dst_pitch =drm_format_info_min_pitch (dst_fi, plane,drm_rect_width (clip));return dst_pitch *drm_rect_height (clip); }@@ -554,7 +554,7 @@ static void drm_test_fb_xrgb8888_to_gray8(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_R8 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -587,7 +587,7 @@ static void drm_test_fb_xrgb8888_to_rgb332(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_RGB332 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -620,7 +620,7 @@ static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_RGB565 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -663,7 +663,7 @@ static void drm_test_fb_xrgb8888_to_xrgb1555(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_XRGB1555 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -697,7 +697,7 @@ static void drm_test_fb_xrgb8888_to_argb1555(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_ARGB1555 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -731,7 +731,7 @@ static void drm_test_fb_xrgb8888_to_rgba5551(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_RGBA5551 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -765,7 +765,7 @@ static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_RGB888 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -803,7 +803,7 @@ static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_ARGB8888 , - result->dst_pitch, ¶ms->clip); + result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -838,7 +838,7 @@ static void drm_test_fb_xrgb8888_to_xrgb2101010(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_XRGB2101010 , - result->dst_pitch, ¶ms->clip); + result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -872,7 +872,7 @@ static void drm_test_fb_xrgb8888_to_argb2101010(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_ARGB2101010 , - result->dst_pitch, ¶ms->clip); + result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -906,7 +906,7 @@ static void drm_test_fb_xrgb8888_to_mono(struct kunit *test) .pitches = { params->pitch, 0, 0 }, }; - dst_size =conversion_buf_size (DRM_FORMAT_C1 , result->dst_pitch, ¶ms->clip); + dst_size =conversion_buf_size (DRM_FORMAT_C1 , result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 );@@ -939,7 +939,7 @@ static void drm_test_fb_swab(struct kunit *test) .pitches = { params->pitch, 0, 0 }, }; - dst_size =conversion_buf_size (DRM_FORMAT_XRGB8888 , result->dst_pitch, ¶ms->clip); + dst_size =conversion_buf_size (DRM_FORMAT_XRGB8888 , result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 );
Re: [PATCH 5/6] drm/format-helper-test: Add multi-plane support to conversion_buf_size()
In reply to Arthur GrilloEm 21/07/2023 15:23, Arthur Grillo escreveu:
Quoted 5 lines
The
drm_fb_memcpy()supports multi-plane formats. To fully test it in the future, add multi-plane support to theconversion_buf_size()helper.Signed-off-by Arthur Grillo <[email protected]>---
I think this would be a more concrect improvement if the plane parameter was really used. Anyway,
Quoted 133 lines
.../gpu/drm/tests/drm_format_helper_test.c | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-)drivers/gpu/drm/tests/drm_format_helper_test.c +14
-14@@ -472,7 +472,7 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {* The size of the destination buffer or negative value on error. */ static size_t conversion_buf_size (u32 dst_format,unsigned int dst_pitch, -const struct drm_rect *clip) +const struct drm_rect *clip,int plane) {const struct drm_format_info *dst_fi =drm_format_info (dst_format);@@ -480,7 +480,7 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch,return -EINVAL ;if (!dst_pitch) - dst_pitch =drm_format_info_min_pitch (dst_fi,0 ,drm_rect_width (clip)); + dst_pitch =drm_format_info_min_pitch (dst_fi, plane,drm_rect_width (clip));return dst_pitch *drm_rect_height (clip); }@@ -554,7 +554,7 @@ static void drm_test_fb_xrgb8888_to_gray8(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_R8 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -587,7 +587,7 @@ static void drm_test_fb_xrgb8888_to_rgb332(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_RGB332 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -620,7 +620,7 @@ static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_RGB565 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -663,7 +663,7 @@ static void drm_test_fb_xrgb8888_to_xrgb1555(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_XRGB1555 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -697,7 +697,7 @@ static void drm_test_fb_xrgb8888_to_argb1555(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_ARGB1555 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -731,7 +731,7 @@ static void drm_test_fb_xrgb8888_to_rgba5551(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_RGBA5551 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -765,7 +765,7 @@ static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_RGB888 , result->dst_pitch, - ¶ms->clip); + ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -803,7 +803,7 @@ static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_ARGB8888 , - result->dst_pitch, ¶ms->clip); + result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -838,7 +838,7 @@ static void drm_test_fb_xrgb8888_to_xrgb2101010(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_XRGB2101010 , - result->dst_pitch, ¶ms->clip); + result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -872,7 +872,7 @@ static void drm_test_fb_xrgb8888_to_argb2101010(struct kunit *test) }; dst_size =conversion_buf_size (DRM_FORMAT_ARGB2101010 , - result->dst_pitch, ¶ms->clip); + result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 ); buf =kunit_kzalloc (test, dst_size,GFP_KERNEL );@@ -906,7 +906,7 @@ static void drm_test_fb_xrgb8888_to_mono(struct kunit *test) .pitches = { params->pitch, 0, 0 }, }; - dst_size =conversion_buf_size (DRM_FORMAT_C1 , result->dst_pitch, ¶ms->clip); + dst_size =conversion_buf_size (DRM_FORMAT_C1 , result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 );@@ -939,7 +939,7 @@ static void drm_test_fb_swab(struct kunit *test) .pitches = { params->pitch, 0, 0 }, }; - dst_size =conversion_buf_size (DRM_FORMAT_XRGB8888 , result->dst_pitch, ¶ms->clip); + dst_size =conversion_buf_size (DRM_FORMAT_XRGB8888 , result->dst_pitch, ¶ms->clip,0 );KUNIT_ASSERT_GT (test, dst_size,0 );
PATCH 6/6 drm/format-helper: Add KUnit tests for drm_fb_memcpy()
In reply to Arthur GrilloInsert parameterized test for the drm_fb_memcpy() to ensure correctness and prevent future regressions. The test case can accept different formats.
--- .../gpu/drm/tests/drm_format_helper_test.c | 391 ++++++++++++++++++ 1 file changed, 391 insertions(+)
drivers/gpu/drm/tests/drm_format_helper_test.c +391 -0
@@ -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), {} };
Signature · 1 line
2.41.0
kernel test robot
build botRe: [PATCH 6/6] drm/format-helper: Add KUnit tests for drm_fb_memcpy()
kernel test robot noticed the following build warnings:
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/[email protected]/config) compiler: nios2-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230725/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
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
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH 6/6] drm/format-helper: Add KUnit tests for drm_fb_memcpy()
In reply to Arthur GrilloQuoted 58 lines · Arthur Grillo
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 <[email protected]>--- .../gpu/drm/tests/drm_format_helper_test.c | 391 ++++++++++++++++++ 1 file changed, 391 insertions(+)drivers/gpu/drm/tests/drm_format_helper_test.c +41
-0@@ -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 },
drivers/gpu/drm/tests/drm_format_helper_test.c static void drm_test_fb_build_fourcc_list(struct kunit *test) · line 1242
Quoted 10 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +10
-0+ { 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
Quoted 350 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +340
-0+ { + .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), {} };
Re: [PATCH 6/6] drm/format-helper: Add KUnit tests for drm_fb_memcpy()
Quoted 63 lines · Maira Canal
Quoted 62 lines · Arthur Grillo
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 <[email protected]>--- .../gpu/drm/tests/drm_format_helper_test.c | 391 ++++++++++++++++++ 1 file changed, 391 insertions(+)drivers/gpu/drm/tests/drm_format_helper_test.c +45
-0@@ -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 = {
Quoted 8 lines
drivers/gpu/drm/tests/drm_format_helper_test.c static void drm_test_fb_build_fourcc_list(struct kunit *test) · line 1242
Quoted 5 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +5
-0+ { 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
Quoted 354 lines
Best Regards,
- MaíraQuoted 350 lines
drivers/gpu/drm/tests/drm_format_helper_test.c +340
-0+ { + .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), {} };