drm/tests: Test default pitch fallback
authorArthur Grillo <arthurgrillo@riseup.net>
Mon, 14 Aug 2023 22:12:00 +0000 (19:12 -0300)
committerMaíra Canal <mairacanal@riseup.net>
Sat, 26 Aug 2023 14:36:10 +0000 (11:36 -0300)
Test the default pitch fallback when NULL is passed as the dst_pitch on
the conversion procedures.

Reviewed-by: Maíra Canal <mairacanal@riseup.net>
Signed-off-by: Arthur Grillo <arthurgrillo@riseup.net>
Signed-off-by: Maíra Canal <mairacanal@riseup.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20230814-gsoc-drm-format-test-v2-v3-1-bd3e9f9bc2fb@riseup.net
drivers/gpu/drm/tests/drm_format_helper_test.c

index 474bb7a1c4ee70046e2ab195f5baf47e92a23885..c35e77e4979b5ef946a1c88fce8f3639a5c7fd1c 100644 (file)
@@ -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,11 @@ 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, &params->clip);
+       const 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, &params->clip);
+
        KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -560,7 +566,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, &params->clip);
+       const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
+               NULL : &result->dst_pitch;
+
+       drm_fb_xrgb8888_to_rgb332(&dst, dst_pitch, &src, &fb, &params->clip);
        KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -590,7 +599,10 @@ 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, &params->clip, false);
+       const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
+               NULL : &result->dst_pitch;
+
+       drm_fb_xrgb8888_to_rgb565(&dst, dst_pitch, &src, &fb, &params->clip, false);
        buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
        KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 
@@ -626,7 +638,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, &params->clip);
+       const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
+               NULL : &result->dst_pitch;
+
+       drm_fb_xrgb8888_to_xrgb1555(&dst, dst_pitch, &src, &fb, &params->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 +672,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, &params->clip);
+       const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
+               NULL : &result->dst_pitch;
+
+       drm_fb_xrgb8888_to_argb1555(&dst, dst_pitch, &src, &fb, &params->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 +706,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, &params->clip);
+       const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
+               NULL : &result->dst_pitch;
+
+       drm_fb_xrgb8888_to_rgba5551(&dst, dst_pitch, &src, &fb, &params->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 +744,10 @@ 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, &params->clip);
+       const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
+               NULL : &result->dst_pitch;
+
+       drm_fb_xrgb8888_to_rgb888(&dst, dst_pitch, &src, &fb, &params->clip);
        KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -753,7 +777,10 @@ 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, &params->clip);
+       const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
+               NULL : &result->dst_pitch;
+
+       drm_fb_xrgb8888_to_argb8888(&dst, dst_pitch, &src, &fb, &params->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 +811,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, &params->clip);
+       const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
+               NULL : &result->dst_pitch;
+
+       drm_fb_xrgb8888_to_xrgb2101010(&dst, dst_pitch, &src, &fb, &params->clip);
        buf = le32buf_to_cpu(test, buf, dst_size / sizeof(u32));
        KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
@@ -815,7 +845,10 @@ 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, &params->clip);
+       const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
+               NULL : &result->dst_pitch;
+
+       drm_fb_xrgb8888_to_argb2101010(&dst, dst_pitch, &src, &fb, &params->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 +879,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, &params->clip);
+       const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
+               NULL : &result->dst_pitch;
+
+       drm_fb_xrgb8888_to_mono(&dst, dst_pitch, &src, &fb, &params->clip);
        KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }