Skip to contentSkip to conversation

drm/amd/display: Introduce KUnit to Display Mode Library

PATCH Superseded Rodrigo Siqueira 2 participants 10 messages Jan 26, 2024 – Jan 29, 2024

Subsystems (6)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover drm/amd/display: Introduce KUnit to Display Mode Library

In 2022, we got a great patchset from a GSoC project introducing unit tests to the amdgpu display. Since version 3, this effort was put on hold, and now I'm attempting to revive it. I'll add part of the original cover letter at the bottom of this cover letter, but you can read all the original messages at:

https://lore.kernel.org/amd-gfx/[email protected]/

Anyway, this new version changes are:
- Rebase and adjust conflicts.
- Rewrite part of the dc_dmub_srv_test to represent a real scenario that simulates some parameter configuration for using 4k144 and 4k240 displays.

Thanks
Siqueira

Original cover letter

Hello,

This series is version 3 of the introduction of unit testing to the AMDPGU driver [1].

Our main goal is to bring unit testing to the AMD display driver; in particular, we'll focus on the Display Mode Library (DML) for DCN2.0, DMUB, and some of the DCE functions. This implementation intends to help developers to recognize bugs before they are merged into the mainline and also makes it possible for future code refactors of the AMD display driver.

For the implementation of the tests, we decided to go with the Kernel Unit Testing Framework (KUnit). KUnit makes it possible to run test suites on kernel boot or load the tests as a module. It reports all test case results through a TAP (Test Anything Protocol) in the kernel log. Moreover, KUnit unifies the test structure and provides tools to simplify the testing for developers and CI systems.

In regards to CI pipelines, we believe kunit_tool [2] provides ease of use, but we are also working on integrating KUnit into IGT [3].

Since the second version, we've chosen a mix of approaches to integrate KUnit tests into amdgpu:
1. Tests that use static functions are included through guards [4].
2. Tests without static functions are included through a Makefile.

We understand that testing static functions is not ideal, but taking into consideration that this driver relies heavily on static functions with complex behavior which would benefit from unit testing, otherwise, black-box tested through public functions with dozens of arguments and sometimes high cyclomatic complexity.

The first seven patches represent what we intend to do for the rest of the DML modules: systematic testing of the DML functions, especially mathematically complicated functions. Also, it shows how simple it is to add new tests to the DML.

Among the tests, we highlight the dcn20_fpu_test, which, had it existed then, could catch the defects introduced to dcn20_fpu.c by 8861c27a6c [5] later fixed by 9ad5d02c2a [6].

In this series, there's also an example of how unit tests can help avoid regressions and keep track of changes in behavior.

[..]

Isabella Basso (1):
drm/amd/display: Introduce KUnit tests to display_rq_dlg_calc_20

Magali Lemes (1):
drm/amd/display: Introduce KUnit tests for dcn20_fpu

Maíra Canal (5):
drm/amd/display: Introduce KUnit tests to the bw_fixed library drm/amd/display: Introduce KUnit tests to the display_mode_vba library drm/amd/display: Introduce KUnit to dcn20/display_mode_vba_20 library drm/amd/display: Introduce KUnit tests to dc_dmub_srv library Documentation/gpu: Add Display Core Unit Test documentation

