Skip to contentSkip to conversation

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

PATCH In review Rodrigo Siqueira 4 participants 17 messages Feb 22, 2024 – Apr 21, 2024

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v5 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]/

Changes since V3:
- 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.

Changes since v4:
- Rebase.
- Change the folder organization to better align with the display code.
- Fix the wrong CONFIG used in the FPU code.
- Drop unstable tests.

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 +
 .../drm/amd/display/test/kunit/.kunitconfig   |   9 +
 .../gpu/drm/amd/display/test/kunit/Makefile   |  18 +
 .../test/kunit/dc/basics/fixpt31_32_test.c    | 232 ++++++
 .../display/test/kunit/dc/dc_dmub_srv_test.c  | 159 ++++
 .../test/kunit/dc/dml/calcs/bw_fixed_test.c   | 323 ++++++++
 .../test/kunit/dc/dml/dcn20/dcn20_fpu_test.c  | 561 +++++++++++++
 .../dc/dml/dcn20/display_mode_vba_20_test.c   | 780 ++++++++++++++++++
 .../dml/dcn20/display_rq_dlg_calc_20_test.c   | 124 +++
 .../test/kunit/dc/dml/display_mode_vba_test.c | 741 +++++++++++++++++
 16 files changed, 3101 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/gpu/amdgpu/display/display-test.rst
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/.kunitconfig
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/Makefile
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/dc/basics/fixpt31_32_test.c
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/dc/dc_dmub_srv_test.c
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/dc/dml/calcs/bw_fixed_test.c
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/dc/dml/dcn20/dcn20_fpu_test.c
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/dc/dml/dcn20/display_mode_vba_20_test.c
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/dc/dml/dcn20/display_rq_dlg_calc_20_test.c
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/dc/dml/display_mode_vba_test.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v5 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/test/kunit
---
 drivers/gpu/drm/amd/display/Kconfig           |  13 +
 drivers/gpu/drm/amd/display/Makefile          |   2 +-
 .../drm/amd/display/test/kunit/.kunitconfig   |   6 +
 .../gpu/drm/amd/display/test/kunit/Makefile   |  12 +
 .../test/kunit/dc/basics/fixpt31_32_test.c    | 232 ++++++++++++++++++
 5 files changed, 264 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/.kunitconfig
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/Makefile
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/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..5e11ee266028 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 test/kunit
 
 DAL_LIBS += modules/hdcp
 
drivers/gpu/drm/amd/display/test/kunit/.kunitconfig new file +6 -0
new file mode 100644
index 000000000000..862e6506ddd3
@@ -0,0 +1,6 @@
+CONFIG_KUNIT=y
+CONFIG_PCI=y
+CONFIG_DRM=y
+CONFIG_DRM_AMDGPU=y
+CONFIG_DRM_AMD_DC=y
+CONFIG_AMD_DC_BASICS_KUNIT_TEST=y
drivers/gpu/drm/amd/display/test/kunit/Makefile new file +12 -0
new file mode 100644
index 000000000000..84b22ecb98df
@@ -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)/test/kunit/,$(DC_TESTS))
+
+AMD_DISPLAY_FILES += $(AMD_DAL_DC_TESTS)
drivers/gpu/drm/amd/display/test/kunit/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 v5 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/test/kunit
---
 drivers/gpu/drm/amd/display/Kconfig           |  13 +
 .../drm/amd/display/test/kunit/.kunitconfig   |   1 +
 .../test/kunit/dc/dml/calcs/bw_fixed_test.c   | 323 ++++++++++++++++++
 3 files changed, 337 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/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/test/kunit/.kunitconfig +1 -0
index 862e6506ddd3..7a58f75a8dfc 100644
@@ -4,3 +4,4 @@ CONFIG_DRM=y
 CONFIG_DRM_AMDGPU=y
 CONFIG_DRM_AMD_DC=y
 CONFIG_AMD_DC_BASICS_KUNIT_TEST=y
