Skip to contentSkip to conversation

KUnit tests for drm_format_helper

PATCH Superseded José Expósito 2 participants 6 messages Jun 12, 2022 – Jun 13, 2022

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover KUnit tests for drm_format_helper

Hello everyone,

Here is the v2 of the series, including the documentation, previously sent as a standalone patch [1], and changes suggested during review.

Thanks a lot,
José Expósito

RFC -> v1: https://lore.kernel.org/dri-devel/[email protected]/T/

- Add .kunitconfig (Maxime Ripard)
- Fix memory leak (Daniel Latypov)
- Make config option generic (Javier Martinez Canillas):
DRM_FORMAR_HELPER_TEST -> DRM_KUNIT_TEST
- Remove DISABLE_STRUCTLEAK_PLUGIN (Daniel Latypov)

v1 -> v2: https://lore.kernel.org/dri-devel/[email protected]/T/

Thomas Zimmermann:
- Add DRM_RECT_INIT() macro
- Move tests to drivers/gpu/drm/kunit
- Improve test documentation

[1] https://lore.kernel.org/dri-devel/[email protected]/T/

José Expósito (3):
drm/rect: Add DRM_RECT_INIT() macro
drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332() drm/doc: Add KUnit documentation

 Documentation/gpu/drm-internals.rst           |  32 ++++
 drivers/gpu/drm/Kconfig                       |  16 ++
 drivers/gpu/drm/Makefile                      |   1 +
 drivers/gpu/drm/kunit/.kunitconfig            |   3 +
 drivers/gpu/drm/kunit/Makefile                |   3 +
 .../gpu/drm/kunit/drm_format_helper_test.c    | 169 ++++++++++++++++++
 include/drm/drm_rect.h                        |  12 ++
 7 files changed, 236 insertions(+)
 create mode 100644 drivers/gpu/drm/kunit/.kunitconfig
 create mode 100644 drivers/gpu/drm/kunit/Makefile
 create mode 100644 drivers/gpu/drm/kunit/drm_format_helper_test.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/3 drm/rect: Add DRM_RECT_INIT() macro

Add a helper macro to initialize a rectangle from x, y, width and height information.

---
 include/drm/drm_rect.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/drm/drm_rect.h +12 -0
index 6f6e19bd4dac..945696323c69 100644
@@ -47,6 +47,18 @@ struct drm_rect {
 	int x1, y1, x2, y2;
 };
 
+/**
+ * DRM_RECT_INIT - initialize a rectangle from x/y/w/h
+ * @x: x coordinate
+ * @y: y coordinate
+ * @w: width
+ * @h: height
+ *
+ * RETURNS:
+ * A new rectangle of the specified size.
+ */
+#define DRM_RECT_INIT(x, y, w, h) { (x), (y), (x) + (w), (y) + (h) }
+
 /**
  * DRM_RECT_FMT - printf string for &struct drm_rect
  */
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v2 1/3] drm/rect: Add DRM_RECT_INIT() macro

Quoted 17 lines · José Expósito

Add a helper macro to initialize a rectangle from x, y, width and height information.

---
 include/drm/drm_rect.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/drm/drm_rect.h +1 -0
index 6f6e19bd4dac..945696323c69 100644
@@ -47,6 +47,18 @@ struct drm_rect {
 	int x1, y1, x2, y2;
 };
 
+/**

include/drm/drm_rect.h struct drm_rect { · line 60

Quoted 10 lines
include/drm/drm_rect.h +10 -0
+ * DRM_RECT_INIT - initialize a rectangle from x/y/w/h
+ * @x: x coordinate
+ * @y: y coordinate
+ * @w: width
+ * @h: height
+ *
+ * RETURNS:
+ * A new rectangle of the specified size.
+ */
+#define DRM_RECT_INIT(x, y, w, h) { (x), (y), (x) + (w), (y) + (h) }

Please use designated initializers.

It might help type safety if it also contained a (struct drm_rect) cast.

BR,
Jani.

Quoted 4 lines
include/drm/drm_rect.h +1 -0
+
 /**
  * DRM_RECT_FMT - printf string for &struct drm_rect
  */
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
#3 lore raw

Re: [PATCH v2 1/3] drm/rect: Add DRM_RECT_INIT() macro

Quoted 31 lines · Jani Nikula
Quoted 17 lines · José Expósito

Add a helper macro to initialize a rectangle from x, y, width and height information.

---
 include/drm/drm_rect.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/drm/drm_rect.h +1 -0
index 6f6e19bd4dac..945696323c69 100644
@@ -47,6 +47,18 @@ struct drm_rect {
 	int x1, y1, x2, y2;
 };
 
+/**

include/drm/drm_rect.h struct drm_rect { · line 60

Quoted 10 lines
include/drm/drm_rect.h +10 -0
+ * DRM_RECT_INIT - initialize a rectangle from x/y/w/h
+ * @x: x coordinate
+ * @y: y coordinate
+ * @w: width
+ * @h: height
+ *
+ * RETURNS:
+ * A new rectangle of the specified size.
+ */
+#define DRM_RECT_INIT(x, y, w, h) { (x), (y), (x) + (w), (y) + (h) }

Please use designated initializers.

Quoted 1 line

It might help type safety if it also contained a (struct drm_rect) cast.

Thanks a lot for your review Jani, just emailed v3 with your suggested changes.

Jose