Tales Aparecida (1):
drm/amd/display: Introduce KUnit tests for fixed31_32 library

 .../gpu/amdgpu/display/display-test.rst       |  88 ++
 Documentation/gpu/amdgpu/display/index.rst    |   1 +
 drivers/gpu/drm/amd/display/Kconfig           |  52 +
 drivers/gpu/drm/amd/display/Makefile          |   2 +-
 drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |   4 +
 .../dc/dml/dcn20/display_mode_vba_20.c        |   4 +
 .../dc/dml/dcn20/display_rq_dlg_calc_20.c     |   4 +
 drivers/gpu/drm/amd/display/tests/Makefile    |  18 +
 .../display/tests/dc/basics/fixpt31_32_test.c | 232 +++++
 .../amd/display/tests/dc/dc_dmub_srv_test.c   | 159 ++++
 .../tests/dc/dml/calcs/bw_fixed_test.c        | 323 +++++++
 .../tests/dc/dml/dcn20/dcn20_fpu_test.c       | 561 +++++++++++
 .../dc/dml/dcn20/display_mode_vba_20_test.c   | 888 ++++++++++++++++++
 .../dml/dcn20/display_rq_dlg_calc_20_test.c   | 124 +++
 .../tests/dc/dml/display_mode_vba_test.c      | 741 +++++++++++++++
 15 files changed, 3200 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/gpu/amdgpu/display/display-test.rst
 create mode 100644 drivers/gpu/drm/amd/display/tests/Makefile
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/basics/fixpt31_32_test.c
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/calcs/bw_fixed_test.c
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_mode_vba_20_test.c
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/display_mode_vba_test.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/8 drm/amd/display: Introduce KUnit tests for fixed31_32 library

From: Tales Aparecida <[email protected]>

The fixed31_32 library performs a lot of the mathematical operations involving fixed-point arithmetic and the conversion of integers to fixed-point representation.

This unit tests intend to assure the proper functioning of the basic mathematical operations of fixed-point arithmetic, such as multiplication, conversion from fractional to fixed-point number, and more. Use kunit_tool to run:

$ ./tools/testing/kunit/kunit.py run --arch=x86_64 \
	--kunitconfig=drivers/gpu/drm/amd/display/tests/
---
 drivers/gpu/drm/amd/display/Kconfig           |  13 +
 drivers/gpu/drm/amd/display/Makefile          |   2 +-
 drivers/gpu/drm/amd/display/tests/Makefile    |  12 +
 .../display/tests/dc/basics/fixpt31_32_test.c | 232 ++++++++++++++++++
 4 files changed, 258 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/amd/display/tests/Makefile
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/basics/fixpt31_32_test.c
drivers/gpu/drm/amd/display/Kconfig +13 -0
index 901d1961b739..e35eef026097 100644
@@ -51,4 +51,17 @@ config DRM_AMD_SECURE_DISPLAY
 	  This option enables the calculation of crc of specific region via
 	  debugfs. Cooperate with specific DMCU FW.
 
+config AMD_DC_BASICS_KUNIT_TEST
+	bool "Enable KUnit tests for the 'basics' sub-component of DAL" if !KUNIT_ALL_TESTS
+	depends on DRM_AMD_DC && KUNIT
+	default KUNIT_ALL_TESTS
+	help
+		Enables unit tests for the Display Core. Only useful for kernel
+		devs running KUnit.
+
+		For more information on KUnit and unit tests in general please refer to
+		the KUnit documentation in Documentation/dev-tools/kunit/.
+
+		If unsure, say N.
+
 endmenu
drivers/gpu/drm/amd/display/Makefile +1 -1
index 92a5c5efcf92..e732a0987d9d 100644
@@ -45,7 +45,7 @@ subdir-ccflags-y += -I$(FULL_AMD_DISPLAY_PATH)/modules/hdcp
 #TODO: remove when Timing Sync feature is complete
 subdir-ccflags-y += -DBUILD_FEATURE_TIMING_SYNC=0
 
-DAL_LIBS = amdgpu_dm dc	modules/freesync modules/color modules/info_packet modules/power dmub/src
+DAL_LIBS = amdgpu_dm dc	modules/freesync modules/color modules/info_packet modules/power dmub/src tests
 
 DAL_LIBS += modules/hdcp
 
drivers/gpu/drm/amd/display/tests/Makefile new file +12 -0
new file mode 100644
index 000000000000..ef16497318e8
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: MIT
+#
+# Makefile for the KUnit Tests for DC
+#
+
+ifdef CONFIG_AMD_DC_BASICS_KUNIT_TEST
+	DC_TESTS += dc/basics/fixpt31_32_test.o
+endif
+
+AMD_DAL_DC_TESTS = $(addprefix $(AMDDALPATH)/tests/,$(DC_TESTS))
+
+AMD_DISPLAY_FILES += $(AMD_DAL_DC_TESTS)
drivers/gpu/drm/amd/display/tests/dc/basics/fixpt31_32_test.c new file +232 -0

