LCOV - code coverage report
Current view: top level - drivers/gpu/drm/tests - drm_cmdline_parser_test.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 600 600 100.0 %
Date: 2023-03-27 20:00:47 Functions: 44 44 100.0 %

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

Generated by: LCOV version 1.14