Skip to contentSkip to conversation

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

PATCH In review Tales Aparecida 5 participants 21 messages Aug 11, 2022 – Aug 13, 2022

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

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

Hello,

This series is the consolidation of an RFC sent earlier this year [RFC] bringing unit testing to the AMDPGU driver. [gsoc]

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[kunit_tool] provides ease of use, but we are also working on integrating KUnit into IGT, for those already depending on the tool [igt_patch].

We've chosen what we believe to be the simplest approach to integrate KUnit tests into amdgpu [kunit_static]. We took 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. Further than that, this approach also helps beginners by avoiding the need to edit any Makefiles. Other approaches are available and we would gladly receive feedback on this matter.

The first three patches add KUnit represent what we intend to do on 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 [dcn20_bug] later fixed by 9ad5d02c2a [dcn20_fix].

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

Applying this series on top of the amd-staging-drm-next (2305916dca04) and running its tests will result in a failure in the dc_dmub_srv test, you can verify that with:

$ ./tools/testing/kunit/kunit.py run --arch=x86_64 \
		--kunitconfig=drivers/gpu/drm/amd/display/tests
```
...
[20:19:00] # Subtest: populate_subvp_cmd_drr_info_test
[20:19:00] # populate_subvp_cmd_drr_info_test: pass:0 fail:5 skip:0 total:5
[20:19:00] not ok 1 - populate_subvp_cmd_drr_info_test
[20:19:00] ======== [FAILED] populate_subvp_cmd_drr_info_test =========
[20:19:00] # Subtest: dc_dmub_srv
[20:19:00] 1..1
[20:19:00] # Totals: pass:0 fail:5 skip:0 total:5
[20:19:00] not ok 8 - dc_dmub_srv
[20:19:00] =================== [FAILED] dc_dmub_srv ===================
[20:19:00] ============================================================
[20:19:00] Testing complete. Passed: 59, Failed: 5, Crashed: 0, Skipped: 0, Errors: 0
```

Full output at: https://share.riseup.net/#SOggjANeLfbibdiHu2e_Ug

This is due to a known regression introduced by commit 5da7f4134357 ("drm/amd/display: fix 32 bit compilation errors in dc_dmub_srv.c") [dmub_bug], which resulted in the struct's members being zero. As an exercise, you can revert the offending patch and run the tests again, but that would still result in failure, albeit with a different output.

Full output when reverted: https://share.riseup.net/#EEBgtgXjAmof5vZ_qs7_sg

This regression is currently being worked on [dmub_fix], and this test-series will result in a success if applied alongside the fix-series, particularly the patches 1-13/32.

```
[17:48:14] Testing complete. Passed: 64, Failed: 0, Crashed: 0, Skipped: 0, Errors: 0
```

Full successful output: https://share.riseup.net/#migyN1Xpy3Gyq1it84HhNw

This series depends on a couple of Kunit patches already merged into torvalds/master, which themselves depends on older patches:

commit 61695f8c5d51 ("kunit: split resource API from test.h into new resource.h") commit 2852ca7fba9f ("panic: Taint kernel if tests are run")
commit cfc1d277891e ("module: Move all into module/")
commit cdebea6968fa ("kunit: split resource API impl from test.c into new resource.c") commit cae56e1740f5 ("kunit: rename print_subtest_{start,end} for clarity (s/subtest/suite)") commit 1cdba21db2ca ("kunit: add ability to specify suite-level init and exit functions") commit c272612cb4a2 ("kunit: Taint the kernel when KUnit tests are run") commit 3d6e44623841 ("kunit: unify module and builtin suite definitions") commit a02353f49162 ("kunit: bail out of test filtering logic quicker if OOM") commit 1b11063d32d7 ("kunit: fix executor OOM error handling logic on non-UML") commit e5857d396f35 ("kunit: flatten kunit_suite*** to kunit_suite** in .kunit_test_suites") commit 94681e289bf5 ("kunit: executor: Fix a memory leak on failure in kunit_filter_tests")

You can get a for branch ready for compilation at
https://gitlab.freedesktop.org/isinyaaa/linux/-/tags/introduce-kunit-for-amd-v1

Thanks in advance for your time taking a look and sending any feedback!

Best regards,
Isabella Basso, Magali Lemes, Maíra Canal, and Tales Aparecida

[RFC] https://lore.kernel.org/amd-gfx/[email protected]/
[gsoc] https://summerofcode.withgoogle.com/programs/2022/organizations/xorg-foundation
[kunit_tool] https://www.kernel.org/doc/html/latest/dev-tools/kunit/kunit-tool.html
[igt_patch] https://lists.freedesktop.org/archives/igt-dev/2022-June/042895.html
[kunit_static] https://docs.kernel.org/dev-tools/kunit/usage.html#testing-static-functions
[dcn20_bug] https://lore.kernel.org/amd-gfx/[email protected]/
[dcn20_fix] https://lore.kernel.org/amd-gfx/[email protected]/
[dmub_bug] https://lore.kernel.org/amd-gfx/[email protected]/
[dmub_fix] https://lore.kernel.org/amd-gfx/[email protected]/T/

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       |  73 ++
 Documentation/gpu/amdgpu/display/index.rst    |   1 +
 drivers/gpu/drm/amd/display/Kconfig           |  25 +
 .../drm/amd/display/dc/basics/fixpt31_32.c    |   5 +
 drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |   4 +
 .../drm/amd/display/dc/dml/calcs/bw_fixed.c   |   3 +
 .../drm/amd/display/dc/dml/dcn20/dcn20_fpu.c  |   4 +
 .../dc/dml/dcn20/display_mode_vba_20.c        |   4 +
 .../dc/dml/dcn20/display_rq_dlg_calc_20.c     |   4 +
 .../drm/amd/display/dc/dml/display_mode_vba.c |   3 +
 .../gpu/drm/amd/display/tests/.kunitconfig    |   7 +
 .../dc/basics/dc_basics_fixpt31_32_test.c     | 232 ++++++
 .../amd/display/tests/dc/dc_dmub_srv_test.c   | 285 +++++++
 .../tests/dc/dml/calcs/bw_fixed_test.c        | 323 ++++++++
 .../tests/dc/dml/dcn20/dcn20_fpu_test.c       | 560 +++++++++++++
 .../dc/dml/dcn20/display_mode_vba_20_test.c   | 227 ++++++
 .../dml/dcn20/display_rq_dlg_calc_20_test.c   | 112 +++
 .../tests/dc/dml/display_mode_vba_test.c      | 741 ++++++++++++++++++
 18 files changed, 2613 insertions(+)
 create mode 100644 Documentation/gpu/amdgpu/display/display-test.rst
 create mode 100644 drivers/gpu/drm/amd/display/tests/.kunitconfig
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/basics/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

base-commit: 2305916dca043ed69bd464f74a886b0216780aa6
prerequisite-patch-id: 83185f6c5da6070e7b0b608bc705a2d3bf295ae6
prerequisite-patch-id: 65407777e3bb20dfe5051f4f4cc7deb6a3c2ed34
prerequisite-patch-id: 60af3dadcfd4a778f10dd09fafbde6061d98528b
prerequisite-patch-id: 92d9259125f2982da5945be995b4ae2af1ca7c32
prerequisite-patch-id: f35acb6c07c0bd5496df919214351399d9aed5b5
prerequisite-patch-id: 8a9637d89966e51adfe11e3fd3d17fcf1328b472
prerequisite-patch-id: ea6f40f1cfb61fddb9d1562111897e184da49bf7
prerequisite-patch-id: ae79651ae7b2e02520b18fc7eded463afea757e5
prerequisite-patch-id: ba795b981f3e94890540f452e658e28408b500d2
prerequisite-patch-id: abd5e51f483a9afb08af468db043e2ebc7ce6867
prerequisite-patch-id: a31028824a461f8b4a6b9244035e246efbee9c71
prerequisite-patch-id: a65dfe200981f8584ba3b1f9813faa4f0022a13e

Signature · 1 line
2.37.0
#1 lore raw

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

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 +
 .../drm/amd/display/dc/basics/fixpt31_32.c    |   5 +
 .../gpu/drm/amd/display/tests/.kunitconfig    |   6 +
 .../dc/basics/dc_basics_fixpt31_32_test.c     | 232 ++++++++++++++++++
 4 files changed, 256 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/tests/.kunitconfig
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/basics/dc_basics_fixpt31_32_test.c
drivers/gpu/drm/amd/display/Kconfig +13 -0
index 96cbc87f7b6b..27981ccb7032 100644
@@ -55,4 +55,17 @@ config DRM_AMD_SECURE_DISPLAY
             Cooperate with specific DMCU FW.
 
 
+config AMD_DC_BASICS_KUNIT_TEST
+	bool "Enable unit 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 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/basics/fixpt31_32.c +5 -0
index 1726bdf89bae..82747d8ab95a 100644
@@ -490,3 +490,8 @@ int dc_fixpt_s4d19(struct fixed31_32 arg)
 	else
 		return ux_dy(arg.value, 4, 19);
 }
+
+#if IS_ENABLED(CONFIG_AMD_DC_BASICS_KUNIT_TEST)
+#include "../../tests/dc/basics/dc_basics_fixpt31_32_test.c"
+#endif
+
drivers/gpu/drm/amd/display/tests/.kunitconfig new file +6 -0
new file mode 100644
index 000000000000..60f2ff8158f5
@@ -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
\ No newline at end of file
drivers/gpu/drm/amd/display/tests/dc/basics/dc_basics_fixpt31_32_test.c new file +232 -0

232 lines not on this page · raw message

Signature · 1 line
2.37.0
#2 lore raw

Re: [PATCH 1/8] drm/amd/display: Introduce KUnit tests for fixed31_32 library

Quoted 5 lines · Tales Aparecida

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

Quoted 7 lines

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/

Nice, thanks for including a kunitconfig, that'll help a lot.

Just as an FYI: if you're working on top of torvalds/master, I think you would no longer need --arch=x86_64.
Before, CONFIG_PCI=y was tricky to enable on UML, but commit 6fc3a8636a7b ("kunit: tool: Enable virtio/PCI by default on UML") landed for 6.0.

I.e. I can run this command on torvalds/master w/ no other patches applied:

$ ./tools/testing/kunit/kunit.py config --kunitconfig=/dev/stdin <<EOF
CONFIG_KUNIT=y
CONFIG_PCI=y
CONFIG_DRM=y
CONFIG_DRM_AMDGPU=y
CONFIG_DRM_AMD_DC=y
EOF

