162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Test cases for the drm_framebuffer functions 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (c) 2022 Maíra Canal <mairacanal@riseup.net> 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include <kunit/test.h> 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <drm/drm_device.h> 1162306a36Sopenharmony_ci#include <drm/drm_mode.h> 1262306a36Sopenharmony_ci#include <drm/drm_fourcc.h> 1362306a36Sopenharmony_ci#include <drm/drm_print.h> 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include "../drm_crtc_internal.h" 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#define MIN_WIDTH 4 1862306a36Sopenharmony_ci#define MAX_WIDTH 4096 1962306a36Sopenharmony_ci#define MIN_HEIGHT 4 2062306a36Sopenharmony_ci#define MAX_HEIGHT 4096 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_cistruct drm_framebuffer_test { 2362306a36Sopenharmony_ci int buffer_created; 2462306a36Sopenharmony_ci struct drm_mode_fb_cmd2 cmd; 2562306a36Sopenharmony_ci const char *name; 2662306a36Sopenharmony_ci}; 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_cistatic const struct drm_framebuffer_test drm_framebuffer_create_cases[] = { 2962306a36Sopenharmony_ci{ .buffer_created = 1, .name = "ABGR8888 normal sizes", 3062306a36Sopenharmony_ci .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_ABGR8888, 3162306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 4 * 600, 0, 0 }, 3262306a36Sopenharmony_ci } 3362306a36Sopenharmony_ci}, 3462306a36Sopenharmony_ci{ .buffer_created = 1, .name = "ABGR8888 max sizes", 3562306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 3662306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 }, 3762306a36Sopenharmony_ci } 3862306a36Sopenharmony_ci}, 3962306a36Sopenharmony_ci{ .buffer_created = 1, .name = "ABGR8888 pitch greater than min required", 4062306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 4162306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH + 1, 0, 0 }, 4262306a36Sopenharmony_ci } 4362306a36Sopenharmony_ci}, 4462306a36Sopenharmony_ci{ .buffer_created = 0, .name = "ABGR8888 pitch less than min required", 4562306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 4662306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH - 1, 0, 0 }, 4762306a36Sopenharmony_ci } 4862306a36Sopenharmony_ci}, 4962306a36Sopenharmony_ci{ .buffer_created = 0, .name = "ABGR8888 Invalid width", 5062306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH + 1, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 5162306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 4 * (MAX_WIDTH + 1), 0, 0 }, 5262306a36Sopenharmony_ci } 5362306a36Sopenharmony_ci}, 5462306a36Sopenharmony_ci{ .buffer_created = 0, .name = "ABGR8888 Invalid buffer handle", 5562306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 5662306a36Sopenharmony_ci .handles = { 0, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 }, 5762306a36Sopenharmony_ci } 5862306a36Sopenharmony_ci}, 5962306a36Sopenharmony_ci{ .buffer_created = 0, .name = "No pixel format", 6062306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 0, 6162306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 }, 6262306a36Sopenharmony_ci } 6362306a36Sopenharmony_ci}, 6462306a36Sopenharmony_ci{ .buffer_created = 0, .name = "ABGR8888 Width 0", 6562306a36Sopenharmony_ci .cmd = { .width = 0, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 6662306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 }, 6762306a36Sopenharmony_ci } 6862306a36Sopenharmony_ci}, 6962306a36Sopenharmony_ci{ .buffer_created = 0, .name = "ABGR8888 Height 0", 7062306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = 0, .pixel_format = DRM_FORMAT_ABGR8888, 7162306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 }, 7262306a36Sopenharmony_ci } 7362306a36Sopenharmony_ci}, 7462306a36Sopenharmony_ci{ .buffer_created = 0, .name = "ABGR8888 Out of bound height * pitch combination", 7562306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 7662306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .offsets = { UINT_MAX - 1, 0, 0 }, 7762306a36Sopenharmony_ci .pitches = { 4 * MAX_WIDTH, 0, 0 }, 7862306a36Sopenharmony_ci } 7962306a36Sopenharmony_ci}, 8062306a36Sopenharmony_ci{ .buffer_created = 1, .name = "ABGR8888 Large buffer offset", 8162306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 8262306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 }, 8362306a36Sopenharmony_ci .pitches = { 4 * MAX_WIDTH, 0, 0 }, 8462306a36Sopenharmony_ci } 8562306a36Sopenharmony_ci}, 8662306a36Sopenharmony_ci{ .buffer_created = 1, .name = "ABGR8888 Set DRM_MODE_FB_MODIFIERS without modifiers", 8762306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 8862306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 }, 8962306a36Sopenharmony_ci .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS, 9062306a36Sopenharmony_ci } 9162306a36Sopenharmony_ci}, 9262306a36Sopenharmony_ci{ .buffer_created = 1, .name = "ABGR8888 Valid buffer modifier", 9362306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 9462306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 }, 9562306a36Sopenharmony_ci .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS, 9662306a36Sopenharmony_ci .modifier = { AFBC_FORMAT_MOD_YTR, 0, 0 }, 9762306a36Sopenharmony_ci } 9862306a36Sopenharmony_ci}, 9962306a36Sopenharmony_ci{ .buffer_created = 0, 10062306a36Sopenharmony_ci .name = "ABGR8888 Invalid buffer modifier(DRM_FORMAT_MOD_SAMSUNG_64_32_TILE)", 10162306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 10262306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 }, 10362306a36Sopenharmony_ci .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS, 10462306a36Sopenharmony_ci .modifier = { DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 0, 0 }, 10562306a36Sopenharmony_ci } 10662306a36Sopenharmony_ci}, 10762306a36Sopenharmony_ci{ .buffer_created = 1, .name = "ABGR8888 Extra pitches without DRM_MODE_FB_MODIFIERS", 10862306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 10962306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 }, 11062306a36Sopenharmony_ci .pitches = { 4 * MAX_WIDTH, 4 * MAX_WIDTH, 0 }, 11162306a36Sopenharmony_ci } 11262306a36Sopenharmony_ci}, 11362306a36Sopenharmony_ci{ .buffer_created = 0, .name = "ABGR8888 Extra pitches with DRM_MODE_FB_MODIFIERS", 11462306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888, 11562306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS, 11662306a36Sopenharmony_ci .pitches = { 4 * MAX_WIDTH, 4 * MAX_WIDTH, 0 }, 11762306a36Sopenharmony_ci } 11862306a36Sopenharmony_ci}, 11962306a36Sopenharmony_ci{ .buffer_created = 1, .name = "NV12 Normal sizes", 12062306a36Sopenharmony_ci .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_NV12, 12162306a36Sopenharmony_ci .handles = { 1, 1, 0 }, .pitches = { 600, 600, 0 }, 12262306a36Sopenharmony_ci } 12362306a36Sopenharmony_ci}, 12462306a36Sopenharmony_ci{ .buffer_created = 1, .name = "NV12 Max sizes", 12562306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12, 12662306a36Sopenharmony_ci .handles = { 1, 1, 0 }, .pitches = { MAX_WIDTH, MAX_WIDTH, 0 }, 12762306a36Sopenharmony_ci } 12862306a36Sopenharmony_ci}, 12962306a36Sopenharmony_ci{ .buffer_created = 0, .name = "NV12 Invalid pitch", 13062306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12, 13162306a36Sopenharmony_ci .handles = { 1, 1, 0 }, .pitches = { MAX_WIDTH, MAX_WIDTH - 1, 0 }, 13262306a36Sopenharmony_ci } 13362306a36Sopenharmony_ci}, 13462306a36Sopenharmony_ci{ .buffer_created = 0, .name = "NV12 Invalid modifier/missing DRM_MODE_FB_MODIFIERS flag", 13562306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12, 13662306a36Sopenharmony_ci .handles = { 1, 1, 0 }, .modifier = { DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 0, 0 }, 13762306a36Sopenharmony_ci .pitches = { MAX_WIDTH, MAX_WIDTH, 0 }, 13862306a36Sopenharmony_ci } 13962306a36Sopenharmony_ci}, 14062306a36Sopenharmony_ci{ .buffer_created = 0, .name = "NV12 different modifier per-plane", 14162306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12, 14262306a36Sopenharmony_ci .handles = { 1, 1, 0 }, .flags = DRM_MODE_FB_MODIFIERS, 14362306a36Sopenharmony_ci .modifier = { DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 0, 0 }, 14462306a36Sopenharmony_ci .pitches = { MAX_WIDTH, MAX_WIDTH, 0 }, 14562306a36Sopenharmony_ci } 14662306a36Sopenharmony_ci}, 14762306a36Sopenharmony_ci{ .buffer_created = 1, .name = "NV12 with DRM_FORMAT_MOD_SAMSUNG_64_32_TILE", 14862306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12, 14962306a36Sopenharmony_ci .handles = { 1, 1, 0 }, .flags = DRM_MODE_FB_MODIFIERS, 15062306a36Sopenharmony_ci .modifier = { DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 15162306a36Sopenharmony_ci DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 0 }, 15262306a36Sopenharmony_ci .pitches = { MAX_WIDTH, MAX_WIDTH, 0 }, 15362306a36Sopenharmony_ci } 15462306a36Sopenharmony_ci}, 15562306a36Sopenharmony_ci{ .buffer_created = 0, .name = "NV12 Valid modifiers without DRM_MODE_FB_MODIFIERS", 15662306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12, 15762306a36Sopenharmony_ci .handles = { 1, 1, 0 }, .modifier = { DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 15862306a36Sopenharmony_ci DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 0 }, 15962306a36Sopenharmony_ci .pitches = { MAX_WIDTH, MAX_WIDTH, 0 }, 16062306a36Sopenharmony_ci } 16162306a36Sopenharmony_ci}, 16262306a36Sopenharmony_ci{ .buffer_created = 0, .name = "NV12 Modifier for inexistent plane", 16362306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12, 16462306a36Sopenharmony_ci .handles = { 1, 1, 0 }, .flags = DRM_MODE_FB_MODIFIERS, 16562306a36Sopenharmony_ci .modifier = { DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 16662306a36Sopenharmony_ci DRM_FORMAT_MOD_SAMSUNG_64_32_TILE }, 16762306a36Sopenharmony_ci .pitches = { MAX_WIDTH, MAX_WIDTH, 0 }, 16862306a36Sopenharmony_ci } 16962306a36Sopenharmony_ci}, 17062306a36Sopenharmony_ci{ .buffer_created = 0, .name = "NV12 Handle for inexistent plane", 17162306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12, 17262306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .flags = DRM_MODE_FB_MODIFIERS, 17362306a36Sopenharmony_ci .pitches = { MAX_WIDTH, MAX_WIDTH, 0 }, 17462306a36Sopenharmony_ci } 17562306a36Sopenharmony_ci}, 17662306a36Sopenharmony_ci{ .buffer_created = 1, .name = "NV12 Handle for inexistent plane without DRM_MODE_FB_MODIFIERS", 17762306a36Sopenharmony_ci .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_NV12, 17862306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .pitches = { 600, 600, 600 }, 17962306a36Sopenharmony_ci } 18062306a36Sopenharmony_ci}, 18162306a36Sopenharmony_ci{ .buffer_created = 1, .name = "YVU420 DRM_MODE_FB_MODIFIERS set without modifier", 18262306a36Sopenharmony_ci .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_YVU420, 18362306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .flags = DRM_MODE_FB_MODIFIERS, 18462306a36Sopenharmony_ci .pitches = { 600, 300, 300 }, 18562306a36Sopenharmony_ci } 18662306a36Sopenharmony_ci}, 18762306a36Sopenharmony_ci{ .buffer_created = 1, .name = "YVU420 Normal sizes", 18862306a36Sopenharmony_ci .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_YVU420, 18962306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .pitches = { 600, 300, 300 }, 19062306a36Sopenharmony_ci } 19162306a36Sopenharmony_ci}, 19262306a36Sopenharmony_ci{ .buffer_created = 1, .name = "YVU420 Max sizes", 19362306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420, 19462306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), 19562306a36Sopenharmony_ci DIV_ROUND_UP(MAX_WIDTH, 2) }, 19662306a36Sopenharmony_ci } 19762306a36Sopenharmony_ci}, 19862306a36Sopenharmony_ci{ .buffer_created = 0, .name = "YVU420 Invalid pitch", 19962306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420, 20062306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2) - 1, 20162306a36Sopenharmony_ci DIV_ROUND_UP(MAX_WIDTH, 2) }, 20262306a36Sopenharmony_ci } 20362306a36Sopenharmony_ci}, 20462306a36Sopenharmony_ci{ .buffer_created = 1, .name = "YVU420 Different pitches", 20562306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420, 20662306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2) + 1, 20762306a36Sopenharmony_ci DIV_ROUND_UP(MAX_WIDTH, 2) + 7 }, 20862306a36Sopenharmony_ci } 20962306a36Sopenharmony_ci}, 21062306a36Sopenharmony_ci{ .buffer_created = 1, .name = "YVU420 Different buffer offsets/pitches", 21162306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420, 21262306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .offsets = { MAX_WIDTH, MAX_WIDTH + 21362306a36Sopenharmony_ci MAX_WIDTH * MAX_HEIGHT, MAX_WIDTH + 2 * MAX_WIDTH * MAX_HEIGHT }, 21462306a36Sopenharmony_ci .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2) + 1, 21562306a36Sopenharmony_ci DIV_ROUND_UP(MAX_WIDTH, 2) + 7 }, 21662306a36Sopenharmony_ci } 21762306a36Sopenharmony_ci}, 21862306a36Sopenharmony_ci{ .buffer_created = 0, 21962306a36Sopenharmony_ci .name = "YVU420 Modifier set just for plane 0, without DRM_MODE_FB_MODIFIERS", 22062306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420, 22162306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .modifier = { AFBC_FORMAT_MOD_SPARSE, 0, 0 }, 22262306a36Sopenharmony_ci .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) }, 22362306a36Sopenharmony_ci } 22462306a36Sopenharmony_ci}, 22562306a36Sopenharmony_ci{ .buffer_created = 0, 22662306a36Sopenharmony_ci .name = "YVU420 Modifier set just for planes 0, 1, without DRM_MODE_FB_MODIFIERS", 22762306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420, 22862306a36Sopenharmony_ci .handles = { 1, 1, 1 }, 22962306a36Sopenharmony_ci .modifier = { AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE, 0 }, 23062306a36Sopenharmony_ci .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) }, 23162306a36Sopenharmony_ci } 23262306a36Sopenharmony_ci}, 23362306a36Sopenharmony_ci{ .buffer_created = 0, 23462306a36Sopenharmony_ci .name = "YVU420 Modifier set just for plane 0, 1, with DRM_MODE_FB_MODIFIERS", 23562306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420, 23662306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .flags = DRM_MODE_FB_MODIFIERS, 23762306a36Sopenharmony_ci .modifier = { AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE, 0 }, 23862306a36Sopenharmony_ci .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) }, 23962306a36Sopenharmony_ci } 24062306a36Sopenharmony_ci}, 24162306a36Sopenharmony_ci{ .buffer_created = 1, .name = "YVU420 Valid modifier", 24262306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420, 24362306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .flags = DRM_MODE_FB_MODIFIERS, 24462306a36Sopenharmony_ci .modifier = { AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE, 24562306a36Sopenharmony_ci AFBC_FORMAT_MOD_SPARSE }, 24662306a36Sopenharmony_ci .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) }, 24762306a36Sopenharmony_ci } 24862306a36Sopenharmony_ci}, 24962306a36Sopenharmony_ci{ .buffer_created = 0, .name = "YVU420 Different modifiers per plane", 25062306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420, 25162306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .flags = DRM_MODE_FB_MODIFIERS, 25262306a36Sopenharmony_ci .modifier = { AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE | AFBC_FORMAT_MOD_YTR, 25362306a36Sopenharmony_ci AFBC_FORMAT_MOD_SPARSE }, 25462306a36Sopenharmony_ci .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) }, 25562306a36Sopenharmony_ci } 25662306a36Sopenharmony_ci}, 25762306a36Sopenharmony_ci{ .buffer_created = 0, .name = "YVU420 Modifier for inexistent plane", 25862306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420, 25962306a36Sopenharmony_ci .handles = { 1, 1, 1 }, .flags = DRM_MODE_FB_MODIFIERS, 26062306a36Sopenharmony_ci .modifier = { AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE, 26162306a36Sopenharmony_ci AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE }, 26262306a36Sopenharmony_ci .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) }, 26362306a36Sopenharmony_ci } 26462306a36Sopenharmony_ci}, 26562306a36Sopenharmony_ci{ .buffer_created = 1, .name = "X0L2 Normal sizes", 26662306a36Sopenharmony_ci .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_X0L2, 26762306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 1200, 0, 0 } 26862306a36Sopenharmony_ci } 26962306a36Sopenharmony_ci}, 27062306a36Sopenharmony_ci{ .buffer_created = 1, .name = "X0L2 Max sizes", 27162306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2, 27262306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 2 * MAX_WIDTH, 0, 0 } 27362306a36Sopenharmony_ci } 27462306a36Sopenharmony_ci}, 27562306a36Sopenharmony_ci{ .buffer_created = 0, .name = "X0L2 Invalid pitch", 27662306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2, 27762306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 2 * MAX_WIDTH - 1, 0, 0 } 27862306a36Sopenharmony_ci } 27962306a36Sopenharmony_ci}, 28062306a36Sopenharmony_ci{ .buffer_created = 1, .name = "X0L2 Pitch greater than minimum required", 28162306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2, 28262306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 2 * MAX_WIDTH + 1, 0, 0 } 28362306a36Sopenharmony_ci } 28462306a36Sopenharmony_ci}, 28562306a36Sopenharmony_ci{ .buffer_created = 0, .name = "X0L2 Handle for inexistent plane", 28662306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2, 28762306a36Sopenharmony_ci .handles = { 1, 1, 0 }, .flags = DRM_MODE_FB_MODIFIERS, 28862306a36Sopenharmony_ci .pitches = { 2 * MAX_WIDTH + 1, 0, 0 } 28962306a36Sopenharmony_ci } 29062306a36Sopenharmony_ci}, 29162306a36Sopenharmony_ci{ .buffer_created = 1, 29262306a36Sopenharmony_ci .name = "X0L2 Offset for inexistent plane, without DRM_MODE_FB_MODIFIERS set", 29362306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2, 29462306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .offsets = { 0, 0, 3 }, 29562306a36Sopenharmony_ci .pitches = { 2 * MAX_WIDTH + 1, 0, 0 } 29662306a36Sopenharmony_ci } 29762306a36Sopenharmony_ci}, 29862306a36Sopenharmony_ci{ .buffer_created = 0, .name = "X0L2 Modifier without DRM_MODE_FB_MODIFIERS set", 29962306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2, 30062306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 2 * MAX_WIDTH + 1, 0, 0 }, 30162306a36Sopenharmony_ci .modifier = { AFBC_FORMAT_MOD_SPARSE, 0, 0 }, 30262306a36Sopenharmony_ci } 30362306a36Sopenharmony_ci}, 30462306a36Sopenharmony_ci{ .buffer_created = 1, .name = "X0L2 Valid modifier", 30562306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2, 30662306a36Sopenharmony_ci .handles = { 1, 0, 0 }, .pitches = { 2 * MAX_WIDTH + 1, 0, 0 }, 30762306a36Sopenharmony_ci .modifier = { AFBC_FORMAT_MOD_SPARSE, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS, 30862306a36Sopenharmony_ci } 30962306a36Sopenharmony_ci}, 31062306a36Sopenharmony_ci{ .buffer_created = 0, .name = "X0L2 Modifier for inexistent plane", 31162306a36Sopenharmony_ci .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, 31262306a36Sopenharmony_ci .pixel_format = DRM_FORMAT_X0L2, .handles = { 1, 0, 0 }, 31362306a36Sopenharmony_ci .pitches = { 2 * MAX_WIDTH + 1, 0, 0 }, 31462306a36Sopenharmony_ci .modifier = { AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE, 0 }, 31562306a36Sopenharmony_ci .flags = DRM_MODE_FB_MODIFIERS, 31662306a36Sopenharmony_ci } 31762306a36Sopenharmony_ci}, 31862306a36Sopenharmony_ci}; 31962306a36Sopenharmony_ci 32062306a36Sopenharmony_cistatic struct drm_framebuffer *fb_create_mock(struct drm_device *dev, 32162306a36Sopenharmony_ci struct drm_file *file_priv, 32262306a36Sopenharmony_ci const struct drm_mode_fb_cmd2 *mode_cmd) 32362306a36Sopenharmony_ci{ 32462306a36Sopenharmony_ci int *buffer_created = dev->dev_private; 32562306a36Sopenharmony_ci *buffer_created = 1; 32662306a36Sopenharmony_ci return ERR_PTR(-EINVAL); 32762306a36Sopenharmony_ci} 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_cistatic struct drm_mode_config_funcs mock_config_funcs = { 33062306a36Sopenharmony_ci .fb_create = fb_create_mock, 33162306a36Sopenharmony_ci}; 33262306a36Sopenharmony_ci 33362306a36Sopenharmony_cistatic int drm_framebuffer_test_init(struct kunit *test) 33462306a36Sopenharmony_ci{ 33562306a36Sopenharmony_ci struct drm_device *mock; 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ci mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL); 33862306a36Sopenharmony_ci KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock); 33962306a36Sopenharmony_ci 34062306a36Sopenharmony_ci mock->mode_config.min_width = MIN_WIDTH; 34162306a36Sopenharmony_ci mock->mode_config.max_width = MAX_WIDTH; 34262306a36Sopenharmony_ci mock->mode_config.min_height = MIN_HEIGHT; 34362306a36Sopenharmony_ci mock->mode_config.max_height = MAX_HEIGHT; 34462306a36Sopenharmony_ci mock->mode_config.funcs = &mock_config_funcs; 34562306a36Sopenharmony_ci 34662306a36Sopenharmony_ci test->priv = mock; 34762306a36Sopenharmony_ci return 0; 34862306a36Sopenharmony_ci} 34962306a36Sopenharmony_ci 35062306a36Sopenharmony_cistatic void drm_test_framebuffer_create(struct kunit *test) 35162306a36Sopenharmony_ci{ 35262306a36Sopenharmony_ci const struct drm_framebuffer_test *params = test->param_value; 35362306a36Sopenharmony_ci struct drm_device *mock = test->priv; 35462306a36Sopenharmony_ci int buffer_created = 0; 35562306a36Sopenharmony_ci 35662306a36Sopenharmony_ci mock->dev_private = &buffer_created; 35762306a36Sopenharmony_ci drm_internal_framebuffer_create(mock, ¶ms->cmd, NULL); 35862306a36Sopenharmony_ci KUNIT_EXPECT_EQ(test, params->buffer_created, buffer_created); 35962306a36Sopenharmony_ci} 36062306a36Sopenharmony_ci 36162306a36Sopenharmony_cistatic void drm_framebuffer_test_to_desc(const struct drm_framebuffer_test *t, char *desc) 36262306a36Sopenharmony_ci{ 36362306a36Sopenharmony_ci strcpy(desc, t->name); 36462306a36Sopenharmony_ci} 36562306a36Sopenharmony_ci 36662306a36Sopenharmony_ciKUNIT_ARRAY_PARAM(drm_framebuffer_create, drm_framebuffer_create_cases, 36762306a36Sopenharmony_ci drm_framebuffer_test_to_desc); 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_cistatic struct kunit_case drm_framebuffer_tests[] = { 37062306a36Sopenharmony_ci KUNIT_CASE_PARAM(drm_test_framebuffer_create, drm_framebuffer_create_gen_params), 37162306a36Sopenharmony_ci { } 37262306a36Sopenharmony_ci}; 37362306a36Sopenharmony_ci 37462306a36Sopenharmony_cistatic struct kunit_suite drm_framebuffer_test_suite = { 37562306a36Sopenharmony_ci .name = "drm_framebuffer", 37662306a36Sopenharmony_ci .init = drm_framebuffer_test_init, 37762306a36Sopenharmony_ci .test_cases = drm_framebuffer_tests, 37862306a36Sopenharmony_ci}; 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_cikunit_test_suite(drm_framebuffer_test_suite); 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ciMODULE_LICENSE("GPL"); 383