+CONFIG_DCE_KUNIT_TEST=y
drivers/gpu/drm/amd/display/test/kunit/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 v5 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.

Change since v4:
- Use DRM_AMD_DC_FP guard for FPU tests

---
 drivers/gpu/drm/amd/display/Kconfig           |  13 ++
 .../dc/dml/dcn20/display_rq_dlg_calc_20.c     |   4 +
 .../drm/amd/display/test/kunit/.kunitconfig   |   1 +
 .../dml/dcn20/display_rq_dlg_calc_20_test.c   | 124 ++++++++++++++++++
 4 files changed, 142 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/dc/dml/dcn20/display_rq_dlg_calc_20_test.c
drivers/gpu/drm/amd/display/Kconfig +13 -0
index d54036dcac78..ab52b135db85 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_FP && 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..45f75a7f84c7 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 "../../../test/kunit/dc/dml/dcn20/display_rq_dlg_calc_20_test.c"
+#endif
drivers/gpu/drm/amd/display/test/kunit/.kunitconfig +1 -0
index 7a58f75a8dfc..eb6f81601757 100644
@@ -5,3 +5,4 @@ CONFIG_DRM_AMDGPU=y
 CONFIG_DRM_AMD_DC=y
 CONFIG_AMD_DC_BASICS_KUNIT_TEST=y
 CONFIG_DCE_KUNIT_TEST=y
+CONFIG_DML_KUNIT_TEST=y
drivers/gpu/drm/amd/display/test/kunit/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 v5 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.

---
 .../gpu/drm/amd/display/test/kunit/Makefile   |   5 +
 .../test/kunit/dc/dml/display_mode_vba_test.c | 741 ++++++++++++++++++
 2 files changed, 746 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/dc/dml/display_mode_vba_test.c
drivers/gpu/drm/amd/display/test/kunit/Makefile +5 -0
index 84b22ecb98df..ec3883029052 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)/test/kunit/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)/test/kunit/,$(DC_TESTS))
 
 AMD_DISPLAY_FILES += $(AMD_DAL_DC_TESTS)
drivers/gpu/drm/amd/display/test/kunit/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 v5 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.

Change since v4:
- Drop some unstable tests

---
 .../dc/dml/dcn20/display_mode_vba_20.c        |   4 +
 .../dc/dml/dcn20/display_mode_vba_20_test.c   | 780 ++++++++++++++++++
 2 files changed, 784 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/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..aea6e29fd6e5 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 "../../test/kunit/dc/dml/dcn20/display_mode_vba_20_test.c"
+#endif
drivers/gpu/drm/amd/display/test/kunit/dc/dml/dcn20/display_mode_vba_20_test.c new file +780 -0

780 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw

PATCH v5 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.

---
 .../gpu/drm/amd/display/test/kunit/Makefile   |   3 +-
 .../test/kunit/dc/dml/dcn20/dcn20_fpu_test.c  | 561 ++++++++++++++++++
 2 files changed, 563 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/dc/dml/dcn20/dcn20_fpu_test.c
drivers/gpu/drm/amd/display/test/kunit/Makefile +2 -1
index ec3883029052..a6ad449f9885 100644
@@ -9,7 +9,8 @@ endif
 
 ifdef CONFIG_DML_KUNIT_TEST
 	CFLAGS_$(AMDDALPATH)/test/kunit/dc/dml/display_mode_vba_test.o := $(dml_ccflags)
-	DC_TESTS += dc/dml/display_mode_vba_test.o
+	CFLAGS_$(AMDDALPATH)/test/kunit/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)/test/kunit/,$(DC_TESTS))
drivers/gpu/drm/amd/display/test/kunit/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 v5 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 +
 .../drm/amd/display/test/kunit/.kunitconfig   |   1 +
 .../display/test/kunit/dc/dc_dmub_srv_test.c  | 159 ++++++++++++++++++
 4 files changed, 177 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/test/kunit/dc/dc_dmub_srv_test.c