232 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

PATCH v4 2/8 drm/amd/display: Introduce KUnit tests to the bw_fixed library

In reply to Rodrigo Siqueira

From: Maíra Canal <[email protected]>

KUnit unifies the test structure and provides helper tools that simplify the development of tests. Basic use case allows running tests as regular processes, which makes easier to run unit tests on a development machine and to integrate the tests in a CI system.

This commit introduces a unit test to the bw_fixed library, which performs a lot of the mathematical operations involving fixed-point arithmetic and the conversion of integers to fixed-point representation inside the Display Mode Library.

As fixed-point representation is the base foundation of the DML calcs operations, this unit tests intend to assure the proper functioning of the basic mathematical operations of fixed-point arithmetic, such as multiplication, conversion from fractional to fixed-point number, and more. You can run it with: ./tools/testing/kunit/kunit.py run \

	--arch=x86_64 \
	--kunitconfig=drivers/gpu/drm/amd/display/tests/
---
 drivers/gpu/drm/amd/display/Kconfig           |  13 +
 .../tests/dc/dml/calcs/bw_fixed_test.c        | 323 ++++++++++++++++++
 2 files changed, 336 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/calcs/bw_fixed_test.c
drivers/gpu/drm/amd/display/Kconfig +13 -0
index e35eef026097..d54036dcac78 100644
@@ -51,6 +51,19 @@ config DRM_AMD_SECURE_DISPLAY
 	  This option enables the calculation of crc of specific region via
 	  debugfs. Cooperate with specific DMCU FW.
 
+config DCE_KUNIT_TEST
+	bool "Run all KUnit tests for DCE" if !KUNIT_ALL_TESTS
+	depends on DRM_AMD_DC && KUNIT
+	default KUNIT_ALL_TESTS
+	help
+		Enables unit tests for the Display Controller Engine. Only useful for kernel
+		devs running KUnit.
+
+		For more information on KUnit and unit tests in general please refer to
+		the KUnit documentation in Documentation/dev-tools/kunit/.
+
+		If unsure, say N.
+
 config AMD_DC_BASICS_KUNIT_TEST
 	bool "Enable KUnit tests for the 'basics' sub-component of DAL" if !KUNIT_ALL_TESTS
 	depends on DRM_AMD_DC && KUNIT
drivers/gpu/drm/amd/display/tests/dc/dml/calcs/bw_fixed_test.c new file +323 -0

323 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

PATCH v4 3/8 drm/amd/display: Introduce KUnit tests to display_rq_dlg_calc_20

In reply to Rodrigo Siqueira

From: Isabella Basso <[email protected]>

This adds tests to the bit encoding format verification functions on the file. They're meant to be simpler so as to provide a proof of concept on testing DML code.

---
 drivers/gpu/drm/amd/display/Kconfig           |  13 ++
 .../dc/dml/dcn20/display_rq_dlg_calc_20.c     |   4 +
 .../dml/dcn20/display_rq_dlg_calc_20_test.c   | 124 ++++++++++++++++++
 3 files changed, 141 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c
drivers/gpu/drm/amd/display/Kconfig +13 -0
index d54036dcac78..877ba3be6aed 100644
@@ -64,6 +64,19 @@ config DCE_KUNIT_TEST
 
 		If unsure, say N.
 
+config DML_KUNIT_TEST
+	bool "Run all KUnit tests for DML" if !KUNIT_ALL_TESTS
+	depends on DRM_AMD_DC_DCN && KUNIT
+	default KUNIT_ALL_TESTS
+	help
+		Enables unit tests for the Display Controller Engine. Only useful for kernel
+		devs running KUnit.
+
+		For more information on KUnit and unit tests in general please refer to
+		the KUnit documentation in Documentation/dev-tools/kunit/.
+
+		If unsure, say N.
+
 config AMD_DC_BASICS_KUNIT_TEST
 	bool "Enable KUnit tests for the 'basics' sub-component of DAL" if !KUNIT_ALL_TESTS
 	depends on DRM_AMD_DC && KUNIT
