Linux Audio

Check our new training course

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