~lkcamp/patches

Fwd: [PATCH v2 2/2] drm: selftests: convert drm_cmdline_parser selftest to KUnit

Details
Message ID
<b2dc240df4a6d01e5a50ac10b0d6ad69@riseup.net>
DKIM signature
pass
Download raw message

-------- Original Message --------
Subject: [PATCH v2 2/2] drm: selftests: convert drm_cmdline_parser
selftest to KUnit
Date: 2021-11-17 19:59
From: Arthur Grillo <arthur.grillo@usp.br>
To: ~lkcamp/patches@lists.sr.ht
Cc: maira.canal@usp.br, isabbasso@riseup.net, Arthur Grillo
<arthur.grillo@usp.br>

From: Maíra Canal <maira.canal@usp.br>

Considering the current adoption of the KUnit framework, convert the
DRM cmdline parser selftest to the KUnit API.

Co-developed-by: Maíra Canal <maira.canal@usp.br>
Signed-off-by: Maíra Canal <maira.canal@usp.br>
Signed-off-by: Arthur Grillo <arthur.grillo@usp.br>
---
 drivers/gpu/drm/Kconfig                       |  13 +
 drivers/gpu/drm/Makefile                      |   2 +-
 drivers/gpu/drm/selftests/Makefile            |   5 +-
 .../drm/selftests/test-drm_cmdline_parser.c   | 970 +++++++++---------
 4 files changed, 485 insertions(+), 505 deletions(-)

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index cea777ae7fb9..fa13993b4cac 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -79,6 +79,19 @@ config DRM_DEBUG_SELFTEST
 
 	  If in doubt, say "N".
 
+config DRM_CMDLINE_PARSER_KUNIT_TESTS
+	tristate "KUnit tests for DRM cmdline parser"
+	depends on DRM && KUNIT
+	select DRM_KMS_HELPER
+	default KUNIT_ALL_TESTS
+	help
+	  This option provides a kunit module that can be used to run
+	  an unit test on the DRM cmdline parser API. This option is not
+	  useful for distributions or general kernels, but only for kernel
+	  developers working on DRM and associated drivers.
+
+	  If in doubt, say "N".
+
 config DRM_KMS_HELPER
 	tristate
 	depends on DRM
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index ad1112154898..e632c43c9b7d 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -58,7 +58,7 @@ drm_kms_helper-$(CONFIG_DRM_DP_AUX_CHARDEV) +=
drm_dp_aux_dev.o
 drm_kms_helper-$(CONFIG_DRM_DP_CEC) += drm_dp_cec.o
 
 obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o
-obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/
+obj-y += selftests/
 
 obj-$(CONFIG_DRM)	+= drm.o
 obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o
diff --git a/drivers/gpu/drm/selftests/Makefile
b/drivers/gpu/drm/selftests/Makefile
index 484c35c7edd0..10867f189ab7 100644
--- a/drivers/gpu/drm/selftests/Makefile
+++ b/drivers/gpu/drm/selftests/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
-obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o
test-drm_cmdline_parser.o \
-				    test-drm_format.o test-drm_framebuffer.o test-drm_rect.o \
+obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_format.o \
+				    test-drm_framebuffer.o test-drm_rect.o \
 				    test-drm_plane_helper.o test-drm_dp_mst_helper.o \
 				    test-drm_damage_helper.o 
+obj-$(CONFIG_DRM_CMDLINE_PARSER_KUNIT_TESTS) +=
test-drm_cmdline_parser.o
diff --git a/drivers/gpu/drm/selftests/test-drm_cmdline_parser.c
b/drivers/gpu/drm/selftests/test-drm_cmdline_parser.c
index 57a229c5fc35..010483b40aeb 100644
--- a/drivers/gpu/drm/selftests/test-drm_cmdline_parser.c
+++ b/drivers/gpu/drm/selftests/test-drm_cmdline_parser.c
@@ -1,874 +1,840 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2019 Bootlin
- * Copyright (c) 2021 Ma�ra Canal <maira.canal@usp.br>,
+ * Copyright (c) 2021 Maíra Canal <maira.canal@usp.br>,
  * Copyright (c) 2021 Arthur Grillo <arthur.grillo@usp.br>
  */
 
-#define pr_fmt(fmt) "drm_cmdline: " fmt
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-
+#include <kunit/test.h>
 #include <drm/drm_connector.h>
 #include <drm/drm_modes.h>
 
-#define TESTS "drm_cmdline_selftests.h"
-#include "drm_selftest.h"
-#include "test-drm_modeset_common.h"
-
 static const struct drm_connector no_connector = {};
 
-static int drm_cmdline_test_properties(void *ignored,
-		struct drm_cmdline_mode *mode, enum drm_connector_force force)
+static void drm_cmdline_test_properties(struct kunit *test,
+					struct drm_cmdline_mode *mode,
+					enum drm_connector_force force)
 {
-	FAIL_ON(mode->rb);
-	FAIL_ON(mode->cvt);
-	FAIL_ON(mode->interlace);
-	FAIL_ON(mode->margins);
-	FAIL_ON(mode->force != force);
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test, mode->rb);
+	KUNIT_EXPECT_FALSE(test, mode->cvt);
+	KUNIT_EXPECT_FALSE(test, mode->interlace);
+	KUNIT_EXPECT_FALSE(test, mode->margins);
+	KUNIT_EXPECT_EQ(test, mode->force, force);
 }
 