drivers/gpu/drm/amd/display/Kconfig +13 -0
index ab52b135db85..11b0e54262f3 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 6083b1dcf050..7aafdfeac60e 100644
@@ -1438,3 +1438,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 "../test/kunit/dc/dc_dmub_srv_test.c"
+#endif
drivers/gpu/drm/amd/display/test/kunit/.kunitconfig +1 -0
index eb6f81601757..4c5861ad58bd 100644
@@ -4,5 +4,6 @@ CONFIG_DRM=y
 CONFIG_DRM_AMDGPU=y
 CONFIG_DRM_AMD_DC=y
 CONFIG_AMD_DC_BASICS_KUNIT_TEST=y
+CONFIG_AMD_DC_KUNIT_TEST=y
 CONFIG_DCE_KUNIT_TEST=y
 CONFIG_DML_KUNIT_TEST=y
drivers/gpu/drm/amd/display/test/kunit/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

Re: [PATCH v5 7/8] drm/amd/display: Introduce KUnit tests to dc_dmub_srv library

drivers/gpu/drm/amd/display/test/kunit/.kunitconfig CONFIG_DRM=y · line 9

Quoted 11 lines · Rodrigo Siqueira
drivers/gpu/drm/amd/display/test/kunit/.kunitconfig +1 -0
index eb6f81601757..4c5861ad58bd 100644
@@ -4,5 +4,6 @@ CONFIG_DRM=y
 CONFIG_DRM_AMDGPU=y
 CONFIG_DRM_AMD_DC=y
 CONFIG_AMD_DC_BASICS_KUNIT_TEST=y
+CONFIG_AMD_DC_KUNIT_TEST=y
 CONFIG_DCE_KUNIT_TEST=y
 CONFIG_DML_KUNIT_TEST=y

A bit random patch to comment on, but this hunk demonstrates the point:

Should all the configs have DRM_AMD_ prefix to put them in a "namespace"?

BR,
Jani.

Signature · 1 line
Jani Nikula, Intel
#9 lore raw

Re: [PATCH v5 7/8] drm/amd/display: Introduce KUnit tests to dc_dmub_srv library

Quoted 15 lines · Jani Nikula

drivers/gpu/drm/amd/display/test/kunit/.kunitconfig CONFIG_DRM=y · line 9

Quoted 11 lines · Rodrigo Siqueira
drivers/gpu/drm/amd/display/test/kunit/.kunitconfig +1 -0
index eb6f81601757..4c5861ad58bd 100644
@@ -4,5 +4,6 @@ CONFIG_DRM=y
  CONFIG_DRM_AMDGPU=y
  CONFIG_DRM_AMD_DC=y
  CONFIG_AMD_DC_BASICS_KUNIT_TEST=y
+CONFIG_AMD_DC_KUNIT_TEST=y
  CONFIG_DCE_KUNIT_TEST=y
  CONFIG_DML_KUNIT_TEST=y

A bit random patch to comment on, but this hunk demonstrates the point:

Quoted 3 lines

Should all the configs have DRM_AMD_ prefix to put them in a "namespace"?

You are right! I'll fix this in the next version.

Thanks
Siqueira

Quoted 5 lines

BR,
Jani.

#10 lore raw

PATCH v5 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 f0c342e00a39..e5895e658943 100644
@@ -92,5 +92,6 @@ table of content:
    dcn-blocks.rst
    mpo-overview.rst
    dc-debug.rst
+   display-test.rst
    display-contributing.rst
    dc-glossary.rst
Signature · 1 line
2.43.0
#11 lore raw

cover drm/amd/display: Update Display Core unit tests

In reply to Rodrigo Siqueira

Hey, I'm interested in contributing for display tests from this patch-set. I've noticed potential updates related to both refactoring and optimization. This patch-set applies these suggestions.

[WHY]