I haven't tried to apply this series locally yet to double-check, but I'm pretty sure that means these tests should work as well. Running under UML would hopefully have faster compile times and be less resource heavy than a QEMU VM (but I've not measured to verify that).

Daniel

#3 lore raw

Re: [PATCH 1/8] drm/amd/display: Introduce KUnit tests for fixed31_32 library

Quoted 34 lines · Daniel Latypov' via KUnit Development
Quoted 5 lines · Tales Aparecida

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

Quoted 7 lines

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/

Nice, thanks for including a kunitconfig, that'll help a lot.

Just as an FYI: if you're working on top of torvalds/master, I think you would no longer need --arch=x86_64.
Before, CONFIG_PCI=y was tricky to enable on UML, but commit 6fc3a8636a7b ("kunit: tool: Enable virtio/PCI by default on UML") landed for 6.0.

I.e. I can run this command on torvalds/master w/ no other patches applied:

$ ./tools/testing/kunit/kunit.py config --kunitconfig=/dev/stdin <<EOF
CONFIG_KUNIT=y
CONFIG_PCI=y
CONFIG_DRM=y
CONFIG_DRM_AMDGPU=y
CONFIG_DRM_AMD_DC=y
EOF
Quoted 6 lines

I haven't tried to apply this series locally yet to double-check, but I'm pretty sure that means these tests should work as well. Running under UML would hopefully have faster compile times and be less resource heavy than a QEMU VM (but I've not measured to verify that).

There are still a few issues which prevent these tests from working on UML I haven't had a chance to go through all of them yet, but I'll drop a couple of quick responses to some of the individual patches.

The first thing to note is that amdgpu doesn't actually build on UML at all without:
https://patchwork.kernel.org/project/linux-rdma/patch/[email protected]/

IIRC, no-one liked spreading !defined(CONFIG_UML) everwhere. Replacing it with IS_ENABLED(CONFIG_X86) also works, as X86_64 is defined on UML, but X86 isn't.

The other issues are basically just other missing #ifdef checks or dependencies. Plus there's a warning on my system even under x86_64 for integer overflow in the MIN_I64 definition.

Cheers,
-- David

#4 lore raw

Re: [PATCH 1/8] drm/amd/display: Introduce KUnit tests for fixed31_32 library

Quoted 52 lines · David Gow
Quoted 34 lines · Daniel Latypov' via KUnit Development
Quoted 5 lines · Tales Aparecida

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

Quoted 7 lines

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/

Nice, thanks for including a kunitconfig, that'll help a lot.

Just as an FYI: if you're working on top of torvalds/master, I think you would no longer need --arch=x86_64.
Before, CONFIG_PCI=y was tricky to enable on UML, but commit 6fc3a8636a7b ("kunit: tool: Enable virtio/PCI by default on UML") landed for 6.0.

I.e. I can run this command on torvalds/master w/ no other patches applied:

$ ./tools/testing/kunit/kunit.py config --kunitconfig=/dev/stdin <<EOF
CONFIG_KUNIT=y
CONFIG_PCI=y
CONFIG_DRM=y
CONFIG_DRM_AMDGPU=y
CONFIG_DRM_AMD_DC=y
EOF
Quoted 6 lines

I haven't tried to apply this series locally yet to double-check, but I'm pretty sure that means these tests should work as well. Running under UML would hopefully have faster compile times and be less resource heavy than a QEMU VM (but I've not measured to verify that).

There are still a few issues which prevent these tests from working on UML I haven't had a chance to go through all of them yet, but I'll drop a couple of quick responses to some of the individual patches.

The first thing to note is that amdgpu doesn't actually build on UML at all without:
https://patchwork.kernel.org/project/linux-rdma/patch/[email protected]/

Quoted 7 lines

IIRC, no-one liked spreading !defined(CONFIG_UML) everwhere. Replacing it with IS_ENABLED(CONFIG_X86) also works, as X86_64 is defined on UML, but X86 isn't.

The other issues are basically just other missing #ifdef checks or dependencies. Plus there's a warning on my system even under x86_64 for integer overflow in the MIN_I64 definition.

Currently, we only support the tests to x86_64, as the DC core don't build to UML yet. In the future, I intend to send the patch that enables the tests to run on UML, but for the first iteration, we focused in running the tests on x86.

If you want with UML, you can apply the following patch (which is working in progress yet):
------
From cac02e5d714d78e1d69995383b818eec26661925 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ma=C3=ADra=20Canal?= <[email protected]>
Date: Sat, 23 Jul 2022 14:57:41 -0300
Subject: [PATCH] drm/amdgpu: Enable compilation under UML
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The User-Mode Linux configuration is used by KUnit to execute kernel results directly. This removes the need for a test machine or a virtual machine. Therefore, as KUnit tests are being added to AMDGPU, it is interesting to enable compilation under UML, as it eases running the tests on CI and developers' machines.

Also, the use of UML is encouraged by the KUnit team [1], as it is considered a better practice to write tests that run on UML to tests that only run under a particular architecture.

[1] https://docs.kernel.org/dev-tools/kunit/usage.html#writing-tests-for-other-architectures

---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c               | 6 +++---
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c           | 2 +-
 drivers/gpu/drm/amd/display/Kconfig                 | 2 +-
 drivers/gpu/drm/amd/display/dc/gpio/hw_gpio.c       | 8 ++++----
 drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c | 2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +3 -3
index a5409531a2fd..bbed3284e78e 100644
@@ -1766,7 +1766,7 @@ static int kfd_fill_mem_info_for_cpu(int numa_node_id, int *avail_size,
 	return 0;
 }
 
-#ifdef CONFIG_X86_64
+#if IS_ENABLED(CONFIG_X86)
 static int kfd_fill_iolink_info_for_cpu(int numa_node_id, int *avail_size,
 				uint32_t *num_entries,
 				struct crat_subtype_iolink *sub_type_hdr)
@@ -1825,7 +1825,7 @@ static int kfd_create_vcrat_image_cpu(void *pcrat_image, size_t *size)
 	struct crat_subtype_generic *sub_type_hdr;
 	int avail_size = *size;
 	int numa_node_id;
-#ifdef CONFIG_X86_64
+#if IS_ENABLED(CONFIG_X86)
 	uint32_t entries = 0;
 #endif
 	int ret = 0;
@@ -1890,7 +1890,7 @@ static int kfd_create_vcrat_image_cpu(void *pcrat_image, size_t *size)
 			sub_type_hdr->length);
 
 		/* Fill in Subtype: IO Link */
-#ifdef CONFIG_X86_64
+#if IS_ENABLED(CONFIG_X86)
 		ret = kfd_fill_iolink_info_for_cpu(numa_node_id, &avail_size,
 				&entries,
 				(struct crat_subtype_iolink *)sub_type_hdr);
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -1
index 25990bec600d..5f0e58c430a1 100644
@@ -1923,7 +1923,7 @@ static int kfd_cpumask_to_apic_id(const struct cpumask *cpumask)
 	first_cpu_of_numa_node = cpumask_first(cpumask);
 	if (first_cpu_of_numa_node >= nr_cpu_ids)
 		return -1;
-#ifdef CONFIG_X86_64
+#if IS_ENABLED(CONFIG_X86)
 	return cpu_data(first_cpu_of_numa_node).apicid;
 #else
 	return first_cpu_of_numa_node;
drivers/gpu/drm/amd/display/Kconfig +1 -1
index 72e7a63da79f..d066af22ecea 100644
@@ -6,7 +6,7 @@ config DRM_AMD_DC
 	bool "AMD DC - Enable new display engine"
 	default y
 	select SND_HDA_COMPONENT if SND_HDA_CORE
-	select DRM_AMD_DC_DCN if (X86 || PPC64)
+	select DRM_AMD_DC_DCN if (X86 || PPC64 || UML)
 	help
 	  Choose this option if you want to use the new display engine
 	  support for AMDGPU. This adds required support for Vega and
drivers/gpu/drm/amd/display/dc/gpio/hw_gpio.c +4 -4
index 660510842ecf..a591090784ee 100644
@@ -39,7 +39,7 @@
 #define REG(reg)\
 	(gpio->regs->reg)
 
-static void store_registers(
+static void hw_gpio_store_registers(
 	struct hw_gpio *gpio)
 {
 	REG_GET(MASK_reg, MASK, &gpio->store.mask);
@@ -48,7 +48,7 @@ static void store_registers(
 	/* TODO store GPIO_MUX_CONTROL if we ever use it */
 }
 
-static void restore_registers(
+static void hw_gpio_restore_registers(
 	struct hw_gpio *gpio)
 {
 	REG_UPDATE(MASK_reg, MASK, gpio->store.mask);
@@ -63,7 +63,7 @@ bool dal_hw_gpio_open(
 {
 	struct hw_gpio *pin = FROM_HW_GPIO_PIN(ptr);
 
-	store_registers(pin);
+	hw_gpio_store_registers(pin);
 
 	ptr->opened = (dal_hw_gpio_config_mode(pin, mode) == GPIO_RESULT_OK);
 
@@ -132,7 +132,7 @@ void dal_hw_gpio_close(
 {
 	struct hw_gpio *pin = FROM_HW_GPIO_PIN(ptr);
 
-	restore_registers(pin);
+	hw_gpio_restore_registers(pin);
 
 	ptr->mode = GPIO_MODE_UNKNOWN;
 	ptr->opened = false;
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c +1 -1
index e4fcbf8a7eb5..825b80590f1b 100644
@@ -1738,7 +1738,7 @@ static int smu7_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
 
 static bool intel_core_rkl_chk(void)
 {
-#if IS_ENABLED(CONFIG_X86_64)
+#if IS_ENABLED(CONFIG_X86)
 	struct cpuinfo_x86 *c = &cpu_data(0);
 
 	return (c->x86 == 6 && c->x86_model == INTEL_FAM6_ROCKETLAKE);
Signature · 5 lines
2.37.1
------

Best Regards,
- Maíra Canal
Quoted 3 lines

Cheers,
-- David

Reviewed-by on v1 1/8
#5 lore raw

Re: [PATCH 1/8] drm/amd/display: Introduce KUnit tests for fixed31_32 library

In reply to Tales Aparecida
Quoted 10 lines · Tales Aparecida

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:

Quoted 5 lines
$ ./tools/testing/kunit/kunit.py run --arch=x86_64 \
        --kunitconfig=drivers/gpu/drm/amd/display/tests/

---

On the whole, I really like these tests: this sort-of fixed-point library code is such an excellent example of the sorts of thing KUnit is really well suited for.

The only thing I'll comment on is that these _could_ be parameterised tests (given most of them are just testing the same function over and over with different inputs). That being said, it's a matter of taste as much as anything.

Otherwise, the remaining comments I'd have apply to most of the patches in the series, particularly around where they live and how they're compiled. I think what you have now is okay, but does have some drawbacks.
In particular, while the #include method is a good lowest-common-denominator (in that it opens up testing static functions), it isn't as flexible and broadly compatible with different testing setups (particularly some with KUNIT=m) as having a separate test module. I tried making this a separate

It's up to you (and the DRM/AMDGPU maintainers) as to whether having consistency between tests which _do_ need to test static functions is worth having those that don't be less accessible.

I've left some comments with more detail below, but regardless, these tests look fine to me:

Cheers,
-- David

Quoted 13 lines
 drivers/gpu/drm/amd/display/Kconfig           |  13 +
 .../drm/amd/display/dc/basics/fixpt31_32.c    |   5 +
 .../gpu/drm/amd/display/tests/.kunitconfig    |   6 +
 .../dc/basics/dc_basics_fixpt31_32_test.c     | 232 ++++++++++++++++++
 4 files changed, 256 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/tests/.kunitconfig
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/basics/dc_basics_fixpt31_32_test.c
drivers/gpu/drm/amd/display/Kconfig +0 -0
index 96cbc87f7b6b..27981ccb7032 100644

drivers/gpu/drm/amd/display/Kconfig config DRM_AMD_SECURE_DISPLAY · line 60

Quoted 6 lines
drivers/gpu/drm/amd/display/Kconfig +3 -0
@@ -55,4 +55,17 @@ config DRM_AMD_SECURE_DISPLAY
             Cooperate with specific DMCU FW.
 
 
+config AMD_DC_BASICS_KUNIT_TEST
+       bool "Enable unit tests for the 'utils' sub-component of DAL" if !KUNIT_ALL_TESTS
+       depends on DRM_AMD_DC && KUNIT

If these tests get compiled into the amdgpu kernel module, and CONFIG_KUNIT=m, this could break loading the driver in some setups.

In particular, see the discussion here:
https://lore.kernel.org/all/[email protected]/T/#u

Given this doesn't affect the "supported" cases, I think you can leave it as-is, but if you want to handle his "build with KUNIT=m, but kunit.ko not installed" case, you'll probably want to either split the tests out into a separate module, or depend on KUNIT=y.

drivers/gpu/drm/amd/display/Kconfig config DRM_AMD_SECURE_DISPLAY · line 64

Quoted 4 lines
drivers/gpu/drm/amd/display/Kconfig +4 -0
+       default KUNIT_ALL_TESTS
+       help
+               Enables unit tests for the Display Core. Only useful for kernel
+               devs running KUnit.

Given the above, maybe it's worth explicitly noting that these tests get compiled into the amdgpu module.

Quoted 69 lines
drivers/gpu/drm/amd/display/Kconfig +6 -0
+
+               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/basics/fixpt31_32.c +5 -0
index 1726bdf89bae..82747d8ab95a 100644
@@ -490,3 +490,8 @@ int dc_fixpt_s4d19(struct fixed31_32 arg)
        else
                return ux_dy(arg.value, 4, 19);
 }
+
+#if IS_ENABLED(CONFIG_AMD_DC_BASICS_KUNIT_TEST)
+#include "../../tests/dc/basics/dc_basics_fixpt31_32_test.c"
+#endif
+
drivers/gpu/drm/amd/display/tests/.kunitconfig new file +6 -0
new file mode 100644
index 000000000000..60f2ff8158f5
@@ -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
\ No newline at end of file
drivers/gpu/drm/amd/display/tests/dc/basics/dc_basics_fixpt31_32_test.c new file +26 -0
new file mode 100644
index 000000000000..2fc489203499
@@ -0,0 +1,232 @@
+// SPDX-License-Identifier: MIT
+/* Unit tests for display/include/fixed31_32.h and dc/basics/fixpt31_32.c
+ *
+ * Copyright (C) 2022, Tales Aparecida <[email protected]>
+ */
+
+#include <kunit/test.h>
+#include "os_types.h"
+#include "fixed31_32.h"
+
+static const struct fixed31_32 dc_fixpt_minus_one = { -0x100000000LL };
+
+/**
+ * dc_fixpt_from_int_test - KUnit test for dc_fixpt_from_int
+ * @test: represents a running instance of a test.
+ */
+static void dc_fixpt_from_int_test(struct kunit *test)
+{
+       struct fixed31_32 res;
+
+       res = dc_fixpt_from_int(0);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_zero.value);
+
+       res = dc_fixpt_from_int(1);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value);
+

drivers/gpu/drm/amd/display/tests/dc/basics/dc_basics_fixpt31_32_test.c line 36

Quoted 10 lines
drivers/gpu/drm/amd/display/tests/dc/basics/dc_basics_fixpt31_32_test.c new file +10 -0
+       res = dc_fixpt_from_int(-1);
+       KUNIT_EXPECT_EQ(test, res.value, -dc_fixpt_one.value);
+
+       res = dc_fixpt_from_int(INT_MAX);
+       KUNIT_EXPECT_EQ(test, res.value, 0x7FFFFFFF00000000LL);
+
+       res = dc_fixpt_from_int(INT_MIN);
+       KUNIT_EXPECT_EQ(test, res.value,
+                       0x8000000000000000LL); /* implicit negative signal */
+}

These could be done as a parameterised test if you prefer, though it's fine either way.

Quoted 203 lines
drivers/gpu/drm/amd/display/tests/dc/basics/dc_basics_fixpt31_32_test.c new file +196 -1
+
+/**
+ * dc_fixpt_from_fraction_test - KUnit test for dc_fixpt_from_fraction
+ * @test: represents a running instance of a test.
+ */
+static void dc_fixpt_from_fraction_test(struct kunit *test)
+{
+       struct fixed31_32 res;
+
+       /* Assert signal works as expected */
+       res = dc_fixpt_from_fraction(1LL, 1LL);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value);
+
+       res = dc_fixpt_from_fraction(-1LL, 1LL);
+       KUNIT_EXPECT_EQ(test, res.value, -dc_fixpt_one.value);
+
+       res = dc_fixpt_from_fraction(1LL, -1LL);
+       KUNIT_EXPECT_EQ(test, res.value, -dc_fixpt_one.value);
+
+       res = dc_fixpt_from_fraction(-1LL, -1LL);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value);
+
+       /* Assert that the greatest parameter values works as expected */
+       res = dc_fixpt_from_fraction(LLONG_MAX, LLONG_MAX);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value);
+
+       res = dc_fixpt_from_fraction(LLONG_MIN, LLONG_MIN);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value);
+
+       /* Edge case using the smallest fraction possible without LSB rounding */
+       res = dc_fixpt_from_fraction(1, 1LL << (FIXED31_32_BITS_PER_FRACTIONAL_PART));
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_epsilon.value);
+
+       /* Edge case using the smallest fraction possible with LSB rounding */
+       res = dc_fixpt_from_fraction(1, 1LL << (FIXED31_32_BITS_PER_FRACTIONAL_PART + 1));
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_epsilon.value);
+
+       /* Assert an nil numerator is a valid input */
+       res = dc_fixpt_from_fraction(0LL, LLONG_MAX);
+       KUNIT_EXPECT_EQ(test, res.value, 0LL);
+
+       /* Edge case using every bit of the decimal part without rounding */
+       res = dc_fixpt_from_fraction(8589934590LL, 8589934592LL);
+       KUNIT_EXPECT_EQ(test, res.value, 0x0FFFFFFFFLL);
+
+       res = dc_fixpt_from_fraction(-8589934590LL, 8589934592LL);
+       KUNIT_EXPECT_EQ(test, res.value, -0x0FFFFFFFFLL);
+
+       /* Edge case using every bit of the decimal part then rounding LSB */
+       res = dc_fixpt_from_fraction(8589934591LL, 8589934592LL);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value);
+
+       res = dc_fixpt_from_fraction(-8589934591LL, 8589934592LL);
+       KUNIT_EXPECT_EQ(test, res.value, -dc_fixpt_one.value);
+       /*  A repeating decimal in binary representation that doesn't round up the LSB */
+       res = dc_fixpt_from_fraction(4, 3);
+       KUNIT_EXPECT_EQ(test, res.value, 0x0000000155555555LL);
+
+       res = dc_fixpt_from_fraction(-4, 3);
+       KUNIT_EXPECT_EQ(test, res.value, -0x0000000155555555LL);
+
+       /* A repeating decimal in binary representation that rounds up the LSB */
+       res = dc_fixpt_from_fraction(5, 3);
+       KUNIT_EXPECT_EQ(test, res.value, 0x00000001AAAAAAABLL);
+
+       res = dc_fixpt_from_fraction(-5, 3);
+       KUNIT_EXPECT_EQ(test, res.value, -0x00000001AAAAAAABLL);
+}
+
+/**
+ * dc_fixpt_mul_test - KUnit test for dc_fixpt_mul
+ * @test: represents a running instance of a test.
+ */
+static void dc_fixpt_mul_test(struct kunit *test)
+{
+       struct fixed31_32 res;
+       struct fixed31_32 arg;
+
+       /* Assert signal works as expected */
+       res = dc_fixpt_mul(dc_fixpt_one, dc_fixpt_one);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value);
+
+       res = dc_fixpt_mul(dc_fixpt_minus_one, dc_fixpt_one);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_minus_one.value);
+
+       res = dc_fixpt_mul(dc_fixpt_one, dc_fixpt_minus_one);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_minus_one.value);
+
+       res = dc_fixpt_mul(dc_fixpt_minus_one, dc_fixpt_minus_one);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value);
+
+       /* Assert that the greatest parameter values works as expected */
+       arg.value = LONG_MAX;
+       res = dc_fixpt_mul(arg, dc_fixpt_one);
+       KUNIT_EXPECT_EQ(test, res.value, arg.value);
+
+       arg.value = LONG_MIN;
+       res = dc_fixpt_mul(arg, dc_fixpt_one);
+       KUNIT_EXPECT_EQ(test, res.value, arg.value);
+
+       arg.value = LONG_MAX;
+       res = dc_fixpt_mul(dc_fixpt_one, arg);
+       KUNIT_EXPECT_EQ(test, res.value, arg.value);
+
+       arg.value = LONG_MIN;
+       res = dc_fixpt_mul(dc_fixpt_one, arg);
+       KUNIT_EXPECT_EQ(test, res.value, arg.value);
+
+       /* Assert it doesn't round LSB as expected */
+       arg.value = 0x7FFFFFFF7fffffffLL;
+       res = dc_fixpt_mul(arg, dc_fixpt_epsilon);
+       KUNIT_EXPECT_EQ(test, res.value, 0x000000007FFFFFFF);
+
+       /* Assert it rounds LSB as expected */
+       arg.value = 0x7FFFFFFF80000000LL;
+       res = dc_fixpt_mul(arg, dc_fixpt_epsilon);
+       KUNIT_EXPECT_EQ(test, res.value, 0x0000000080000000);
+}
+
+/**
+ * dc_fixpt_sqr_test - KUnit test for dc_fixpt_sqr
+ * @test: represents a running instance of a test.
+ */
+static void dc_fixpt_sqr_test(struct kunit *test)
+{
+       struct fixed31_32 res;
+       struct fixed31_32 arg;
+
+       arg.value = dc_fixpt_one.value;
+       res = dc_fixpt_sqr(arg);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value);
+
+       arg.value = dc_fixpt_minus_one.value;
+       res = dc_fixpt_sqr(arg);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value);
+
+       arg.value = 0;
+       res = dc_fixpt_sqr(arg);
+       KUNIT_EXPECT_EQ(test, res.value, 0);
+
+       /* Test some recognizable values */
+       arg = dc_fixpt_from_int(100);
+       res = dc_fixpt_sqr(arg);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_from_int(10000).value);
+
+       arg = dc_fixpt_from_fraction(1, 100);
+       res = dc_fixpt_sqr(arg);
+       KUNIT_EXPECT_EQ(test, res.value,
+                       dc_fixpt_from_fraction(1, 10000).value);
+
+       /* LSB rounding */
+       arg = dc_fixpt_from_fraction(3, 2);
+       res = dc_fixpt_sqr(arg);
+       KUNIT_EXPECT_EQ(test, res.value,
+                       dc_fixpt_from_fraction(9, 4).value + 1LL);
+}
+
+/**
+ * dc_fixpt_recip_test - KUnit test for dc_fixpt_recip
+ * @test: represents a running instance of a test.
+ */
+static void dc_fixpt_recip_test(struct kunit *test)
+{
+       struct fixed31_32 res;
+       struct fixed31_32 arg;
+
+       /* Assert 1/1 works as expected */
+       res = dc_fixpt_recip(dc_fixpt_one);
+       KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value);
+
+       /* Assert smallest parameters work as expected. */
+       arg.value = 3LL;
+       res = dc_fixpt_recip(arg);
+       KUNIT_EXPECT_EQ(test, res.value, 0x5555555555555555LL);
+
+       arg.value = -3LL;
+       res = dc_fixpt_recip(arg);
+       KUNIT_EXPECT_EQ(test, res.value, -0x5555555555555555LL);
+}
+
+static struct kunit_case dc_basics_fixpt31_32_test_cases[] = {
+       KUNIT_CASE(dc_fixpt_from_int_test),
+       KUNIT_CASE(dc_fixpt_from_fraction_test),
+       KUNIT_CASE(dc_fixpt_mul_test),
+       KUNIT_CASE(dc_fixpt_sqr_test),
+       KUNIT_CASE(dc_fixpt_recip_test),
+       {}
+};
+
+static struct kunit_suite dc_basics_fixpt31_32_test_suite = {
+       .name = "dc_basics_fixpt31_32",
+       .test_cases = dc_basics_fixpt31_32_test_cases,
+};
+
+kunit_test_suites(&dc_basics_fixpt31_32_test_suite);
+
--