drivers/gpu/drm/amd/display/dc/dml/dcn20/display_rq_dlg_calc_20.c +4 -0
index 548cdef8a8ad..ab688c9ba0d1 100644
@@ -1683,3 +1683,7 @@ static void calculate_ttu_cursor(struct display_mode_lib *mode_lib,
 		ASSERT(*refcyc_per_req_delivery_cur < dml_pow(2, 13));
 	}
 }
+
+#if IS_ENABLED(CONFIG_DML_KUNIT_TEST)
+#include "../../../tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c"
+#endif
drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
2.43.0
#4 lore raw

PATCH v4 4/8 drm/amd/display: Introduce KUnit tests to the display_mode_vba library

In reply to Rodrigo Siqueira

From: Maíra Canal <[email protected]>

The display_mode_vba library deals with hundreds of display parameters and sometimes does it in odd ways. The addition of unit tests intends to assure the quality of the code delivered by HW engineers and, also make it possible to refactor the code decreasing concerns about adding bugs to the codebase.

---
 drivers/gpu/drm/amd/display/tests/Makefile    |   5 +
 .../tests/dc/dml/display_mode_vba_test.c      | 741 ++++++++++++++++++
 2 files changed, 746 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/display_mode_vba_test.c
drivers/gpu/drm/amd/display/tests/Makefile +5 -0
index ef16497318e8..cc1e9edd38c3 100644
@@ -7,6 +7,11 @@ ifdef CONFIG_AMD_DC_BASICS_KUNIT_TEST
 	DC_TESTS += dc/basics/fixpt31_32_test.o
 endif
 
+ifdef CONFIG_DML_KUNIT_TEST
+	CFLAGS_$(AMDDALPATH)/tests/dc/dml/display_mode_vba_test.o := $(dml_ccflags)
+	DC_TESTS += dc/dml/display_mode_vba_test.o
+endif
+
 AMD_DAL_DC_TESTS = $(addprefix $(AMDDALPATH)/tests/,$(DC_TESTS))
 
 AMD_DISPLAY_FILES += $(AMD_DAL_DC_TESTS)
drivers/gpu/drm/amd/display/tests/dc/dml/display_mode_vba_test.c new file +741 -0

741 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

PATCH v4 5/8 drm/amd/display: Introduce KUnit to dcn20/display_mode_vba_20 library

In reply to Rodrigo Siqueira

From: Maíra Canal <[email protected]>

The display_mode_vba_20 deals with hundreds of display parameters for the DCN20 and sometimes does it in odd ways. The addition of unit tests intends to assure the quality of the code delivered by HW engineers and, also make it possible to refactor the code decreasing concerns about adding bugs to the codebase.

---
 .../dc/dml/dcn20/display_mode_vba_20.c        |   4 +
 .../dc/dml/dcn20/display_mode_vba_20_test.c   | 888 ++++++++++++++++++
 2 files changed, 892 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_mode_vba_20_test.c
drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c +4 -0
index 7bf4bb7ad044..29ef47028630 100644
@@ -5116,3 +5116,7 @@ void dml20_ModeSupportAndSystemConfigurationFull(struct display_mode_lib *mode_l
 				locals->OutputBppPerState[mode_lib->vba.VoltageLevel][k];
 	}
 }
+
+#if IS_ENABLED(CONFIG_DML_KUNIT_TEST)
+#include "../../tests/dc/dml/dcn20/display_mode_vba_20_test.c"
+#endif
drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_mode_vba_20_test.c new file +888 -0

888 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw

PATCH v4 6/8 drm/amd/display: Introduce KUnit tests for dcn20_fpu

In reply to Rodrigo Siqueira

From: Magali Lemes <[email protected]>

This commit adds unit tests to the functions dcn20_cap_soc_clocks and dcn21_update_bw_bounding_box from dcn20/dcn20_fpu.

---
 drivers/gpu/drm/amd/display/tests/Makefile    |   3 +-
 .../tests/dc/dml/dcn20/dcn20_fpu_test.c       | 561 ++++++++++++++++++
 2 files changed, 563 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c