1. The single test suite in the file
test/kunit/dc/dml/calcs/bw_fixed_test.c, which tests some static functions defined in the dc/basics/bpw_fixed.c, is not being run. According to kunit documentation
(https://www.kernel.org/doc/html/latest/dev-tools/kunit/usage.html#testing-static-functions),
there are two strategies for testing
static functions, but none of them seem to be configured. Additionally, it appears that the Config DCE_KUNIT_TEST should be associated with this test, since it was introduced in the same patch of the test
(https://lore.kernel.org/amd-gfx/[email protected]/),
but it is not being used anywhere in the display driver.

2. Also, according to the documentation, "The display/tests folder replicates
the folder hierarchy of the display folder". However, note that this test file (test/kunit/dc/dml/calcs/bw_fixed_test.c) has a conflicting path with the file that is being tested (dc/basics/bw_fixed.c).

3. Config Names and Helps are a bit misleading and don't follow a strict
pattern. For example, the config DML_KUNIT_TEST indicates that it is used to activate tests for the Display Core Engine, but instead activates tests for the Display Core Next. Also, note the different name patterns in DML_KUNIT_TEST and AMD_DC_BASICS_KUNIT_TEST.

4. The test suite dcn21_update_bw_bounding_box_test_suite configures an init
function that doesn't need to be executed before every test, but only once before the suite runs.

5. There are some not updated info in the Documentation, such as the
recommended command to run the tests:
$ ./tools/testing/kunit/kunit.py run --arch=x86_64 \
--kunitconfig=drivers/gpu/drm/amd/display/tests (it doesn't work since there is no .kunitconfig in drivers/gpu/drm/amd/display/tests)

[HOW]

1. Revise Config names and Help blocks.

2. Change the path of the test file bw_fixed_test from
test/kunit/dc/dml/calcs/bw_fixed_test.c to test/kunit/dc/basics/bw_fixed_test.c to make it consistent with the Documentation and the other display driver tests. Make this same test file run by importing it conditionally in the file dc/basics/bw_fixed_test.c.

3. Turn the test init function of the suite
dcn21_update_bw_bounding_box_test_suite into a suite init.

4. Update Documentation

Joao Paulo Pereira da Silva (4):
drm/amd/display: Refactor AMD display KUnit tests configs drm/amd/display/test: Fix kunit test that is not running drm/amd/display/test: Optimize kunit test suite

    dml_dcn20_fpu_dcn21_update_bw_bounding_box_test

Documentation/gpu: Update AMD Display Core Unit Test documentation

 .../gpu/amdgpu/display/display-test.rst       | 20 ++++++------
 drivers/gpu/drm/amd/display/Kconfig           | 31 ++++++-------------
 .../gpu/drm/amd/display/dc/basics/bw_fixed.c  |  3 ++
 drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |  2 +-
 .../dc/dml/dcn20/display_mode_vba_20.c        |  2 +-
 .../dc/dml/dcn20/display_rq_dlg_calc_20.c     |  2 +-
 .../drm/amd/display/test/kunit/.kunitconfig   |  7 ++---
 .../gpu/drm/amd/display/test/kunit/Makefile   |  4 +--
 .../dc/{dml/calcs => basics}/bw_fixed_test.c  |  0
 .../test/kunit/dc/dml/dcn20/dcn20_fpu_test.c  |  6 ++--
 10 files changed, 32 insertions(+), 45 deletions(-)
 rename drivers/gpu/drm/amd/display/test/kunit/dc/{dml/calcs => basics}/bw_fixed_test.c (100%)
Signature · 1 line
2.44.0
#12 lore raw

PATCH 1/4 drm/amd/display: Refactor AMD display KUnit tests configs

Configs in AMD display KUnit tests can be clarified. Remove unnecessary configs, rename configs to follow a pattern, and update config Help blocks.

---
 drivers/gpu/drm/amd/display/Kconfig           | 31 ++++++-------------
 drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |  2 +-
 .../dc/dml/dcn20/display_mode_vba_20.c        |  2 +-
 .../dc/dml/dcn20/display_rq_dlg_calc_20.c     |  2 +-
 .../drm/amd/display/test/kunit/.kunitconfig   |  7 ++---
 .../gpu/drm/amd/display/test/kunit/Makefile   |  4 +--
 6 files changed, 17 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/display/Kconfig +9 -22
index 11b0e54262f3..b2760adb3da9 100644
@@ -51,25 +51,25 @@ 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
+config DRM_AMD_DC_KUNIT_TEST
+	bool "Enable KUnit tests for the root of DC" 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.
+		Enables unit tests for files in the root of the Display Core directory.
+		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 DML_KUNIT_TEST
+config DRM_AMD_DC_DML_KUNIT_TEST
 	bool "Run all KUnit tests for DML" if !KUNIT_ALL_TESTS
 	depends on DRM_AMD_DC_FP && KUNIT
 	default KUNIT_ALL_TESTS
 	help
-		Enables unit tests for the Display Controller Engine. Only useful for kernel
+		Enables unit tests for the Display Controller Next. Only useful for kernel
 		devs running KUnit.
 
 		For more information on KUnit and unit tests in general please refer to
@@ -77,26 +77,13 @@ config DML_KUNIT_TEST
 
 		If unsure, say N.
 
-config AMD_DC_BASICS_KUNIT_TEST
+config DRM_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.
-
-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.
+		Enables unit tests for the basics folder of 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/.
drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c +1 -1
index 7aafdfeac60e..7efd4768b0d7 100644
@@ -1439,6 +1439,6 @@ 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)
+#if IS_ENABLED(CONFIG_DRM_AMD_DC_KUNIT_TEST)
 #include "../test/kunit/dc/dc_dmub_srv_test.c"
 #endif
drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c +1 -1
index aea6e29fd6e5..5c5be75c08e0 100644
@@ -5117,6 +5117,6 @@ void dml20_ModeSupportAndSystemConfigurationFull(struct display_mode_lib *mode_l
 	}
 }
 
-#if IS_ENABLED(CONFIG_DML_KUNIT_TEST)
+#if IS_ENABLED(CONFIG_DRM_AMD_DC_DML_KUNIT_TEST)
 #include "../../test/kunit/dc/dml/dcn20/display_mode_vba_20_test.c"
 #endif
drivers/gpu/drm/amd/display/dc/dml/dcn20/display_rq_dlg_calc_20.c +1 -1
index 45f75a7f84c7..aab34156e9ae 100644
@@ -1684,6 +1684,6 @@ static void calculate_ttu_cursor(struct display_mode_lib *mode_lib,
 	}
 }
 