2.37.0

--
You received this message because you are subscribed to the Google Groups "KUnit Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20220811004010.61299-2-tales.aparecida%40gmail.com.

#6 lore raw

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

In reply to Tales Aparecida

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           |  12 +
 .../drm/amd/display/dc/dml/calcs/bw_fixed.c   |   3 +
 .../gpu/drm/amd/display/tests/.kunitconfig    |   3 +-
 .../tests/dc/dml/calcs/bw_fixed_test.c        | 323 ++++++++++++++++++
 4 files changed, 340 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/calcs/bw_fixed_test.c
drivers/gpu/drm/amd/display/Kconfig +12 -0
index 27981ccb7032..72e7a63da79f 100644
@@ -54,6 +54,18 @@ config DRM_AMD_SECURE_DISPLAY
             of crc of specific region via debugfs.
             Cooperate with specific DMCU FW.
 
+config DML_KUNIT_TEST
+	bool "Run all unit tests for DML" if !KUNIT_ALL_TESTS
+	depends on DRM_AMD_DC && KUNIT
+	default KUNIT_ALL_TESTS
+	help
+		Enables unit tests for the Display Mode Library. 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 unit tests for the 'utils' sub-component of DAL" if !KUNIT_ALL_TESTS
drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c +3 -0
index 6ca288fb5fb9..fbe8d0661396 100644
@@ -189,3 +189,6 @@ struct bw_fixed bw_mul(const struct bw_fixed arg1, const struct bw_fixed arg2)
 	return res;
 }
 
+#if IS_ENABLED(CONFIG_DML_KUNIT_TEST)
+#include "../../../tests/dc/dml/calcs/bw_fixed_test.c"
+#endif
drivers/gpu/drm/amd/display/tests/.kunitconfig +2 -1
index 60f2ff8158f5..dd52cae852d2 100644
@@ -3,4 +3,5 @@ CONFIG_PCI=y
 CONFIG_DRM=y
 CONFIG_DRM_AMDGPU=y
 CONFIG_DRM_AMD_DC=y
-CONFIG_AMD_DC_BASICS_KUNIT_TEST=y
\ No newline at end of file
+CONFIG_AMD_DC_BASICS_KUNIT_TEST=y
+CONFIG_DML_KUNIT_TEST=y
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.37.0
#7 lore raw

Re: [PATCH 2/8] drm/amd/display: Introduce KUnit tests to the bw_fixed library

Quoted 21 lines · Tales Aparecida

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/
Quoted 6 lines

---

Not directly related to this patch, but I get a whole stack of
warnings about the definition of MIN_I64 causing integer overflow:
../drivers/gpu/drm/amd/amdgpu/../display/dc/dml/calcs/../../../tests/dc/dml/calcs/bw_fixed_test.c:214:31:
note: in expansion of macro ‘MIN_I64’
214 | KUNIT_EXPECT_EQ(test, MIN_I64 + 1, res.value);
| ^~~~~~~
../drivers/gpu/drm/amd/amdgpu/../display/dc/dml/calcs/bw_fixed.c:30:19:
warning: integer overflow in expression ‘-9223372036854775808’ of type
‘long long int’ results in ‘-9223372036854775808’ [-Woverflow]
30 | (int64_t)(-(1LL << 63))
| ^

This seems to fix it (I'll re-send it out as a separate patch so gmail doesn't mangle it once I'm a bit more convinced it's the best implementation):

--- 8< ---
From 84e84664873dc9e98dff5ee9f74d95872e6cd423 Mon Sep 17 00:00:00 2001
From: David Gow <[email protected]>
Date: Thu, 11 Aug 2022 15:21:02 +0800
Subject: [PATCH] drm/amd/display: MIN_I64 definition causes overflow
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The definition of MIN_I64 in bw_fixed.c can cause gcc to whinge about integer overflow, because it is treated as a positive value, which is then negated. The temporary postive value is not necessarily representable.

This causes the following warning:
../drivers/gpu/drm/amd/amdgpu/../display/dc/dml/calcs/bw_fixed.c:30:19:
warning: integer overflow in expression ‘-9223372036854775808’ of type ‘long long int’ results in ‘-9223372036854775808’ [-Woverflow]
30 | (int64_t)(-(1LL << 63))
| ^

Writing out (INT_MIN - 1) - 1 works instead.