-static int drm_cmdline_test_force_only(void *ignored, char *cmdline,
-		const struct drm_connector *connector, enum drm_connector_force
force)
+static void drm_cmdline_test_force_only(struct kunit *test, char
*cmdline,
+					const struct drm_connector *connector,
+					enum drm_connector_force force)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(!drm_mode_parse_command_line_for_connector(cmdline,
-							   connector, &mode));
-	FAIL_ON(mode.specified);
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
-
-	FAIL_ON(mode.rb);
-	FAIL_ON(mode.cvt);
-	FAIL_ON(mode.interlace);
-	FAIL_ON(mode.margins);
-	FAIL_ON(mode.force != force);
+	KUNIT_EXPECT_TRUE(test,
drm_mode_parse_command_line_for_connector(cmdline,
+									  connector,
+									  &mode));
+	KUNIT_EXPECT_FALSE(test, mode.specified);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	return 0;
+	KUNIT_EXPECT_FALSE(test, mode.rb);
+	KUNIT_EXPECT_FALSE(test, mode.cvt);
+	KUNIT_EXPECT_FALSE(test, mode.interlace);
+	KUNIT_EXPECT_FALSE(test, mode.margins);
+	KUNIT_EXPECT_EQ(test, mode.force, force);
 }
 
-static int drm_cmdline_test_freestanding(void *ignored,
-		struct drm_cmdline_mode *mode, char *cmdline,
-		const struct drm_connector *connector)
+static void drm_cmdline_test_freestanding(struct kunit *test,
+					  struct drm_cmdline_mode *mode,
+					  char *cmdline,
+					  const struct drm_connector *connector)
 {
-	FAIL_ON(!drm_mode_parse_command_line_for_connector(cmdline,
-							   connector, mode));
-	FAIL_ON(mode->specified);
-	FAIL_ON(mode->refresh_specified);
-	FAIL_ON(mode->bpp_specified);
+	KUNIT_EXPECT_TRUE(test,
+			  drm_mode_parse_command_line_for_connector(cmdline,
+								    connector,
+								    mode));
+	KUNIT_EXPECT_FALSE(test, mode->specified);
+	KUNIT_EXPECT_FALSE(test, mode->refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode->bpp_specified);
 
-	FAIL_ON(mode->tv_margins.right != 14);
-	FAIL_ON(mode->tv_margins.left != 24);
-	FAIL_ON(mode->tv_margins.bottom != 36);
-	FAIL_ON(mode->tv_margins.top != 42);
-
-	return 0;
+	KUNIT_EXPECT_EQ(test, mode->tv_margins.right, 14);
+	KUNIT_EXPECT_EQ(test, mode->tv_margins.left, 24);
+	KUNIT_EXPECT_EQ(test, mode->tv_margins.bottom, 36);
+	KUNIT_EXPECT_EQ(test, mode->tv_margins.top, 42);
 }
 
-static int drm_cmdline_test_res_init(void *ignored,
-		struct drm_cmdline_mode *mode, char *cmdline)
+static void drm_cmdline_test_res_init(struct kunit *test,
+				      struct drm_cmdline_mode *mode,
+				      char *cmdline)
 {
-	FAIL_ON(!drm_mode_parse_command_line_for_connector(cmdline,
-							   &no_connector, mode));
-	FAIL_ON(!mode->specified);
-	FAIL_ON(mode->xres != 720);
-	FAIL_ON(mode->yres != 480);
-
-	return 0;
+	KUNIT_EXPECT_TRUE(test,
+			  drm_mode_parse_command_line_for_connector(cmdline,
+								    &no_connector,
+								    mode));
+	KUNIT_EXPECT_TRUE(test, mode->specified);
+	KUNIT_EXPECT_EQ(test, mode->xres, 720);
+	KUNIT_EXPECT_EQ(test, mode->yres, 480);
 }
 
-static int drm_cmdline_test_res_bpp_init(void *ignored,
-		struct drm_cmdline_mode *mode, char *cmdline)
+static void drm_cmdline_test_res_bpp_init(struct kunit *test,
+					  struct drm_cmdline_mode *mode,
+					  char *cmdline)
 {
-	FAIL_ON(!drm_mode_parse_command_line_for_connector(cmdline,
-							   &no_connector, mode));
-	FAIL_ON(!mode->specified);
-	FAIL_ON(mode->xres != 720);
-	FAIL_ON(mode->yres != 480);
-
-	FAIL_ON(!mode->refresh_specified);
-	FAIL_ON(mode->refresh != 60);
-	FAIL_ON(!mode->bpp_specified);
-	FAIL_ON(mode->bpp != 24);
+	KUNIT_EXPECT_TRUE(test,
+			  drm_mode_parse_command_line_for_connector(cmdline,
+								    &no_connector,
+								    mode));
+	KUNIT_EXPECT_TRUE(test, mode->specified);
+	KUNIT_EXPECT_EQ(test, mode->xres, 720);
+	KUNIT_EXPECT_EQ(test, mode->yres, 480);
 
-	return 0;
+	KUNIT_EXPECT_TRUE(test, mode->refresh_specified);
+	KUNIT_EXPECT_EQ(test, mode->refresh, 60);
+	KUNIT_EXPECT_TRUE(test, mode->bpp_specified);
+	KUNIT_EXPECT_EQ(test, mode->bpp, 24);
 }
 