-#if IS_ENABLED(CONFIG_DML_KUNIT_TEST)
+#if IS_ENABLED(CONFIG_DRM_AMD_DC_DML_KUNIT_TEST)
 #include "../../../test/kunit/dc/dml/dcn20/display_rq_dlg_calc_20_test.c"
 #endif
drivers/gpu/drm/amd/display/test/kunit/.kunitconfig +3 -4
index 4c5861ad58bd..1dede9da74d3 100644
@@ -3,7 +3,6 @@ CONFIG_PCI=y
 CONFIG_DRM=y
 CONFIG_DRM_AMDGPU=y
 CONFIG_DRM_AMD_DC=y
-CONFIG_AMD_DC_BASICS_KUNIT_TEST=y
-CONFIG_AMD_DC_KUNIT_TEST=y
-CONFIG_DCE_KUNIT_TEST=y
-CONFIG_DML_KUNIT_TEST=y
+CONFIG_DRM_AMD_DC_BASICS_KUNIT_TEST=y
+CONFIG_DRM_AMD_DC_KUNIT_TEST=y
+CONFIG_DRM_AMD_DC_DML_KUNIT_TEST=y
drivers/gpu/drm/amd/display/test/kunit/Makefile +2 -2
index a6ad449f9885..4eb08477d6dc 100644
@@ -3,11 +3,11 @@
 # Makefile for the KUnit Tests for DC
 #
 