---
drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c | 6 +++---

1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c index fbe8d0661396..3850f7f0f679 100644

drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c +0 -0
@@ -26,12 +26,12 @@

#include "bw_fixed.h"

-#define MIN_I64 \
- (int64_t)(-(1LL << 63))
-

#define MAX_I64 \
       (int64_t)((1ULL << 63) - 1)

+#define MIN_I64 \
+ (-MAX_I64 - 1)
+

#define FRACTIONAL_PART_MASK \
       ((1ULL << BW_FIXED_BITS_PER_FRACTIONAL_PART) - 1)

--
2.37.1.595.g718a3a8f04-goog
--- 8< ---

Otherwise, this test seems to okay. I'll review it (and the series) more properly over then next few days.

Cheers,
-- David

#8 lore raw

Re: [PATCH 2/8] drm/amd/display: Introduce KUnit tests to the bw_fixed library

Quoted 42 lines · David Gow
Quoted 21 lines · Tales Aparecida

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/
Quoted 6 lines

---

Not directly related to this patch, but I get a whole stack of
warnings about the definition of MIN_I64 causing integer overflow:
../drivers/gpu/drm/amd/amdgpu/../display/dc/dml/calcs/../../../tests/dc/dml/calcs/bw_fixed_test.c:214:31:
note: in expansion of macro ‘MIN_I64’
214 | KUNIT_EXPECT_EQ(test, MIN_I64 + 1, res.value);
| ^~~~~~~
../drivers/gpu/drm/amd/amdgpu/../display/dc/dml/calcs/bw_fixed.c:30:19:
warning: integer overflow in expression ‘-9223372036854775808’ of type
‘long long int’ results in ‘-9223372036854775808’ [-Woverflow]
30 | (int64_t)(-(1LL << 63))
| ^

Quoted 3 lines

This seems to fix it (I'll re-send it out as a separate patch so gmail doesn't mangle it once I'm a bit more convinced it's the best implementation):

Thanks!

We were aware of this warnings, in fact there was a patch fixing this that got dropped in the last minute to expedite its review as a standalone patch, I'm sorry I didn't mention it in the cover letter.

To make amends I've sent your approach to the mailing list, hope you don't mind!

https://lore.kernel.org/all/[email protected]/

Quoted 54 lines

--- 8< ---
From 84e84664873dc9e98dff5ee9f74d95872e6cd423 Mon Sep 17 00:00:00 2001
From: David Gow <[email protected]>
Date: Thu, 11 Aug 2022 15:21:02 +0800
Subject: [PATCH] drm/amd/display: MIN_I64 definition causes overflow
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The definition of MIN_I64 in bw_fixed.c can cause gcc to whinge about integer overflow, because it is treated as a positive value, which is then negated. The temporary postive value is not necessarily representable.

This causes the following warning:
../drivers/gpu/drm/amd/amdgpu/../display/dc/dml/calcs/bw_fixed.c:30:19:
warning: integer overflow in expression ‘-9223372036854775808’ of type ‘long long int’ results in ‘-9223372036854775808’ [-Woverflow]
30 | (int64_t)(-(1LL << 63))
| ^

Writing out (INT_MIN - 1) - 1 works instead.

---
drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c | 6 +++---

1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c +3 -4
index fbe8d0661396..3850f7f0f679 100644
@@ -26,12 +26,12 @@
 #include "bw_fixed.h"
 
 
-#define MIN_I64 \
-       (int64_t)(-(1LL << 63))
-
 #define MAX_I64 \
        (int64_t)((1ULL << 63) - 1)
 
+#define MIN_I64 \
+       (-MAX_I64 - 1)
+
 #define FRACTIONAL_PART_MASK \
        ((1ULL << BW_FIXED_BITS_PER_FRACTIONAL_PART) - 1)
 
--

2.37.1.595.g718a3a8f04-goog
--- 8< ---

Quoted 5 lines

Otherwise, this test seems to okay. I'll review it (and the series) more properly over then next few days.

Cheers,
-- David

Thanks for reviewing,
Tales

#9 lore raw

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

In reply to Tales Aparecida

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.

---
 .../dc/dml/dcn20/display_rq_dlg_calc_20.c     |   4 +
 .../dml/dcn20/display_rq_dlg_calc_20_test.c   | 112 ++++++++++++++++++
 2 files changed, 116 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/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 +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.37.0
#10 lore raw

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

In reply to Tales Aparecida

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.

---
 .../drm/amd/display/dc/dml/display_mode_vba.c |   3 +
 .../tests/dc/dml/display_mode_vba_test.c      | 741 ++++++++++++++++++
 2 files changed, 744 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/display_mode_vba_test.c
drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c +3 -0
index 503e7d984ff0..71a3aa75ac56 100644
@@ -1132,3 +1132,6 @@ double CalculateWriteBackDISPCLK(
 	return CalculateWriteBackDISPCLK;
 }
 
+#if IS_ENABLED(CONFIG_DML_KUNIT_TEST)
+#include "../../tests/dc/dml/display_mode_vba_test.c"
+#endif
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.37.0
#11 lore raw

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

In reply to Tales Aparecida

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   | 227 ++++++++++++++++++
 2 files changed, 231 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 d3b5b6fedf04..738d8c1f5def 100644
@@ -5112,3 +5112,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 +227 -0

227 lines not on this page · raw message

Signature · 1 line
2.37.0
#12 lore raw

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

In reply to Tales Aparecida

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.

---
 .../drm/amd/display/dc/dml/dcn20/dcn20_fpu.c  |   4 +
 .../tests/dc/dml/dcn20/dcn20_fpu_test.c       | 560 ++++++++++++++++++
 2 files changed, 564 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c
drivers/gpu/drm/amd/display/dc/dml/dcn20/dcn20_fpu.c +4 -0
index ca44df4fca74..ad30d6ef9603 100644
@@ -2390,3 +2390,7 @@ void dcn201_populate_dml_writeback_from_context_fpu(struct dc *dc,
 	}
 
 }
+
+#if IS_ENABLED(CONFIG_DML_KUNIT_TEST)
+#include "../../tests/dc/dml/dcn20/dcn20_fpu_test.c"
+#endif
drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c new file +560 -0

560 lines not on this page · raw message

Signature · 1 line
2.37.0
#13 lore raw

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

In reply to Tales Aparecida

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

Add unit test to the SubVP feature in order to avoid possible regressions and assure the code robustness.

---
 drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |   4 +
 .../amd/display/tests/dc/dc_dmub_srv_test.c   | 285 ++++++++++++++++++
 2 files changed, 289 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c
drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c +4 -0
index 2d61c2a91cee..f5dd1f69840e 100644
@@ -809,3 +809,7 @@ void dc_dmub_srv_log_diagnostic_data(struct dc_dmub_srv *dc_dmub_srv)
 		diag_data.is_cw0_enabled,
 		diag_data.is_cw6_enabled);
 }
+
+#if IS_ENABLED(CONFIG_AMD_DC_BASICS_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 +285 -0

285 lines not on this page · raw message

Signature · 1 line
2.37.0
#14 lore raw

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

Quoted 9 lines · Tales Aparecida

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

Add unit test to the SubVP feature in order to avoid possible regressions and assure the code robustness.

---

FYI: This seems to have a dependency issue. See below.

Otherwise, I haven't had a chance to review it properly yet, but I'll try to take a closer look over the next few days.

Cheers,
-- David

Quoted 274 lines
 drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |   4 +
 .../amd/display/tests/dc/dc_dmub_srv_test.c   | 285 ++++++++++++++++++
 2 files changed, 289 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c
drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c +4 -0
index 2d61c2a91cee..f5dd1f69840e 100644
@@ -809,3 +809,7 @@ void dc_dmub_srv_log_diagnostic_data(struct dc_dmub_srv *dc_dmub_srv)
                diag_data.is_cw0_enabled,
                diag_data.is_cw6_enabled);
 }
+
+#if IS_ENABLED(CONFIG_AMD_DC_BASICS_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 +251 -0
new file mode 100644
index 000000000000..051079cbf65e
@@ -0,0 +1,285 @@
+// SPDX-License-Identifier: MIT
+/*
+ * KUnit tests for dc_dmub_srv.c
+ *
+ * Copyright (C) 2022, Maíra Canal <[email protected]>
+ */
+
+#include <kunit/test.h>
+#include "dc_dmub_srv.h"
+
+struct populate_subvp_cmd_drr_info_test_case {
+       const char *desc;
+       struct dc *dc;
+       struct pipe_ctx *subvp_pipe;
+       struct pipe_ctx *vblank_pipe;
+       const u8 drr_in_use;
+       const u8 drr_window_size_ms;
+       const u16 min_vtotal_supported;
+       const u16 max_vtotal_supported;
+       const u8 use_ramping;
+};
+
+struct populate_subvp_cmd_drr_info_test_case populate_subvp_cmd_drr_info_cases[] = {
+       {
+               .desc = "Same Clock Frequency",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 0,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 3600,
+                                                       .v_total = 1111,
+                                                       .v_addressable = 1080,
+                                                       .v_front_porch = 3,
+                                                       .pix_clk_100hz = 1855800,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_total = 1111,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 2540,
+               .max_vtotal_supported = 2619,
+       },
+       {
+               .desc = "Same Clock Frequency with Prefetch End to Mall Start",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 500,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 3600,
+                                                       .v_total = 1111,
+                                                       .v_addressable = 1080,
+                                                       .v_front_porch = 3,
+                                                       .pix_clk_100hz = 1855800,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_total = 1111,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 2540,
+               .max_vtotal_supported = 2619,
+       },
+       {
+               .desc = "Same Clock Frequency Not Multiple of 2",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 0,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1866743,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 3600,
+                                                       .v_total = 2400,
+                                                       .v_addressable = 2360,
+                                                       .v_front_porch = 4,
+                                                       .pix_clk_100hz = 1866743,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 3600,
+                                       .v_total = 2400,
+                                       .v_addressable = 2360,
+                                       .pix_clk_100hz = 1866743,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 1387,
+               .max_vtotal_supported = 2875,
+       },
+       {
+               .desc = "Different Clock Frequency for smaller h_total and v_total",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 300,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 1280,
+                                       .v_addressable = 600,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 1280,
+                                                       .v_total = 720,
+                                                       .v_addressable = 600,
+                                                       .v_front_porch = 4,
+                                                       .pix_clk_100hz = 1866743,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 1280,
+                                       .v_total = 720,
+                                       .v_addressable = 600,
+                                       .pix_clk_100hz = 2100800,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 1477,
+               .max_vtotal_supported = 9954,
+       },
+       {
+               .desc = "Different Clock Frequency for approximately 1920x1080",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 0,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 1920,
+                                       .v_addressable = 1000,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 1911,
+                                                       .v_total = 1080,
+                                                       .v_addressable = 1000,
+                                                       .v_front_porch = 7,
+                                                       .pix_clk_100hz = 1866743,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 1280,
+                                       .v_total = 720,
+                                       .v_addressable = 600,
+                                       .pix_clk_100hz = 2100800,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 2482,
+               .max_vtotal_supported = 8971,
+       },
+};
+
+static void populate_subvp_cmd_drr_info_test_to_desc(struct
+               populate_subvp_cmd_drr_info_test_case * t, char *desc)
+{
+       strcpy(desc, t->desc);
+}
+
+KUNIT_ARRAY_PARAM(populate_subvp_cmd_drr_info, populate_subvp_cmd_drr_info_cases,
+                 populate_subvp_cmd_drr_info_test_to_desc);
+
+static void populate_subvp_cmd_drr_info_test(struct kunit *test)
+{

drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c line 261

Quoted 10 lines
drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c new file +10 -0
+       const struct populate_subvp_cmd_drr_info_test_case *test_param =
+               test->param_value;
+       struct dmub_cmd_fw_assisted_mclk_switch_pipe_data_v2 *pipe_data;
+
+       pipe_data = kunit_kzalloc(test,
+                                 sizeof(struct dmub_cmd_fw_assisted_mclk_switch_pipe_data_v2),
+                                 GFP_KERNEL);
+
+       populate_subvp_cmd_drr_info(test_param->dc, test_param->subvp_pipe,
+                                   test_param->vblank_pipe, pipe_data);

Should this be hidden behind an #ifdef CONFIG_DRM_AMD_DC_DCN

Otherwise, there are build issues under UML:
../drivers/gpu/drm/amd/amdgpu/../display/dc/../tests/dc/dc_dmub_srv_test.c:
In function ‘populate_subvp_cmd_drr_info_test’:
../drivers/gpu/drm/amd/amdgpu/../display/dc/../tests/dc/dc_dmub_srv_test.c:260:9:
error: implicit declaration of function ‘populate_subvp_cmd_drr_info’; did you mean ‘populate_subvp_cmd_drr_info_test’? [-Werror =implicit-function-declaration]
260 | populate_subvp_cmd_drr_info(test_param->dc,
test_param->subvp_pipe,

     |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
     |         populate_subvp_cmd_drr_info_test

cc1: some warnings being treated as errors
make[5]: *** [../scripts/Makefile.build:249:
drivers/gpu/drm/amd/amdgpu/../display/dc/dc_dmub_srv.o] Error 1

Making the test skip itself if this isn't enabled worked fine here.

Quoted 31 lines
drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c new file +24 -1
+
+       KUNIT_EXPECT_EQ(test, test_param->drr_in_use,
+                       pipe_data->pipe_config.vblank_data.drr_info.drr_in_use);
+       KUNIT_EXPECT_EQ(test, test_param->drr_window_size_ms,
+                       pipe_data->pipe_config.vblank_data.drr_info.drr_window_size_ms);
+       KUNIT_EXPECT_EQ(test, test_param->use_ramping,
+                       pipe_data->pipe_config.vblank_data.drr_info.use_ramping);
+       KUNIT_EXPECT_EQ(test, test_param->min_vtotal_supported,
+                       pipe_data->pipe_config.vblank_data.drr_info.min_vtotal_supported);
+       KUNIT_EXPECT_EQ(test, test_param->max_vtotal_supported,
+                       pipe_data->pipe_config.vblank_data.drr_info.max_vtotal_supported);
+}
+
+static struct kunit_case dc_dmub_srv_cases[] = {
+       KUNIT_CASE_PARAM(populate_subvp_cmd_drr_info_test, populate_subvp_cmd_drr_info_gen_params),
+       {  }
+};
+
+static struct kunit_suite dc_dmub_srv_suite = {
+       .name = "dc_dmub_srv",
+       .test_cases = dc_dmub_srv_cases,
+};
+
+kunit_test_suite(dc_dmub_srv_suite);
--

2.37.0

--
You received this message because you are subscribed to the Google Groups "KUnit Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20220811004010.61299-8-tales.aparecida%40gmail.com.

#15 lore raw

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

Quoted 316 lines · David Gow
Quoted 9 lines · Tales Aparecida

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

Add unit test to the SubVP feature in order to avoid possible regressions and assure the code robustness.

---

FYI: This seems to have a dependency issue. See below.

Otherwise, I haven't had a chance to review it properly yet, but I'll try to take a closer look over the next few days.

Cheers,
-- David

Quoted 274 lines
  drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |   4 +
  .../amd/display/tests/dc/dc_dmub_srv_test.c   | 285 ++++++++++++++++++
  2 files changed, 289 insertions(+)

create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c

drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c +4 -0
index 2d61c2a91cee..f5dd1f69840e 100644
@@ -809,3 +809,7 @@ void dc_dmub_srv_log_diagnostic_data(struct dc_dmub_srv *dc_dmub_srv)
                 diag_data.is_cw0_enabled,
                 diag_data.is_cw6_enabled);
  }