drivers/gpu/drm/amd/display/tests/Makefile +2 -1
index cc1e9edd38c3..a34677808e48 100644
@@ -9,7 +9,8 @@ endif
 
 ifdef CONFIG_DML_KUNIT_TEST
 	CFLAGS_$(AMDDALPATH)/tests/dc/dml/display_mode_vba_test.o := $(dml_ccflags)
-	DC_TESTS += dc/dml/display_mode_vba_test.o
+	CFLAGS_$(AMDDALPATH)/tests/dc/dml/dcn20/dcn20_fpu_test.o := $(dml_ccflags)
+	DC_TESTS += dc/dml/display_mode_vba_test.o dc/dml/dcn20/dcn20_fpu_test.o
 endif
 
 AMD_DAL_DC_TESTS = $(addprefix $(AMDDALPATH)/tests/,$(DC_TESTS))
drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c new file +561 -0

561 lines not on this page · raw message

Signature · 1 line
2.43.0
#7 lore raw

PATCH v4 7/8 drm/amd/display: Introduce KUnit tests to dc_dmub_srv library

In reply to Rodrigo Siqueira

From: Maíra Canal <[email protected]>

Add a unit test to the SubVP feature in order to avoid possible regressions and ensure code robustness. In particular, this new test validates the expected parameters when using 4k144 and 4k240 displays.

---
 drivers/gpu/drm/amd/display/Kconfig           |  13 ++
 drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |   4 +
 .../amd/display/tests/dc/dc_dmub_srv_test.c   | 159 ++++++++++++++++++
 3 files changed, 176 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c
drivers/gpu/drm/amd/display/Kconfig +13 -0
index 877ba3be6aed..9724162d7509 100644
@@ -90,4 +90,17 @@ config AMD_DC_BASICS_KUNIT_TEST
 
 		If unsure, say N.
 
+config AMD_DC_KUNIT_TEST
+	bool "Enable KUnit tests for the 'utils' sub-component of DAL" if !KUNIT_ALL_TESTS
+	depends on DRM_AMD_DC && KUNIT
+	default KUNIT_ALL_TESTS
+	help
+		Enables unit tests for the basics folder of Display Core. Only useful for
+		kernel devs running KUnit.
+
+		For more information on KUnit and unit tests in general please refer to
+		the KUnit documentation in Documentation/dev-tools/kunit/.
+
+		If unsure, say N.
+
 endmenu
drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c +4 -0
index 2b79a0e5638e..181d1bcabb0f 100644
@@ -1415,3 +1415,7 @@ bool dc_wake_and_execute_gpint(const struct dc_context *ctx, enum dmub_gpint_com
 
 	return result;
 }
+
+#if IS_ENABLED(CONFIG_AMD_DC_KUNIT_TEST)
+#include "../tests/dc/dc_dmub_srv_test.c"
+#endif
drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c new file +159 -0

159 lines not on this page · raw message

Signature · 1 line
2.43.0
#8 lore raw

PATCH v4 8/8 Documentation/gpu: Add Display Core Unit Test documentation

In reply to Rodrigo Siqueira

From: Maíra Canal <[email protected]>

Explain how to run the KUnit tests present in the AMDGPU's Display Core and clarify which architectures and tools can be used to run the tests. Moreover, explains how to add new tests to the existing tests.

---
 .../gpu/amdgpu/display/display-test.rst       | 88 +++++++++++++++++++
 Documentation/gpu/amdgpu/display/index.rst    |  1 +
 2 files changed, 89 insertions(+)
 create mode 100644 Documentation/gpu/amdgpu/display/display-test.rst