-ifdef CONFIG_AMD_DC_BASICS_KUNIT_TEST
+ifdef CONFIG_DRM_AMD_DC_BASICS_KUNIT_TEST
 	DC_TESTS += dc/basics/fixpt31_32_test.o
 endif
 
-ifdef CONFIG_DML_KUNIT_TEST
+ifdef CONFIG_DRM_AMD_DC_DML_KUNIT_TEST
 	CFLAGS_$(AMDDALPATH)/test/kunit/dc/dml/display_mode_vba_test.o := $(dml_ccflags)
 	CFLAGS_$(AMDDALPATH)/test/kunit/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
Signature · 1 line
2.44.0
#13 lore raw

PATCH 2/4 drm/amd/display/test: Fix kunit test that is not running

In reply to Joao Paulo Pereira da Silva

The KUnit test file test/kunit/dc/dml/calcs/bw_fixed_test.c does not have the correct path relative to the file being tested, dc/basics/bw_fixed.c. Also, it is neither compiling nor running.
Therefore, change the test file path and import it conditionally in the file dc/basics/bw_fixed.c to make it runnable.

---
 drivers/gpu/drm/amd/display/dc/basics/bw_fixed.c               | 3 +++
 .../test/kunit/dc/{dml/calcs => basics}/bw_fixed_test.c        | 0
 2 files changed, 3 insertions(+)
 rename drivers/gpu/drm/amd/display/test/kunit/dc/{dml/calcs => basics}/bw_fixed_test.c (100%)
drivers/gpu/drm/amd/display/dc/basics/bw_fixed.c +3 -0
index c8cb89e0d4d0..f18945fc84b9 100644
@@ -186,3 +186,6 @@ struct bw_fixed bw_mul(const struct bw_fixed arg1, const struct bw_fixed arg2)
 	return res;
 }
 
+#if IS_ENABLED(CONFIG_DRM_AMD_DC_BASICS_KUNIT_TEST)
+#include "../../test/kunit/dc/basics/bw_fixed_test.c"
+#endif
drivers/gpu/drm/amd/display/test/kunit/dc/basics/bw_fixed_test.c renamed from drivers/gpu/drm/amd/display/test/kunit/dc/dml/calcs/bw_fixed_test.c +0 -0
similarity index 100%
rename from drivers/gpu/drm/amd/display/test/kunit/dc/dml/calcs/bw_fixed_test.c
rename to drivers/gpu/drm/amd/display/test/kunit/dc/basics/bw_fixed_test.c
Signature · 1 line
2.44.0
#14 lore raw

PATCH 3/4 drm/amd/display/test: Optimize kunit test suite dml_dcn20_fpu_dcn21_update_bw_bounding_box_test

In reply to Joao Paulo Pereira da Silva

The KUnit init function of the suite dml_dcn20_fpu_dcn21_update_bw_bounding_box_test does not need to be executed before every test, but only once before the test suite, since it's just used to store backup copies of DCN global structures.
So, turn it into a suite_init.

---
 .../amd/display/test/kunit/dc/dml/dcn20/dcn20_fpu_test.c    | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/test/kunit/dc/dml/dcn20/dcn20_fpu_test.c +3 -3
index c51a0afbe518..b13a952e0227 100644
@@ -449,10 +449,10 @@ static struct _vcs_dpi_soc_bounding_box_st original_dcn2_1_soc;
 static struct _vcs_dpi_ip_params_st original_dcn2_1_ip;
 
 /**
- * dcn20_fpu_dcn21_update_bw_bounding_box_test_init - Store backup copies of DCN global structures
+ * dcn20_fpu_dcn21_update_bw_bounding_box_test_suite_init - Store backup copies of DCN global structures
  * @test: represents a running instance of a test.
  */