+
+#if IS_ENABLED(CONFIG_AMD_DC_BASICS_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 +251 -0
new file mode 100644
index 000000000000..051079cbf65e
@@ -0,0 +1,285 @@
+// SPDX-License-Identifier: MIT
+/*
+ * KUnit tests for dc_dmub_srv.c
+ *
+ * Copyright (C) 2022, Maíra Canal <[email protected]>
+ */
+
+#include <kunit/test.h>
+#include "dc_dmub_srv.h"
+
+struct populate_subvp_cmd_drr_info_test_case {
+       const char *desc;
+       struct dc *dc;
+       struct pipe_ctx *subvp_pipe;
+       struct pipe_ctx *vblank_pipe;
+       const u8 drr_in_use;
+       const u8 drr_window_size_ms;
+       const u16 min_vtotal_supported;
+       const u16 max_vtotal_supported;
+       const u8 use_ramping;
+};
+
+struct populate_subvp_cmd_drr_info_test_case populate_subvp_cmd_drr_info_cases[] = {
+       {
+               .desc = "Same Clock Frequency",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 0,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 3600,
+                                                       .v_total = 1111,
+                                                       .v_addressable = 1080,
+                                                       .v_front_porch = 3,
+                                                       .pix_clk_100hz = 1855800,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_total = 1111,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 2540,
+               .max_vtotal_supported = 2619,
+       },
+       {
+               .desc = "Same Clock Frequency with Prefetch End to Mall Start",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 500,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 3600,
+                                                       .v_total = 1111,
+                                                       .v_addressable = 1080,
+                                                       .v_front_porch = 3,
+                                                       .pix_clk_100hz = 1855800,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_total = 1111,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 2540,
+               .max_vtotal_supported = 2619,
+       },
+       {
+               .desc = "Same Clock Frequency Not Multiple of 2",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 0,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1866743,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 3600,
+                                                       .v_total = 2400,
+                                                       .v_addressable = 2360,
+                                                       .v_front_porch = 4,
+                                                       .pix_clk_100hz = 1866743,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 3600,
+                                       .v_total = 2400,
+                                       .v_addressable = 2360,
+                                       .pix_clk_100hz = 1866743,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 1387,
+               .max_vtotal_supported = 2875,
+       },
+       {
+               .desc = "Different Clock Frequency for smaller h_total and v_total",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 300,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 1280,
+                                       .v_addressable = 600,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 1280,
+                                                       .v_total = 720,
+                                                       .v_addressable = 600,
+                                                       .v_front_porch = 4,
+                                                       .pix_clk_100hz = 1866743,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 1280,
+                                       .v_total = 720,
+                                       .v_addressable = 600,
+                                       .pix_clk_100hz = 2100800,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 1477,
+               .max_vtotal_supported = 9954,
+       },
+       {
+               .desc = "Different Clock Frequency for approximately 1920x1080",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 0,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 1920,
+                                       .v_addressable = 1000,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 1911,
+                                                       .v_total = 1080,
+                                                       .v_addressable = 1000,
+                                                       .v_front_porch = 7,
+                                                       .pix_clk_100hz = 1866743,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 1280,
+                                       .v_total = 720,
+                                       .v_addressable = 600,
+                                       .pix_clk_100hz = 2100800,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 2482,
+               .max_vtotal_supported = 8971,
+       },
+};
+
+static void populate_subvp_cmd_drr_info_test_to_desc(struct
+               populate_subvp_cmd_drr_info_test_case * t, char *desc)
+{
+       strcpy(desc, t->desc);
+}
+
+KUNIT_ARRAY_PARAM(populate_subvp_cmd_drr_info, populate_subvp_cmd_drr_info_cases,
+                 populate_subvp_cmd_drr_info_test_to_desc);
+
+static void populate_subvp_cmd_drr_info_test(struct kunit *test)
+{

drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c line 261

Quoted 10 lines
drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c new file +10 -0
+       const struct populate_subvp_cmd_drr_info_test_case *test_param =
+               test->param_value;
+       struct dmub_cmd_fw_assisted_mclk_switch_pipe_data_v2 *pipe_data;
+
+       pipe_data = kunit_kzalloc(test,
+                                 sizeof(struct dmub_cmd_fw_assisted_mclk_switch_pipe_data_v2),
+                                 GFP_KERNEL);
+
+       populate_subvp_cmd_drr_info(test_param->dc, test_param->subvp_pipe,
+                                   test_param->vblank_pipe, pipe_data);

Should this be hidden behind an #ifdef CONFIG_DRM_AMD_DC_DCN

Otherwise, there are build issues under UML:
../drivers/gpu/drm/amd/amdgpu/../display/dc/../tests/dc/dc_dmub_srv_test.c:
In function ‘populate_subvp_cmd_drr_info_test’:
../drivers/gpu/drm/amd/amdgpu/../display/dc/../tests/dc/dc_dmub_srv_test.c:260:9:
error: implicit declaration of function ‘populate_subvp_cmd_drr_info’; did you mean ‘populate_subvp_cmd_drr_info_test’? [-Werror =implicit-function-declaration]
260 | populate_subvp_cmd_drr_info(test_param->dc,
test_param->subvp_pipe,

Quoted 9 lines
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      |         populate_subvp_cmd_drr_info_test

cc1: some warnings being treated as errors
make[5]: *** [../scripts/Makefile.build:249:
drivers/gpu/drm/amd/amdgpu/../display/dc/dc_dmub_srv.o] Error 1

Making the test skip itself if this isn't enabled worked fine here.

Currently, we don't support UML as there are some build problems on AMDGPU. You can apply the patch that I sent previously to run the tests with UML, and this warning will not happen anymore, but for now, the tests will work properly only on x86_64.

Moreover, I don't know if it is worth adding an #ifdef CONFIG_DRM_AMD_DC_DCN on all the functions, as most of the functions that we are testing are built under CONFIG_DRM_AMD_DC_DCN.

Best Regards
- Maíra Canal

Quoted 33 lines
Quoted 33 lines
drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c new file +24 -1
+
+       KUNIT_EXPECT_EQ(test, test_param->drr_in_use,
+                       pipe_data->pipe_config.vblank_data.drr_info.drr_in_use);
+       KUNIT_EXPECT_EQ(test, test_param->drr_window_size_ms,
+                       pipe_data->pipe_config.vblank_data.drr_info.drr_window_size_ms);
+       KUNIT_EXPECT_EQ(test, test_param->use_ramping,
+                       pipe_data->pipe_config.vblank_data.drr_info.use_ramping);
+       KUNIT_EXPECT_EQ(test, test_param->min_vtotal_supported,
+                       pipe_data->pipe_config.vblank_data.drr_info.min_vtotal_supported);
+       KUNIT_EXPECT_EQ(test, test_param->max_vtotal_supported,
+                       pipe_data->pipe_config.vblank_data.drr_info.max_vtotal_supported);
+}
+
+static struct kunit_case dc_dmub_srv_cases[] = {
+       KUNIT_CASE_PARAM(populate_subvp_cmd_drr_info_test, populate_subvp_cmd_drr_info_gen_params),
+       {  }
+};
+
+static struct kunit_suite dc_dmub_srv_suite = {
+       .name = "dc_dmub_srv",
+       .test_cases = dc_dmub_srv_cases,
+};
+
+kunit_test_suite(dc_dmub_srv_suite);
--

2.37.0

--
You received this message because you are subscribed to the Google Groups "KUnit Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20220811004010.61299-8-tales.aparecida%40gmail.com.

#16 lore raw

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

Quoted 326 lines · Maíra Canal
Quoted 322 lines · David Gow
Quoted 9 lines · Tales Aparecida

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

Add unit test to the SubVP feature in order to avoid possible regressions and assure the code robustness.

---

FYI: This seems to have a dependency issue. See below.

Otherwise, I haven't had a chance to review it properly yet, but I'll try to take a closer look over the next few days.

Cheers,
-- David

Quoted 274 lines
  drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |   4 +
  .../amd/display/tests/dc/dc_dmub_srv_test.c   | 285 ++++++++++++++++++
  2 files changed, 289 insertions(+)

create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c

drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c +4 -0
index 2d61c2a91cee..f5dd1f69840e 100644
@@ -809,3 +809,7 @@ void dc_dmub_srv_log_diagnostic_data(struct dc_dmub_srv *dc_dmub_srv)
                 diag_data.is_cw0_enabled,
                 diag_data.is_cw6_enabled);
  }
