// SPDX-License-Identifier: GPL-2.0+
#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>
#include <drm/drm_framebuffer.h>
#include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_kunit_helpers.h>
#include <drm/drm_mode.h>
#include <drm/drm_print.h>
#include <drm/drm_rect.h>
#include "../drm_crtc_internal.h"
#define TEST_BUF_SIZE 50
#define TEST_USE_DEFAULT_PITCH 0
static unsigned char fmtcnv_state_mem[PAGE_SIZE];
static struct drm_format_conv_state fmtcnv_state =
DRM_FORMAT_CONV_STATE_INIT_PREALLOCATED(fmtcnv_state_mem, sizeof (fmtcnv_state_mem));
struct convert_to_gray8_result {
unsigned int dst_pitch;
const u8 expected[TEST_BUF_SIZE];
};
struct convert_to_rgb332_result {
unsigned int dst_pitch;
const u8 expected[TEST_BUF_SIZE];
};
struct convert_to_rgb565_result {
unsigned int dst_pitch;
const u16 expected[TEST_BUF_SIZE];
const u16 expected_swab[TEST_BUF_SIZE];
};
struct convert_to_xrgb1555_result {
unsigned int dst_pitch;
const u16 expected[TEST_BUF_SIZE];
};
struct convert_to_argb1555_result {
unsigned int dst_pitch;
const u16 expected[TEST_BUF_SIZE];
};
struct convert_to_rgba5551_result {
unsigned int dst_pitch;
const u16 expected[TEST_BUF_SIZE];
};
struct convert_to_rgb888_result {
unsigned int dst_pitch;
const u8 expected[TEST_BUF_SIZE];
};
struct convert_to_bgr888_result {
unsigned int dst_pitch;
const u8 expected[TEST_BUF_SIZE];
};
struct convert_to_argb8888_result {
unsigned int dst_pitch;
const u32 expected[TEST_BUF_SIZE];
};
struct convert_to_xrgb2101010_result {
unsigned int dst_pitch;
const u32 expected[TEST_BUF_SIZE];
};
struct convert_to_argb2101010_result {
unsigned int dst_pitch;
const u32 expected[TEST_BUF_SIZE];
};
struct convert_to_mono_result {
unsigned int dst_pitch;
const u8 expected[TEST_BUF_SIZE];
};
struct fb_swab_result {
unsigned int dst_pitch;
const u32 expected[TEST_BUF_SIZE];
};
struct convert_to_xbgr8888_result {
unsigned int dst_pitch;
const u32 expected[TEST_BUF_SIZE];
};
struct convert_to_abgr8888_result {
unsigned int dst_pitch;
const u32 expected[TEST_BUF_SIZE];
};
struct convert_xrgb8888_case {
const char *name;
unsigned int pitch;
struct drm_rect clip;
const u32 xrgb8888[TEST_BUF_SIZE];
struct convert_to_gray8_result gray8_result;
struct convert_to_rgb332_result rgb332_result;
struct convert_to_rgb565_result rgb565_result;
struct convert_to_xrgb1555_result xrgb1555_result;
struct convert_to_argb1555_result argb1555_result;
struct convert_to_rgba5551_result rgba5551_result;
struct convert_to_rgb888_result rgb888_result;
struct convert_to_bgr888_result bgr888_result;
struct convert_to_argb8888_result argb8888_result;
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;
struct convert_to_xbgr8888_result xbgr8888_result;
struct convert_to_abgr8888_result abgr8888_result;
};
static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
{
.name = "single_pixel_source_buffer" ,
.pitch = 1 * 4 ,
.clip = DRM_RECT_INIT(0 , 0 , 1 , 1 ),
.xrgb8888 = { 0 x01FF0000 },
.gray8_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 x4C },
},
.rgb332_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xE0 },
},
.rgb565_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xF800 },
.expected_swab = { 0 x00F8 },
},
.xrgb1555_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 x7C00 },
},
.argb1555_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xFC00 },
},
.rgba5551_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xF801 },
},
.rgb888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 x00, 0 x00, 0 xFF },
},
.bgr888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xFF, 0 x00, 0 x00 },
},
.argb8888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xFFFF0000 },
},
.xrgb2101010_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 x3FF00000 },
},
.argb2101010_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xFFF00000 },
},
.mono_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 b0 },
},
.swab_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 x0000FF01 },
},
.xbgr8888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 x010000FF },
},
.abgr8888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xFF0000FF },
},
},
{
.name = "single_pixel_clip_rectangle" ,
.pitch = 2 * 4 ,
.clip = DRM_RECT_INIT(1 , 1 , 1 , 1 ),
.xrgb8888 = {
0 x00000000, 0 x00000000,
0 x00000000, 0 x10FF0000,
},
.gray8_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 x4C },
},
.rgb332_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xE0 },
},
.rgb565_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xF800 },
.expected_swab = { 0 x00F8 },
},
.xrgb1555_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 x7C00 },
},
.argb1555_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xFC00 },
},
.rgba5551_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xF801 },
},
.rgb888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 x00, 0 x00, 0 xFF },
},
.bgr888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xFF, 0 x00, 0 x00 },
},
.argb8888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xFFFF0000 },
},
.xrgb2101010_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 x3FF00000 },
},
.argb2101010_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xFFF00000 },
},
.mono_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 b0 },
},
.swab_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 x0000FF10 },
},
.xbgr8888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 x100000FF },
},
.abgr8888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = { 0 xFF0000FF },
},
},
{
/* Well known colors: White, black, red, green, blue, magenta,
* yellow and cyan. Different values for the X in XRGB8888 to
* make sure it is ignored. Partial clip area.
*/
.name = "well_known_colors" ,
.pitch = 4 * 4 ,
.clip = DRM_RECT_INIT(1 , 1 , 2 , 4 ),
.xrgb8888 = {
0 x00000000, 0 x00000000, 0 x00000000, 0 x00000000,
0 x00000000, 0 x11FFFFFF, 0 x22000000, 0 x00000000,
0 x00000000, 0 x33FF0000, 0 x4400FF00, 0 x00000000,
0 x00000000, 0 x550000FF, 0 x66FF00FF, 0 x00000000,
0 x00000000, 0 x77FFFF00, 0 x8800FFFF, 0 x00000000,
},
.gray8_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 xFF, 0 x00,
0 x4C, 0 x95,
0 x1C, 0 x69,
0 xE2, 0 xB2,
},
},
.rgb332_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 xFF, 0 x00,
0 xE0, 0 x1C,
0 x03, 0 xE3,
0 xFC, 0 x1F,
},
},
.rgb565_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 xFFFF, 0 x0000,
0 xF800, 0 x07E0,
0 x001F, 0 xF81F,
0 xFFE0, 0 x07FF,
},
.expected_swab = {
0 xFFFF, 0 x0000,
0 x00F8, 0 xE007,
0 x1F00, 0 x1FF8,
0 xE0FF, 0 xFF07,
},
},
.xrgb1555_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 x7FFF, 0 x0000,
0 x7C00, 0 x03E0,
0 x001F, 0 x7C1F,
0 x7FE0, 0 x03FF,
},
},
.argb1555_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 xFFFF, 0 x8000,
0 xFC00, 0 x83E0,
0 x801F, 0 xFC1F,
0 xFFE0, 0 x83FF,
},
},
.rgba5551_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 xFFFF, 0 x0001,
0 xF801, 0 x07C1,
0 x003F, 0 xF83F,
0 xFFC1, 0 x07FF,
},
},
.rgb888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 xFF, 0 xFF, 0 xFF, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 xFF, 0 x00, 0 xFF, 0 x00,
0 xFF, 0 x00, 0 x00, 0 xFF, 0 x00, 0 xFF,
0 x00, 0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 x00,
},
},
.bgr888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 xFF, 0 xFF, 0 xFF, 0 x00, 0 x00, 0 x00,
0 xFF, 0 x00, 0 x00, 0 x00, 0 xFF, 0 x00,
0 x00, 0 x00, 0 xFF, 0 xFF, 0 x00, 0 xFF,
0 xFF, 0 xFF, 0 x00, 0 x00, 0 xFF, 0 xFF,
},
},
.argb8888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 xFFFFFFFF, 0 xFF000000,
0 xFFFF0000, 0 xFF00FF00,
0 xFF0000FF, 0 xFFFF00FF,
0 xFFFFFF00, 0 xFF00FFFF,
},
},
.xrgb2101010_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 x3FFFFFFF, 0 x00000000,
0 x3FF00000, 0 x000FFC00,
0 x000003FF, 0 x3FF003FF,
0 x3FFFFC00, 0 x000FFFFF,
},
},
.argb2101010_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 xFFFFFFFF, 0 xC0000000,
0 xFFF00000, 0 xC00FFC00,
0 xC00003FF, 0 xFFF003FF,
0 xFFFFFC00, 0 xC00FFFFF,
},
},
.mono_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 b01,
0 b10,
0 b00,
0 b11,
},
},
.swab_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 xFFFFFF11, 0 x00000022,
0 x0000FF33, 0 x00FF0044,
0 xFF000055, 0 xFF00FF66,
0 x00FFFF77, 0 xFFFF0088,
},
},
.xbgr8888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 x11FFFFFF, 0 x22000000,
0 x330000FF, 0 x4400FF00,
0 x55FF0000, 0 x66FF00FF,
0 x7700FFFF, 0 x88FFFF00,
},
},
.abgr8888_result = {
.dst_pitch = TEST_USE_DEFAULT_PITCH,
.expected = {
0 xFFFFFFFF, 0 xFF000000,
0 xFF0000FF, 0 xFF00FF00,
0 xFFFF0000, 0 xFFFF00FF,
0 xFF00FFFF, 0 xFFFFFF00,
},
},
},
{
/* Randomly picked colors. Full buffer within the clip area. */
.name = "destination_pitch" ,
.pitch = 3 * 4 ,
.clip = DRM_RECT_INIT(0 , 0 , 3 , 3 ),
.xrgb8888 = {
0 xA10E449C, 0 xB1114D05, 0 xC1A8F303,
0 xD16CF073, 0 xA20E449C, 0 xB2114D05,
0 xC2A80303, 0 xD26CF073, 0 xA30E449C,
},
.gray8_result = {
.dst_pitch = 5 ,
.expected = {
0 x3D, 0 x32, 0 xC1, 0 x00, 0 x00,
0 xBA, 0 x3D, 0 x32, 0 x00, 0 x00,
0 x34, 0 xBA, 0 x3D, 0 x00, 0 x00,
},
},
.rgb332_result = {
.dst_pitch = 5 ,
.expected = {
0 x0A, 0 x08, 0 xBC, 0 x00, 0 x00,
0 x7D, 0 x0A, 0 x08, 0 x00, 0 x00,
0 xA0, 0 x7D, 0 x0A, 0 x00, 0 x00,
},
},
.rgb565_result = {
.dst_pitch = 10 ,
.expected = {
0 x0A33, 0 x1260, 0 xAF80, 0 x0000, 0 x0000,
0 x6F8E, 0 x0A33, 0 x1260, 0 x0000, 0 x0000,
0 xA800, 0 x6F8E, 0 x0A33, 0 x0000, 0 x0000,
},
.expected_swab = {
0 x330A, 0 x6012, 0 x80AF, 0 x0000, 0 x0000,
0 x8E6F, 0 x330A, 0 x6012, 0 x0000, 0 x0000,
0 x00A8, 0 x8E6F, 0 x330A, 0 x0000, 0 x0000,
},
},
.xrgb1555_result = {
.dst_pitch = 10 ,
.expected = {
0 x0513, 0 x0920, 0 x57C0, 0 x0000, 0 x0000,
0 x37CE, 0 x0513, 0 x0920, 0 x0000, 0 x0000,
0 x5400, 0 x37CE, 0 x0513, 0 x0000, 0 x0000,
},
},
.argb1555_result = {
.dst_pitch = 10 ,
.expected = {
0 x8513, 0 x8920, 0 xD7C0, 0 x0000, 0 x0000,
0 xB7CE, 0 x8513, 0 x8920, 0 x0000, 0 x0000,
0 xD400, 0 xB7CE, 0 x8513, 0 x0000, 0 x0000,
},
},
.rgba5551_result = {
.dst_pitch = 10 ,
.expected = {
0 x0A27, 0 x1241, 0 xAF81, 0 x0000, 0 x0000,
0 x6F9D, 0 x0A27, 0 x1241, 0 x0000, 0 x0000,
0 xA801, 0 x6F9D, 0 x0A27, 0 x0000, 0 x0000,
},
},
.rgb888_result = {
.dst_pitch = 15 ,
.expected = {
0 x9C, 0 x44, 0 x0E, 0 x05, 0 x4D, 0 x11, 0 x03, 0 xF3, 0 xA8,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x73, 0 xF0, 0 x6C, 0 x9C, 0 x44, 0 x0E, 0 x05, 0 x4D, 0 x11,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x03, 0 x03, 0 xA8, 0 x73, 0 xF0, 0 x6C, 0 x9C, 0 x44, 0 x0E,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
},
},
.bgr888_result = {
.dst_pitch = 15 ,
.expected = {
0 x0E, 0 x44, 0 x9C, 0 x11, 0 x4D, 0 x05, 0 xA8, 0 xF3, 0 x03,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x6C, 0 xF0, 0 x73, 0 x0E, 0 x44, 0 x9C, 0 x11, 0 x4D, 0 x05,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 xA8, 0 x03, 0 x03, 0 x6C, 0 xF0, 0 x73, 0 x0E, 0 x44, 0 x9C,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
},
},
.argb8888_result = {
.dst_pitch = 20 ,
.expected = {
0 xFF0E449C, 0 xFF114D05, 0 xFFA8F303, 0 x00000000, 0 x00000000,
0 xFF6CF073, 0 xFF0E449C, 0 xFF114D05, 0 x00000000, 0 x00000000,
0 xFFA80303, 0 xFF6CF073, 0 xFF0E449C, 0 x00000000, 0 x00000000,
},
},
.xrgb2101010_result = {
.dst_pitch = 20 ,
.expected = {
0 x03844672, 0 x0444D414, 0 x2A2F3C0C, 0 x00000000, 0 x00000000,
0 x1B1F0DCD, 0 x03844672, 0 x0444D414, 0 x00000000, 0 x00000000,
0 x2A20300C, 0 x1B1F0DCD, 0 x03844672, 0 x00000000, 0 x00000000,
},
},
.argb2101010_result = {
.dst_pitch = 20 ,
.expected = {
0 xC3844672, 0 xC444D414, 0 xEA2F3C0C, 0 x00000000, 0 x00000000,
0 xDB1F0DCD, 0 xC3844672, 0 xC444D414, 0 x00000000, 0 x00000000,
0 xEA20300C, 0 xDB1F0DCD, 0 xC3844672, 0 x00000000, 0 x00000000,
},
},
.mono_result = {
.dst_pitch = 2 ,
.expected = {
0 b100, 0 b000,
0 b001, 0 b000,
0 b010, 0 b000,
},
},
.swab_result = {
.dst_pitch = 20 ,
.expected = {
0 x9C440EA1, 0 x054D11B1, 0 x03F3A8C1, 0 x00000000, 0 x00000000,
0 x73F06CD1, 0 x9C440EA2, 0 x054D11B2, 0 x00000000, 0 x00000000,
0 x0303A8C2, 0 x73F06CD2, 0 x9C440EA3, 0 x00000000, 0 x00000000,
},
},
.xbgr8888_result = {
.dst_pitch = 20 ,
.expected = {
0 xA19C440E, 0 xB1054D11, 0 xC103F3A8, 0 x00000000, 0 x00000000,
0 xD173F06C, 0 xA29C440E, 0 xB2054D11, 0 x00000000, 0 x00000000,
0 xC20303A8, 0 xD273F06C, 0 xA39C440E, 0 x00000000, 0 x00000000,
},
},
.abgr8888_result = {
.dst_pitch = 20 ,
.expected = {
0 xFF9C440E, 0 xFF054D11, 0 xFF03F3A8, 0 x00000000, 0 x00000000,
0 xFF73F06C, 0 xFF9C440E, 0 xFF054D11, 0 x00000000, 0 x00000000,
0 xFF0303A8, 0 xFF73F06C, 0 xFF9C440E, 0 x00000000, 0 x00000000,
},
},
},
};
/*
* conversion_buf_size - Return the destination buffer size required to convert
* between formats.
* @dst_format: destination buffer pixel format (DRM_FORMAT_*)
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
* @clip: Clip rectangle area to convert
*
* Returns:
* 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, int plane)
{
const struct drm_format_info *dst_fi = drm_format_info(dst_format);
if (!dst_fi)
return -EINVAL;
if (!dst_pitch)
dst_pitch = drm_format_info_min_pitch(dst_fi, plane, drm_rect_width(clip));
return dst_pitch * drm_rect_height(clip);
}
static u16 *le16buf_to_cpu(struct kunit *test, const __le16 *buf, size_t buf_size)
{
u16 *dst = NULL;
int n;
dst = kunit_kzalloc(test, sizeof (*dst) * buf_size, GFP_KERNEL);
if (!dst)
return NULL;
for (n = 0 ; n < buf_size; n++)
dst[n] = le16_to_cpu(buf[n]);
return dst;
}
static u32 *le32buf_to_cpu(struct kunit *test, const __le32 *buf, size_t buf_size)
{
u32 *dst = NULL;
int n;
dst = kunit_kzalloc(test, sizeof (*dst) * buf_size, GFP_KERNEL);
if (!dst)
return NULL;
for (n = 0 ; n < buf_size; n++)
dst[n] = le32_to_cpu((__force __le32)buf[n]);
return dst;
}
static __le32 *cpubuf_to_le32(struct kunit *test, const u32 *buf, size_t buf_size)
{
__le32 *dst = NULL;
int n;
dst = kunit_kzalloc(test, sizeof (*dst) * buf_size, GFP_KERNEL);
if (!dst)
return NULL;
for (n = 0 ; n < buf_size; n++)
dst[n] = cpu_to_le32(buf[n]);
return dst;
}
static void convert_xrgb8888_case_desc(struct convert_xrgb8888_case *t,
char *desc)
{
strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
}
KUNIT_ARRAY_PARAM(convert_xrgb8888, convert_xrgb8888_cases,
convert_xrgb8888_case_desc);
static void drm_test_fb_xrgb8888_to_gray8(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_gray8_result *result = ¶ms->gray8_result;
size_t dst_size;
u8 *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_R8, result->dst_pitch,
¶ms->clip, 0 );
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);
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, ¶ms->clip, &fmtcnv_state);
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_rgb332(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_rgb332_result *result = ¶ms->rgb332_result;
size_t dst_size;
u8 *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_RGB332, result->dst_pitch,
¶ms->clip, 0 );
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);
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, ¶ms->clip, &fmtcnv_state);
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_rgb565_result *result = ¶ms->rgb565_result;
size_t dst_size;
u16 *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_RGB565, result->dst_pitch,
¶ms->clip, 0 );
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);
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, ¶ms->clip,
&fmtcnv_state);
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_rgb565be(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip,
&fmtcnv_state);
buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof (__le16));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected_swab, dst_size);
buf = dst.vaddr;
memset(buf, 0 , dst_size);
drm_fb_xrgb8888_to_rgb565(&dst, dst_pitch, &src, &fb, ¶ms->clip,
&fmtcnv_state);
buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof (__le16));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_xrgb1555(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_xrgb1555_result *result = ¶ms->xrgb1555_result;
size_t dst_size;
u16 *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_XRGB1555, result->dst_pitch,
¶ms->clip, 0 );
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);
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, ¶ms->clip, &fmtcnv_state);
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 */
memset(buf, 0 , dst_size);
drm_fb_xrgb8888_to_xrgb1555(&dst, dst_pitch, &src, &fb, ¶ms->clip, &fmtcnv_state);
buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof (__le16));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_argb1555(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_argb1555_result *result = ¶ms->argb1555_result;
size_t dst_size;
u16 *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_ARGB1555, result->dst_pitch,
¶ms->clip, 0 );
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);
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, ¶ms->clip, &fmtcnv_state);
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 */
memset(buf, 0 , dst_size);
drm_fb_xrgb8888_to_argb1555(&dst, dst_pitch, &src, &fb, ¶ms->clip, &fmtcnv_state);
buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof (__le16));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_rgba5551(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_rgba5551_result *result = ¶ms->rgba5551_result;
size_t dst_size;
u16 *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_RGBA5551, result->dst_pitch,
¶ms->clip, 0 );
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);
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, ¶ms->clip, &fmtcnv_state);
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 */
memset(buf, 0 , dst_size);
drm_fb_xrgb8888_to_rgba5551(&dst, dst_pitch, &src, &fb, ¶ms->clip, &fmtcnv_state);
buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof (__le16));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_rgb888_result *result = ¶ms->rgb888_result;
size_t dst_size;
u8 *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_RGB888, result->dst_pitch,
¶ms->clip, 0 );
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);
/*
* RGB888 expected results are already in little-endian
* order, so there's no need to convert the test output.
*/
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, ¶ms->clip, &fmtcnv_state);
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
buf = dst.vaddr; /* restore original value of buf */
memset(buf, 0 , dst_size);
drm_fb_xrgb8888_to_rgb888(&dst, dst_pitch, &src, &fb, ¶ms->clip, &fmtcnv_state);
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_bgr888(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_bgr888_result *result = ¶ms->bgr888_result;
size_t dst_size;
u8 *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_BGR888, result->dst_pitch,
¶ms->clip, 0 );
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);
/*
* BGR888 expected results are already in little-endian
* order, so there's no need to convert the test output.
*/
drm_fb_xrgb8888_to_bgr888(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip,
&fmtcnv_state);
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
buf = dst.vaddr; /* restore original value of buf */
memset(buf, 0 , dst_size);
drm_fb_xrgb8888_to_bgr888(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip,
&fmtcnv_state);
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_argb8888_result *result = ¶ms->argb8888_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_ARGB8888,
result->dst_pitch, ¶ms->clip, 0 );
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);
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, ¶ms->clip, &fmtcnv_state);
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof (u32));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
buf = dst.vaddr; /* restore original value of buf */
memset(buf, 0 , dst_size);
drm_fb_xrgb8888_to_argb8888(&dst, dst_pitch, &src, &fb, ¶ms->clip, &fmtcnv_state);
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof (u32));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_xrgb2101010(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_xrgb2101010_result *result = ¶ms->xrgb2101010_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_XRGB2101010,
result->dst_pitch, ¶ms->clip, 0 );
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);
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, ¶ms->clip, &fmtcnv_state);
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof (u32));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
buf = dst.vaddr; /* restore original value of buf */
memset(buf, 0 , dst_size);
drm_fb_xrgb8888_to_xrgb2101010(&dst, dst_pitch, &src, &fb, ¶ms->clip, &fmtcnv_state);
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof (u32));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_argb2101010(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_argb2101010_result *result = ¶ms->argb2101010_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_ARGB2101010,
result->dst_pitch, ¶ms->clip, 0 );
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);
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, ¶ms->clip, &fmtcnv_state);
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof (u32));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
buf = dst.vaddr; /* restore original value of buf */
memset(buf, 0 , dst_size);
drm_fb_xrgb8888_to_argb2101010(&dst, dst_pitch, &src, &fb, ¶ms->clip, &fmtcnv_state);
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof (u32));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_mono(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_mono_result *result = ¶ms->mono_result;
size_t dst_size;
u8 *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_C1, result->dst_pitch, ¶ms->clip, 0 );
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);
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, ¶ms->clip, &fmtcnv_state);
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, 0 );
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);
const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
NULL : &result->dst_pitch;
drm_fb_swab(&dst, dst_pitch, &src, &fb, ¶ms->clip, false , &fmtcnv_state);
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof (u32));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
buf = dst.vaddr; /* restore original value of buf */
memset(buf, 0 , dst_size);
drm_fb_swab(&dst, dst_pitch, &src, &fb, ¶ms->clip, false , &fmtcnv_state);
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof (u32));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
buf = dst.vaddr;
memset(buf, 0 , dst_size);
drm_fb_xrgb8888_to_bgrx8888(&dst, dst_pitch, &src, &fb, ¶ms->clip, &fmtcnv_state);
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof (u32));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
buf = dst.vaddr;
memset(buf, 0 , dst_size);
struct drm_format_info mock_format = *fb.format;
mock_format.format |= DRM_FORMAT_BIG_ENDIAN;
fb.format = &mock_format;
drm_fb_swab(&dst, dst_pitch, &src, &fb, ¶ms->clip, false , &fmtcnv_state);
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof (u32));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_abgr8888(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_abgr8888_result *result = ¶ms->abgr8888_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_XBGR8888, result->dst_pitch, ¶ms->clip, 0 );
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);
const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
NULL : &result->dst_pitch;
drm_fb_xrgb8888_to_abgr8888(&dst, dst_pitch, &src, &fb, ¶ms->clip, &fmtcnv_state);
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof (u32));
KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
}
static void drm_test_fb_xrgb8888_to_xbgr8888(struct kunit *test)
{
const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_xbgr8888_result *result = ¶ms->xbgr8888_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_XBGR8888, result->dst_pitch, ¶ms->clip, 0 );
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);
const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
NULL : &result->dst_pitch;
drm_fb_xrgb8888_to_xbgr8888(&dst, dst_pitch, &src, &fb, ¶ms->clip, &fmtcnv_state);
buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof (u32));
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;
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);
}
struct fb_memcpy_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];
unsigned int dst_pitches[DRM_FORMAT_MAX_PLANES];
const u32 expected[DRM_FORMAT_MAX_PLANES][TEST_BUF_SIZE];
};
/* 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 fb_memcpy_case fb_memcpy_cases[] = {
{
.name = "single_pixel_source_buffer" ,
.format = DRM_FORMAT_XRGB8888,
.clip = DRM_RECT_INIT(0 , 0 , 1 , 1 ),
.src_pitches = { 1 * 4 },
.src = {{ 0 x01020304 }},
.dst_pitches = { TEST_USE_DEFAULT_PITCH },
.expected = {{ 0 x01020304 }},
},
{
.name = "single_pixel_source_buffer" ,
.format = DRM_FORMAT_XRGB8888_A8,
.clip = DRM_RECT_INIT(0 , 0 , 1 , 1 ),
.src_pitches = { 1 * 4 , 1 },
.src = {
{ 0 x01020304 },
{ 0 xFFFFFF01 },
},
.dst_pitches = { TEST_USE_DEFAULT_PITCH },
.expected = {
{ 0 x01020304 },
{ 0 x00000001 },
},
},
{
.name = "single_pixel_source_buffer" ,
.format = DRM_FORMAT_YUV444,
.clip = DRM_RECT_INIT(0 , 0 , 1 , 1 ),
.src_pitches = { 1 , 1 , 1 },
.src = {
{ 0 xFFFFFF01 },
{ 0 xFFFFFF01 },
{ 0 xFFFFFF01 },
},
.dst_pitches = { TEST_USE_DEFAULT_PITCH },
.expected = {
{ 0 x00000001 },
{ 0 x00000001 },
{ 0 x00000001 },
},
},
{
.name = "single_pixel_clip_rectangle" ,
.format = DRM_FORMAT_XBGR8888,
.clip = DRM_RECT_INIT(1 , 1 , 1 , 1 ),
.src_pitches = { 2 * 4 },
.src = {
{
0 x00000000, 0 x00000000,
0 x00000000, 0 x01020304,
},
},
.dst_pitches = { TEST_USE_DEFAULT_PITCH },
.expected = {
{ 0 x01020304 },
},
},
{
.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 = {
{
0 x00000000, 0 x00000000,
0 x00000000, 0 x01020304,
},
{ 0 x01000000 },
},
.dst_pitches = { TEST_USE_DEFAULT_PITCH },
.expected = {
{ 0 x01020304 },
{ 0 x00000001 },
},
},
{
.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 = {
{ 0 x01000000 },
{ 0 x01000000 },
{ 0 x01000000 },
},
.dst_pitches = { TEST_USE_DEFAULT_PITCH },
.expected = {
{ 0 x00000001 },
{ 0 x00000001 },
{ 0 x00000001 },
},
},
{
.name = "well_known_colors" ,
.format = DRM_FORMAT_XBGR8888,
.clip = DRM_RECT_INIT(1 , 1 , 2 , 4 ),
.src_pitches = { 4 * 4 },
.src = {
{
0 x00000000, 0 x00000000, 0 x00000000, 0 x00000000,
0 x00000000, 0 x11FFFFFF, 0 x22000000, 0 x00000000,
0 x00000000, 0 x33FF0000, 0 x4400FF00, 0 x00000000,
0 x00000000, 0 x550000FF, 0 x66FF00FF, 0 x00000000,
0 x00000000, 0 x77FFFF00, 0 x8800FFFF, 0 x00000000,
},
},
.dst_pitches = { TEST_USE_DEFAULT_PITCH },
.expected = {
{
0 x11FFFFFF, 0 x22000000,
0 x33FF0000, 0 x4400FF00,
0 x550000FF, 0 x66FF00FF,
0 x77FFFF00, 0 x8800FFFF,
},
},
},
{
.name = "well_known_colors" ,
.format = DRM_FORMAT_XRGB8888_A8,
.clip = DRM_RECT_INIT(1 , 1 , 2 , 4 ),
.src_pitches = { 4 * 4 , 4 * 1 },
.src = {
{
0 x00000000, 0 x00000000, 0 x00000000, 0 x00000000,
0 x00000000, 0 xFFFFFFFF, 0 xFF000000, 0 x00000000,
0 x00000000, 0 xFFFF0000, 0 xFF00FF00, 0 x00000000,
0 x00000000, 0 xFF0000FF, 0 xFFFF00FF, 0 x00000000,
0 x00000000, 0 xFFFFFF00, 0 xFF00FFFF, 0 x00000000,
},
{
0 x00000000,
0 x00221100,
0 x00443300,
0 x00665500,
0 x00887700,
},
},
.dst_pitches = { TEST_USE_DEFAULT_PITCH },
.expected = {
{
0 xFFFFFFFF, 0 xFF000000,
0 xFFFF0000, 0 xFF00FF00,
0 xFF0000FF, 0 xFFFF00FF,
0 xFFFFFF00, 0 xFF00FFFF,
},
{
0 x44332211,
0 x88776655,
},
},
},
{
.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 = {
{
0 x00000000,
0 x0000FF00,
0 x00954C00,
0 x00691D00,
0 x00B2E100,
},
{
0 x00000000,
0 x00000000,
0 x00BEDE00,
0 x00436500,
0 x00229B00,
},
{
0 x00000000,
0 x00000000,
0 x007E9C00,
0 x0083E700,
0 x00641A00,
},
},
.dst_pitches = { TEST_USE_DEFAULT_PITCH },
.expected = {
{
0 x954C00FF,
0 xB2E1691D,
},
{
0 xBEDE0000,
0 x229B4365,
},
{
0 x7E9C0000,
0 x641A83E7,
},
},
},
{
.name = "destination_pitch" ,
.format = DRM_FORMAT_XBGR8888,
.clip = DRM_RECT_INIT(0 , 0 , 3 , 3 ),
.src_pitches = { 3 * 4 },
.src = {
{
0 xA10E449C, 0 xB1114D05, 0 xC1A8F303,
0 xD16CF073, 0 xA20E449C, 0 xB2114D05,
0 xC2A80303, 0 xD26CF073, 0 xA30E449C,
},
},
.dst_pitches = { 5 * 4 },
.expected = {
{
0 xA10E449C, 0 xB1114D05, 0 xC1A8F303, 0 x00000000, 0 x00000000,
0 xD16CF073, 0 xA20E449C, 0 xB2114D05, 0 x00000000, 0 x00000000,
0 xC2A80303, 0 xD26CF073, 0 xA30E449C, 0 x00000000, 0 x00000000,
},
},
},
{
.name = "destination_pitch" ,
.format = DRM_FORMAT_XRGB8888_A8,
.clip = DRM_RECT_INIT(0 , 0 , 3 , 3 ),
.src_pitches = { 3 * 4 , 3 * 1 },
.src = {
{
0 xFF0E449C, 0 xFF114D05, 0 xFFA8F303,
0 xFF6CF073, 0 xFF0E449C, 0 xFF114D05,
0 xFFA80303, 0 xFF6CF073, 0 xFF0E449C,
},
{
0 xB2C1B1A1,
0 xD2A3D1A2,
0 xFFFFFFC2,
},
},
.dst_pitches = { 5 * 4 , 5 * 1 },
.expected = {
{
0 xFF0E449C, 0 xFF114D05, 0 xFFA8F303, 0 x00000000, 0 x00000000,
0 xFF6CF073, 0 xFF0E449C, 0 xFF114D05, 0 x00000000, 0 x00000000,
0 xFFA80303, 0 xFF6CF073, 0 xFF0E449C, 0 x00000000, 0 x00000000,
},
{
0 x00C1B1A1,
0 xD1A2B200,
0 xD2A30000,
0 xFF0000C2,
},
},
},
{
.name = "destination_pitch" ,
.format = DRM_FORMAT_YUV444,
.clip = DRM_RECT_INIT(0 , 0 , 3 , 3 ),
.src_pitches = { 3 * 1 , 3 * 1 , 3 * 1 },
.src = {
{
0 xBAC1323D,
0 xBA34323D,
0 xFFFFFF3D,
},
{
0 xE1ABEC2A,
0 xE1EAEC2A,
0 xFFFFFF2A,
},
{
0 xBCEBE4D7,
0 xBC65E4D7,
0 xFFFFFFD7,
},
},
.dst_pitches = { 5 * 1 , 5 * 1 , 5 * 1 },
.expected = {
{
0 x00C1323D,
0 x323DBA00,
0 xBA340000,
0 xFF00003D,
},
{
0 x00ABEC2A,
0 xEC2AE100,
0 xE1EA0000,
0 xFF00002A,
},
{
0 x00EBE4D7,
0 xE4D7BC00,
0 xBC650000,
0 xFF0000D7,
},
},
},
};
static void fb_memcpy_case_desc(struct fb_memcpy_case *t, char *desc)
{
snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s: %p4cc" , t->name, &t->format);
}
KUNIT_ARRAY_PARAM(fb_memcpy, fb_memcpy_cases, fb_memcpy_case_desc);
static void drm_test_fb_memcpy(struct kunit *test)
{
const struct fb_memcpy_case *params = test->param_value;
size_t dst_size[DRM_FORMAT_MAX_PLANES] = { 0 };
u32 *buf[DRM_FORMAT_MAX_PLANES] = { 0 };
__le32 *src_cp[DRM_FORMAT_MAX_PLANES] = { 0 };
__le32 *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, params->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]);
}
const unsigned int *dst_pitches = params->dst_pitches[0 ] == TEST_USE_DEFAULT_PITCH ? NULL :
params->dst_pitches;
drm_fb_memcpy(dst, dst_pitches, src, &fb, ¶ms->clip);
for (size_t i = 0 ; i < fb.format->num_planes; i++) {
expected[i] = cpubuf_to_le32(test, params->expected[i], TEST_BUF_SIZE);
KUNIT_EXPECT_MEMEQ_MSG(test, buf[i], expected[i], dst_size[i],
"Failed expectation on plane %zu" , i);
memset(buf[i], 0 , dst_size[i]);
}
drm_fb_memcpy(dst, dst_pitches, src, &fb, ¶ms->clip);
for (size_t i = 0 ; i < fb.format->num_planes; i++) {
expected[i] = cpubuf_to_le32(test, params->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),
KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb565, convert_xrgb8888_gen_params),
KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb1555, convert_xrgb8888_gen_params),
KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb1555, convert_xrgb8888_gen_params),
KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgba5551, convert_xrgb8888_gen_params),
KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888, convert_xrgb8888_gen_params),
KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_bgr888, convert_xrgb8888_gen_params),
KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb8888, convert_xrgb8888_gen_params),
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),
KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xbgr8888, convert_xrgb8888_gen_params),
KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_abgr8888, convert_xrgb8888_gen_params),
KUNIT_CASE_PARAM(drm_test_fb_clip_offset, clip_offset_gen_params),
KUNIT_CASE_PARAM(drm_test_fb_memcpy, fb_memcpy_gen_params),
{}
};
static struct kunit_suite drm_format_helper_test_suite = {
.name = "drm_format_helper_test" ,
.test_cases = drm_format_helper_test_cases,
};
kunit_test_suite(drm_format_helper_test_suite);
MODULE_DESCRIPTION("KUnit tests for the drm_format_helper APIs" );
MODULE_LICENSE("GPL" );
MODULE_AUTHOR("José Expósito <jose.exposito89@gmail.com>" );
Messung V0.5 in Prozent C=97 H=94 G=95
¤ Dauer der Verarbeitung: 0.22 Sekunden
(vorverarbeitet am 2026-06-07)
¤
*© Formatika GbR, Deutschland