-static int drm_cmdline_test_force_e_only(void *ignored)
+static void drm_cmdline_test_force_e_only(struct kunit *test)
 {
-	drm_cmdline_test_force_only(ignored, "e", &no_connector,
DRM_FORCE_ON);
-
-	return 0;
+	drm_cmdline_test_force_only(test, "e", &no_connector, DRM_FORCE_ON);
 }
 
-static int drm_cmdline_test_force_D_only_not_digital(void *ignored)
+static void drm_cmdline_test_force_D_only_not_digital(struct kunit
*test)
 {
-	drm_cmdline_test_force_only(ignored, "D", &no_connector,
DRM_FORCE_ON);
-
-	return 0;
+	drm_cmdline_test_force_only(test, "D", &no_connector, DRM_FORCE_ON);
 }
 
 static const struct drm_connector connector_hdmi = {
 	.connector_type	= DRM_MODE_CONNECTOR_HDMIB,
-
 };
 
-static int drm_cmdline_test_force_D_only_hdmi(void *ignored)
+static void drm_cmdline_test_force_D_only_hdmi(struct kunit *test)
 {
-	drm_cmdline_test_force_only(ignored, "D", &connector_hdmi,
+	drm_cmdline_test_force_only(test, "D", &connector_hdmi,
 			DRM_FORCE_ON_DIGITAL);
-
-	return 0;
 }
 
 static const struct drm_connector connector_dvi = {
 	.connector_type	= DRM_MODE_CONNECTOR_DVII,
-
 };
 
-static int drm_cmdline_test_force_D_only_dvi(void *ignored)
+static void drm_cmdline_test_force_D_only_dvi(struct kunit *test)
 {
-	drm_cmdline_test_force_only(ignored, "D", &connector_dvi,
+	drm_cmdline_test_force_only(test, "D", &connector_dvi,
 			DRM_FORCE_ON_DIGITAL);
-
-	return 0;
 }
 
-static int drm_cmdline_test_force_d_only(void *ignored)
+static void drm_cmdline_test_force_d_only(struct kunit *test)
 {
-	drm_cmdline_test_force_only(ignored, "d", &no_connector,
DRM_FORCE_OFF);
-
-	return 0;
+	drm_cmdline_test_force_only(test, "d", &no_connector, DRM_FORCE_OFF);
 }
 
-static int drm_cmdline_test_margin_only(void *ignored)
+static void drm_cmdline_test_margin_only(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("m",
-							  &no_connector,
-							  &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("m",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_interlace_only(void *ignored)
+static void drm_cmdline_test_interlace_only(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("i",
-							  &no_connector,
-							  &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("i",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_res(void *ignored)
+static void drm_cmdline_test_res(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480");
+	drm_cmdline_test_res_init(test, &mode, "720x480");
 
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	FAIL_ON(mode.rb);
-	FAIL_ON(mode.cvt);
-	FAIL_ON(mode.interlace);
-	FAIL_ON(mode.margins);
-	FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED);
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test, mode.rb);
+	KUNIT_EXPECT_FALSE(test, mode.cvt);
+	KUNIT_EXPECT_FALSE(test, mode.interlace);
+	KUNIT_EXPECT_FALSE(test, mode.margins);
+	KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_res_missing_x(void *ignored)
+static void drm_cmdline_test_res_missing_x(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("x480",
-							  &no_connector,
-							  &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("x480",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_res_missing_y(void *ignored)
+static void drm_cmdline_test_res_missing_y(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("1024x",
-							  &no_connector,
-							  &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("1024x",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_res_bad_y(void *ignored)
+static void drm_cmdline_test_res_bad_y(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("1024xtest",
-							  &no_connector,
-							  &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("1024xtest",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_res_missing_y_bpp(void *ignored)
+static void drm_cmdline_test_res_missing_y_bpp(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("1024x-24",
-							  &no_connector,
-							  &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("1024x-24",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_res_vesa(void *ignored)
+static void drm_cmdline_test_res_vesa(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480M");
+	drm_cmdline_test_res_init(test, &mode, "720x480M");
 
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	FAIL_ON(mode.rb);
-	FAIL_ON(!mode.cvt);
-	FAIL_ON(mode.interlace);
-	FAIL_ON(mode.margins);
-	FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED);
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test, mode.rb);
+	KUNIT_EXPECT_TRUE(test, mode.cvt);
+	KUNIT_EXPECT_FALSE(test, mode.interlace);
+	KUNIT_EXPECT_FALSE(test, mode.margins);
+	KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_res_vesa_rblank(void *ignored)
+static void drm_cmdline_test_res_vesa_rblank(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480MR");
-
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	drm_cmdline_test_res_init(test, &mode, "720x480MR");
 
-	FAIL_ON(!mode.rb);
-	FAIL_ON(!mode.cvt);
-	FAIL_ON(mode.interlace);
-	FAIL_ON(mode.margins);
-	FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	return 0;
+	KUNIT_EXPECT_TRUE(test, mode.rb);
+	KUNIT_EXPECT_TRUE(test, mode.cvt);
+	KUNIT_EXPECT_FALSE(test, mode.interlace);
+	KUNIT_EXPECT_FALSE(test, mode.margins);
+	KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_res_rblank(void *ignored)
+static void drm_cmdline_test_res_rblank(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480R");
+	drm_cmdline_test_res_init(test, &mode, "720x480R");
 
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	FAIL_ON(!mode.rb);
-	FAIL_ON(mode.cvt);
-	FAIL_ON(mode.interlace);
-	FAIL_ON(mode.margins);
-	FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED);
-
-	return 0;
+	KUNIT_EXPECT_TRUE(test, mode.rb);
+	KUNIT_EXPECT_FALSE(test, mode.cvt);
+	KUNIT_EXPECT_FALSE(test, mode.interlace);
+	KUNIT_EXPECT_FALSE(test, mode.margins);
+	KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_res_bpp(void *ignored)
+static void drm_cmdline_test_res_bpp(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480-24");
-
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(!mode.bpp_specified);
-	FAIL_ON(mode.bpp != 24);
+	drm_cmdline_test_res_init(test, &mode, "720x480-24");
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
+	KUNIT_EXPECT_EQ(test, mode.bpp, 24);
 
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_res_bad_bpp(void *ignored)
+static void drm_cmdline_test_res_bad_bpp(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("720x480-test",
-							  &no_connector,
-							  &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("720x480-test",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_res_refresh(void *ignored)
+static void drm_cmdline_test_res_refresh(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480@60");
+	drm_cmdline_test_res_init(test, &mode, "720x480@60");
 
-	FAIL_ON(!mode.refresh_specified);
-	FAIL_ON(mode.refresh != 60);
-	FAIL_ON(mode.bpp_specified);
+	KUNIT_EXPECT_TRUE(test, mode.refresh_specified);
+	KUNIT_EXPECT_EQ(test, mode.refresh, 60);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
-
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_res_bad_refresh(void *ignored)
+static void drm_cmdline_test_res_bad_refresh(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("720x480@refresh",
-							  &no_connector,
-							  &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("720x480@refresh",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_res_bpp_refresh(void *ignored)
+static void drm_cmdline_test_res_bpp_refresh(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_bpp_init(ignored, &mode, "720x480-24@60");
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
-
-	return 0;
+	drm_cmdline_test_res_bpp_init(test, &mode, "720x480-24@60");
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_res_bpp_refresh_interlaced(void *ignored)
+static void drm_cmdline_test_res_bpp_refresh_interlaced(struct kunit
*test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_bpp_init(ignored, &mode, "720x480-24@60i");
-
-	FAIL_ON(mode.rb);
-	FAIL_ON(mode.cvt);
-	FAIL_ON(!mode.interlace);
-	FAIL_ON(mode.margins);
-	FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED);
+	drm_cmdline_test_res_bpp_init(test, &mode, "720x480-24@60i");
 
-	return 0;
+	KUNIT_EXPECT_FALSE(test, mode.rb);
+	KUNIT_EXPECT_FALSE(test, mode.cvt);
+	KUNIT_EXPECT_TRUE(test, mode.interlace);
+	KUNIT_EXPECT_FALSE(test, mode.margins);
+	KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_res_bpp_refresh_margins(void *ignored)
+static void drm_cmdline_test_res_bpp_refresh_margins(struct kunit
*test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_bpp_init(ignored, &mode, "720x480-24@60m");
-
-	FAIL_ON(mode.rb);
-	FAIL_ON(mode.cvt);
-	FAIL_ON(mode.interlace);
-	FAIL_ON(!mode.margins);
-	FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED);
+	drm_cmdline_test_res_bpp_init(test, &mode, "720x480-24@60m");
 
-	return 0;
+	KUNIT_EXPECT_FALSE(test, mode.rb);
+	KUNIT_EXPECT_FALSE(test, mode.cvt);
+	KUNIT_EXPECT_FALSE(test, mode.interlace);
+	KUNIT_EXPECT_TRUE(test, mode.margins);
+	KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_res_bpp_refresh_force_off(void *ignored)
+static void drm_cmdline_test_res_bpp_refresh_force_off(struct kunit
*test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_bpp_init(ignored, &mode, "720x480-24@60d");
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_OFF);
-
-	return 0;
+	drm_cmdline_test_res_bpp_init(test, &mode, "720x480-24@60d");
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_OFF);
 }
 
-static int drm_cmdline_test_res_bpp_refresh_force_on_off(void *ignored)
+static void drm_cmdline_test_res_bpp_refresh_force_on_off(struct kunit
*test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("720x480-24@60de",
-							  &no_connector,
-							  &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("720x480-24@60de",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_res_bpp_refresh_force_on(void *ignored)
+static void drm_cmdline_test_res_bpp_refresh_force_on(struct kunit
*test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_bpp_init(ignored, &mode, "720x480-24@60e");
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_ON);
-
-	return 0;
+	drm_cmdline_test_res_bpp_init(test, &mode, "720x480-24@60e");
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_ON);
 }
 
-static int drm_cmdline_test_res_bpp_refresh_force_on_analog(void
*ignored)
+static void drm_cmdline_test_res_bpp_refresh_force_on_analog(struct
kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_bpp_init(ignored, &mode, "720x480-24@60D");
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_ON);
-
-	return 0;
+	drm_cmdline_test_res_bpp_init(test, &mode, "720x480-24@60D");
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_ON);
 }
 
-static int drm_cmdline_test_res_bpp_refresh_force_on_digital(void
*ignored)
+static void drm_cmdline_test_res_bpp_refresh_force_on_digital(struct
kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 	static const struct drm_connector connector = {
 		.connector_type = DRM_MODE_CONNECTOR_DVII,
 	};
 
-	FAIL_ON(!drm_mode_parse_command_line_for_connector("720x480-24@60D",
-							   &connector, &mode));
-	FAIL_ON(!mode.specified);
-	FAIL_ON(mode.xres != 720);
-	FAIL_ON(mode.yres != 480);
+	KUNIT_EXPECT_TRUE(test,
+			  drm_mode_parse_command_line_for_connector("720x480-24@60D",
+								    &connector,
+								    &mode));
+	KUNIT_EXPECT_TRUE(test, mode.specified);
+	KUNIT_EXPECT_EQ(test, mode.xres, 720);
+	KUNIT_EXPECT_EQ(test, mode.yres, 480);
 
-	FAIL_ON(!mode.refresh_specified);
-	FAIL_ON(mode.refresh != 60);
+	KUNIT_EXPECT_TRUE(test, mode.refresh_specified);
+	KUNIT_EXPECT_EQ(test, mode.refresh, 60);
 
-	FAIL_ON(!mode.bpp_specified);
-	FAIL_ON(mode.bpp != 24);
+	KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
+	KUNIT_EXPECT_EQ(test, mode.bpp, 24);
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_ON_DIGITAL);
-
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_ON_DIGITAL);
 }
 
-static int
drm_cmdline_test_res_bpp_refresh_interlaced_margins_force_on(void
*ignored)
+static void
drm_cmdline_test_res_bpp_refresh_interlaced_margins_force_on(struct
kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_bpp_init(ignored, &mode, "720x480-24@60ime");
-
-	FAIL_ON(mode.rb);
-	FAIL_ON(mode.cvt);
-	FAIL_ON(!mode.interlace);
-	FAIL_ON(!mode.margins);
-	FAIL_ON(mode.force != DRM_FORCE_ON);
+	drm_cmdline_test_res_bpp_init(test, &mode, "720x480-24@60ime");
 
-	return 0;
+	KUNIT_EXPECT_FALSE(test, mode.rb);
+	KUNIT_EXPECT_FALSE(test, mode.cvt);
+	KUNIT_EXPECT_TRUE(test, mode.interlace);
+	KUNIT_EXPECT_TRUE(test, mode.margins);
+	KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON);
 }
 
-static int drm_cmdline_test_res_margins_force_on(void *ignored)
+static void drm_cmdline_test_res_margins_force_on(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480me");
+	drm_cmdline_test_res_init(test, &mode, "720x480me");
 
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	FAIL_ON(mode.rb);
-	FAIL_ON(mode.cvt);
-	FAIL_ON(mode.interlace);
-	FAIL_ON(!mode.margins);
-	FAIL_ON(mode.force != DRM_FORCE_ON);
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test, mode.rb);
+	KUNIT_EXPECT_FALSE(test, mode.cvt);
+	KUNIT_EXPECT_FALSE(test, mode.interlace);
+	KUNIT_EXPECT_TRUE(test, mode.margins);
+	KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_ON);
 }
 
-static int drm_cmdline_test_res_vesa_margins(void *ignored)
+static void drm_cmdline_test_res_vesa_margins(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480Mm");
-
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	drm_cmdline_test_res_init(test, &mode, "720x480Mm");
 
-	FAIL_ON(mode.rb);
-	FAIL_ON(!mode.cvt);
-	FAIL_ON(mode.interlace);
-	FAIL_ON(!mode.margins);
-	FAIL_ON(mode.force != DRM_FORCE_UNSPECIFIED);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	return 0;
+	KUNIT_EXPECT_FALSE(test, mode.rb);
+	KUNIT_EXPECT_TRUE(test, mode.cvt);
+	KUNIT_EXPECT_FALSE(test, mode.interlace);
+	KUNIT_EXPECT_TRUE(test, mode.margins);
+	KUNIT_EXPECT_EQ(test, mode.force, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_res_invalid_mode(void *ignored)
+static void drm_cmdline_test_res_invalid_mode(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("720x480f",
-							  &no_connector,
-							  &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("720x480f",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_res_bpp_wrong_place_mode(void *ignored)
+static void drm_cmdline_test_res_bpp_wrong_place_mode(struct kunit
*test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("720x480e-24",
-							  &no_connector,
-							  &mode));
-
-	return 0;
-}
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("720x480e-24",
+								     &no_connector,
+								     &mode)); }
 
-static int drm_cmdline_test_name(void *ignored)
+static void drm_cmdline_test_name(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(!drm_mode_parse_command_line_for_connector("NTSC",
-							   &no_connector,
-							   &mode));
-	FAIL_ON(strcmp(mode.name, "NTSC"));
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
-
-	return 0;
+	KUNIT_EXPECT_TRUE(test,
+			  drm_mode_parse_command_line_for_connector("NTSC",
+								    &no_connector,
+								    &mode));
+	KUNIT_EXPECT_FALSE(test, strcmp(mode.name, "NTSC"));
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 }
 
-static int drm_cmdline_test_name_bpp(void *ignored)
+static void drm_cmdline_test_name_bpp(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(!drm_mode_parse_command_line_for_connector("NTSC-24",
-							   &no_connector,
-							   &mode));
-	FAIL_ON(strcmp(mode.name, "NTSC"));
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(!mode.bpp_specified);
-
-	FAIL_ON(mode.bpp != 24);
+	KUNIT_EXPECT_TRUE(test,
+			  drm_mode_parse_command_line_for_connector("NTSC-24",
+								    &no_connector,
+								    &mode));
+	KUNIT_EXPECT_FALSE(test, strcmp(mode.name, "NTSC"));
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
 
-	return 0;
+	KUNIT_EXPECT_EQ(test, mode.bpp, 24);
 }
 
-static int drm_cmdline_test_name_bpp_refresh(void *ignored)
+static void drm_cmdline_test_name_bpp_refresh(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("NTSC-24@60",
-							  &no_connector,
-							  &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("NTSC-24@60",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_name_refresh(void *ignored)
+static void drm_cmdline_test_name_refresh(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("NTSC@60",
-							  &no_connector,
-							  &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("NTSC@60",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_name_refresh_wrong_mode(void *ignored)
+static void drm_cmdline_test_name_refresh_wrong_mode(struct kunit
*test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("NTSC@60m",
-							  &no_connector,
-							  &mode));
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("NTSC@60m",
+								     &no_connector,
+								     &mode)); }
 
-	return 0;
-}
-
-static int drm_cmdline_test_name_refresh_invalid_mode(void *ignored)
+static void drm_cmdline_test_name_refresh_invalid_mode(struct kunit
*test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector("NTSC@60f",
-							  &no_connector,
-							  &mode));
-
-	return 0;
-}
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("NTSC@60f",
+								     &no_connector,
+								     &mode)); }
 
-static int drm_cmdline_test_name_option(void *ignored)
+static void drm_cmdline_test_name_option(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(!drm_mode_parse_command_line_for_connector("NTSC,rotate=180",
-							   &no_connector,
-							   &mode));
-	FAIL_ON(!mode.specified);
-	FAIL_ON(strcmp(mode.name, "NTSC"));
-	FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_180);
-
-	return 0;
+	KUNIT_EXPECT_TRUE(test,
+			  drm_mode_parse_command_line_for_connector("NTSC,rotate=180",
+								    &no_connector,
+								    &mode));
+	KUNIT_EXPECT_TRUE(test, mode.specified);
+	KUNIT_EXPECT_FALSE(test, strcmp(mode.name, "NTSC"));
+	KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180);
 }
 
-static int drm_cmdline_test_name_bpp_option(void *ignored)
+static void drm_cmdline_test_name_bpp_option(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(!drm_mode_parse_command_line_for_connector("NTSC-24,rotate=180",
-							   &no_connector,
-							   &mode));
-	FAIL_ON(!mode.specified);
-	FAIL_ON(strcmp(mode.name, "NTSC"));
-	FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_180);
-	FAIL_ON(!mode.bpp_specified);
-	FAIL_ON(mode.bpp != 24);
-
-	return 0;
+	KUNIT_EXPECT_TRUE(test,
+			  drm_mode_parse_command_line_for_connector("NTSC-24,rotate=180",
+								    &no_connector,
+								    &mode));
+	KUNIT_EXPECT_TRUE(test, mode.specified);
+	KUNIT_EXPECT_FALSE(test, strcmp(mode.name, "NTSC"));
+	KUNIT_EXPECT_FALSE(test, mode.rotation_reflection !=
DRM_MODE_ROTATE_180);
+	KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp != 24);
 }
 
-static int drm_cmdline_test_rotate_0(void *ignored)
+static void drm_cmdline_test_rotate_0(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480,rotate=0");
+	drm_cmdline_test_res_init(test, &mode, "720x480,rotate=0");
 
-	FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_0);
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_0);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
-
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_rotate_90(void *ignored)
+static void drm_cmdline_test_rotate_90(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480,rotate=90");
-
-	FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_90);
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	drm_cmdline_test_res_init(test, &mode, "720x480,rotate=90");
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
+	KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_90);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_rotate_180(void *ignored)
+static void drm_cmdline_test_rotate_180(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480,rotate=180");
+	drm_cmdline_test_res_init(test, &mode, "720x480,rotate=180");
 
-	FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_180);
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
-
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_rotate_270(void *ignored)
+static void drm_cmdline_test_rotate_270(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480,rotate=270");
-
-	FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_270);
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	drm_cmdline_test_res_init(test, &mode, "720x480,rotate=270");
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
+	KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_270);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_rotate_multiple(void *ignored)
+static void drm_cmdline_test_rotate_multiple(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector(
-				"720x480,rotate=0,rotate=90", &no_connector, &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			  
drm_mode_parse_command_line_for_connector("720x480,rotate=0,rotate=90",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_rotate_invalid_val(void *ignored)
+static void drm_cmdline_test_rotate_invalid_val(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector(
-				"720x480,rotate=42", &no_connector, &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("720x480,rotate=42",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_rotate_truncated(void *ignored)
+static void drm_cmdline_test_rotate_truncated(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector(
-				"720x480,rotate=", &no_connector, &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("720x480,rotate=",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_hmirror(void *ignored)
+static void drm_cmdline_test_hmirror(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480,reflect_x");
+	drm_cmdline_test_res_init(test, &mode, "720x480,reflect_x");
 
-	FAIL_ON(mode.rotation_reflection != (DRM_MODE_ROTATE_0 |
DRM_MODE_REFLECT_X));
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	KUNIT_EXPECT_EQ(test, mode.rotation_reflection,
+			DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_X);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
-
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_vmirror(void *ignored)
+static void drm_cmdline_test_vmirror(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480,reflect_y");
-
-	FAIL_ON(mode.rotation_reflection != (DRM_MODE_ROTATE_0 |
DRM_MODE_REFLECT_Y));
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	drm_cmdline_test_res_init(test, &mode, "720x480,reflect_y");
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
+	KUNIT_EXPECT_EQ(test, mode.rotation_reflection,
+			DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_Y);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_margin_options(void *ignored)
+static void drm_cmdline_test_margin_options(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode,
+	drm_cmdline_test_res_init(test, &mode,

			"720x480,margin_right=14,margin_left=24,margin_bottom=36,margin_top=42");
 
-	FAIL_ON(mode.tv_margins.right != 14);
-	FAIL_ON(mode.tv_margins.left != 24);
-	FAIL_ON(mode.tv_margins.bottom != 36);
-	FAIL_ON(mode.tv_margins.top != 42);
+	KUNIT_EXPECT_EQ(test, mode.tv_margins.right, 14);
+	KUNIT_EXPECT_EQ(test, mode.tv_margins.left, 24);
+	KUNIT_EXPECT_EQ(test, mode.tv_margins.bottom, 36);
+	KUNIT_EXPECT_EQ(test, mode.tv_margins.top, 42);
 
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
-
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_multiple_options(void *ignored)
+static void drm_cmdline_test_multiple_options(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode,
"720x480,rotate=270,reflect_x");
-
-	FAIL_ON(mode.rotation_reflection != (DRM_MODE_ROTATE_270 |
DRM_MODE_REFLECT_X));
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	drm_cmdline_test_res_init(test, &mode,
"720x480,rotate=270,reflect_x");
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
+	KUNIT_EXPECT_EQ(test, mode.rotation_reflection,
+			DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_invalid_option(void *ignored)
+static void drm_cmdline_test_invalid_option(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(drm_mode_parse_command_line_for_connector(
-				"720x480,test=42", &no_connector, &mode));
-
-	return 0;
+	KUNIT_EXPECT_FALSE(test,
+			   drm_mode_parse_command_line_for_connector("720x480,test=42",
+								     &no_connector,
+								     &mode));
 }
 
-static int drm_cmdline_test_bpp_extra_and_option(void *ignored)
+static void drm_cmdline_test_bpp_extra_and_option(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480-24e,rotate=180");
-
-	FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_180);
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(!mode.bpp_specified);
-	FAIL_ON(mode.bpp != 24);
+	drm_cmdline_test_res_init(test, &mode, "720x480-24e,rotate=180");
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_ON);
+	KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_TRUE(test, mode.bpp_specified);
+	KUNIT_EXPECT_EQ(test, mode.bpp, 24);
 
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_ON);
 }
 
-static int drm_cmdline_test_extra_and_option(void *ignored)
+static void drm_cmdline_test_extra_and_option(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_res_init(ignored, &mode, "720x480e,rotate=180");
+	drm_cmdline_test_res_init(test, &mode, "720x480e,rotate=180");
 
-	FAIL_ON(mode.rotation_reflection != DRM_MODE_ROTATE_180);
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	KUNIT_EXPECT_EQ(test, mode.rotation_reflection, DRM_MODE_ROTATE_180);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_ON);
-
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_ON);
 }
 
-static int drm_cmdline_test_freestanding_options(void *ignored)
+static void drm_cmdline_test_freestanding_options(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_freestanding(ignored, &mode,
-			"margin_right=14,margin_left=24,margin_bottom=36,margin_top=42",
-			&no_connector);
-
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
+	drm_cmdline_test_freestanding(test, &mode,
+				     
"margin_right=14,margin_left=24,margin_bottom=36,margin_top=42",
+				      &no_connector);
 
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-static int drm_cmdline_test_freestanding_force_e_and_options(void
*ignored)
+static void drm_cmdline_test_freestanding_force_e_and_options(struct
kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	drm_cmdline_test_freestanding(ignored, &mode,
-			"e,margin_right=14,margin_left=24,margin_bottom=36,margin_top=42",
-			&no_connector);
-
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_ON);
+	drm_cmdline_test_freestanding(test, &mode,
+				     
"e,margin_right=14,margin_left=24,margin_bottom=36,margin_top=42",
+				      &no_connector);
 
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_ON);
 }
 
-static int drm_cmdline_test_panel_orientation(void *ignored)
+static void drm_cmdline_test_panel_orientation(struct kunit *test)
 {
 	struct drm_cmdline_mode mode = { };
 
-	FAIL_ON(!drm_mode_parse_command_line_for_connector(
-				"panel_orientation=upside_down", &no_connector, &mode));
+	KUNIT_EXPECT_TRUE(test,
+			 
drm_mode_parse_command_line_for_connector("panel_orientation=upside_down",
+								    &no_connector,
+								    &mode));
 
-	FAIL_ON(mode.specified);
-	FAIL_ON(mode.refresh_specified);
-	FAIL_ON(mode.bpp_specified);
+	KUNIT_EXPECT_FALSE(test, mode.specified);
+	KUNIT_EXPECT_FALSE(test, mode.refresh_specified);
+	KUNIT_EXPECT_FALSE(test, mode.bpp_specified);
 
 
-	FAIL_ON(mode.panel_orientation !=
DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP);
+	KUNIT_EXPECT_EQ(test, mode.panel_orientation,
+			DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP);
 
-	drm_cmdline_test_properties(ignored, &mode, DRM_FORCE_UNSPECIFIED);
-
-	return 0;
+	drm_cmdline_test_properties(test, &mode, DRM_FORCE_UNSPECIFIED);
 }
 
-#include "drm_selftest.c"
-
-static int __init test_drm_cmdline_init(void)
-{
-	int err;
+static struct kunit_case drm_cmdline_parser_test_cases[] = {
+	KUNIT_CASE(drm_cmdline_test_force_d_only),
+	KUNIT_CASE(drm_cmdline_test_force_D_only_dvi),
+	KUNIT_CASE(drm_cmdline_test_force_D_only_hdmi),
+	KUNIT_CASE(drm_cmdline_test_force_D_only_not_digital),
+	KUNIT_CASE(drm_cmdline_test_force_e_only),
+	KUNIT_CASE(drm_cmdline_test_margin_only),
+	KUNIT_CASE(drm_cmdline_test_interlace_only),
+	KUNIT_CASE(drm_cmdline_test_res),
+	KUNIT_CASE(drm_cmdline_test_res_missing_x),
+	KUNIT_CASE(drm_cmdline_test_res_missing_y),
+	KUNIT_CASE(drm_cmdline_test_res_bad_y),
+	KUNIT_CASE(drm_cmdline_test_res_missing_y_bpp),
+	KUNIT_CASE(drm_cmdline_test_res_vesa),
+	KUNIT_CASE(drm_cmdline_test_res_vesa_rblank),
+	KUNIT_CASE(drm_cmdline_test_res_rblank),
+	KUNIT_CASE(drm_cmdline_test_res_bpp),
+	KUNIT_CASE(drm_cmdline_test_res_bad_bpp),
+	KUNIT_CASE(drm_cmdline_test_res_refresh),
+	KUNIT_CASE(drm_cmdline_test_res_bad_refresh),
+	KUNIT_CASE(drm_cmdline_test_res_bpp_refresh),
+	KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_interlaced),
+	KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_margins),
+	KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_force_off),
+	KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_force_on_off),
+	KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_force_on),
+	KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_force_on_analog),
+	KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_force_on_digital),
+	KUNIT_CASE(drm_cmdline_test_res_bpp_refresh_interlaced_margins_force_on),
+	KUNIT_CASE(drm_cmdline_test_res_margins_force_on),
+	KUNIT_CASE(drm_cmdline_test_res_vesa_margins),
+	KUNIT_CASE(drm_cmdline_test_res_invalid_mode),
+	KUNIT_CASE(drm_cmdline_test_res_bpp_wrong_place_mode),
+	KUNIT_CASE(drm_cmdline_test_name),
+	KUNIT_CASE(drm_cmdline_test_name_bpp),
+	KUNIT_CASE(drm_cmdline_test_name_refresh),
+	KUNIT_CASE(drm_cmdline_test_name_bpp_refresh),
+	KUNIT_CASE(drm_cmdline_test_name_refresh_wrong_mode),
+	KUNIT_CASE(drm_cmdline_test_name_refresh_invalid_mode),
+	KUNIT_CASE(drm_cmdline_test_name_option),
+	KUNIT_CASE(drm_cmdline_test_name_bpp_option),
+	KUNIT_CASE(drm_cmdline_test_rotate_0),
+	KUNIT_CASE(drm_cmdline_test_rotate_90),
+	KUNIT_CASE(drm_cmdline_test_rotate_180),
+	KUNIT_CASE(drm_cmdline_test_rotate_270),
+	KUNIT_CASE(drm_cmdline_test_rotate_multiple),
+	KUNIT_CASE(drm_cmdline_test_rotate_invalid_val),
+	KUNIT_CASE(drm_cmdline_test_rotate_truncated),
+	KUNIT_CASE(drm_cmdline_test_hmirror),
+	KUNIT_CASE(drm_cmdline_test_vmirror),
+	KUNIT_CASE(drm_cmdline_test_margin_options),
+	KUNIT_CASE(drm_cmdline_test_multiple_options),
+	KUNIT_CASE(drm_cmdline_test_invalid_option),
+	KUNIT_CASE(drm_cmdline_test_bpp_extra_and_option),
+	KUNIT_CASE(drm_cmdline_test_extra_and_option),
+	KUNIT_CASE(drm_cmdline_test_freestanding_options),
+	KUNIT_CASE(drm_cmdline_test_freestanding_force_e_and_options),
+	KUNIT_CASE(drm_cmdline_test_panel_orientation),
+	{}
+};
 
-	err = run_selftests(selftests, ARRAY_SIZE(selftests), NULL);
+static struct kunit_suite drm_cmdline_parser_test_suite = {
+	.name = "drm_cmdline_parser",
+	.test_cases = drm_cmdline_parser_test_cases
+};
 
-	return err > 0 ? 0 : err;
-}
-module_init(test_drm_cmdline_init);
+kunit_test_suite(drm_cmdline_parser_test_suite);
 
 MODULE_AUTHOR("Maxime Ripard <maxime.ripard@bootlin.com>");
 MODULE_LICENSE("GPL");
Reply to thread Export thread (mbox)