Line data Source code
1 : // SPDX-License-Identifier: GPL-2.0
2 : /*
3 : * Copyright (c) 2019 Bootlin
4 : * Copyright (c) 2022 MaĆra Canal <mairacanal@riseup.net>
5 : */
6 :
7 : #include <kunit/test.h>
8 :
9 : #include <drm/drm_connector.h>
10 : #include <drm/drm_modes.h>
11 :
12 : static const struct drm_connector no_connector = {};
13 :
14 0 : static void drm_test_cmdline_force_e_only(struct kunit *test)
15 : {
16 0 : struct drm_cmdline_mode mode = { };
17 0 : const char *cmdline = "e";
18 :
19 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
20 : &no_connector, &mode));
21 0 : KUNIT_EXPECT_FALSE(test, mode.specified);
22 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
23 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
24 :
25 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
26 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
27 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
28 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
29 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON);
30 0 : }
31 :
32 0 : static void drm_test_cmdline_force_D_only_not_digital(struct kunit *test)
33 : {
34 0 : struct drm_cmdline_mode mode = { };
35 0 : const char *cmdline = "D";
36 :
37 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
38 : &no_connector, &mode));
39 0 : KUNIT_EXPECT_FALSE(test, mode.specified);
40 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
41 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
42 :
43 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
44 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
45 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
46 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
47 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON);
48 0 : }
49 :
50 : static const struct drm_connector connector_hdmi = {
51 : .connector_type = DRM_MODE_CONNECTOR_HDMIB,
52 : };
53 :
54 0 : static void drm_test_cmdline_force_D_only_hdmi(struct kunit *test)
55 : {
56 0 : struct drm_cmdline_mode mode = { };
57 0 : const char *cmdline = "D";
58 :
59 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
60 : &connector_hdmi, &mode));
61 0 : KUNIT_EXPECT_FALSE(test, mode.specified);
62 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
63 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
64 :
65 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
66 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
67 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
68 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
69 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON_DIGITAL);
70 0 : }
71 :
72 : static const struct drm_connector connector_dvi = {
73 : .connector_type = DRM_MODE_CONNECTOR_DVII,
74 : };
75 :
76 0 : static void drm_test_cmdline_force_D_only_dvi(struct kunit *test)
77 : {
78 0 : struct drm_cmdline_mode mode = { };
79 0 : const char *cmdline = "D";
80 :
81 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
82 : &connector_dvi, &mode));
83 0 : KUNIT_EXPECT_FALSE(test, mode.specified);
84 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
85 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
86 :
87 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
88 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
89 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
90 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
91 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON_DIGITAL);
92 0 : }
93 :
94 0 : static void drm_test_cmdline_force_d_only(struct kunit *test)
95 : {
96 0 : struct drm_cmdline_mode mode = { };
97 0 : const char *cmdline = "d";
98 :
99 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
100 : &no_connector, &mode));
101 0 : KUNIT_EXPECT_FALSE(test, mode.specified);
102 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
103 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
104 :
105 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
106 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
107 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
108 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
109 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_OFF);
110 0 : }
111 :
112 0 : static void drm_test_cmdline_res(struct kunit *test)
113 : {
114 0 : struct drm_cmdline_mode mode = { };
115 0 : const char *cmdline = "720x480";
116 :
117 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
118 : &no_connector, &mode));
119 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
120 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
121 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
122 :
123 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
124 :
125 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
126 :
127 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
128 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
129 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
130 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
131 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
132 0 : }
133 :
134 0 : static void drm_test_cmdline_res_vesa(struct kunit *test)
135 : {
136 0 : struct drm_cmdline_mode mode = { };
137 0 : const char *cmdline = "720x480M";
138 :
139 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
140 : &no_connector, &mode));
141 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
142 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
143 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
144 :
145 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
146 :
147 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
148 :
149 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
150 0 : KUNIT_EXPECT_TRUE(test, mode.cvt);
151 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
152 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
153 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
154 0 : }
155 :
156 0 : static void drm_test_cmdline_res_vesa_rblank(struct kunit *test)
157 : {
158 0 : struct drm_cmdline_mode mode = { };
159 0 : const char *cmdline = "720x480MR";
160 :
161 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
162 : &no_connector, &mode));
163 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
164 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
165 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
166 :
167 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
168 :
169 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
170 :
171 0 : KUNIT_EXPECT_TRUE(test, mode.rb);
172 0 : KUNIT_EXPECT_TRUE(test, mode.cvt);
173 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
174 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
175 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
176 0 : }
177 :
178 0 : static void drm_test_cmdline_res_rblank(struct kunit *test)
179 : {
180 0 : struct drm_cmdline_mode mode = { };
181 0 : const char *cmdline = "720x480R";
182 :
183 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
184 : &no_connector, &mode));
185 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
186 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
187 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
188 :
189 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
190 :
191 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
192 :
193 0 : KUNIT_EXPECT_TRUE(test, mode.rb);
194 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
195 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
196 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
197 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
198 0 : }
199 :
200 0 : static void drm_test_cmdline_res_bpp(struct kunit *test)
201 : {
202 0 : struct drm_cmdline_mode mode = { };
203 0 : const char *cmdline = "720x480-24";
204 :
205 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
206 : &no_connector, &mode));
207 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
208 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
209 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
210 :
211 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
212 :
213 0 : KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
214 0 : KUNIT_EXPECT_EQ(test, mode.bpp, 24);
215 :
216 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
217 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
218 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
219 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
220 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
221 0 : }
222 :
223 0 : static void drm_test_cmdline_res_refresh(struct kunit *test)
224 : {
225 0 : struct drm_cmdline_mode mode = { };
226 0 : const char *cmdline = "720x480@60";
227 :
228 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
229 : &no_connector, &mode));
230 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
231 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
232 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
233 :
234 0 : KUNIT_EXPECT_TRUE(test, mode.refresh_specified);
235 0 : KUNIT_EXPECT_EQ(test, mode.refresh, 60);
236 :
237 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
238 :
239 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
240 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
241 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
242 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
243 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
244 0 : }
245 :
246 0 : static void drm_test_cmdline_res_bpp_refresh(struct kunit *test)
247 : {
248 0 : struct drm_cmdline_mode mode = { };
249 0 : const char *cmdline = "720x480-24@60";
250 :
251 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
252 : &no_connector, &mode));
253 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
254 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
255 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
256 :
257 0 : KUNIT_EXPECT_TRUE(test, mode.refresh_specified);
258 0 : KUNIT_EXPECT_EQ(test, mode.refresh, 60);
259 :
260 0 : KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
261 0 : KUNIT_EXPECT_EQ(test, mode.bpp, 24);
262 :
263 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
264 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
265 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
266 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
267 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
268 0 : }
269 :
270 0 : static void drm_test_cmdline_res_bpp_refresh_interlaced(struct kunit *test)
271 : {
272 0 : struct drm_cmdline_mode mode = { };
273 0 : const char *cmdline = "720x480-24@60i";
274 :
275 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
276 : &no_connector, &mode));
277 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
278 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
279 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
280 :
281 0 : KUNIT_EXPECT_TRUE(test, mode.refresh_specified);
282 0 : KUNIT_EXPECT_EQ(test, mode.refresh, 60);
283 :
284 0 : KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
285 0 : KUNIT_EXPECT_EQ(test, mode.bpp, 24);
286 :
287 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
288 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
289 0 : KUNIT_EXPECT_TRUE(test, mode.interlace);
290 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
291 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
292 0 : }
293 :
294 0 : static void drm_test_cmdline_res_bpp_refresh_margins(struct kunit *test)
295 : {
296 0 : struct drm_cmdline_mode mode = { };
297 0 : const char *cmdline = "720x480-24@60m";
298 :
299 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
300 : &no_connector, &mode));
301 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
302 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
303 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
304 :
305 0 : KUNIT_EXPECT_TRUE(test, mode.refresh_specified);
306 0 : KUNIT_EXPECT_EQ(test, mode.refresh, 60);
307 :
308 0 : KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
309 0 : KUNIT_EXPECT_EQ(test, mode.bpp, 24);
310 :
311 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
312 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
313 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
314 0 : KUNIT_EXPECT_TRUE(test, mode.margins);
315 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
316 0 : }
317 :
318 0 : static void drm_test_cmdline_res_bpp_refresh_force_off(struct kunit *test)
319 : {
320 0 : struct drm_cmdline_mode mode = { };
321 0 : const char *cmdline = "720x480-24@60d";
322 :
323 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
324 : &no_connector, &mode));
325 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
326 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
327 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
328 :
329 0 : KUNIT_EXPECT_TRUE(test, mode.refresh_specified);
330 0 : KUNIT_EXPECT_EQ(test, mode.refresh, 60);
331 :
332 0 : KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
333 0 : KUNIT_EXPECT_EQ(test, mode.bpp, 24);
334 :
335 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
336 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
337 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
338 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
339 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_OFF);
340 0 : }
341 :
342 0 : static void drm_test_cmdline_res_bpp_refresh_force_on(struct kunit *test)
343 : {
344 0 : struct drm_cmdline_mode mode = { };
345 0 : const char *cmdline = "720x480-24@60e";
346 :
347 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
348 : &no_connector, &mode));
349 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
350 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
351 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
352 :
353 0 : KUNIT_EXPECT_TRUE(test, mode.refresh_specified);
354 0 : KUNIT_EXPECT_EQ(test, mode.refresh, 60);
355 :
356 0 : KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
357 0 : KUNIT_EXPECT_EQ(test, mode.bpp, 24);
358 :
359 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
360 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
361 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
362 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
363 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON);
364 0 : }
365 :
366 0 : static void drm_test_cmdline_res_bpp_refresh_force_on_analog(struct kunit *test)
367 : {
368 0 : struct drm_cmdline_mode mode = { };
369 0 : const char *cmdline = "720x480-24@60D";
370 :
371 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
372 : &no_connector, &mode));
373 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
374 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
375 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
376 :
377 0 : KUNIT_EXPECT_TRUE(test, mode.refresh_specified);
378 0 : KUNIT_EXPECT_EQ(test, mode.refresh, 60);
379 :
380 0 : KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
381 0 : KUNIT_EXPECT_EQ(test, mode.bpp, 24);
382 :
383 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
384 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
385 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
386 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
387 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON);
388 0 : }
389 :
390 0 : static void drm_test_cmdline_res_bpp_refresh_force_on_digital(struct kunit *test)
391 : {
392 0 : struct drm_cmdline_mode mode = { };
393 : static const struct drm_connector connector = {
394 : .connector_type = DRM_MODE_CONNECTOR_DVII,
395 : };
396 0 : const char *cmdline = "720x480-24@60D";
397 :
398 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
399 : &connector, &mode));
400 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
401 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
402 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
403 :
404 0 : KUNIT_EXPECT_TRUE(test, mode.refresh_specified);
405 0 : KUNIT_EXPECT_EQ(test, mode.refresh, 60);
406 :
407 0 : KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
408 0 : KUNIT_EXPECT_EQ(test, mode.bpp, 24);
409 :
410 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
411 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
412 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
413 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
414 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON_DIGITAL);
415 0 : }
416 :
417 0 : static void drm_test_cmdline_res_bpp_refresh_interlaced_margins_force_on(struct kunit *test)
418 : {
419 0 : struct drm_cmdline_mode mode = { };
420 0 : const char *cmdline = "720x480-24@60ime";
421 :
422 0 : KUNIT_EXPECT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
423 : &no_connector, &mode));
424 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
425 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
426 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
427 :
428 0 : KUNIT_EXPECT_TRUE(test, mode.refresh_specified);
429 0 : KUNIT_EXPECT_EQ(test, mode.refresh, 60);
430 :
431 0 : KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
432 0 : KUNIT_EXPECT_EQ(test, mode.bpp, 24);
433 :
434 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
435 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
436 0 : KUNIT_EXPECT_TRUE(test, mode.interlace);
437 0 : KUNIT_EXPECT_TRUE(test, mode.margins);
438 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON);
439 0 : }
440 :
441 0 : static void drm_test_cmdline_res_margins_force_on(struct kunit *test)
442 : {
443 0 : struct drm_cmdline_mode mode = { };
444 0 : const char *cmdline = "720x480me";
445 :
446 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
447 : &no_connector, &mode));
448 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
449 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
450 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
451 :
452 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
453 :
454 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
455 :
456 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
457 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
458 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
459 0 : KUNIT_EXPECT_TRUE(test, mode.margins);
460 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON);
461 0 : }
462 :
463 0 : static void drm_test_cmdline_res_vesa_margins(struct kunit *test)
464 : {
465 0 : struct drm_cmdline_mode mode = { };
466 0 : const char *cmdline = "720x480Mm";
467 :
468 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
469 : &no_connector, &mode));
470 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
471 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
472 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
473 :
474 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
475 :
476 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
477 :
478 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
479 0 : KUNIT_EXPECT_TRUE(test, mode.cvt);
480 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
481 0 : KUNIT_EXPECT_TRUE(test, mode.margins);
482 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
483 0 : }
484 :
485 0 : static void drm_test_cmdline_name(struct kunit *test)
486 : {
487 0 : struct drm_cmdline_mode mode = { };
488 0 : const char *cmdline = "NTSC";
489 :
490 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
491 : &no_connector, &mode));
492 0 : KUNIT_EXPECT_STREQ(test, mode.name, "NTSC");
493 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
494 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
495 0 : }
496 :
497 0 : static void drm_test_cmdline_name_bpp(struct kunit *test)
498 : {
499 0 : struct drm_cmdline_mode mode = { };
500 0 : const char *cmdline = "NTSC-24";
501 :
502 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
503 : &no_connector, &mode));
504 0 : KUNIT_EXPECT_STREQ(test, mode.name, "NTSC");
505 :
506 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
507 :
508 0 : KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
509 0 : KUNIT_EXPECT_EQ(test, mode.bpp, 24);
510 0 : }
511 :
512 0 : static void drm_test_cmdline_name_option(struct kunit *test)
513 : {
514 0 : struct drm_cmdline_mode mode = { };
515 0 : const char *cmdline = "NTSC,rotate=180";
516 :
517 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
518 : &no_connector, &mode));
519 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
520 0 : KUNIT_EXPECT_STREQ(test, mode.name, "NTSC");
521 0 : KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180);
522 0 : }
523 :
524 0 : static void drm_test_cmdline_name_bpp_option(struct kunit *test)
525 : {
526 0 : struct drm_cmdline_mode mode = { };
527 0 : const char *cmdline = "NTSC-24,rotate=180";
528 :
529 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
530 : &no_connector, &mode));
531 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
532 0 : KUNIT_EXPECT_STREQ(test, mode.name, "NTSC");
533 0 : KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180);
534 0 : KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
535 0 : KUNIT_EXPECT_EQ(test, mode.bpp, 24);
536 0 : }
537 :
538 0 : static void drm_test_cmdline_rotate_0(struct kunit *test)
539 : {
540 0 : struct drm_cmdline_mode mode = { };
541 0 : const char *cmdline = "720x480,rotate=0";
542 :
543 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
544 : &no_connector, &mode));
545 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
546 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
547 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
548 0 : KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_0);
549 :
550 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
551 :
552 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
553 :
554 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
555 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
556 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
557 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
558 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
559 0 : }
560 :
561 0 : static void drm_test_cmdline_rotate_90(struct kunit *test)
562 : {
563 0 : struct drm_cmdline_mode mode = { };
564 0 : const char *cmdline = "720x480,rotate=90";
565 :
566 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
567 : &no_connector, &mode));
568 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
569 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
570 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
571 0 : KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_90);
572 :
573 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
574 :
575 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
576 :
577 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
578 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
579 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
580 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
581 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
582 0 : }
583 :
584 0 : static void drm_test_cmdline_rotate_180(struct kunit *test)
585 : {
586 0 : struct drm_cmdline_mode mode = { };
587 0 : const char *cmdline = "720x480,rotate=180";
588 :
589 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
590 : &no_connector, &mode));
591 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
592 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
593 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
594 0 : KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180);
595 :
596 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
597 :
598 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
599 :
600 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
601 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
602 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
603 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
604 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
605 0 : }
606 :
607 0 : static void drm_test_cmdline_rotate_270(struct kunit *test)
608 : {
609 0 : struct drm_cmdline_mode mode = { };
610 0 : const char *cmdline = "720x480,rotate=270";
611 :
612 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
613 : &no_connector, &mode));
614 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
615 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
616 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
617 0 : KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_270);
618 :
619 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
620 :
621 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
622 :
623 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
624 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
625 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
626 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
627 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
628 0 : }
629 :
630 0 : static void drm_test_cmdline_hmirror(struct kunit *test)
631 : {
632 0 : struct drm_cmdline_mode mode = { };
633 0 : const char *cmdline = "720x480,reflect_x";
634 :
635 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
636 : &no_connector, &mode));
637 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
638 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
639 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
640 0 : KUNIT_EXPECT_EQ(test, mode.rotation_reflection, (DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_X));
641 :
642 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
643 :
644 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
645 :
646 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
647 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
648 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
649 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
650 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
651 0 : }
652 :
653 0 : static void drm_test_cmdline_vmirror(struct kunit *test)
654 : {
655 0 : struct drm_cmdline_mode mode = { };
656 0 : const char *cmdline = "720x480,reflect_y";
657 :
658 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
659 : &no_connector, &mode));
660 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
661 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
662 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
663 0 : KUNIT_EXPECT_EQ(test, mode.rotation_reflection, (DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_Y));
664 :
665 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
666 :
667 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
668 :
669 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
670 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
671 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
672 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
673 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
674 0 : }
675 :
676 0 : static void drm_test_cmdline_margin_options(struct kunit *test)
677 : {
678 0 : struct drm_cmdline_mode mode = { };
679 0 : const char *cmdline =
680 : "720x480,margin_right=14,margin_left=24,margin_bottom=36,margin_top=42";
681 :
682 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
683 : &no_connector, &mode));
684 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
685 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
686 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
687 0 : KUNIT_EXPECT_EQ(test, mode.tv_margins.right, 14);
688 0 : KUNIT_EXPECT_EQ(test, mode.tv_margins.left, 24);
689 0 : KUNIT_EXPECT_EQ(test, mode.tv_margins.bottom, 36);
690 0 : KUNIT_EXPECT_EQ(test, mode.tv_margins.top, 42);
691 :
692 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
693 :
694 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
695 :
696 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
697 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
698 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
699 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
700 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
701 0 : }
702 :
703 0 : static void drm_test_cmdline_multiple_options(struct kunit *test)
704 : {
705 0 : struct drm_cmdline_mode mode = { };
706 0 : const char *cmdline = "720x480,rotate=270,reflect_x";
707 :
708 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
709 : &no_connector, &mode));
710 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
711 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
712 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
713 0 : KUNIT_EXPECT_EQ(test, mode.rotation_reflection, (DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X));
714 :
715 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
716 :
717 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
718 :
719 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
720 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
721 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
722 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
723 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
724 0 : }
725 :
726 0 : static void drm_test_cmdline_bpp_extra_and_option(struct kunit *test)
727 : {
728 0 : struct drm_cmdline_mode mode = { };
729 0 : const char *cmdline = "720x480-24e,rotate=180";
730 :
731 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
732 : &no_connector, &mode));
733 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
734 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
735 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
736 0 : KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180);
737 :
738 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
739 :
740 0 : KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
741 0 : KUNIT_EXPECT_EQ(test, mode.bpp, 24);
742 :
743 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
744 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
745 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
746 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
747 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON);
748 0 : }
749 :
750 0 : static void drm_test_cmdline_extra_and_option(struct kunit *test)
751 : {
752 0 : struct drm_cmdline_mode mode = { };
753 0 : const char *cmdline = "720x480e,rotate=180";
754 :
755 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
756 : &no_connector, &mode));
757 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
758 0 : KUNIT_EXPECT_EQ(test, mode.xres, 720);
759 0 : KUNIT_EXPECT_EQ(test, mode.yres, 480);
760 0 : KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180);
761 :
762 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
763 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
764 :
765 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
766 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
767 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
768 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
769 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON);
770 0 : }
771 :
772 0 : static void drm_test_cmdline_freestanding_options(struct kunit *test)
773 : {
774 0 : struct drm_cmdline_mode mode = { };
775 0 : const char *cmdline = "margin_right=14,margin_left=24,margin_bottom=36,margin_top=42";
776 :
777 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
778 : &no_connector, &mode));
779 0 : KUNIT_EXPECT_FALSE(test, mode.specified);
780 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
781 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
782 :
783 0 : KUNIT_EXPECT_EQ(test, mode.tv_margins.right, 14);
784 0 : KUNIT_EXPECT_EQ(test, mode.tv_margins.left, 24);
785 0 : KUNIT_EXPECT_EQ(test, mode.tv_margins.bottom, 36);
786 0 : KUNIT_EXPECT_EQ(test, mode.tv_margins.top, 42);
787 :
788 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
789 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
790 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
791 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
792 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
793 0 : }
794 :
795 0 : static void drm_test_cmdline_freestanding_force_e_and_options(struct kunit *test)
796 : {
797 0 : struct drm_cmdline_mode mode = { };
798 0 : const char *cmdline = "e,margin_right=14,margin_left=24,margin_bottom=36,margin_top=42";
799 :
800 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
801 : &no_connector, &mode));
802 0 : KUNIT_EXPECT_FALSE(test, mode.specified);
803 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
804 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
805 :
806 0 : KUNIT_EXPECT_EQ(test, mode.tv_margins.right, 14);
807 0 : KUNIT_EXPECT_EQ(test, mode.tv_margins.left, 24);
808 0 : KUNIT_EXPECT_EQ(test, mode.tv_margins.bottom, 36);
809 0 : KUNIT_EXPECT_EQ(test, mode.tv_margins.top, 42);
810 :
811 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
812 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
813 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
814 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
815 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON);
816 0 : }
817 :
818 0 : static void drm_test_cmdline_panel_orientation(struct kunit *test)
819 : {
820 0 : struct drm_cmdline_mode mode = { };
821 0 : const char *cmdline = "panel_orientation=upside_down";
822 :
823 0 : KUNIT_ASSERT_TRUE(test, drm_mode_parse_command_line_for_connector(cmdline,
824 : &no_connector, &mode));
825 0 : KUNIT_EXPECT_FALSE(test, mode.specified);
826 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
827 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
828 :
829 0 : KUNIT_EXPECT_EQ(test, mode.panel_orientation, DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP);
830 :
831 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
832 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
833 0 : KUNIT_EXPECT_FALSE(test, mode.interlace);
834 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
835 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
836 0 : }
837 :
838 : struct drm_cmdline_invalid_test {
839 : const char *name;
840 : const char *cmdline;
841 : };
842 :
843 0 : static void drm_test_cmdline_invalid(struct kunit *test)
844 : {
845 0 : const struct drm_cmdline_invalid_test *params = test->param_value;
846 0 : struct drm_cmdline_mode mode = { };
847 :
848 0 : KUNIT_EXPECT_FALSE(test, drm_mode_parse_command_line_for_connector(params->cmdline,
849 : &no_connector,
850 : &mode));
851 0 : }
852 :
853 : static const struct drm_cmdline_invalid_test drm_cmdline_invalid_tests[] = {
854 : {
855 : .name = "margin_only",
856 : .cmdline = "m",
857 : },
858 : {
859 : .name = "interlace_only",
860 : .cmdline = "i",
861 : },
862 : {
863 : .name = "res_missing_x",
864 : .cmdline = "x480",
865 : },
866 : {
867 : .name = "res_missing_y",
868 : .cmdline = "1024x",
869 : },
870 : {
871 : .name = "res_bad_y",
872 : .cmdline = "1024xtest",
873 : },
874 : {
875 : .name = "res_missing_y_bpp",
876 : .cmdline = "1024x-24",
877 : },
878 : {
879 : .name = "res_bad_bpp",
880 : .cmdline = "720x480-test",
881 : },
882 : {
883 : .name = "res_bad_refresh",
884 : .cmdline = "720x480@refresh",
885 : },
886 : {
887 : .name = "res_bpp_refresh_force_on_off",
888 : .cmdline = "720x480-24@60de",
889 : },
890 : {
891 : .name = "res_invalid_mode",
892 : .cmdline = "720x480f",
893 : },
894 : {
895 : .name = "res_bpp_wrong_place_mode",
896 : .cmdline = "720x480e-24",
897 : },
898 : {
899 : .name = "name_bpp_refresh",
900 : .cmdline = "NTSC-24@60",
901 : },
902 : {
903 : .name = "name_refresh",
904 : .cmdline = "NTSC@60",
905 : },
906 : {
907 : .name = "name_refresh_wrong_mode",
908 : .cmdline = "NTSC@60m",
909 : },
910 : {
911 : .name = "name_refresh_invalid_mode",
912 : .cmdline = "NTSC@60f",
913 : },
914 : {
915 : .name = "rotate_multiple",
916 : .cmdline = "720x480,rotate=0,rotate=90",
917 : },
918 : {
919 : .name = "rotate_invalid_val",
920 : .cmdline = "720x480,rotate=42",
921 : },
922 : {
923 : .name = "rotate_truncated",
924 : .cmdline = "720x480,rotate=",
925 : },
926 : {
927 : .name = "invalid_option",
928 : .cmdline = "720x480,test=42",
929 : },
930 : {
931 : .name = "invalid_tv_option",
932 : .cmdline = "720x480i,tv_mode=invalid",
933 : },
934 : {
935 : .name = "truncated_tv_option",
936 : .cmdline = "720x480i,tv_mode=NTS",
937 : },
938 : };
939 :
940 0 : static void drm_cmdline_invalid_desc(const struct drm_cmdline_invalid_test *t,
941 : char *desc)
942 : {
943 0 : sprintf(desc, "%s", t->name);
944 0 : }
945 :
946 0 : KUNIT_ARRAY_PARAM(drm_cmdline_invalid, drm_cmdline_invalid_tests, drm_cmdline_invalid_desc);
947 :
948 : struct drm_cmdline_tv_option_test {
949 : const char *name;
950 : const char *cmdline;
951 : struct drm_display_mode *(*mode_fn)(struct drm_device *dev);
952 : enum drm_connector_tv_mode tv_mode;
953 : };
954 :
955 0 : static void drm_test_cmdline_tv_options(struct kunit *test)
956 : {
957 0 : const struct drm_cmdline_tv_option_test *params = test->param_value;
958 0 : const struct drm_display_mode *expected_mode = params->mode_fn(NULL);
959 0 : struct drm_cmdline_mode mode = { };
960 :
961 0 : KUNIT_EXPECT_TRUE(test, drm_mode_parse_command_line_for_connector(params->cmdline,
962 : &no_connector, &mode));
963 0 : KUNIT_EXPECT_TRUE(test, mode.specified);
964 0 : KUNIT_EXPECT_EQ(test, mode.xres, expected_mode->hdisplay);
965 0 : KUNIT_EXPECT_EQ(test, mode.yres, expected_mode->vdisplay);
966 0 : KUNIT_EXPECT_EQ(test, mode.tv_mode, params->tv_mode);
967 :
968 0 : KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
969 :
970 0 : KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
971 :
972 0 : KUNIT_EXPECT_FALSE(test, mode.rb);
973 0 : KUNIT_EXPECT_FALSE(test, mode.cvt);
974 0 : KUNIT_EXPECT_EQ(test, mode.interlace, !!(expected_mode->flags & DRM_MODE_FLAG_INTERLACE));
975 0 : KUNIT_EXPECT_FALSE(test, mode.margins);
976 0 : KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
977 0 : }
978 :
979 : #define TV_OPT_TEST(_opt, _cmdline, _mode_fn) \
980 : { \
981 : .name = #_opt, \
982 : .cmdline = _cmdline, \
983 : .mode_fn = _mode_fn, \
984 : .tv_mode = DRM_MODE_TV_MODE_ ## _opt, \
985 : }
986 :
987 : static const struct drm_cmdline_tv_option_test drm_cmdline_tv_option_tests[] = {
988 : TV_OPT_TEST(NTSC, "720x480i,tv_mode=NTSC", drm_mode_analog_ntsc_480i),
989 : TV_OPT_TEST(NTSC_443, "720x480i,tv_mode=NTSC-443", drm_mode_analog_ntsc_480i),
990 : TV_OPT_TEST(NTSC_J, "720x480i,tv_mode=NTSC-J", drm_mode_analog_ntsc_480i),
991 : TV_OPT_TEST(PAL, "720x576i,tv_mode=PAL", drm_mode_analog_pal_576i),
992 : TV_OPT_TEST(PAL_M, "720x480i,tv_mode=PAL-M", drm_mode_analog_ntsc_480i),
993 : TV_OPT_TEST(PAL_N, "720x576i,tv_mode=PAL-N", drm_mode_analog_pal_576i),
994 : TV_OPT_TEST(SECAM, "720x576i,tv_mode=SECAM", drm_mode_analog_pal_576i),
995 : };
996 :
997 0 : static void drm_cmdline_tv_option_desc(const struct drm_cmdline_tv_option_test *t,
998 : char *desc)
999 : {
1000 0 : sprintf(desc, "%s", t->name);
1001 0 : }
1002 :
1003 0 : KUNIT_ARRAY_PARAM(drm_cmdline_tv_option,
1004 : drm_cmdline_tv_option_tests,
1005 : drm_cmdline_tv_option_desc);
1006 :
1007 : static struct kunit_case drm_cmdline_parser_tests[] = {
1008 : KUNIT_CASE(drm_test_cmdline_force_d_only),
1009 : KUNIT_CASE(drm_test_cmdline_force_D_only_dvi),
1010 : KUNIT_CASE(drm_test_cmdline_force_D_only_hdmi),
1011 : KUNIT_CASE(drm_test_cmdline_force_D_only_not_digital),
1012 : KUNIT_CASE(drm_test_cmdline_force_e_only),
1013 : KUNIT_CASE(drm_test_cmdline_res),
1014 : KUNIT_CASE(drm_test_cmdline_res_vesa),
1015 : KUNIT_CASE(drm_test_cmdline_res_vesa_rblank),
1016 : KUNIT_CASE(drm_test_cmdline_res_rblank),
1017 : KUNIT_CASE(drm_test_cmdline_res_bpp),
1018 : KUNIT_CASE(drm_test_cmdline_res_refresh),
1019 : KUNIT_CASE(drm_test_cmdline_res_bpp_refresh),
1020 : KUNIT_CASE(drm_test_cmdline_res_bpp_refresh_interlaced),
1021 : KUNIT_CASE(drm_test_cmdline_res_bpp_refresh_margins),
1022 : KUNIT_CASE(drm_test_cmdline_res_bpp_refresh_force_off),
1023 : KUNIT_CASE(drm_test_cmdline_res_bpp_refresh_force_on),
1024 : KUNIT_CASE(drm_test_cmdline_res_bpp_refresh_force_on_analog),
1025 : KUNIT_CASE(drm_test_cmdline_res_bpp_refresh_force_on_digital),
1026 : KUNIT_CASE(drm_test_cmdline_res_bpp_refresh_interlaced_margins_force_on),
1027 : KUNIT_CASE(drm_test_cmdline_res_margins_force_on),
1028 : KUNIT_CASE(drm_test_cmdline_res_vesa_margins),
1029 : KUNIT_CASE(drm_test_cmdline_name),
1030 : KUNIT_CASE(drm_test_cmdline_name_bpp),
1031 : KUNIT_CASE(drm_test_cmdline_name_option),
1032 : KUNIT_CASE(drm_test_cmdline_name_bpp_option),
1033 : KUNIT_CASE(drm_test_cmdline_rotate_0),
1034 : KUNIT_CASE(drm_test_cmdline_rotate_90),
1035 : KUNIT_CASE(drm_test_cmdline_rotate_180),
1036 : KUNIT_CASE(drm_test_cmdline_rotate_270),
1037 : KUNIT_CASE(drm_test_cmdline_hmirror),
1038 : KUNIT_CASE(drm_test_cmdline_vmirror),
1039 : KUNIT_CASE(drm_test_cmdline_margin_options),
1040 : KUNIT_CASE(drm_test_cmdline_multiple_options),
1041 : KUNIT_CASE(drm_test_cmdline_bpp_extra_and_option),
1042 : KUNIT_CASE(drm_test_cmdline_extra_and_option),
1043 : KUNIT_CASE(drm_test_cmdline_freestanding_options),
1044 : KUNIT_CASE(drm_test_cmdline_freestanding_force_e_and_options),
1045 : KUNIT_CASE(drm_test_cmdline_panel_orientation),
1046 : KUNIT_CASE_PARAM(drm_test_cmdline_invalid, drm_cmdline_invalid_gen_params),
1047 : KUNIT_CASE_PARAM(drm_test_cmdline_tv_options, drm_cmdline_tv_option_gen_params),
1048 : {}
1049 : };
1050 :
1051 : static struct kunit_suite drm_cmdline_parser_test_suite = {
1052 : .name = "drm_cmdline_parser",
1053 : .test_cases = drm_cmdline_parser_tests
1054 : };
1055 :
1056 : kunit_test_suite(drm_cmdline_parser_test_suite);
1057 :
1058 : MODULE_AUTHOR("Maxime Ripard <maxime.ripard@bootlin.com>");
1059 : MODULE_LICENSE("GPL");
|