cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

test-drm_format.c (11387B)


      1// SPDX-License-Identifier: GPL-2.0
      2/*
      3 * Test cases for the drm_format functions
      4 */
      5
      6#define pr_fmt(fmt) "drm_format: " fmt
      7
      8#include <linux/errno.h>
      9#include <linux/kernel.h>
     10
     11#include <drm/drm_fourcc.h>
     12
     13#include "test-drm_modeset_common.h"
     14
     15int igt_check_drm_format_block_width(void *ignored)
     16{
     17	const struct drm_format_info *info = NULL;
     18
     19	/* Test invalid arguments */
     20	FAIL_ON(drm_format_info_block_width(info, 0) != 0);
     21	FAIL_ON(drm_format_info_block_width(info, -1) != 0);
     22	FAIL_ON(drm_format_info_block_width(info, 1) != 0);
     23
     24	/* Test 1 plane format */
     25	info = drm_format_info(DRM_FORMAT_XRGB4444);
     26	FAIL_ON(!info);
     27	FAIL_ON(drm_format_info_block_width(info, 0) != 1);
     28	FAIL_ON(drm_format_info_block_width(info, 1) != 0);
     29	FAIL_ON(drm_format_info_block_width(info, -1) != 0);
     30
     31	/* Test 2 planes format */
     32	info = drm_format_info(DRM_FORMAT_NV12);
     33	FAIL_ON(!info);
     34	FAIL_ON(drm_format_info_block_width(info, 0) != 1);
     35	FAIL_ON(drm_format_info_block_width(info, 1) != 1);
     36	FAIL_ON(drm_format_info_block_width(info, 2) != 0);
     37	FAIL_ON(drm_format_info_block_width(info, -1) != 0);
     38
     39	/* Test 3 planes format */
     40	info = drm_format_info(DRM_FORMAT_YUV422);
     41	FAIL_ON(!info);
     42	FAIL_ON(drm_format_info_block_width(info, 0) != 1);
     43	FAIL_ON(drm_format_info_block_width(info, 1) != 1);
     44	FAIL_ON(drm_format_info_block_width(info, 2) != 1);
     45	FAIL_ON(drm_format_info_block_width(info, 3) != 0);
     46	FAIL_ON(drm_format_info_block_width(info, -1) != 0);
     47
     48	/* Test a tiled format */
     49	info = drm_format_info(DRM_FORMAT_X0L0);
     50	FAIL_ON(!info);
     51	FAIL_ON(drm_format_info_block_width(info, 0) != 2);
     52	FAIL_ON(drm_format_info_block_width(info, 1) != 0);
     53	FAIL_ON(drm_format_info_block_width(info, -1) != 0);
     54
     55	return 0;
     56}
     57
     58int igt_check_drm_format_block_height(void *ignored)
     59{
     60	const struct drm_format_info *info = NULL;
     61
     62	/* Test invalid arguments */
     63	FAIL_ON(drm_format_info_block_height(info, 0) != 0);
     64	FAIL_ON(drm_format_info_block_height(info, -1) != 0);
     65	FAIL_ON(drm_format_info_block_height(info, 1) != 0);
     66
     67	/* Test 1 plane format */
     68	info = drm_format_info(DRM_FORMAT_XRGB4444);
     69	FAIL_ON(!info);
     70	FAIL_ON(drm_format_info_block_height(info, 0) != 1);
     71	FAIL_ON(drm_format_info_block_height(info, 1) != 0);
     72	FAIL_ON(drm_format_info_block_height(info, -1) != 0);
     73
     74	/* Test 2 planes format */
     75	info = drm_format_info(DRM_FORMAT_NV12);
     76	FAIL_ON(!info);
     77	FAIL_ON(drm_format_info_block_height(info, 0) != 1);
     78	FAIL_ON(drm_format_info_block_height(info, 1) != 1);
     79	FAIL_ON(drm_format_info_block_height(info, 2) != 0);
     80	FAIL_ON(drm_format_info_block_height(info, -1) != 0);
     81
     82	/* Test 3 planes format */
     83	info = drm_format_info(DRM_FORMAT_YUV422);
     84	FAIL_ON(!info);
     85	FAIL_ON(drm_format_info_block_height(info, 0) != 1);
     86	FAIL_ON(drm_format_info_block_height(info, 1) != 1);
     87	FAIL_ON(drm_format_info_block_height(info, 2) != 1);
     88	FAIL_ON(drm_format_info_block_height(info, 3) != 0);
     89	FAIL_ON(drm_format_info_block_height(info, -1) != 0);
     90
     91	/* Test a tiled format */
     92	info = drm_format_info(DRM_FORMAT_X0L0);
     93	FAIL_ON(!info);
     94	FAIL_ON(drm_format_info_block_height(info, 0) != 2);
     95	FAIL_ON(drm_format_info_block_height(info, 1) != 0);
     96	FAIL_ON(drm_format_info_block_height(info, -1) != 0);
     97
     98	return 0;
     99}
    100
    101int igt_check_drm_format_min_pitch(void *ignored)
    102{
    103	const struct drm_format_info *info = NULL;
    104
    105	/* Test invalid arguments */
    106	FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
    107	FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
    108	FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
    109
    110	/* Test 1 plane 8 bits per pixel format */
    111	info = drm_format_info(DRM_FORMAT_RGB332);
    112	FAIL_ON(!info);
    113	FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
    114	FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
    115	FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
    116
    117	FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 1);
    118	FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 2);
    119	FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 640);
    120	FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 1024);
    121	FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 1920);
    122	FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 4096);
    123	FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 671);
    124	FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
    125			(uint64_t)UINT_MAX);
    126	FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)) !=
    127			(uint64_t)(UINT_MAX - 1));
    128
    129	/* Test 1 plane 16 bits per pixel format */
    130	info = drm_format_info(DRM_FORMAT_XRGB4444);
    131	FAIL_ON(!info);
    132	FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
    133	FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
    134	FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
    135
    136	FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 2);
    137	FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 4);
    138	FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 1280);
    139	FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 2048);
    140	FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 3840);
    141	FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 8192);
    142	FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 1342);
    143	FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
    144			(uint64_t)UINT_MAX * 2);
    145	FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)) !=
    146			(uint64_t)(UINT_MAX - 1) * 2);
    147
    148	/* Test 1 plane 24 bits per pixel format */
    149	info = drm_format_info(DRM_FORMAT_RGB888);
    150	FAIL_ON(!info);
    151	FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
    152	FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
    153	FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
    154
    155	FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 3);
    156	FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 6);
    157	FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 1920);
    158	FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 3072);
    159	FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 5760);
    160	FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 12288);
    161	FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 2013);
    162	FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
    163			(uint64_t)UINT_MAX * 3);
    164	FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX - 1) !=
    165			(uint64_t)(UINT_MAX - 1) * 3);
    166
    167	/* Test 1 plane 32 bits per pixel format */
    168	info = drm_format_info(DRM_FORMAT_ABGR8888);
    169	FAIL_ON(!info);
    170	FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
    171	FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
    172	FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
    173
    174	FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 4);
    175	FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 8);
    176	FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 2560);
    177	FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 4096);
    178	FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 7680);
    179	FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 16384);
    180	FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 2684);
    181	FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
    182			(uint64_t)UINT_MAX * 4);
    183	FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX - 1) !=
    184			(uint64_t)(UINT_MAX - 1) * 4);
    185
    186	/* Test 2 planes format */
    187	info = drm_format_info(DRM_FORMAT_NV12);
    188	FAIL_ON(!info);
    189	FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
    190	FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
    191	FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
    192	FAIL_ON(drm_format_info_min_pitch(info, 2, 0) != 0);
    193
    194	FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 1);
    195	FAIL_ON(drm_format_info_min_pitch(info, 1, 1) != 2);
    196	FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 2);
    197	FAIL_ON(drm_format_info_min_pitch(info, 1, 1) != 2);
    198	FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 640);
    199	FAIL_ON(drm_format_info_min_pitch(info, 1, 320) != 640);
    200	FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 1024);
    201	FAIL_ON(drm_format_info_min_pitch(info, 1, 512) != 1024);
    202	FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 1920);
    203	FAIL_ON(drm_format_info_min_pitch(info, 1, 960) != 1920);
    204	FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 4096);
    205	FAIL_ON(drm_format_info_min_pitch(info, 1, 2048) != 4096);
    206	FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 671);
    207	FAIL_ON(drm_format_info_min_pitch(info, 1, 336) != 672);
    208	FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
    209			(uint64_t)UINT_MAX);
    210	FAIL_ON(drm_format_info_min_pitch(info, 1, UINT_MAX / 2 + 1) !=
    211			(uint64_t)UINT_MAX + 1);
    212	FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)) !=
    213			(uint64_t)(UINT_MAX - 1));
    214	FAIL_ON(drm_format_info_min_pitch(info, 1, (UINT_MAX - 1) /  2) !=
    215			(uint64_t)(UINT_MAX - 1));
    216
    217	/* Test 3 planes 8 bits per pixel format */
    218	info = drm_format_info(DRM_FORMAT_YUV422);
    219	FAIL_ON(!info);
    220	FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
    221	FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
    222	FAIL_ON(drm_format_info_min_pitch(info, 2, 0) != 0);
    223	FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
    224	FAIL_ON(drm_format_info_min_pitch(info, 3, 0) != 0);
    225
    226	FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 1);
    227	FAIL_ON(drm_format_info_min_pitch(info, 1, 1) != 1);
    228	FAIL_ON(drm_format_info_min_pitch(info, 2, 1) != 1);
    229	FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 2);
    230	FAIL_ON(drm_format_info_min_pitch(info, 1, 2) != 2);
    231	FAIL_ON(drm_format_info_min_pitch(info, 2, 2) != 2);
    232	FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 640);
    233	FAIL_ON(drm_format_info_min_pitch(info, 1, 320) != 320);
    234	FAIL_ON(drm_format_info_min_pitch(info, 2, 320) != 320);
    235	FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 1024);
    236	FAIL_ON(drm_format_info_min_pitch(info, 1, 512) != 512);
    237	FAIL_ON(drm_format_info_min_pitch(info, 2, 512) != 512);
    238	FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 1920);
    239	FAIL_ON(drm_format_info_min_pitch(info, 1, 960) != 960);
    240	FAIL_ON(drm_format_info_min_pitch(info, 2, 960) != 960);
    241	FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 4096);
    242	FAIL_ON(drm_format_info_min_pitch(info, 1, 2048) != 2048);
    243	FAIL_ON(drm_format_info_min_pitch(info, 2, 2048) != 2048);
    244	FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 671);
    245	FAIL_ON(drm_format_info_min_pitch(info, 1, 336) != 336);
    246	FAIL_ON(drm_format_info_min_pitch(info, 2, 336) != 336);
    247	FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
    248			(uint64_t)UINT_MAX);
    249	FAIL_ON(drm_format_info_min_pitch(info, 1, UINT_MAX / 2 + 1) !=
    250			(uint64_t)UINT_MAX / 2 + 1);
    251	FAIL_ON(drm_format_info_min_pitch(info, 2, UINT_MAX / 2 + 1) !=
    252			(uint64_t)UINT_MAX / 2 + 1);
    253	FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1) / 2) !=
    254			(uint64_t)(UINT_MAX - 1) / 2);
    255	FAIL_ON(drm_format_info_min_pitch(info, 1, (UINT_MAX - 1) / 2) !=
    256			(uint64_t)(UINT_MAX - 1) / 2);
    257	FAIL_ON(drm_format_info_min_pitch(info, 2, (UINT_MAX - 1) / 2) !=
    258			(uint64_t)(UINT_MAX - 1) / 2);
    259
    260	/* Test tiled format */
    261	info = drm_format_info(DRM_FORMAT_X0L2);
    262	FAIL_ON(!info);
    263	FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
    264	FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
    265	FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
    266
    267	FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 2);
    268	FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 4);
    269	FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 1280);
    270	FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 2048);
    271	FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 3840);
    272	FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 8192);
    273	FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 1342);
    274	FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
    275			(uint64_t)UINT_MAX * 2);
    276	FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX - 1) !=
    277			(uint64_t)(UINT_MAX - 1) * 2);
    278
    279	return 0;
    280}