-static int dcn20_fpu_dcn21_update_bw_bounding_box_test_init(struct kunit *test)
+static int dcn20_fpu_dcn21_update_bw_bounding_box_test_suite_init(struct kunit_suite *suite)
 {
 	memcpy(&original_dcn2_1_soc, &dcn2_1_soc, sizeof(struct _vcs_dpi_soc_bounding_box_st));
 	memcpy(&original_dcn2_1_ip, &dcn2_1_ip, sizeof(struct _vcs_dpi_ip_params_st));
@@ -553,7 +553,7 @@ static struct kunit_case dcn20_fpu_dcn21_update_bw_bounding_box_test_cases[] = {
 
 static struct kunit_suite dcn21_update_bw_bounding_box_test_suite = {
 	.name = "dml_dcn20_fpu_dcn21_update_bw_bounding_box_test",
-	.init = dcn20_fpu_dcn21_update_bw_bounding_box_test_init,
+	.suite_init = dcn20_fpu_dcn21_update_bw_bounding_box_test_suite_init,
 	.exit = dcn20_fpu_dcn21_update_bw_bounding_box_test_exit,
 	.test_cases = dcn20_fpu_dcn21_update_bw_bounding_box_test_cases,
 };
Signature · 1 line
2.44.0
#15 lore raw

PATCH 4/4 Documentation/gpu: Update AMD Display Core Unit Test documentation

In reply to Joao Paulo Pereira da Silva

Display Core unit tests documentation is a bit outdated, therefore update it to follow current configuration.

---
 .../gpu/amdgpu/display/display-test.rst       | 20 +++++++++----------
 1 file changed, 9 insertions(+), 11 deletions(-)
Documentation/gpu/amdgpu/display/display-test.rst +9 -11
index a8c136ce87b7..a9fddf0adae7 100644
@@ -15,14 +15,14 @@ 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
+in ``drivers/gpu/drm/amd/display/test/kunit/.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
+    $ ./tools/testing/kunit/kunit.py run --arch=x86_64 \
+        --kunitconfig=drivers/gpu/drm/amd/display/test/kunit
 
 Currently, the Display Core Unit Tests are only supported on x86_64.
 
@@ -34,10 +34,9 @@ you might add the following config options to your ``.config``:
 
 	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
+	CONFIG_DRM_AMD_DC_BASICS_KUNIT_TEST=y
+	CONFIG_DRM_AMD_DC_KUNIT_TEST=y
+	CONFIG_DRM_AMD_DC_DML_KUNIT_TEST=y
 
 Once the kernel is built and installed, you can load the ``amdgpu`` module
 to run all tests available.
@@ -49,10 +48,9 @@ following config options to your ``.config``:
 
 	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
+	CONFIG_DRM_AMD_DC_BASICS_KUNIT_TEST=y
+	CONFIG_DRM_AMD_DC_KUNIT_TEST=y
+	CONFIG_DRM_AMD_DC_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.
Signature · 1 line
2.44.0
#16 lore raw

Re: [PATCH 0/4] drm/amd/display: Update Display Core unit tests

In reply to Joao Paulo Pereira da Silva

Em sáb., 20 de abr. de 2024 às 15:50, Joao Paulo Pereira da Silva <[email protected]> escreveu:

Quoted 5 lines

Hey, I'm interested in contributing for display tests from this patch-set. I've noticed potential updates related to both refactoring and optimization. This patch-set applies these suggestions.

Hi,

It's great to see this moving forward!

Overall the suggested changes make sense to me, and honestly I already don't remember the discussions that went behind some of them. The only thing that I would like to raise for you, and anyone else reviewing this, is that apparently
there are now stronger feeling towards the "preferred way"[1] to handle tests in static functions, using EXPORT_SYMBOL_IF_KUNIT (or EXPORT_SYMBOL_FOR_TESTS_ONLY in the case of DRM), so they might be more adequate to work on refactoring this code.

[1]: https://lore.kernel.org/all/5z66ivuhfrzrnuzt6lwjfm5fuozxlgqsco3qb5rfzyf6mil5ms@2svqtlcncyjj/

Kind regards,
Tales

Quoted 76 lines

[WHY]

1. The single test suite in the file
test/kunit/dc/dml/calcs/bw_fixed_test.c, which tests some static functions defined in the dc/basics/bpw_fixed.c, is not being run. According to kunit documentation
(https://www.kernel.org/doc/html/latest/dev-tools/kunit/usage.html#testing-static-functions),
there are two strategies for testing
static functions, but none of them seem to be configured. Additionally, it appears that the Config DCE_KUNIT_TEST should be associated with this test, since it was introduced in the same patch of the test
(https://lore.kernel.org/amd-gfx/[email protected]/),
but it is not being used anywhere in the display driver.

2. Also, according to the documentation, "The display/tests folder replicates
the folder hierarchy of the display folder". However, note that this test file (test/kunit/dc/dml/calcs/bw_fixed_test.c) has a conflicting path with the file that is being tested (dc/basics/bw_fixed.c).

3. Config Names and Helps are a bit misleading and don't follow a strict
pattern. For example, the config DML_KUNIT_TEST indicates that it is used to activate tests for the Display Core Engine, but instead activates tests for the Display Core Next. Also, note the different name patterns in DML_KUNIT_TEST and AMD_DC_BASICS_KUNIT_TEST.

4. The test suite dcn21_update_bw_bounding_box_test_suite configures an init
function that doesn't need to be executed before every test, but only once before the suite runs.

5. There are some not updated info in the Documentation, such as the
recommended command to run the tests:
$ ./tools/testing/kunit/kunit.py run --arch=x86_64 \
--kunitconfig=drivers/gpu/drm/amd/display/tests (it doesn't work since there is no .kunitconfig in drivers/gpu/drm/amd/display/tests)

[HOW]

1. Revise Config names and Help blocks.

2. Change the path of the test file bw_fixed_test from
test/kunit/dc/dml/calcs/bw_fixed_test.c to test/kunit/dc/basics/bw_fixed_test.c to make it consistent with the Documentation and the other display driver tests. Make this same test file run by importing it conditionally in the file dc/basics/bw_fixed_test.c.

3. Turn the test init function of the suite
dcn21_update_bw_bounding_box_test_suite into a suite init.

4. Update Documentation

Joao Paulo Pereira da Silva (4):
drm/amd/display: Refactor AMD display KUnit tests configs drm/amd/display/test: Fix kunit test that is not running drm/amd/display/test: Optimize kunit test suite

    dml_dcn20_fpu_dcn21_update_bw_bounding_box_test

Documentation/gpu: Update AMD Display Core Unit Test documentation

 .../gpu/amdgpu/display/display-test.rst       | 20 ++++++------
 drivers/gpu/drm/amd/display/Kconfig           | 31 ++++++-------------
 .../gpu/drm/amd/display/dc/basics/bw_fixed.c  |  3 ++
 drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |  2 +-
 .../dc/dml/dcn20/display_mode_vba_20.c        |  2 +-
 .../dc/dml/dcn20/display_rq_dlg_calc_20.c     |  2 +-
 .../drm/amd/display/test/kunit/.kunitconfig   |  7 ++---
 .../gpu/drm/amd/display/test/kunit/Makefile   |  4 +--
 .../dc/{dml/calcs => basics}/bw_fixed_test.c  |  0
 .../test/kunit/dc/dml/dcn20/dcn20_fpu_test.c  |  6 ++--
 10 files changed, 32 insertions(+), 45 deletions(-)
 rename drivers/gpu/drm/amd/display/test/kunit/dc/{dml/calcs => basics}/bw_fixed_test.c (100%)

--
2.44.0