Documentation/gpu/amdgpu/display/display-test.rst new file +88 -0
new file mode 100644
index 000000000000..a8c136ce87b7
@@ -0,0 +1,88 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+========================
+Display Core Unit Tests
+========================
+
+Display core provides a set of unit tests, currently focused on the Display Mode
+Library. The unit tests use KUnit (Kernel Unit Testing Framework), a common
+framework for unit tests within the Linux Kernel.
+
+This section covers the specifics of the tests for the AMDGPU driver. 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/amd/display/tests/dc/.kunitconfig``. This configuration file
+can be used to run the kunit_tool, a Python script (``tools/testing/kunit/kunit.py``)
+used to configure, build, exec, parse and run tests.
+
+.. code-block:: bash
+
+	$ ./tools/testing/kunit/kunit.py run --arch=x86_64 \
+	    --kunitconfig=drivers/gpu/drm/amd/display/tests
+
+Currently, the Display Core Unit Tests are only supported on x86_64.
+
+Moreover, the tests can also be run on real hardware or in other emulation
+environments. To include the Display Core Unit Tests on a deployable kernel,
+you might add the following config options to your ``.config``:
+
+.. code-block:: none
+
+	CONFIG_KUNIT=y
+	CONFIG_AMDGPU=m
+	CONFIG_AMD_DC_BASICS_KUNIT_TEST=y
+	CONFIG_AMD_DC_KUNIT_TEST=y
+	CONFIG_DCE_KUNIT_TEST=y
+	CONFIG_DML_KUNIT_TEST=y
+
+Once the kernel is built and installed, you can load the ``amdgpu`` module
+to run all tests available.
+
+Also, the tests can be added to the kernel as built-in modules, by adding the
+following config options to your ``.config``:
+
+.. code-block:: none
+
+	CONFIG_KUNIT=y
+	CONFIG_AMDGPU=y
+	CONFIG_AMD_DC_BASICS_KUNIT_TEST=y
+	CONFIG_AMD_DC_KUNIT_TEST=y
+	CONFIG_DCE_KUNIT_TEST=y
+	CONFIG_DML_KUNIT_TEST=y
+
+In order to run specific tests, you can check the filter options from KUnit on
+Documentation/dev-tools/kunit/kunit-tool.rst.
+
+How to add new tests?
+=====================
+
+Tests covering different parts of the Display Core are always welcomed. Adding
+a new test is a simple procedure, that consists in creating a unit test file
+and adding the following guard to the end of the tested file when you are
+testing static functions:
+
+.. code-block:: c
+
+	#ifdef CONFIG_MY_KUNIT_TEST
+	#include "my_kunit_test.c"
+	#endif
+
+If you are not testing static functions, you should use the Makefile placed on
+``display/tests``. In order to add a test to the Makefile, you can just add
+the following entry to the Makefile:
+
+.. code-block:: make
+
+	ifdef CONFIG_MY_KUNIT_TEST
+		DC_TESTS += my_kunit_test.o
+	endif
+
+The ``display/tests`` folder replicates the folder hierarchy of the ``display``
+folder, so this must be considered while adding new tests.
+
+More information on how to write unit tests with the KUnit API can be provided
+on Documentation/dev-tools/kunit/api/test.rst.
Documentation/gpu/amdgpu/display/index.rst +1 -0
index f8a4f53d70d8..9b13f0f3524f 100644
@@ -29,4 +29,5 @@ table of content:
    dc-debug.rst
    dcn-overview.rst
    mpo-overview.rst
+   display-test.rst
    dc-glossary.rst
Signature · 1 line
2.43.0
maintainer
#9 lore raw
In reply to Rodrigo Siqueira

That we include so many C files with relative paths seems to be odd.

Apart from that looks good to me.

Christian.

Am 26.01.24 um 16:48 schrieb Rodrigo Siqueira:

Quoted 107 lines

In 2022, we got a great patchset from a GSoC project introducing unit tests to the amdgpu display. Since version 3, this effort was put on hold, and now I'm attempting to revive it. I'll add part of the original cover letter at the bottom of this cover letter, but you can read all the original messages at:

https://lore.kernel.org/amd-gfx/[email protected]/

Anyway, this new version changes are:
- Rebase and adjust conflicts.
- Rewrite part of the dc_dmub_srv_test to represent a real scenario that simulates some parameter configuration for using 4k144 and 4k240 displays.

Thanks
Siqueira

Original cover letter

Hello,