Quoted 11 lines

BR,
Jani.

Quoted 4 lines
include/drm/drm_rect.h +1 -0
+
 /**
  * DRM_RECT_FMT - printf string for &struct drm_rect
  */
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
#4 lore raw

PATCH v2 2/3 drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb332()

In reply to José Expósito

Test the conversion from XRGB8888 to RGB332.

What is tested?

- Different values for the X in XRGB8888 to make sure it is ignored
- Different clip values: Single pixel and full and partial buffer
- Well known colors: White, black, red, green, blue, magenta, yellow and cyan
- Other colors: Randomly picked
- Destination pitch

How to run the tests?

 $ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/kunit \
         --kconfig_add CONFIG_VIRTIO_UML=y \
         --kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y
---
 drivers/gpu/drm/Kconfig                       |  16 ++
 drivers/gpu/drm/Makefile                      |   1 +
 drivers/gpu/drm/kunit/.kunitconfig            |   3 +
 drivers/gpu/drm/kunit/Makefile                |   3 +
 .../gpu/drm/kunit/drm_format_helper_test.c    | 169 ++++++++++++++++++
 5 files changed, 192 insertions(+)
 create mode 100644 drivers/gpu/drm/kunit/.kunitconfig
 create mode 100644 drivers/gpu/drm/kunit/Makefile
 create mode 100644 drivers/gpu/drm/kunit/drm_format_helper_test.c
drivers/gpu/drm/Kconfig +16 -0
index 22e7fa48d693..6c2256e8474b 100644
@@ -70,6 +70,22 @@ config DRM_DEBUG_SELFTEST
 
 	  If in doubt, say "N".
 
+config DRM_KUNIT_TEST
+	tristate "KUnit tests for DRM" if !KUNIT_ALL_TESTS
+	depends on DRM && KUNIT=y
+	select DRM_KMS_HELPER
+	default KUNIT_ALL_TESTS
+	help
+	  This builds unit tests for DRM. This option is not useful for
+	  distributions or general kernels, but only for kernel
+	  developers working on DRM and associated drivers.
+
+	  For more information on KUnit and unit tests in general,
+	  please refer to the KUnit documentation in
+	  Documentation/dev-tools/kunit/.
+
+	  If in doubt, say "N".
+
 config DRM_KMS_HELPER
 	tristate
 	depends on DRM
drivers/gpu/drm/Makefile +1 -0
index 13ef240b3d2b..3171437d74f8 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o
 #
 
 obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/
+obj-$(CONFIG_DRM_KUNIT_TEST) += kunit/
 
 obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o
 obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o
drivers/gpu/drm/kunit/.kunitconfig new file +3 -0
new file mode 100644
index 000000000000..6ec04b4c979d
@@ -0,0 +1,3 @@
+CONFIG_KUNIT=y
+CONFIG_DRM=y
+CONFIG_DRM_KUNIT_TEST=y
drivers/gpu/drm/kunit/Makefile new file +3 -0
new file mode 100644
index 000000000000..2c8273796d9d
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_DRM_KUNIT_TEST) += drm_format_helper_test.o
drivers/gpu/drm/kunit/drm_format_helper_test.c new file +169 -0

169 lines not on this page · raw message

Signature · 1 line
2.25.1
#5 lore raw

PATCH v2 3/3 drm/doc: Add KUnit documentation

In reply to José Expósito

Explain how to run the KUnit tests present in the DRM subsystem and clarify why the UML-only options were not added to the configuration file present in drivers/gpu/drm/.kunitconfig [1] [2].

[1] https://lore.kernel.org/dri-devel/CABVgOSn8i=LO5p7830h2XU1Jgg0KrN0qTnxkOMhf1oTgxjaKKw@mail.gmail.com/
[2] https://lore.kernel.org/dri-devel/CAGS_qxqpiCim_sy1LDK7PLwVgWf-LKW+uNFTGM=T7ydk-dYcEw@mail.gmail.com/

---
 Documentation/gpu/drm-internals.rst | 32 +++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
Documentation/gpu/drm-internals.rst +32 -0
index 38afed24a75c..f1d97e80ca29 100644
@@ -207,6 +207,38 @@ Utilities
    :internal:
 
 
+Unit testing
+============
+
+KUnit
+-----
+
+KUnit (Kernel unit testing framework) provides a common framework for unit tests
+within the Linux kernel.
+
+This section covers the specifics for the DRM subsystem. For general information
+about KUnit, please refer to Documentation/dev-tools/kunit/start.rst.
+
+How to run the tests?
+~~~~~~~~~~~~~~~~~~~~~
+
+In order to facilitate running the test suite, a configuration file is present
+in ``drivers/gpu/drm/kunit/.kunitconfig``. It can be used by ``kunit.py`` as
+follows:
+
+.. code-block:: bash
+
+	$ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/kunit \
+		--kconfig_add CONFIG_VIRTIO_UML=y \
+		--kconfig_add CONFIG_UML_PCI_OVER_VIRTIO=y
+
+.. note::
+	The configuration included in ``.kunitconfig`` should be as generic as
+	possible.
+	``CONFIG_VIRTIO_UML`` and ``CONFIG_UML_PCI_OVER_VIRTIO`` are not
+	included in it because they are only required for User Mode Linux.
+
+
 Legacy Support Code
 ===================
 
Signature · 1 line
2.25.1