1 // SPDX-License-Identifier: GPL-2.0
3 * Test cases for the drm_format functions
6 #define pr_fmt(fmt) "drm_format: " fmt
8 #include <linux/errno.h>
9 #include <linux/kernel.h>
11 #include <drm/drm_fourcc.h>
13 #include "test-drm_modeset_common.h"
15 int igt_check_drm_format_block_width(void *ignored
)
17 const struct drm_format_info
*info
= NULL
;
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);
24 /* Test 1 plane format */
25 info
= drm_format_info(DRM_FORMAT_XRGB4444
);
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);
31 /* Test 2 planes format */
32 info
= drm_format_info(DRM_FORMAT_NV12
);
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);
39 /* Test 3 planes format */
40 info
= drm_format_info(DRM_FORMAT_YUV422
);
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);
48 /* Test a tiled format */
49 info
= drm_format_info(DRM_FORMAT_X0L0
);
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);
58 int igt_check_drm_format_block_height(void *ignored
)
60 const struct drm_format_info
*info
= NULL
;
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);
67 /* Test 1 plane format */
68 info
= drm_format_info(DRM_FORMAT_XRGB4444
);
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);
74 /* Test 2 planes format */
75 info
= drm_format_info(DRM_FORMAT_NV12
);
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);
82 /* Test 3 planes format */
83 info
= drm_format_info(DRM_FORMAT_YUV422
);
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);
91 /* Test a tiled format */
92 info
= drm_format_info(DRM_FORMAT_X0L0
);
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);
101 int igt_check_drm_format_min_pitch(void *ignored
)
103 const struct drm_format_info
*info
= NULL
;
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);
110 /* Test 1 plane 8 bits per pixel format */
111 info
= drm_format_info(DRM_FORMAT_RGB332
);
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);
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
) !=
126 FAIL_ON(drm_format_info_min_pitch(info
, 0, (UINT_MAX
- 1)) !=
127 (uint64_t)(UINT_MAX
- 1));
129 /* Test 1 plane 16 bits per pixel format */
130 info
= drm_format_info(DRM_FORMAT_XRGB4444
);
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);
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);
148 /* Test 1 plane 24 bits per pixel format */
149 info
= drm_format_info(DRM_FORMAT_RGB888
);
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);
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);
167 /* Test 1 plane 32 bits per pixel format */
168 info
= drm_format_info(DRM_FORMAT_ABGR8888
);
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);
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);
186 /* Test 2 planes format */
187 info
= drm_format_info(DRM_FORMAT_NV12
);
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);
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
) !=
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));
217 /* Test 3 planes 8 bits per pixel format */
218 info
= drm_format_info(DRM_FORMAT_YUV422
);
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);
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
) !=
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);
260 /* Test tiled format */
261 info
= drm_format_info(DRM_FORMAT_X0L2
);
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);
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);