+
+#if IS_ENABLED(CONFIG_AMD_DC_BASICS_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 +251 -0
new file mode 100644
index 000000000000..051079cbf65e
@@ -0,0 +1,285 @@
+// SPDX-License-Identifier: MIT
+/*
+ * KUnit tests for dc_dmub_srv.c
+ *
+ * Copyright (C) 2022, Maíra Canal <[email protected]>
+ */
+
+#include <kunit/test.h>
+#include "dc_dmub_srv.h"
+
+struct populate_subvp_cmd_drr_info_test_case {
+       const char *desc;
+       struct dc *dc;
+       struct pipe_ctx *subvp_pipe;
+       struct pipe_ctx *vblank_pipe;
+       const u8 drr_in_use;
+       const u8 drr_window_size_ms;
+       const u16 min_vtotal_supported;
+       const u16 max_vtotal_supported;
+       const u8 use_ramping;
+};
+
+struct populate_subvp_cmd_drr_info_test_case populate_subvp_cmd_drr_info_cases[] = {
+       {
+               .desc = "Same Clock Frequency",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 0,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 3600,
+                                                       .v_total = 1111,
+                                                       .v_addressable = 1080,
+                                                       .v_front_porch = 3,
+                                                       .pix_clk_100hz = 1855800,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_total = 1111,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 2540,
+               .max_vtotal_supported = 2619,
+       },
+       {
+               .desc = "Same Clock Frequency with Prefetch End to Mall Start",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 500,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 3600,
+                                                       .v_total = 1111,
+                                                       .v_addressable = 1080,
+                                                       .v_front_porch = 3,
+                                                       .pix_clk_100hz = 1855800,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_total = 1111,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 2540,
+               .max_vtotal_supported = 2619,
+       },
+       {
+               .desc = "Same Clock Frequency Not Multiple of 2",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 0,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 2784,
+                                       .v_addressable = 1080,
+                                       .pix_clk_100hz = 1866743,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 3600,
+                                                       .v_total = 2400,
+                                                       .v_addressable = 2360,
+                                                       .v_front_porch = 4,
+                                                       .pix_clk_100hz = 1866743,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 3600,
+                                       .v_total = 2400,
+                                       .v_addressable = 2360,
+                                       .pix_clk_100hz = 1866743,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 1387,
+               .max_vtotal_supported = 2875,
+       },
+       {
+               .desc = "Different Clock Frequency for smaller h_total and v_total",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 300,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 1280,
+                                       .v_addressable = 600,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 1280,
+                                                       .v_total = 720,
+                                                       .v_addressable = 600,
+                                                       .v_front_porch = 4,
+                                                       .pix_clk_100hz = 1866743,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 1280,
+                                       .v_total = 720,
+                                       .v_addressable = 600,
+                                       .pix_clk_100hz = 2100800,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 1477,
+               .max_vtotal_supported = 9954,
+       },
+       {
+               .desc = "Different Clock Frequency for approximately 1920x1080",
+               .dc = &(struct dc) {
+                       .caps = {
+                               .subvp_prefetch_end_to_mall_start_us = 0,
+                       }
+               },
+               .subvp_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 1920,
+                                       .v_addressable = 1000,
+                                       .pix_clk_100hz = 1855800,
+                               },
+                               .mall_stream_config = {
+                                       .paired_stream = &(struct dc_stream_state) {
+                                               .timing = {
+                                                       .h_total = 1911,
+                                                       .v_total = 1080,
+                                                       .v_addressable = 1000,
+                                                       .v_front_porch = 7,
+                                                       .pix_clk_100hz = 1866743,
+                                               },
+                                       },
+                               },
+                       },
+               },
+               .vblank_pipe = &(struct pipe_ctx) {
+                       .stream = &(struct dc_stream_state) {
+                               .timing = {
+                                       .h_total = 1280,
+                                       .v_total = 720,
+                                       .v_addressable = 600,
+                                       .pix_clk_100hz = 2100800,
+                               },
+                       },
+               },
+               .drr_in_use = true,
+               .use_ramping = false,
+               .drr_window_size_ms = 4,
+               .min_vtotal_supported = 2482,
+               .max_vtotal_supported = 8971,
+       },
+};
+
+static void populate_subvp_cmd_drr_info_test_to_desc(struct
+               populate_subvp_cmd_drr_info_test_case * t, char *desc)
+{
+       strcpy(desc, t->desc);
+}
+
+KUNIT_ARRAY_PARAM(populate_subvp_cmd_drr_info, populate_subvp_cmd_drr_info_cases,
+                 populate_subvp_cmd_drr_info_test_to_desc);
+
+static void populate_subvp_cmd_drr_info_test(struct kunit *test)
+{

drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c line 261

Quoted 10 lines
drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c new file +10 -0
+       const struct populate_subvp_cmd_drr_info_test_case *test_param =
+               test->param_value;
+       struct dmub_cmd_fw_assisted_mclk_switch_pipe_data_v2 *pipe_data;
+
+       pipe_data = kunit_kzalloc(test,
+                                 sizeof(struct dmub_cmd_fw_assisted_mclk_switch_pipe_data_v2),
+                                 GFP_KERNEL);
+
+       populate_subvp_cmd_drr_info(test_param->dc, test_param->subvp_pipe,
+                                   test_param->vblank_pipe, pipe_data);

Should this be hidden behind an #ifdef CONFIG_DRM_AMD_DC_DCN

Otherwise, there are build issues under UML:
../drivers/gpu/drm/amd/amdgpu/../display/dc/../tests/dc/dc_dmub_srv_test.c:
In function ‘populate_subvp_cmd_drr_info_test’:
../drivers/gpu/drm/amd/amdgpu/../display/dc/../tests/dc/dc_dmub_srv_test.c:260:9:
error: implicit declaration of function ‘populate_subvp_cmd_drr_info’; did you mean ‘populate_subvp_cmd_drr_info_test’? [-Werror =implicit-function-declaration]
260 | populate_subvp_cmd_drr_info(test_param->dc,
test_param->subvp_pipe,

      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      |         populate_subvp_cmd_drr_info_test

cc1: some warnings being treated as errors
make[5]: *** [../scripts/Makefile.build:249:
drivers/gpu/drm/amd/amdgpu/../display/dc/dc_dmub_srv.o] Error 1

Quoted 9 lines
Quoted 3 lines

Making the test skip itself if this isn't enabled worked fine here.

Currently, we don't support UML as there are some build problems on AMDGPU. You can apply the patch that I sent previously to run the tests with UML, and this warning will not happen anymore, but for now, the tests will work properly only on x86_64.

Fair enough: I definitely don't expect these all to work perfectly on UML (particularly in v1).

Quoted 4 lines

Moreover, I don't know if it is worth adding an #ifdef CONFIG_DRM_AMD_DC_DCN on all the functions, as most of the functions that we are testing are built under CONFIG_DRM_AMD_DC_DCN.

Even if it's not worth explicitly #ifdef-ing around individual tests which use this, it's definitely important to make sure this test code is behind some sort of dependency on CONFIG_DRM_AMD_DC_DCN. It shouldn't be possible to create a valid .config which will cause a compile error here. (It breaks, for example, randconfig builds.)

Could we at least have a "depends on" in the Kconfig, so that it's not possible to create a broken config?

Cheers,
-- David

#17 lore raw

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

In reply to Tales Aparecida

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       | 73 +++++++++++++++++++
 Documentation/gpu/amdgpu/display/index.rst    |  1 +
 2 files changed, 74 insertions(+)
 create mode 100644 Documentation/gpu/amdgpu/display/display-test.rst
Documentation/gpu/amdgpu/display/display-test.rst new file +73 -0
new file mode 100644
index 000000000000..f2eb8e3213ea
@@ -0,0 +1,73 @@
+.. 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_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_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:
+
+.. code-block:: c
+
+	#ifdef CONFIG_MY_KUNIT_TEST
+	#include "my_kunit_test.c"
+	#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 c1fb2fb3c710..4f4e72e3e75f 100644
@@ -28,4 +28,5 @@ table of content:
    display-manager.rst
    dc-debug.rst
    dcn-overview.rst
+   display-test.rst
    dc-glossary.rst
Signature · 1 line
2.37.0
maintainer
#18 lore raw
In reply to Tales Aparecida

Am 11.08.22 um 02:40 schrieb Tales Aparecida:

Quoted 23 lines

Hello,

This series is the consolidation of an RFC sent earlier this year [RFC] bringing unit testing to the AMDPGU driver. [gsoc]

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[kunit_tool] provides ease of use, but we are also working on integrating KUnit into IGT, for those already depending on the tool [igt_patch].

Quoted 8 lines

We've chosen what we believe to be the simplest approach to integrate KUnit tests into amdgpu [kunit_static]. We took 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. Further than that, this approach also helps beginners by avoiding the need to edit any Makefiles. Other approaches are available and we would gladly receive feedback on this matter.

Yeah, that approach immediately trigger goosebumps for me. We should absolutely not do that.

The static functions are subject to change and we shouldn't need to change the unit tests when only the internals change.

Instead black box testing and/or exposing tests as a separate module (e.g. for the fixed point calculations for example) is probably the way to go.

Just my thoughts on this, essentially our display team has to take a look.

Regards,
Christian.

Quoted 146 lines

The first three patches add KUnit represent what we intend to do on 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 [dcn20_bug] later fixed by 9ad5d02c2a [dcn20_fix].

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

Applying this series on top of the amd-staging-drm-next (2305916dca04) and running its tests will result in a failure in the dc_dmub_srv test, you can verify that with:

$ ./tools/testing/kunit/kunit.py run --arch=x86_64 \
		--kunitconfig=drivers/gpu/drm/amd/display/tests
```
...
[20:19:00] # Subtest: populate_subvp_cmd_drr_info_test
[20:19:00] # populate_subvp_cmd_drr_info_test: pass:0 fail:5 skip:0 total:5
[20:19:00] not ok 1 - populate_subvp_cmd_drr_info_test
[20:19:00] ======== [FAILED] populate_subvp_cmd_drr_info_test =========
[20:19:00] # Subtest: dc_dmub_srv
[20:19:00] 1..1
[20:19:00] # Totals: pass:0 fail:5 skip:0 total:5
[20:19:00] not ok 8 - dc_dmub_srv
[20:19:00] =================== [FAILED] dc_dmub_srv ===================
[20:19:00] ============================================================
[20:19:00] Testing complete. Passed: 59, Failed: 5, Crashed: 0, Skipped: 0, Errors: 0
```

Full output at: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fshare.riseup.net%2F%23SOggjANeLfbibdiHu2e_Ug&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=kiaq3dfpSMiFGkMIXKHhHsMyr7o%2FuvKgny0ifF%2FzrmA%3D&amp;reserved=0

This is due to a known regression introduced by commit 5da7f4134357 ("drm/amd/display: fix 32 bit compilation errors in dc_dmub_srv.c") [dmub_bug], which resulted in the struct's members being zero. As an exercise, you can revert the offending patch and run the tests again, but that would still result in failure, albeit with a different output.

Full output when reverted: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fshare.riseup.net%2F%23EEBgtgXjAmof5vZ_qs7_sg&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=%2Flv%2FAOosByeD8vPteKdqGqv2QHf50S6nTNTqma91fm8%3D&amp;reserved=0

This regression is currently being worked on [dmub_fix], and this test-series will result in a success if applied alongside the fix-series, particularly the patches 1-13/32.

```
[17:48:14] Testing complete. Passed: 64, Failed: 0, Crashed: 0, Skipped: 0, Errors: 0
```

Full successful output: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fshare.riseup.net%2F%23migyN1Xpy3Gyq1it84HhNw&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=zMOuzPypnx6oH9rMUYZwLpHELZd%2FaId4Tdh93LRr8bM%3D&amp;reserved=0

This series depends on a couple of Kunit patches already merged into torvalds/master, which themselves depends on older patches:

commit 61695f8c5d51 ("kunit: split resource API from test.h into new resource.h") commit 2852ca7fba9f ("panic: Taint kernel if tests are run")
commit cfc1d277891e ("module: Move all into module/")
commit cdebea6968fa ("kunit: split resource API impl from test.c into new resource.c") commit cae56e1740f5 ("kunit: rename print_subtest_{start,end} for clarity (s/subtest/suite)") commit 1cdba21db2ca ("kunit: add ability to specify suite-level init and exit functions") commit c272612cb4a2 ("kunit: Taint the kernel when KUnit tests are run") commit 3d6e44623841 ("kunit: unify module and builtin suite definitions") commit a02353f49162 ("kunit: bail out of test filtering logic quicker if OOM") commit 1b11063d32d7 ("kunit: fix executor OOM error handling logic on non-UML") commit e5857d396f35 ("kunit: flatten kunit_suite*** to kunit_suite** in .kunit_test_suites") commit 94681e289bf5 ("kunit: executor: Fix a memory leak on failure in kunit_filter_tests")

You can get a for branch ready for compilation at
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fisinyaaa%2Flinux%2F-%2Ftags%2Fintroduce-kunit-for-amd-v1&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=hqIFUFjM1UDOTXYsckuoLP9nyxAvlVB4iCMs8FWkGnc%3D&amp;reserved=0

Thanks in advance for your time taking a look and sending any feedback!

Best regards,
Isabella Basso, Magali Lemes, Maíra Canal, and Tales Aparecida

[RFC] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220608010709.272962-1-maira.canal%40usp.br%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=XEk%2FNJacxlhjCymXuo3tVQHle9MtiSCKIOXyP%2B4Pa3M%3D&amp;reserved=0
[gsoc] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsummerofcode.withgoogle.com%2Fprograms%2F2022%2Forganizations%2Fxorg-foundation&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=ZxjFnl5bjczfWxzpHOEKDU314QS4hmbIxTgvjPxqmJs%3D&amp;reserved=0
[kunit_tool] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kernel.org%2Fdoc%2Fhtml%2Flatest%2Fdev-tools%2Fkunit%2Fkunit-tool.html&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=0jUQGUFKW8BVVgpD4sNkkLdqMn23X1S67y7Fj0RqZKY%3D&amp;reserved=0
[igt_patch] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Farchives%2Figt-dev%2F2022-June%2F042895.html&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=JmOfrDfQIWohsDCg%2F1BLyFckeG1CWfmM3NPwcpE5WFQ%3D&amp;reserved=0
[kunit_static] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.kernel.org%2Fdev-tools%2Fkunit%2Fusage.html%23testing-static-functions&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=IWA0KRuA1T3YCZIpq9JD8wTxE8gTZi%2B9aLJywU1Os4k%3D&amp;reserved=0
[dcn20_bug] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220603185042.3408844-6-Rodrigo.Siqueira%40amd.com%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=b7B7QscRHX2STfVGRiE09RxYSvZTDLW59vi7lQTPrM0%3D&amp;reserved=0
[dcn20_fix] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220608164856.1870594-1-sunpeng.li%40amd.com%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=yQR9AxoguAvVR%2BGni9GUhSdhgHKujcUXujFL30QZqAc%3D&amp;reserved=0
[dmub_bug] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220708052650.1029150-1-alexander.deucher%40amd.com%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=WUb4zaBIhOd8oAjmcn19itKTbulUFepGfAtY%2FWLmrq8%3D&amp;reserved=0
[dmub_fix] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220805175826.2992171-14-chiahsuan.chung%40amd.com%2FT%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752285150231%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=Z4AWumNHtXuHo8h7%2Fh%2Bdd0VqBQeywtbaD35pCKs0neQ%3D&amp;reserved=0

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       |  73 ++
  Documentation/gpu/amdgpu/display/index.rst    |   1 +
  drivers/gpu/drm/amd/display/Kconfig           |  25 +
  .../drm/amd/display/dc/basics/fixpt31_32.c    |   5 +
  drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |   4 +
  .../drm/amd/display/dc/dml/calcs/bw_fixed.c   |   3 +
  .../drm/amd/display/dc/dml/dcn20/dcn20_fpu.c  |   4 +
  .../dc/dml/dcn20/display_mode_vba_20.c        |   4 +
  .../dc/dml/dcn20/display_rq_dlg_calc_20.c     |   4 +
  .../drm/amd/display/dc/dml/display_mode_vba.c |   3 +
  .../gpu/drm/amd/display/tests/.kunitconfig    |   7 +
  .../dc/basics/dc_basics_fixpt31_32_test.c     | 232 ++++++
  .../amd/display/tests/dc/dc_dmub_srv_test.c   | 285 +++++++
  .../tests/dc/dml/calcs/bw_fixed_test.c        | 323 ++++++++
  .../tests/dc/dml/dcn20/dcn20_fpu_test.c       | 560 +++++++++++++
  .../dc/dml/dcn20/display_mode_vba_20_test.c   | 227 ++++++
  .../dml/dcn20/display_rq_dlg_calc_20_test.c   | 112 +++
  .../tests/dc/dml/display_mode_vba_test.c      | 741 ++++++++++++++++++
  18 files changed, 2613 insertions(+)

create mode 100644 Documentation/gpu/amdgpu/display/display-test.rst
create mode 100644 drivers/gpu/drm/amd/display/tests/.kunitconfig
create mode 100644 drivers/gpu/drm/amd/display/tests/dc/basics/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

base-commit: 2305916dca043ed69bd464f74a886b0216780aa6
prerequisite-patch-id: 83185f6c5da6070e7b0b608bc705a2d3bf295ae6
prerequisite-patch-id: 65407777e3bb20dfe5051f4f4cc7deb6a3c2ed34
prerequisite-patch-id: 60af3dadcfd4a778f10dd09fafbde6061d98528b
prerequisite-patch-id: 92d9259125f2982da5945be995b4ae2af1ca7c32
prerequisite-patch-id: f35acb6c07c0bd5496df919214351399d9aed5b5
prerequisite-patch-id: 8a9637d89966e51adfe11e3fd3d17fcf1328b472
prerequisite-patch-id: ea6f40f1cfb61fddb9d1562111897e184da49bf7
prerequisite-patch-id: ae79651ae7b2e02520b18fc7eded463afea757e5
prerequisite-patch-id: ba795b981f3e94890540f452e658e28408b500d2
prerequisite-patch-id: abd5e51f483a9afb08af468db043e2ebc7ce6867
prerequisite-patch-id: a31028824a461f8b4a6b9244035e246efbee9c71
prerequisite-patch-id: a65dfe200981f8584ba3b1f9813faa4f0022a13e

#19 lore raw
Quoted 35 lines · Christian König

Am 11.08.22 um 02:40 schrieb Tales Aparecida:

Quoted 23 lines

Hello,

This series is the consolidation of an RFC sent earlier this year [RFC] bringing unit testing to the AMDPGU driver. [gsoc]

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[kunit_tool] provides ease of use, but we are also working on integrating KUnit into IGT, for those already depending on the tool [igt_patch].

Quoted 8 lines

We've chosen what we believe to be the simplest approach to integrate KUnit tests into amdgpu [kunit_static]. We took 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. Further than that, this approach also helps beginners by avoiding the need to edit any Makefiles. Other approaches are available and we would gladly receive feedback on this matter.

Quoted 3 lines

Yeah, that approach immediately trigger goosebumps for me. We should absolutely not do that.

The static functions are subject to change and we shouldn't need to change the unit tests when only the internals change.

I agree with you that ideally, we should not test static functions. But, considering the scope of the AMD Display Core functions, it is pretty hard to avoid it.

Most of the exposed functions on the AMD Display Core have dozens of side effects and some functions pass the 500 lines. In this sense, it is pretty hard to write a proper unit test for the function. If we think through the theory of equivalence partition, when we have two parameters, we have a simple area to analyze the boundary values and the partition. If we have more than 4 parameters, we have a hyperplane with dimension n to analyze, which means that finding the partitions and the boundary values gets harder and harder.

In the Display Core, there are static functions with more than 50 parameters and the exposed functions call more the one static function, so we might be analyzing more than 100 parameters, which I don't believe is possible for a unit test.

In theory, I agree that we should not test the static functions. But, considering the current scope of the AMD Display code, I don't believe it is viable to test on the exposed functions.

Best Regards,
- Maíra Canal

Quoted 169 lines

Instead black box testing and/or exposing tests as a separate module (e.g. for the fixed point calculations for example) is probably the way to go.

Just my thoughts on this, essentially our display team has to take a look.

Regards,
Christian.

Quoted 160 lines

The first three patches add KUnit represent what we intend to do on 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 [dcn20_bug] later fixed by 9ad5d02c2a [dcn20_fix].

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

Applying this series on top of the amd-staging-drm-next (2305916dca04) and running its tests will result in a failure in the dc_dmub_srv test, you can verify that with:

$ ./tools/testing/kunit/kunit.py run --arch=x86_64 \
        --kunitconfig=drivers/gpu/drm/amd/display/tests
```
...
[20:19:00] # Subtest: populate_subvp_cmd_drr_info_test
[20:19:00] # populate_subvp_cmd_drr_info_test: pass:0 fail:5 skip:0 total:5
[20:19:00] not ok 1 - populate_subvp_cmd_drr_info_test
[20:19:00] ======== [FAILED] populate_subvp_cmd_drr_info_test =========
[20:19:00] # Subtest: dc_dmub_srv
[20:19:00] 1..1
[20:19:00] # Totals: pass:0 fail:5 skip:0 total:5
[20:19:00] not ok 8 - dc_dmub_srv
[20:19:00] =================== [FAILED] dc_dmub_srv ===================
[20:19:00] ============================================================
[20:19:00] Testing complete. Passed: 59, Failed: 5, Crashed: 0, Skipped: 0, Errors: 0
```

Full output at: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fshare.riseup.net%2F%23SOggjANeLfbibdiHu2e_Ug&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=kiaq3dfpSMiFGkMIXKHhHsMyr7o%2FuvKgny0ifF%2FzrmA%3D&amp;reserved=0

This is due to a known regression introduced by commit 5da7f4134357 ("drm/amd/display: fix 32 bit compilation errors in dc_dmub_srv.c") [dmub_bug], which resulted in the struct's members being zero.  As an exercise, you can revert the offending patch and run the tests again, but that would still result in failure, albeit with a different output.

Full output when reverted: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fshare.riseup.net%2F%23EEBgtgXjAmof5vZ_qs7_sg&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=%2Flv%2FAOosByeD8vPteKdqGqv2QHf50S6nTNTqma91fm8%3D&amp;reserved=0

This regression is currently being worked on [dmub_fix], and this test-series will result in a success if applied alongside the fix-series, particularly the patches 1-13/32.

```
[17:48:14] Testing complete. Passed: 64, Failed: 0, Crashed: 0, Skipped: 0, Errors: 0
```

Full successful output: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fshare.riseup.net%2F%23migyN1Xpy3Gyq1it84HhNw&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=zMOuzPypnx6oH9rMUYZwLpHELZd%2FaId4Tdh93LRr8bM%3D&amp;reserved=0

This series depends on a couple of Kunit patches already merged into torvalds/master, which themselves depends on older patches:

commit 61695f8c5d51 ("kunit: split resource API from test.h into new resource.h") commit 2852ca7fba9f ("panic: Taint kernel if tests are run")
commit cfc1d277891e ("module: Move all into module/")
commit cdebea6968fa ("kunit: split resource API impl from test.c into new resource.c") commit cae56e1740f5 ("kunit: rename print_subtest_{start,end} for clarity (s/subtest/suite)") commit 1cdba21db2ca ("kunit: add ability to specify suite-level init and exit functions") commit c272612cb4a2 ("kunit: Taint the kernel when KUnit tests are run") commit 3d6e44623841 ("kunit: unify module and builtin suite definitions") commit a02353f49162 ("kunit: bail out of test filtering logic quicker if OOM") commit 1b11063d32d7 ("kunit: fix executor OOM error handling logic on non-UML") commit e5857d396f35 ("kunit: flatten kunit_suite*** to kunit_suite** in .kunit_test_suites") commit 94681e289bf5 ("kunit: executor: Fix a memory leak on failure in kunit_filter_tests")

You can get a for branch ready for compilation at
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fisinyaaa%2Flinux%2F-%2Ftags%2Fintroduce-kunit-for-amd-v1&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=hqIFUFjM1UDOTXYsckuoLP9nyxAvlVB4iCMs8FWkGnc%3D&amp;reserved=0

Thanks in advance for your time taking a look and sending any feedback!

Best regards,
Isabella Basso, Magali Lemes, Maíra Canal, and Tales Aparecida

[RFC] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220608010709.272962-1-maira.canal%40usp.br%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=XEk%2FNJacxlhjCymXuo3tVQHle9MtiSCKIOXyP%2B4Pa3M%3D&amp;reserved=0

[gsoc] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsummerofcode.withgoogle.com%2Fprograms%2F2022%2Forganizations%2Fxorg-foundation&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=ZxjFnl5bjczfWxzpHOEKDU314QS4hmbIxTgvjPxqmJs%3D&amp;reserved=0

[kunit_tool] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kernel.org%2Fdoc%2Fhtml%2Flatest%2Fdev-tools%2Fkunit%2Fkunit-tool.html&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=0jUQGUFKW8BVVgpD4sNkkLdqMn23X1S67y7Fj0RqZKY%3D&amp;reserved=0

[igt_patch] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Farchives%2Figt-dev%2F2022-June%2F042895.html&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=JmOfrDfQIWohsDCg%2F1BLyFckeG1CWfmM3NPwcpE5WFQ%3D&amp;reserved=0

[kunit_static] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.kernel.org%2Fdev-tools%2Fkunit%2Fusage.html%23testing-static-functions&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=IWA0KRuA1T3YCZIpq9JD8wTxE8gTZi%2B9aLJywU1Os4k%3D&amp;reserved=0

[dcn20_bug] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220603185042.3408844-6-Rodrigo.Siqueira%40amd.com%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=b7B7QscRHX2STfVGRiE09RxYSvZTDLW59vi7lQTPrM0%3D&amp;reserved=0

[dcn20_fix] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220608164856.1870594-1-sunpeng.li%40amd.com%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=yQR9AxoguAvVR%2BGni9GUhSdhgHKujcUXujFL30QZqAc%3D&amp;reserved=0

[dmub_bug] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220708052650.1029150-1-alexander.deucher%40amd.com%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=WUb4zaBIhOd8oAjmcn19itKTbulUFepGfAtY%2FWLmrq8%3D&amp;reserved=0

[dmub_fix] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220805175826.2992171-14-chiahsuan.chung%40amd.com%2FT%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752285150231%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=Z4AWumNHtXuHo8h7%2Fh%2Bdd0VqBQeywtbaD35pCKs0neQ%3D&amp;reserved=0

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       |  73 ++ Documentation/gpu/amdgpu/display/index.rst    |   1 + drivers/gpu/drm/amd/display/Kconfig           |  25 + .../drm/amd/display/dc/basics/fixpt31_32.c    |   5 + drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |   4 + .../drm/amd/display/dc/dml/calcs/bw_fixed.c   |   3 + .../drm/amd/display/dc/dml/dcn20/dcn20_fpu.c  |   4 + .../dc/dml/dcn20/display_mode_vba_20.c        |   4 + .../dc/dml/dcn20/display_rq_dlg_calc_20.c     |   4 + .../drm/amd/display/dc/dml/display_mode_vba.c |   3 + .../gpu/drm/amd/display/tests/.kunitconfig    |   7 + .../dc/basics/dc_basics_fixpt31_32_test.c     | 232 ++++++ .../amd/display/tests/dc/dc_dmub_srv_test.c   | 285 +++++++ .../tests/dc/dml/calcs/bw_fixed_test.c        | 323 ++++++++ .../tests/dc/dml/dcn20/dcn20_fpu_test.c       | 560 +++++++++++++ .../dc/dml/dcn20/display_mode_vba_20_test.c   | 227 ++++++ .../dml/dcn20/display_rq_dlg_calc_20_test.c   | 112 +++ .../tests/dc/dml/display_mode_vba_test.c      | 741 ++++++++++++++++++

  18 files changed, 2613 insertions(+)

  create mode 100644 Documentation/gpu/amdgpu/display/display-test.rst
  create mode 100644 drivers/gpu/drm/amd/display/tests/.kunitconfig
  create mode 100644 drivers/gpu/drm/amd/display/tests/dc/basics/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

base-commit: 2305916dca043ed69bd464f74a886b0216780aa6
prerequisite-patch-id: 83185f6c5da6070e7b0b608bc705a2d3bf295ae6
prerequisite-patch-id: 65407777e3bb20dfe5051f4f4cc7deb6a3c2ed34
prerequisite-patch-id: 60af3dadcfd4a778f10dd09fafbde6061d98528b
prerequisite-patch-id: 92d9259125f2982da5945be995b4ae2af1ca7c32
prerequisite-patch-id: f35acb6c07c0bd5496df919214351399d9aed5b5
prerequisite-patch-id: 8a9637d89966e51adfe11e3fd3d17fcf1328b472
prerequisite-patch-id: ea6f40f1cfb61fddb9d1562111897e184da49bf7
prerequisite-patch-id: ae79651ae7b2e02520b18fc7eded463afea757e5
prerequisite-patch-id: ba795b981f3e94890540f452e658e28408b500d2
prerequisite-patch-id: abd5e51f483a9afb08af468db043e2ebc7ce6867
prerequisite-patch-id: a31028824a461f8b4a6b9244035e246efbee9c71
prerequisite-patch-id: a65dfe200981f8584ba3b1f9813faa4f0022a13e

#20 lore raw
In reply to Christian König
Quoted 42 lines · Christian König' via KUnit Development

Am 11.08.22 um 02:40 schrieb Tales Aparecida:

Quoted 23 lines

Hello,

This series is the consolidation of an RFC sent earlier this year [RFC] bringing unit testing to the AMDPGU driver. [gsoc]

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[kunit_tool] provides ease of use, but we are also working on integrating KUnit into IGT, for those already depending on the tool [igt_patch].

Quoted 8 lines

We've chosen what we believe to be the simplest approach to integrate KUnit tests into amdgpu [kunit_static]. We took 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. Further than that, this approach also helps beginners by avoiding the need to edit any Makefiles. Other approaches are available and we would gladly receive feedback on this matter.

Yeah, that approach immediately trigger goosebumps for me. We should absolutely not do that.

The static functions are subject to change and we shouldn't need to change the unit tests when only the internals change.

Quoted 9 lines

Instead black box testing and/or exposing tests as a separate module (e.g. for the fixed point calculations for example) is probably the way to go.

Just my thoughts on this, essentially our display team has to take a look.

Regards,
Christian.

To jump in from a KUnit maintainer point-of-view, I think the need to test static functions (in at least some cases) is inevitable. Ideally, we'd have a much better way of doing so than just #include-ing the test code into the main module, but all of the other options we have around at the moment would require exporting the otherwise-static functions, which seems like a greater leap at present.

Note that one of the goals of KUnit is to allow internals and implementation details to be tested, where that makes sense. It's certainly not going to be the right thing for every case, and there is the overhead of having to update tests when refactoring or otherwise changing the internals, but the benefit of being able to isolate exactly the calculation / function/ etc. which needs to be verified is often worth these costs.

That being said, there's no reason all of the AMDGPU tests would need to take the same approach, and if, e.g., including the fixed-point code in a separate test module makes more sense there, I don't think there's anything that'd prevent you from doing that. (And having tests in independent modules is definitely preferable where it's practical to do so.)

Cheers,
-- David-

Quoted 151 lines
Quoted 133 lines

The first three patches add KUnit represent what we intend to do on 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 [dcn20_bug] later fixed by 9ad5d02c2a [dcn20_fix].

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

Applying this series on top of the amd-staging-drm-next (2305916dca04) and running its tests will result in a failure in the dc_dmub_srv test, you can verify that with:

$ ./tools/testing/kunit/kunit.py run --arch=x86_64 \
              --kunitconfig=drivers/gpu/drm/amd/display/tests
```
...
[20:19:00] # Subtest: populate_subvp_cmd_drr_info_test
[20:19:00] # populate_subvp_cmd_drr_info_test: pass:0 fail:5 skip:0 total:5
[20:19:00] not ok 1 - populate_subvp_cmd_drr_info_test
[20:19:00] ======== [FAILED] populate_subvp_cmd_drr_info_test =========
[20:19:00] # Subtest: dc_dmub_srv
[20:19:00] 1..1
[20:19:00] # Totals: pass:0 fail:5 skip:0 total:5
[20:19:00] not ok 8 - dc_dmub_srv
[20:19:00] =================== [FAILED] dc_dmub_srv ===================
[20:19:00] ============================================================
[20:19:00] Testing complete. Passed: 59, Failed: 5, Crashed: 0, Skipped: 0, Errors: 0
```

Full output at: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fshare.riseup.net%2F%23SOggjANeLfbibdiHu2e_Ug&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=kiaq3dfpSMiFGkMIXKHhHsMyr7o%2FuvKgny0ifF%2FzrmA%3D&amp;reserved=0

This is due to a known regression introduced by commit 5da7f4134357 ("drm/amd/display: fix 32 bit compilation errors in dc_dmub_srv.c") [dmub_bug], which resulted in the struct's members being zero. As an exercise, you can revert the offending patch and run the tests again, but that would still result in failure, albeit with a different output.

Full output when reverted: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fshare.riseup.net%2F%23EEBgtgXjAmof5vZ_qs7_sg&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=%2Flv%2FAOosByeD8vPteKdqGqv2QHf50S6nTNTqma91fm8%3D&amp;reserved=0

This regression is currently being worked on [dmub_fix], and this test-series will result in a success if applied alongside the fix-series, particularly the patches 1-13/32.

```
[17:48:14] Testing complete. Passed: 64, Failed: 0, Crashed: 0, Skipped: 0, Errors: 0
```

Full successful output: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fshare.riseup.net%2F%23migyN1Xpy3Gyq1it84HhNw&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=zMOuzPypnx6oH9rMUYZwLpHELZd%2FaId4Tdh93LRr8bM%3D&amp;reserved=0

This series depends on a couple of Kunit patches already merged into torvalds/master, which themselves depends on older patches:

commit 61695f8c5d51 ("kunit: split resource API from test.h into new resource.h") commit 2852ca7fba9f ("panic: Taint kernel if tests are run")
commit cfc1d277891e ("module: Move all into module/")
commit cdebea6968fa ("kunit: split resource API impl from test.c into new resource.c") commit cae56e1740f5 ("kunit: rename print_subtest_{start,end} for clarity (s/subtest/suite)") commit 1cdba21db2ca ("kunit: add ability to specify suite-level init and exit functions") commit c272612cb4a2 ("kunit: Taint the kernel when KUnit tests are run") commit 3d6e44623841 ("kunit: unify module and builtin suite definitions") commit a02353f49162 ("kunit: bail out of test filtering logic quicker if OOM") commit 1b11063d32d7 ("kunit: fix executor OOM error handling logic on non-UML") commit e5857d396f35 ("kunit: flatten kunit_suite*** to kunit_suite** in .kunit_test_suites") commit 94681e289bf5 ("kunit: executor: Fix a memory leak on failure in kunit_filter_tests")

You can get a for branch ready for compilation at
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fisinyaaa%2Flinux%2F-%2Ftags%2Fintroduce-kunit-for-amd-v1&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=hqIFUFjM1UDOTXYsckuoLP9nyxAvlVB4iCMs8FWkGnc%3D&amp;reserved=0

Thanks in advance for your time taking a look and sending any feedback!

Best regards,
Isabella Basso, Magali Lemes, Maíra Canal, and Tales Aparecida

[RFC] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220608010709.272962-1-maira.canal%40usp.br%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=XEk%2FNJacxlhjCymXuo3tVQHle9MtiSCKIOXyP%2B4Pa3M%3D&amp;reserved=0
[gsoc] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsummerofcode.withgoogle.com%2Fprograms%2F2022%2Forganizations%2Fxorg-foundation&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=ZxjFnl5bjczfWxzpHOEKDU314QS4hmbIxTgvjPxqmJs%3D&amp;reserved=0
[kunit_tool] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kernel.org%2Fdoc%2Fhtml%2Flatest%2Fdev-tools%2Fkunit%2Fkunit-tool.html&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=0jUQGUFKW8BVVgpD4sNkkLdqMn23X1S67y7Fj0RqZKY%3D&amp;reserved=0
[igt_patch] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Farchives%2Figt-dev%2F2022-June%2F042895.html&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=JmOfrDfQIWohsDCg%2F1BLyFckeG1CWfmM3NPwcpE5WFQ%3D&amp;reserved=0
[kunit_static] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.kernel.org%2Fdev-tools%2Fkunit%2Fusage.html%23testing-static-functions&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=IWA0KRuA1T3YCZIpq9JD8wTxE8gTZi%2B9aLJywU1Os4k%3D&amp;reserved=0
[dcn20_bug] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220603185042.3408844-6-Rodrigo.Siqueira%40amd.com%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=b7B7QscRHX2STfVGRiE09RxYSvZTDLW59vi7lQTPrM0%3D&amp;reserved=0
[dcn20_fix] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220608164856.1870594-1-sunpeng.li%40amd.com%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=yQR9AxoguAvVR%2BGni9GUhSdhgHKujcUXujFL30QZqAc%3D&amp;reserved=0
[dmub_bug] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220708052650.1029150-1-alexander.deucher%40amd.com%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752284993982%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=WUb4zaBIhOd8oAjmcn19itKTbulUFepGfAtY%2FWLmrq8%3D&amp;reserved=0
[dmub_fix] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Famd-gfx%2F20220805175826.2992171-14-chiahsuan.chung%40amd.com%2FT%2F&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7Cb44787cd3628425b078d08da7b3213c7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637957752285150231%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=Z4AWumNHtXuHo8h7%2Fh%2Bdd0VqBQeywtbaD35pCKs0neQ%3D&amp;reserved=0

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       |  73 ++
  Documentation/gpu/amdgpu/display/index.rst    |   1 +
  drivers/gpu/drm/amd/display/Kconfig           |  25 +
  .../drm/amd/display/dc/basics/fixpt31_32.c    |   5 +
  drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c  |   4 +
  .../drm/amd/display/dc/dml/calcs/bw_fixed.c   |   3 +
  .../drm/amd/display/dc/dml/dcn20/dcn20_fpu.c  |   4 +
  .../dc/dml/dcn20/display_mode_vba_20.c        |   4 +
  .../dc/dml/dcn20/display_rq_dlg_calc_20.c     |   4 +
  .../drm/amd/display/dc/dml/display_mode_vba.c |   3 +
  .../gpu/drm/amd/display/tests/.kunitconfig    |   7 +
  .../dc/basics/dc_basics_fixpt31_32_test.c     | 232 ++++++
  .../amd/display/tests/dc/dc_dmub_srv_test.c   | 285 +++++++
  .../tests/dc/dml/calcs/bw_fixed_test.c        | 323 ++++++++
  .../tests/dc/dml/dcn20/dcn20_fpu_test.c       | 560 +++++++++++++
  .../dc/dml/dcn20/display_mode_vba_20_test.c   | 227 ++++++
  .../dml/dcn20/display_rq_dlg_calc_20_test.c   | 112 +++
  .../tests/dc/dml/display_mode_vba_test.c      | 741 ++++++++++++++++++
  18 files changed, 2613 insertions(+)

create mode 100644 Documentation/gpu/amdgpu/display/display-test.rst
create mode 100644 drivers/gpu/drm/amd/display/tests/.kunitconfig
create mode 100644 drivers/gpu/drm/amd/display/tests/dc/basics/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

Quoted 13 lines

base-commit: 2305916dca043ed69bd464f74a886b0216780aa6
prerequisite-patch-id: 83185f6c5da6070e7b0b608bc705a2d3bf295ae6
prerequisite-patch-id: 65407777e3bb20dfe5051f4f4cc7deb6a3c2ed34
prerequisite-patch-id: 60af3dadcfd4a778f10dd09fafbde6061d98528b
prerequisite-patch-id: 92d9259125f2982da5945be995b4ae2af1ca7c32
prerequisite-patch-id: f35acb6c07c0bd5496df919214351399d9aed5b5
prerequisite-patch-id: 8a9637d89966e51adfe11e3fd3d17fcf1328b472
prerequisite-patch-id: ea6f40f1cfb61fddb9d1562111897e184da49bf7
prerequisite-patch-id: ae79651ae7b2e02520b18fc7eded463afea757e5
prerequisite-patch-id: ba795b981f3e94890540f452e658e28408b500d2
prerequisite-patch-id: abd5e51f483a9afb08af468db043e2ebc7ce6867
prerequisite-patch-id: a31028824a461f8b4a6b9244035e246efbee9c71
prerequisite-patch-id: a65dfe200981f8584ba3b1f9813faa4f0022a13e

--
You received this message because you are subscribed to the Google Groups "KUnit Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/6d24ac92-7ea9-0c35-a97a-bfb53b84f655%40amd.com.