This series is version 3 of the introduction of unit testing to the AMDPGU driver [1].

Our main goal is to bring unit testing to the AMD display driver; in particular, we'll focus on the Display Mode Library (DML) for DCN2.0, DMUB, and some of the DCE functions. This implementation intends to help developers to recognize bugs before they are merged into the mainline and also makes it possible for future code refactors of the AMD display driver.

For the implementation of the tests, we decided to go with the Kernel Unit Testing Framework (KUnit). KUnit makes it possible to run test suites on kernel boot or load the tests as a module. It reports all test case results through a TAP (Test Anything Protocol) in the kernel log. Moreover, KUnit unifies the test structure and provides tools to simplify the testing for developers and CI systems.

In regards to CI pipelines, we believe kunit_tool [2] provides ease of use, but we are also working on integrating KUnit into IGT [3].

Since the second version, we've chosen a mix of approaches to integrate KUnit tests into amdgpu:
1. Tests that use static functions are included through guards [4].
2. Tests without static functions are included through a Makefile.

We understand that testing static functions is not ideal, but taking into consideration that this driver relies heavily on static functions with complex behavior which would benefit from unit testing, otherwise, black-box tested through public functions with dozens of arguments and sometimes high cyclomatic complexity.

The first seven patches represent what we intend to do for the rest of the DML modules: systematic testing of the DML functions, especially mathematically complicated functions. Also, it shows how simple it is to add new tests to the DML.

Among the tests, we highlight the dcn20_fpu_test, which, had it existed then, could catch the defects introduced to dcn20_fpu.c by 8861c27a6c [5] later fixed by 9ad5d02c2a [6].

In this series, there's also an example of how unit tests can help avoid regressions and keep track of changes in behavior.

[..]

Isabella Basso (1):
drm/amd/display: Introduce KUnit tests to display_rq_dlg_calc_20

Magali Lemes (1):
drm/amd/display: Introduce KUnit tests for dcn20_fpu

Maíra Canal (5):
drm/amd/display: Introduce KUnit tests to the bw_fixed library drm/amd/display: Introduce KUnit tests to the display_mode_vba library drm/amd/display: Introduce KUnit to dcn20/display_mode_vba_20 library drm/amd/display: Introduce KUnit tests to dc_dmub_srv library Documentation/gpu: Add Display Core Unit Test documentation

Tales Aparecida (1):
drm/amd/display: Introduce KUnit tests for fixed31_32 library

  .../gpu/amdgpu/display/display-test.rst       |  88 ++
  Documentation/gpu/amdgpu/display/index.rst    |   1 +
  drivers/gpu/drm/amd/display/Kconfig           |  52 +
  drivers/gpu/drm/amd/display/Makefile          |   2 +-
  drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |   4 +
  .../dc/dml/dcn20/display_mode_vba_20.c        |   4 +
  .../dc/dml/dcn20/display_rq_dlg_calc_20.c     |   4 +
  drivers/gpu/drm/amd/display/tests/Makefile    |  18 +
  .../display/tests/dc/basics/fixpt31_32_test.c | 232 +++++
  .../amd/display/tests/dc/dc_dmub_srv_test.c   | 159 ++++
  .../tests/dc/dml/calcs/bw_fixed_test.c        | 323 +++++++
  .../tests/dc/dml/dcn20/dcn20_fpu_test.c       | 561 +++++++++++
  .../dc/dml/dcn20/display_mode_vba_20_test.c   | 888 ++++++++++++++++++
  .../dml/dcn20/display_rq_dlg_calc_20_test.c   | 124 +++
  .../tests/dc/dml/display_mode_vba_test.c      | 741 +++++++++++++++
  15 files changed, 3200 insertions(+), 1 deletion(-)

create mode 100644 Documentation/gpu/amdgpu/display/display-test.rst
create mode 100644 drivers/gpu/drm/amd/display/tests/Makefile
create mode 100644 drivers/gpu/drm/amd/display/tests/dc/basics/fixpt31_32_test.c create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/calcs/bw_fixed_test.c create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_mode_vba_20_test.c create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/display_mode_vba_test.c