[PATCH 0/8] drm/amd/display: Introduce KUnit to Display Mode Library

10 views
Skip to first unread message

Tales Aparecida

unread,
Aug 10, 2022, 8:40:24 PM8/10/22
to Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, kuni...@googlegroups.com, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, maira...@riseup.net, Isabella Basso, magali...@gmail.com, tales.a...@gmail.com
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/20220608010709.27...@usp.br/
[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/20220603185042.34088...@amd.com/
[dcn20_fix] https://lore.kernel.org/amd-gfx/20220608164856.18...@amd.com/
[dmub_bug] https://lore.kernel.org/amd-gfx/20220708052650.102915...@amd.com/
[dmub_fix] https://lore.kernel.org/amd-gfx/20220805175826.29921...@amd.com/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
--
2.37.0

Tales Aparecida

unread,
Aug 10, 2022, 8:40:28 PM8/10/22
to Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, kuni...@googlegroups.com, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, maira...@riseup.net, Isabella Basso, magali...@gmail.com, tales.a...@gmail.com
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/

Signed-off-by: Tales Aparecida <tales.a...@gmail.com>
---
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

diff --git a/drivers/gpu/drm/amd/display/Kconfig b/drivers/gpu/drm/amd/display/Kconfig
index 96cbc87f7b6b..27981ccb7032 100644
--- a/drivers/gpu/drm/amd/display/Kconfig
+++ b/drivers/gpu/drm/amd/display/Kconfig
@@ -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
diff --git a/drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c b/drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c
index 1726bdf89bae..82747d8ab95a 100644
--- a/drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c
+++ b/drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c
@@ -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
+
diff --git a/drivers/gpu/drm/amd/display/tests/.kunitconfig b/drivers/gpu/drm/amd/display/tests/.kunitconfig
new file mode 100644
index 000000000000..60f2ff8158f5
--- /dev/null
+++ b/drivers/gpu/drm/amd/display/tests/.kunitconfig
@@ -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
diff --git a/drivers/gpu/drm/amd/display/tests/dc/basics/dc_basics_fixpt31_32_test.c b/drivers/gpu/drm/amd/display/tests/dc/basics/dc_basics_fixpt31_32_test.c
new file mode 100644
index 000000000000..2fc489203499
--- /dev/null
+++ b/drivers/gpu/drm/amd/display/tests/dc/basics/dc_basics_fixpt31_32_test.c
@@ -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 <tales.a...@gmail.com>
+ */
+
+#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);
+
+ 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 */
+}
+
+/**
+ * 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

Tales Aparecida

unread,
Aug 10, 2022, 8:40:34 PM8/10/22
to Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, kuni...@googlegroups.com, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, maira...@riseup.net, Isabella Basso, magali...@gmail.com, tales.a...@gmail.com, Maíra Canal
From: Maíra Canal <maira...@usp.br>

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/

Signed-off-by: Maíra Canal <maira...@usp.br>
Co-developed-by: Magali Lemes <magali...@gmail.com>
Signed-off-by: Magali Lemes <magali...@gmail.com>
Co-developed-by: Tales Aparecida <tales.a...@gmail.com>
Signed-off-by: Tales Aparecida <tales.a...@gmail.com>
---
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

diff --git a/drivers/gpu/drm/amd/display/Kconfig b/drivers/gpu/drm/amd/display/Kconfig
index 27981ccb7032..72e7a63da79f 100644
--- a/drivers/gpu/drm/amd/display/Kconfig
+++ b/drivers/gpu/drm/amd/display/Kconfig
@@ -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
diff --git a/drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c b/drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c
index 6ca288fb5fb9..fbe8d0661396 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c
@@ -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
diff --git a/drivers/gpu/drm/amd/display/tests/.kunitconfig b/drivers/gpu/drm/amd/display/tests/.kunitconfig
index 60f2ff8158f5..dd52cae852d2 100644
--- a/drivers/gpu/drm/amd/display/tests/.kunitconfig
+++ b/drivers/gpu/drm/amd/display/tests/.kunitconfig
@@ -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
diff --git a/drivers/gpu/drm/amd/display/tests/dc/dml/calcs/bw_fixed_test.c b/drivers/gpu/drm/amd/display/tests/dc/dml/calcs/bw_fixed_test.c
new file mode 100644
index 000000000000..1369da49f444
--- /dev/null
+++ b/drivers/gpu/drm/amd/display/tests/dc/dml/calcs/bw_fixed_test.c
@@ -0,0 +1,323 @@
+// SPDX-License-Identifier: MIT
+/*
+ * KUnit tests for dml/calcs/bw_fixed.h
+ *
+ * Copyright (C) 2022, Magali Lemes <magali...@gmail.com>
+ * Copyright (C) 2022, Maíra Canal <maira...@riseup.net>
+ * Copyright (C) 2022, Tales Aparecida <tales.a...@gmail.com>
+ */
+
+#include <kunit/test.h>
+#include <drm/drm_util.h>
+#include "bw_fixed.h"
+
+/**
+ * DOC: Unit tests for AMDGPU DML calcs/bw_fixed.h
+ *
+ * bw_fixed.h performs a lot of the mathematical operations involving
+ * fixed-point arithmetic and the conversion of integers to fixed-point
+ * representation.
+ *
+ * As fixed-point representation is the base foundation of the DML calcs
+ * operations, these 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.
+ *
+ */
+
+/**
+ * abs_i64_test - KUnit test for abs_i64
+ * @test: represents a running instance of a test.
+ */
+static void abs_i64_test(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test, 0ULL, abs_i64(0LL));
+
+ /* Argument type limits */
+ KUNIT_EXPECT_EQ(test, (uint64_t)MAX_I64, abs_i64(MAX_I64));
+ KUNIT_EXPECT_EQ(test, (uint64_t)MAX_I64 + 1, abs_i64(MIN_I64));
+}
+
+/**
+ * bw_int_to_fixed_nonconst_test - KUnit test for bw_int_to_fixed_nonconst
+ * @test: represents a running instance of a test.
+ */
+static void bw_int_to_fixed_nonconst_test(struct kunit *test)
+{
+ struct bw_fixed res;
+
+ /* Add BW_FIXED_BITS_PER_FRACTIONAL_PART trailing 0s to binary number */
+ res = bw_int_to_fixed_nonconst(1000); /* 0x3E8 */
+ KUNIT_EXPECT_EQ(test, 16777216000, res.value); /* 0x3E8000000 */
+
+ res = bw_int_to_fixed_nonconst(-1000); /* -0x3E8 */
+ KUNIT_EXPECT_EQ(test, -16777216000, res.value); /* -0x3E8000000 */
+
+ res = bw_int_to_fixed_nonconst(0LL);
+ KUNIT_EXPECT_EQ(test, 0, res.value);
+
+ /**
+ * Test corner cases, as the function's argument has to be an int64_t
+ * between BW_FIXED_MIN_I32 and BW_FIXED_MAX_I32.
+ */
+ res = bw_int_to_fixed_nonconst(BW_FIXED_MAX_I32 - 1); /* 0x7FFFFFFFFE */
+ KUNIT_EXPECT_EQ(test, 9223372036821221376, res.value); /* 0x7FFFFFFFFE000000 */
+
+ res = bw_int_to_fixed_nonconst(BW_FIXED_MIN_I32 + 1); /* -0x7FFFFFFFFF */
+ KUNIT_EXPECT_EQ(test, -9223372036837998592, res.value); /* -0x7FFFFFFFFF000000 */
+}
+
+/**
+ * bw_frc_to_fixed_test - KUnit test for bw_frc_to_fixed
+ * @test: represents a running instance of a test.
+ */
+static void bw_frc_to_fixed_test(struct kunit *test)
+{
+ struct bw_fixed res;
+
+ /* Extreme scenarios */
+
+ /* A fraction of N/N should result in "1.0" */
+ res = bw_frc_to_fixed(MAX_I64, MAX_I64);
+ KUNIT_EXPECT_EQ(test, 1LL << BW_FIXED_BITS_PER_FRACTIONAL_PART, res.value);
+
+ res = bw_frc_to_fixed(1, MAX_I64);
+ KUNIT_EXPECT_EQ(test, 0LL, res.value);
+
+ res = bw_frc_to_fixed(0, MAX_I64);
+ KUNIT_EXPECT_EQ(test, 0LL, res.value);
+
+ /* Turn a repeating decimal to the fixed-point representation */
+
+ /* A repeating decimal that doesn't round up the LSB */
+ res = bw_frc_to_fixed(4, 3);
+ KUNIT_EXPECT_EQ(test, 22369621LL, res.value); /* 0x1555555 */
+
+ res = bw_frc_to_fixed(-4, 3);
+ KUNIT_EXPECT_EQ(test, -22369621LL, res.value); /* -0x1555555 */
+
+ res = bw_frc_to_fixed(99999997, 100000000);
+ KUNIT_EXPECT_EQ(test, 16777215LL, res.value); /* 0x0FFFFFF */
+
+ /* A repeating decimal that rounds up the MSB */
+ res = bw_frc_to_fixed(5, 3);
+ KUNIT_EXPECT_EQ(test, 27962027LL, res.value); /* 0x1AAAAAB */
+
+ res = bw_frc_to_fixed(-5, 3);
+ KUNIT_EXPECT_EQ(test, -27962027LL, res.value); /* -0x1AAAAAB */
+
+ res = bw_frc_to_fixed(99999998, 100000000);
+ KUNIT_EXPECT_EQ(test, 1LL << BW_FIXED_BITS_PER_FRACTIONAL_PART, res.value);
+
+ /* Turn a terminating decimal to the fixed-point representation */
+ res = bw_frc_to_fixed(62609, 100);
+ KUNIT_EXPECT_EQ(test, 10504047165LL, res.value); /* 0X272170A3D */
+
+ res = bw_frc_to_fixed(-62609, 100);
+ KUNIT_EXPECT_EQ(test, -10504047165LL, res.value); /* -0X272170A3D */
+}
+
+/**
+ * bw_floor2_test - KUnit test for bw_floor2
+ * @test: represents a running instance of a test.
+ */
+static void bw_floor2_test(struct kunit *test)
+{
+ struct bw_fixed arg;
+ struct bw_fixed significance;
+ struct bw_fixed res;
+
+ /* Round 10 down to the nearest multiple of 3 */
+ arg.value = 10;
+ significance.value = 3;
+ res = bw_floor2(arg, significance);
+ KUNIT_EXPECT_EQ(test, 9, res.value);
+
+ /* Round 10 down to the nearest multiple of 5 */
+ arg.value = 10;
+ significance.value = 5;
+ res = bw_floor2(arg, significance);
+ KUNIT_EXPECT_EQ(test, 10, res.value);
+
+ /* Round 100 down to the nearest multiple of 7 */
+ arg.value = 100;
+ significance.value = 7;
+ res = bw_floor2(arg, significance);
+ KUNIT_EXPECT_EQ(test, 98, res.value);
+
+ /* Round an integer down to its nearest multiple should return itself */
+ arg.value = MAX_I64;
+ significance.value = MAX_I64;
+ res = bw_floor2(arg, significance);
+ KUNIT_EXPECT_EQ(test, MAX_I64, res.value);
+
+ arg.value = MIN_I64;
+ significance.value = MIN_I64;
+ res = bw_floor2(arg, significance);
+ KUNIT_EXPECT_EQ(test, MIN_I64, res.value);
+
+ /* Value is a multiple of significance, result should be value */
+ arg.value = MAX_I64;
+ significance.value = MIN_I64 + 1;
+ res = bw_floor2(arg, significance);
+ KUNIT_EXPECT_EQ(test, MAX_I64, res.value);
+
+ /* Round 0 down to the nearest multiple of any number should return 0 */
+ arg.value = 0;
+ significance.value = MAX_I64;
+ res = bw_floor2(arg, significance);
+ KUNIT_EXPECT_EQ(test, 0, res.value);
+
+ arg.value = 0;
+ significance.value = MIN_I64;
+ res = bw_floor2(arg, significance);
+ KUNIT_EXPECT_EQ(test, 0, res.value);
+}
+
+/**
+ * bw_ceil2_test - KUnit test for bw_ceil2
+ * @test: represents a running instance of a test.
+ */
+static void bw_ceil2_test(struct kunit *test)
+{
+ struct bw_fixed arg;
+ struct bw_fixed significance;
+ struct bw_fixed res;
+
+ /* Round 10 up to the nearest multiple of 3 */
+ arg.value = 10;
+ significance.value = 3;
+ res = bw_ceil2(arg, significance);
+ KUNIT_EXPECT_EQ(test, 12, res.value);
+
+ /* Round 10 up to the nearest multiple of 5 */
+ arg.value = 10;
+ significance.value = 5;
+ res = bw_ceil2(arg, significance);
+ KUNIT_EXPECT_EQ(test, 10, res.value);
+
+ /* Round 100 up to the nearest multiple of 7 */
+ arg.value = 100;
+ significance.value = 7;
+ res = bw_ceil2(arg, significance);
+ KUNIT_EXPECT_EQ(test, 105, res.value);
+
+ /* Round an integer up to its nearest multiple should return itself */
+ arg.value = MAX_I64;
+ significance.value = MAX_I64;
+ res = bw_ceil2(arg, significance);
+ KUNIT_EXPECT_EQ(test, MAX_I64, res.value);
+
+ arg.value = MIN_I64 + 1;
+ significance.value = MIN_I64 + 1;
+ res = bw_ceil2(arg, significance);
+ KUNIT_EXPECT_EQ(test, MIN_I64 + 1, res.value);
+
+ /* Value is a multiple of significance, result should be value */
+ arg.value = MAX_I64;
+ significance.value = MIN_I64 + 1;
+ res = bw_ceil2(arg, significance);
+ KUNIT_EXPECT_EQ(test, MAX_I64, res.value);
+
+ /* Round 0 up to the nearest multiple of any number should return 0 */
+ arg.value = 0;
+ significance.value = MAX_I64;
+ res = bw_ceil2(arg, significance);
+ KUNIT_EXPECT_EQ(test, 0, res.value);
+
+ arg.value = 0;
+ significance.value = MIN_I64;
+ res = bw_ceil2(arg, significance);
+ KUNIT_EXPECT_EQ(test, 0, res.value);
+}
+
+/**
+ * bw_mul_test - KUnit test for bw_mul
+ * @test: represents a running instance of a test.
+ */
+static void bw_mul_test(struct kunit *test)
+{
+ struct bw_fixed arg1;
+ struct bw_fixed arg2;
+ struct bw_fixed res;
+ struct bw_fixed expected;
+
+ /* Extreme scenario */
+ arg1.value = MAX_I64;
+ arg2.value = MIN_I64;
+ res = bw_mul(arg1, arg2);
+ KUNIT_EXPECT_EQ(test, BW_FIXED_MAX_I32 + 1, res.value);
+
+ /* Testing multiplication property: x * 1 = x */
+ arg1.value = 1;
+ arg2.value = MAX_I64;
+ res = bw_mul(arg1, arg2);
+ KUNIT_EXPECT_EQ(test, BW_FIXED_MAX_I32 + 1, res.value);
+
+ arg1.value = 1;
+ arg2.value = MIN_I64;
+ res = bw_mul(arg1, arg2);
+ KUNIT_EXPECT_EQ(test, BW_FIXED_MIN_I32, res.value);
+
+ /* Testing multiplication property: x * 0 = 0 */
+ arg1.value = 0;
+ arg2.value = 0;
+ res = bw_mul(arg1, arg2);
+ KUNIT_EXPECT_EQ(test, 0, res.value);
+
+ arg1.value = 0;
+ arg2.value = MAX_I64;
+ res = bw_mul(arg1, arg2);
+ KUNIT_EXPECT_EQ(test, 0, res.value);
+
+ arg1.value = 0;
+ arg2.value = MIN_I64;
+ res = bw_mul(arg1, arg2);
+ KUNIT_EXPECT_EQ(test, 0, res.value);
+
+ /* Testing multiplication between integers */
+ res = bw_mul(bw_int_to_fixed(8), bw_int_to_fixed(10));
+ KUNIT_EXPECT_EQ(test, 1342177280LL, res.value); /* 0x50000000 */
+
+ res = bw_mul(bw_int_to_fixed(10), bw_int_to_fixed(5));
+ KUNIT_EXPECT_EQ(test, 838860800LL, res.value); /* 0x32000000 */
+
+ res = bw_mul(bw_int_to_fixed(-10), bw_int_to_fixed(7));
+ KUNIT_EXPECT_EQ(test, -1174405120LL, res.value); /* -0x46000000 */
+
+ /* Testing multiplication between fractions and integers */
+ res = bw_mul(bw_frc_to_fixed(4, 3), bw_int_to_fixed(3));
+ expected = bw_int_to_fixed(4);
+
+ /*
+ * As bw_frc_to_fixed(4, 3) didn't round up the fixed-point representation,
+ * the expected must be subtracted by 1.
+ */
+ KUNIT_EXPECT_EQ(test, expected.value - 1, res.value);
+
+ res = bw_mul(bw_frc_to_fixed(5, 3), bw_int_to_fixed(3));
+ expected = bw_int_to_fixed(5);
+
+ /*
+ * As bw_frc_to_fixed(5, 3) rounds up the fixed-point representation,
+ * the expected must be added by 1.
+ */
+ KUNIT_EXPECT_EQ(test, expected.value + 1, res.value);
+}
+
+static struct kunit_case bw_fixed_test_cases[] = {
+ KUNIT_CASE(abs_i64_test),
+ KUNIT_CASE(bw_int_to_fixed_nonconst_test),
+ KUNIT_CASE(bw_frc_to_fixed_test),
+ KUNIT_CASE(bw_floor2_test),
+ KUNIT_CASE(bw_ceil2_test),
+ KUNIT_CASE(bw_mul_test),
+ { }
+};
+
+static struct kunit_suite bw_fixed_test_suite = {
+ .name = "dml_calcs_bw_fixed",
+ .test_cases = bw_fixed_test_cases,
+};
+
+kunit_test_suites(&bw_fixed_test_suite);
--
2.37.0

Tales Aparecida

unread,
Aug 10, 2022, 8:40:40 PM8/10/22
to Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, kuni...@googlegroups.com, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, maira...@riseup.net, Isabella Basso, magali...@gmail.com, tales.a...@gmail.com
From: Isabella Basso <isab...@riseup.net>

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.

Signed-off-by: Isabella Basso <isab...@riseup.net>
Signed-off-by: Tales Aparecida <tales.a...@gmail.com>
---
.../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

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_rq_dlg_calc_20.c b/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_rq_dlg_calc_20.c
index 548cdef8a8ad..ab688c9ba0d1 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_rq_dlg_calc_20.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_rq_dlg_calc_20.c
@@ -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
diff --git a/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c b/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c
new file mode 100644
index 000000000000..03ac3522e804
--- /dev/null
+++ b/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: MIT
+/*
+ * KUnit tests for dml/dcn20/display_rq_dlg_calc_20.c
+ *
+ * Copyright (c) 2022, Isabella Basso <isab...@riseup.net>
+ */
+
+#include <kunit/test.h>
+#include "dml/display_mode_lib.h"
+
+static void get_bytes_per_element_test(struct kunit *test)
+{
+ /* last numbers should tell us the horizontal 4-element region binary
+ * size N used for subsampling, thus giving us N/8 bytes per element
+ */
+ /* note that 4:4:4 is not subsampled */
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_16, false), 2);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_32, false), 4);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_64, false), 8);
+
+ /* dcn20 doesn't support bit depths over 10b */
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_420_12, false), 0);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_420_12, true), 0);
+
+ /* dm_444_XX are not dual plane */
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_16, true), 0);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_32, true), 0);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_64, true), 0);
+
+ /* in the dm_42* values, last numbers specify bit depth, demanding we
+ * treat chroma and luma channels separately
+ */
+ /* thus we'll now have ceil(N/8) bytes for luma */
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_420_8, false), 1);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_420_10, false), 2);
+ /* and double the luma value for accommodating blue and red chroma
+ * channels
+ */
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_420_8, true), 2);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_420_10, true), 4);
+
+ /* monochrome encodings should mirror non-subsampled variants */
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_mono_8, false),
+ get_bytes_per_element(dm_444_8, false));
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_mono_16, false),
+ get_bytes_per_element(dm_444_16, false));
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_mono_16, true), 0);
+
+ /* dcn20 doesn't support 4:2:2 chroma subsampling */
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_422_8, false), 0);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_422_8, true), 0);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_422_10, false), 0);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_422_10, true), 0);
+
+ /* dcn20 doesn't support RGBE encodings */
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_rgbe, false), 0);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_rgbe, true), 0);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_rgbe_alpha, false), 0);
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_rgbe_alpha, true), 0);
+
+ /* as in the first values, _8 here represents horizontal binary length */
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_8, false), 1);
+ /* in a non-subsampled monochrome encoding chroma and luma should be the
+ * same length
+ */
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_8, false),
+ get_bytes_per_element(dm_444_8, true));
+
+ /* as dm_mono_8 == dm_444_8, it must behave the same way */
+ KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_mono_8, false),
+ get_bytes_per_element(dm_mono_8, true));
+}
+
+static void is_dual_plane_test(struct kunit *test)
+{
+ /* strictly speaking monochrome formats are not dual plane, but they're
+ * included here for completeness
+ */
+ int source_format_count = 11;
+
+ for (int i = 0; i < source_format_count; i++) {
+ /* dcn20 doesn't support other dual plane formats */
+ if (i == 3 || i == 4)
+ KUNIT_ASSERT_TRUE(test, is_dual_plane(i));
+ else
+ KUNIT_ASSERT_FALSE(test, is_dual_plane(i));
+ }
+}
+
+static void get_blk_size_bytes_test(struct kunit *test)
+{
+ /* corresponds to 4^4 kB tiles */
+ KUNIT_ASSERT_EQ(test, get_blk_size_bytes(dm_256k_tile), 256 * 1024);
+ /* corresponds to 4^3 kB tiles */
+ KUNIT_ASSERT_EQ(test, get_blk_size_bytes(dm_64k_tile), 64 * 1024);
+ /* corresponds to 4^1 kB tiles */
+ KUNIT_ASSERT_EQ(test, get_blk_size_bytes(dm_4k_tile), 4 * 1024);
+}
+
+static struct kunit_case dcn20_rq_dlg_calc_20_test_cases[] = {
+ KUNIT_CASE(get_bytes_per_element_test),
+ KUNIT_CASE(is_dual_plane_test),
+ KUNIT_CASE(get_blk_size_bytes_test),
+ { }
+};
+
+static struct kunit_suite dcn20_rq_dlg_calc_20_test_suite = {
+ .name = "display_rq_dlg_calc_20",
+ .test_cases = dcn20_rq_dlg_calc_20_test_cases,
+};
+
+kunit_test_suites(&dcn20_rq_dlg_calc_20_test_suite);
--
2.37.0

Tales Aparecida

unread,
Aug 10, 2022, 8:40:45 PM8/10/22
to Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, kuni...@googlegroups.com, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, maira...@riseup.net, Isabella Basso, magali...@gmail.com, tales.a...@gmail.com
From: Maíra Canal <maira...@riseup.net>

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.

Signed-off-by: Maíra Canal <maira...@riseup.net>
Signed-off-by: Tales Aparecida <tales.a...@gmail.com>
---
.../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

diff --git a/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c b/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c
index 503e7d984ff0..71a3aa75ac56 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c
@@ -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
diff --git a/drivers/gpu/drm/amd/display/tests/dc/dml/display_mode_vba_test.c b/drivers/gpu/drm/amd/display/tests/dc/dml/display_mode_vba_test.c
new file mode 100644
index 000000000000..d3e3a9f50c3d
--- /dev/null
+++ b/drivers/gpu/drm/amd/display/tests/dc/dml/display_mode_vba_test.c
@@ -0,0 +1,741 @@
+// SPDX-License-Identifier: MIT
+/*
+ * KUnit tests for dml/display_mode_vba.h
+ *
+ * Copyright (C) 2022, Maíra Canal <maira...@riseup.net>
+ */
+
+#include <kunit/test.h>
+#include "dml/display_mode_lib.h"
+
+struct pixel_clock_adjustment_for_progressive_to_interlace_unit_expected {
+ const double pixel_clock[DC__NUM_DPP__MAX];
+ const double pixel_clock_backend[DC__NUM_DPP__MAX];
+};
+
+struct pixel_clock_adjustment_for_progressive_to_interlace_unit_test_case {
+ const char *desc;
+ const unsigned int number_of_active_planes;
+ const bool interlace[DC__NUM_DPP__MAX];
+ const bool progressive_to_interlace_unit_in_OPP;
+ const double pixel_clock[DC__NUM_DPP__MAX];
+ const struct pixel_clock_adjustment_for_progressive_to_interlace_unit_expected expected;
+};
+
+struct calculate_256B_block_sizes_test_case {
+ const char *desc;
+ const enum source_format_class source_pixel_format;
+ const enum dm_swizzle_mode surface_tiling;
+ const unsigned int byte_per_pixel_Y;
+ const unsigned int byte_per_pixel_C;
+ const unsigned int block_height_256_bytes_Y;
+ const unsigned int block_height_256_bytes_C;
+ const unsigned int block_width_256_bytes_Y;
+ const unsigned int block_width_256_bytes_C;
+};
+
+struct calculate_write_back_DISPCLK_test_case {
+ const char *desc;
+ const enum source_format_class writeback_pixel_format;
+ const double pixel_clock;
+ const double writeback_HRatio;
+ const double writeback_VRatio;
+ const unsigned int writeback_luma_HTaps;
+ const unsigned int writeback_luma_VTaps;
+ const unsigned int writeback_chroma_HTaps;
+ const unsigned int writeback_chroma_VTaps;
+ const double writeback_destination_width;
+ const unsigned int HTotal;
+ const unsigned int writeback_chroma_line_buffer_width;
+ const double calculate_write_back_DISPCLK;
+};
+
+/**
+ * pclk_adjustment_for_progressive_to_interlace_unit_test - KUnit test
+ * for PixelClockAdjustmentForProgressiveToInterlaceUnit
+ * @test: represents a running instance of a test.
+ */
+static void pclk_adjustment_for_progressive_to_interlace_unit_test(struct kunit *test)
+{
+ const struct pixel_clock_adjustment_for_progressive_to_interlace_unit_test_case
+ *test_param = test->param_value;
+ struct display_mode_lib *mode_lib;
+ size_t pixel_clock_size = DC__NUM_DPP__MAX * sizeof(const double);
+ size_t interlace_size = DC__NUM_DPP__MAX * sizeof(const bool);
+
+ mode_lib = kunit_kzalloc(test, sizeof(struct display_mode_lib),
+ GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mode_lib);
+
+ mode_lib->vba.NumberOfActivePlanes = test_param->number_of_active_planes;
+ memcpy(mode_lib->vba.Interlace, test_param->interlace, interlace_size);
+ mode_lib->vba.ProgressiveToInterlaceUnitInOPP =
+ test_param->progressive_to_interlace_unit_in_OPP;
+ memcpy(mode_lib->vba.PixelClock, test_param->pixel_clock, pixel_clock_size);
+
+ PixelClockAdjustmentForProgressiveToInterlaceUnit(mode_lib);
+
+ KUNIT_EXPECT_TRUE(test, !memcmp(mode_lib->vba.PixelClock,
+ test_param->expected.pixel_clock,
+ pixel_clock_size));
+ KUNIT_EXPECT_TRUE(test, !memcmp(mode_lib->vba.PixelClockBackEnd,
+ test_param->expected.pixel_clock_backend,
+ pixel_clock_size));
+}
+
+/**
+ * calculate_256B_block_sizes_test - KUnit test for Calculate256BBlockSizes
+ * @test: represents a running instance of a test.
+ */
+static void calculate_256B_block_sizes_test(struct kunit *test)
+{
+ const struct calculate_256B_block_sizes_test_case *test_param =
+ test->param_value;
+ unsigned int *block_height_256_bytes_Y, *block_height_256_bytes_C;
+ unsigned int *block_width_256_bytes_Y, *block_width_256_bytes_C;
+
+ block_height_256_bytes_Y = kunit_kzalloc(test, sizeof(unsigned int), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, block_height_256_bytes_Y);
+
+ block_height_256_bytes_C = kunit_kzalloc(test, sizeof(unsigned int), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, block_height_256_bytes_C);
+
+ block_width_256_bytes_Y = kunit_kzalloc(test, sizeof(unsigned int), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, block_width_256_bytes_Y);
+
+ block_width_256_bytes_C = kunit_kzalloc(test, sizeof(unsigned int), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, block_width_256_bytes_C);
+
+ Calculate256BBlockSizes(test_param->source_pixel_format,
+ test_param->surface_tiling,
+ test_param->byte_per_pixel_Y,
+ test_param->byte_per_pixel_C,
+ block_height_256_bytes_Y,
+ block_height_256_bytes_C,
+ block_width_256_bytes_Y,
+ block_width_256_bytes_C);
+
+ KUNIT_EXPECT_EQ(test, *block_height_256_bytes_Y,
+ test_param->block_height_256_bytes_Y);
+ KUNIT_EXPECT_EQ(test, *block_height_256_bytes_C,
+ test_param->block_height_256_bytes_C);
+ KUNIT_EXPECT_EQ(test, *block_width_256_bytes_Y,
+ test_param->block_width_256_bytes_Y);
+ KUNIT_EXPECT_EQ(test, *block_width_256_bytes_C,
+ test_param->block_width_256_bytes_C);
+}
+
+/**
+ * calculate_min_and_max_prefetch_mode_test - KUnit test for CalculateMinAndMaxPrefetchMode
+ * @test: represents a running instance of a test.
+ */
+static void calculate_min_and_max_prefetch_mode_test(struct kunit *test)
+{
+ unsigned int *min_prefetch_mode, *max_prefetch_mode;
+
+ min_prefetch_mode = kunit_kzalloc(test, sizeof(unsigned int), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, min_prefetch_mode);
+
+ max_prefetch_mode = kunit_kzalloc(test, sizeof(unsigned int), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, max_prefetch_mode);
+
+ /* Try to allow DRAM self-refresh and MCLK switch */
+ KUNIT_EXPECT_FALSE(test, CalculateMinAndMaxPrefetchMode
+ (dm_try_to_allow_self_refresh_and_mclk_switch,
+ min_prefetch_mode, max_prefetch_mode));
+ KUNIT_EXPECT_EQ(test, *min_prefetch_mode, 0);
+ KUNIT_EXPECT_EQ(test, *max_prefetch_mode, 2);
+
+ /* Allow DRAM self-refresh and MCLK switch */
+ KUNIT_EXPECT_FALSE(test, CalculateMinAndMaxPrefetchMode
+ (dm_allow_self_refresh_and_mclk_switch,
+ min_prefetch_mode, max_prefetch_mode));
+ KUNIT_EXPECT_EQ(test, *min_prefetch_mode, 0);
+ KUNIT_EXPECT_EQ(test, *max_prefetch_mode, 0);
+
+ /* Allow only DRAM self-refresh */
+ KUNIT_EXPECT_FALSE(test, CalculateMinAndMaxPrefetchMode
+ (dm_allow_self_refresh,
+ min_prefetch_mode, max_prefetch_mode));
+ KUNIT_EXPECT_EQ(test, *min_prefetch_mode, 1);
+ KUNIT_EXPECT_EQ(test, *max_prefetch_mode, 1);
+
+ /* Allow neither DRAM self-refresh nor MCLK switch */
+ KUNIT_EXPECT_FALSE(test, CalculateMinAndMaxPrefetchMode
+ (dm_neither_self_refresh_nor_mclk_switch,
+ min_prefetch_mode, max_prefetch_mode));
+ KUNIT_EXPECT_EQ(test, *min_prefetch_mode, 2);
+ KUNIT_EXPECT_EQ(test, *max_prefetch_mode, 2);
+
+ /* Invalid self-refresh affinity */
+ KUNIT_EXPECT_TRUE(test, CalculateMinAndMaxPrefetchMode(-1,
+ min_prefetch_mode,
+ max_prefetch_mode));
+ KUNIT_EXPECT_EQ(test, *min_prefetch_mode, 0);
+ KUNIT_EXPECT_EQ(test, *max_prefetch_mode, 2);
+}
+
+/**
+ * calculate_write_back_DISPCLK_test - KUnit test for CalculateWriteBackDISPCLK
+ * @test: represents a running instance of a test.
+ */
+static void calculate_write_back_DISPCLK_test(struct kunit *test)
+{
+ const struct calculate_write_back_DISPCLK_test_case *test_param = test->param_value;
+ double calculate_write_back_DISPCLK;
+
+ DC_FP_START();
+ calculate_write_back_DISPCLK = CalculateWriteBackDISPCLK
+ (test_param->writeback_pixel_format,
+ test_param->pixel_clock, test_param->writeback_HRatio,
+ test_param->writeback_VRatio, test_param->writeback_luma_HTaps,
+ test_param->writeback_luma_VTaps, test_param->writeback_chroma_HTaps,
+ test_param->writeback_chroma_VTaps,
+ test_param->writeback_destination_width, test_param->HTotal,
+ test_param->writeback_chroma_line_buffer_width);
+ DC_FP_END();
+
+ KUNIT_EXPECT_EQ(test, test_param->calculate_write_back_DISPCLK,
+ calculate_write_back_DISPCLK);
+}
+
+static const struct pixel_clock_adjustment_for_progressive_to_interlace_unit_test_case
+pixel_clock_adjustment_for_progressive_to_interlace_unit_cases[] = {
+ {
+ .desc = "No active planes",
+ .number_of_active_planes = 0,
+ .interlace = {false, false, false, false, false, false, false, false},
+ .progressive_to_interlace_unit_in_OPP = false,
+ .pixel_clock = {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00},
+ .expected = {
+ .pixel_clock = {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00},
+ .pixel_clock_backend = {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00},
+ },
+ },
+ {
+ .desc = "Two active planes with no interlaced output",
+ .number_of_active_planes = 2,
+ .interlace = {false, false, false, false, false, false, false, false},
+ .progressive_to_interlace_unit_in_OPP = true,
+ .pixel_clock = {3200.00, 1360.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00},
+ .expected = {
+ .pixel_clock = {3200.00, 1360.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00},
+ .pixel_clock_backend = {3200.00, 1360.00, 0.00, 0.00, 0.00, 0.00,
+ 0.00, 0.00},
+ },
+ },
+ {
+ .desc = "Three active planes with one interlaced plane",
+ .number_of_active_planes = 3,
+ .interlace = {false, true, false, false, false, false, false, false},
+ .progressive_to_interlace_unit_in_OPP = true,
+ .pixel_clock = {3200.00, 1360.00, 400.00, 0.00, 0.00, 0.00, 0.00, 0.00},
+ .expected = {
+ .pixel_clock = {3200.00, 2720.00, 400.00, 0.00,
+ 0.00, 0.00, 0.00, 0.00},
+ .pixel_clock_backend = {3200.00, 1360.00, 400.00, 0.00,
+ 0.00, 0.00, 0.00, 0.00},
+ },
+ },
+ {
+ .desc = "Five active planes with three interlaced planes",
+ .number_of_active_planes = 5,
+ .interlace = {false, true, false, true, true, false, false, false},
+ .progressive_to_interlace_unit_in_OPP = true,
+ .pixel_clock = {3200.00, 1360.00, 400.00, 340.00, 680.00, 0.00, 0.00, 0.00},
+ .expected = {
+ .pixel_clock = {3200.00, 2720.00, 400.00, 680.00,
+ 1360.00, 0.00, 0.00, 0.00},
+ .pixel_clock_backend = {3200.00, 1360.00, 400.00, 340.00,
+ 680.00, 0.00, 0.00, 0.00},
+ },
+ },
+ {
+ .desc = "Eight active planes with five interlaced planes",
+ .number_of_active_planes = 8,
+ .interlace = {true, true, false, true, true, false, true, false},
+ .progressive_to_interlace_unit_in_OPP = true,
+ .pixel_clock = {3200.00, 1360.00, 400.00, 340.00, 680.00, 1360.00, 2720.00, 340.00},
+ .expected = {
+ .pixel_clock = {6400.00, 2720.00, 400.00, 680.00,
+ 1360.00, 1360.00, 5440.00, 340.00},
+ .pixel_clock_backend = {3200.00, 1360.00, 400.00, 340.00,
+ 680.00, 1360.00, 2720.00, 340.0},
+ },
+ },
+ {
+ .desc = "Eight active planes with all planes interlaced",
+ .number_of_active_planes = 8,
+ .interlace = {true, true, true, true, true, true, true, true},
+ .progressive_to_interlace_unit_in_OPP = true,
+ .pixel_clock = {3200.00, 1360.00, 400.00, 340.00, 680.00, 1360.00, 2720.00, 340.00},
+ .expected = {
+ .pixel_clock = {6400.00, 2720.00, 800.0, 680.00,
+ 1360.00, 2720.00, 5440.0, 680.00},
+ .pixel_clock_backend = {3200.00, 1360.00, 400.00, 340.00,
+ 680.00, 1360.00, 2720.00, 340.00},
+ },
+ },
+ {
+ .desc = "Eight active planes with no interlaced plane",
+ .number_of_active_planes = 8,
+ .interlace = {false, false, false, false, false, false, false, false},
+ .progressive_to_interlace_unit_in_OPP = false,
+ .pixel_clock = {3200.00, 1360.00, 400.00, 340.00, 680.00, 1360.00, 2720.00, 340.00},
+ .expected = {
+ .pixel_clock = {3200.00, 1360.00, 400.00, 340.00,
+ 680.00, 1360.00, 2720.00, 340.00},
+ .pixel_clock_backend = {3200.00, 1360.00, 400.00, 340.00,
+ 680.00, 1360.00, 2720.00, 340.00},
+ },
+ },
+ {
+ .desc = "Eight active planes with no progressive_to_interlace_unit_in_OPP",
+ .number_of_active_planes = 8,
+ .interlace = {true, true, true, true, true, true, true, true},
+ .progressive_to_interlace_unit_in_OPP = false,
+ .pixel_clock = {3200.00, 1360.00, 400.00, 340.00, 680.00, 1360.00, 2720.00, 340.00},
+ .expected = {
+ .pixel_clock = {3200.00, 1360.00, 400.00, 340.00,
+ 680.00, 1360.00, 2720.00, 340.00},
+ .pixel_clock_backend = {3200.00, 1360.00, 400.00, 340.00,
+ 680.00, 1360.00, 2720.00, 340.00},
+ },
+ },
+};
+
+static const struct calculate_256B_block_sizes_test_case calculate_256B_block_sizes_cases[] = {
+ /*
+ * Here 16-bit specifies the number of bits in the horizontal 4-element region
+ * used for subsampling
+ */
+ {
+ .desc = "4:4:4 16-bit encoding with linear swizzle",
+ .source_pixel_format = dm_444_16,
+ .surface_tiling = dm_sw_linear,
+ .byte_per_pixel_Y = 2,
+ .byte_per_pixel_C = 0,
+ .block_height_256_bytes_Y = 1,
+ .block_width_256_bytes_Y = 128,
+ .block_height_256_bytes_C = 0,
+ .block_width_256_bytes_C = 0,
+ },
+ {
+ .desc = "4:4:4 16-bit encoding with 256B standard swizzle",
+ .source_pixel_format = dm_444_16,
+ .surface_tiling = dm_sw_256b_s,
+ .byte_per_pixel_Y = 2,
+ .byte_per_pixel_C = 0,
+ .block_height_256_bytes_Y = 8,
+ .block_width_256_bytes_Y = 16,
+ .block_height_256_bytes_C = 0,
+ .block_width_256_bytes_C = 0,
+ },
+ /*
+ * Here 32-bit specifies the number of bits in the horizontal
+ * 4-element region used for subsampling
+ */
+ {
+ .desc = "4:4:4 32-bit encoding with linear swizzle",
+ .source_pixel_format = dm_444_32,
+ .surface_tiling = dm_sw_linear,
+ .byte_per_pixel_Y = 4,
+ .byte_per_pixel_C = 0,
+ .block_height_256_bytes_Y = 1,
+ .block_width_256_bytes_Y = 64,
+ .block_height_256_bytes_C = 0,
+ .block_width_256_bytes_C = 0,
+ },
+ {
+ .desc = "4:4:4 32-bit encoding with 256B display swizzle",
+ .source_pixel_format = dm_444_32,
+ .surface_tiling = dm_sw_256b_d,
+ .byte_per_pixel_Y = 4,
+ .byte_per_pixel_C = 0,
+ .block_height_256_bytes_Y = 8,
+ .block_width_256_bytes_Y = 8,
+ .block_height_256_bytes_C = 0,
+ .block_width_256_bytes_C = 0,
+ },
+ /*
+ * Here 64-bit specifies the number of bits in the horizontal 4-element region
+ * used for subsampling
+ */
+ {
+ .desc = "4:4:4 64-bit encoding with linear swizzle",
+ .source_pixel_format = dm_444_64,
+ .surface_tiling = dm_sw_linear,
+ .byte_per_pixel_Y = 8,
+ .byte_per_pixel_C = 0,
+ .block_height_256_bytes_Y = 1,
+ .block_width_256_bytes_Y = 32,
+ .block_height_256_bytes_C = 0,
+ .block_width_256_bytes_C = 0,
+ },
+ {
+ .desc = "4:4:4 64-bit encoding with 4KB standard swizzle",
+ .source_pixel_format = dm_444_64,
+ .surface_tiling = dm_sw_4kb_s,
+ .byte_per_pixel_Y = 8,
+ .byte_per_pixel_C = 0,
+ .block_height_256_bytes_Y = 4,
+ .block_width_256_bytes_Y = 8,
+ .block_height_256_bytes_C = 0,
+ .block_width_256_bytes_C = 0,
+ },
+ {
+ .desc = "4:4:4 8-bit encoding with linear swizzle",
+ .source_pixel_format = dm_444_8,
+ .surface_tiling = dm_sw_linear,
+ .byte_per_pixel_Y = 1,
+ .byte_per_pixel_C = 0,
+ .block_height_256_bytes_Y = 1,
+ .block_width_256_bytes_Y = 256,
+ .block_height_256_bytes_C = 0,
+ .block_width_256_bytes_C = 0,
+ },
+ {
+ .desc = "4:4:4 8-bit encoding with 4KB display swizzle",
+ .source_pixel_format = dm_444_8,
+ .surface_tiling = dm_sw_4kb_d,
+ .byte_per_pixel_Y = 1,
+ .byte_per_pixel_C = 0,
+ .block_height_256_bytes_Y = 16,
+ .block_width_256_bytes_Y = 16,
+ .block_height_256_bytes_C = 0,
+ .block_width_256_bytes_C = 0,
+ },
+ {
+ .desc = "8-bit mono encoding with linear swizzle",
+ .source_pixel_format = dm_mono_8,
+ .surface_tiling = dm_sw_linear,
+ .byte_per_pixel_Y = 1,
+ .byte_per_pixel_C = 0,
+ .block_height_256_bytes_Y = 1,
+ .block_width_256_bytes_Y = 256,
+ .block_height_256_bytes_C = 0,
+ .block_width_256_bytes_C = 0,
+ },
+ {
+ .desc = "8-bit mono encoding with 64KB standard swizzle",
+ .source_pixel_format = dm_mono_8,
+ .surface_tiling = dm_sw_64kb_s,
+ .byte_per_pixel_Y = 1,
+ .byte_per_pixel_C = 0,
+ .block_height_256_bytes_Y = 16,
+ .block_width_256_bytes_Y = 16,
+ .block_height_256_bytes_C = 0,
+ .block_width_256_bytes_C = 0,
+ },
+ {
+ .desc = "16-bit mono encoding with linear swizzle",
+ .source_pixel_format = dm_mono_16,
+ .surface_tiling = dm_sw_linear,
+ .byte_per_pixel_Y = 2,
+ .byte_per_pixel_C = 0,
+ .block_height_256_bytes_Y = 1,
+ .block_width_256_bytes_Y = 128,
+ .block_height_256_bytes_C = 0,
+ .block_width_256_bytes_C = 0,
+ },
+ {
+ .desc = "16-bit mono encoding with 64KB display swizzle",
+ .source_pixel_format = dm_mono_16,
+ .surface_tiling = dm_sw_64kb_d,
+ .byte_per_pixel_Y = 2,
+ .byte_per_pixel_C = 0,
+ .block_height_256_bytes_Y = 8,
+ .block_width_256_bytes_Y = 16,
+ .block_height_256_bytes_C = 0,
+ .block_width_256_bytes_C = 0,
+ },
+ {
+ .desc = "8-bit 4:2:0 encoding with linear swizzle",
+ .source_pixel_format = dm_420_8,
+ .surface_tiling = dm_sw_linear,
+ .byte_per_pixel_Y = 1,
+ .byte_per_pixel_C = 2,
+ .block_height_256_bytes_Y = 1,
+ .block_width_256_bytes_Y = 256,
+ .block_height_256_bytes_C = 1,
+ .block_width_256_bytes_C = 128,
+ },
+ {
+ .desc = "8-bit 4:2:0 encoding with VAR standard swizzle",
+ .source_pixel_format = dm_420_8,
+ .surface_tiling = dm_sw_var_s,
+ .byte_per_pixel_Y = 1,
+ .byte_per_pixel_C = 2,
+ .block_height_256_bytes_Y = 16,
+ .block_width_256_bytes_Y = 16,
+ .block_height_256_bytes_C = 8,
+ .block_width_256_bytes_C = 16,
+ },
+ {
+ .desc = "10-bit 4:2:0 encoding with linear swizzle",
+ .source_pixel_format = dm_420_10,
+ .surface_tiling = dm_sw_linear,
+ .byte_per_pixel_Y = 4.0 / 3.0,
+ .byte_per_pixel_C = 8.0 / 3.0,
+ .block_height_256_bytes_Y = 1,
+ .block_width_256_bytes_Y = 256,
+ .block_height_256_bytes_C = 1,
+ .block_width_256_bytes_C = 128,
+ },
+ {
+ .desc = "10-bit 4:2:0 encoding with VAR display swizzle",
+ .source_pixel_format = dm_420_10,
+ .surface_tiling = dm_sw_var_d,
+ .byte_per_pixel_Y = 4.0 / 3.0,
+ .byte_per_pixel_C = 8.0 / 3.0,
+ .block_height_256_bytes_Y = 8,
+ .block_width_256_bytes_Y = 32,
+ .block_height_256_bytes_C = 8,
+ .block_width_256_bytes_C = 16,
+ },
+};
+
+static const struct calculate_write_back_DISPCLK_test_case calculate_write_back_DISPCLK_cases[] = {
+ {
+ .desc = "Trivial test",
+ .writeback_pixel_format = dm_444_32,
+ .pixel_clock = 0.00,
+ .writeback_HRatio = 1.0,
+ .writeback_VRatio = 1.0,
+ .writeback_luma_HTaps = 4,
+ .writeback_luma_VTaps = 4,
+ .writeback_chroma_HTaps = 5,
+ .writeback_chroma_VTaps = 5,
+ .writeback_destination_width = 2400.0,
+ .HTotal = 1400,
+ .writeback_chroma_line_buffer_width = 2,
+ .calculate_write_back_DISPCLK = 0,
+ },
+ {
+ .desc = "Simple Writeback Ratio",
+ .writeback_pixel_format = dm_444_32,
+ .pixel_clock = 1800.00,
+ .writeback_HRatio = 1.0,
+ .writeback_VRatio = 1.0,
+ .writeback_luma_HTaps = 4,
+ .writeback_luma_VTaps = 4,
+ .writeback_chroma_HTaps = 5,
+ .writeback_chroma_VTaps = 5,
+ .writeback_destination_width = 2400.0,
+ .HTotal = 1400,
+ .writeback_chroma_line_buffer_width = 2,
+ .calculate_write_back_DISPCLK = 0x1.e7c6a11ep+11,
+ },
+ {
+ .desc = "Non-integer WritebackVRatio with same number of Luma and Chroma taps",
+ .writeback_pixel_format = dm_444_32,
+ .pixel_clock = 1360.00,
+ .writeback_HRatio = 1.0,
+ .writeback_VRatio = 1.5,
+ .writeback_luma_HTaps = 7,
+ .writeback_luma_VTaps = 7,
+ .writeback_chroma_HTaps = 7,
+ .writeback_chroma_VTaps = 7,
+ .writeback_destination_width = 400.56,
+ .HTotal = 1400,
+ .writeback_chroma_line_buffer_width = 4,
+ .calculate_write_back_DISPCLK = 0x1.5766666666666p+11,
+ },
+ {
+ .desc = "No Writeback to Chroma Taps",
+ .writeback_pixel_format = dm_444_32,
+ .pixel_clock = 2720.72,
+ .writeback_HRatio = 1.0,
+ .writeback_VRatio = 1.5,
+ .writeback_luma_HTaps = 5,
+ .writeback_luma_VTaps = 5,
+ .writeback_chroma_HTaps = 0,
+ .writeback_chroma_VTaps = 0,
+ .writeback_destination_width = 2400.0,
+ .HTotal = 1400,
+ .writeback_chroma_line_buffer_width = 4,
+ .calculate_write_back_DISPCLK = 0x1.ba5e02226985ep+12,
+ },
+ {
+ .desc = "No Writeback to Luma Taps",
+ .writeback_pixel_format = dm_444_32,
+ .pixel_clock = 1800.66,
+ .writeback_HRatio = 2.0,
+ .writeback_VRatio = 1.5,
+ .writeback_luma_HTaps = 0,
+ .writeback_luma_VTaps = 0,
+ .writeback_chroma_HTaps = 3,
+ .writeback_chroma_VTaps = 3,
+ .writeback_destination_width = 2400.0,
+ .HTotal = 1400,
+ .writeback_chroma_line_buffer_width = 4,
+ .calculate_write_back_DISPCLK = 0x1.85b6dabefdfd9p+11,
+ },
+ {
+ .desc = "Reduce numeric error by decreasing pixel clock",
+ .writeback_pixel_format = dm_444_32,
+ .pixel_clock = 400.756,
+ .writeback_HRatio = 2.0,
+ .writeback_VRatio = 1.0,
+ .writeback_luma_HTaps = 5,
+ .writeback_luma_VTaps = 5,
+ .writeback_chroma_HTaps = 5,
+ .writeback_chroma_VTaps = 5,
+ .writeback_destination_width = 2400.0,
+ .HTotal = 1100,
+ .writeback_chroma_line_buffer_width = 2,
+ .calculate_write_back_DISPCLK = 0x1.4bb8ddb60f598p+10,
+ },
+ {
+ .desc = "Increase numeric error by increasing pixel clock",
+ .writeback_pixel_format = dm_444_32,
+ .pixel_clock = 3200.8,
+ .writeback_HRatio = 2.0,
+ .writeback_VRatio = 1.0,
+ .writeback_luma_HTaps = 4,
+ .writeback_luma_VTaps = 4,
+ .writeback_chroma_HTaps = 2,
+ .writeback_chroma_VTaps = 2,
+ .writeback_destination_width = 1686.7,
+ .HTotal = 1100,
+ .writeback_chroma_line_buffer_width = 2,
+ .calculate_write_back_DISPCLK = 0x1.847ced698147bp+12,
+ },
+ {
+ .desc = "Simple Writeback Ratio for 4:4:4 8-bit encoding",
+ .writeback_pixel_format = dm_444_8,
+ .pixel_clock = 1800.00,
+ .writeback_HRatio = 1.0,
+ .writeback_VRatio = 1.0,
+ .writeback_luma_HTaps = 4,
+ .writeback_luma_VTaps = 4,
+ .writeback_chroma_HTaps = 5,
+ .writeback_chroma_VTaps = 5,
+ .writeback_destination_width = 2400.0,
+ .HTotal = 1400,
+ .writeback_chroma_line_buffer_width = 2,
+ .calculate_write_back_DISPCLK = 0x1.24aa62p+12,
+ },
+ {
+ .desc = "Non-integer WritebackVRatio with same number of Luma and Chroma taps for 4:4:4 64-bit encoding",
+ .writeback_pixel_format = dm_444_64,
+ .pixel_clock = 1360.00,
+ .writeback_HRatio = 1.0,
+ .writeback_VRatio = 1.5,
+ .writeback_luma_HTaps = 7,
+ .writeback_luma_VTaps = 7,
+ .writeback_chroma_HTaps = 7,
+ .writeback_chroma_VTaps = 7,
+ .writeback_destination_width = 400.56,
+ .HTotal = 1400,
+ .writeback_chroma_line_buffer_width = 4,
+ .calculate_write_back_DISPCLK = 0x1.576666p+11,
+ },
+ {
+ .desc = "No Writeback to Chroma Taps for 4:2:0 8-bit encoding",
+ .writeback_pixel_format = dm_420_8,
+ .pixel_clock = 2720.72,
+ .writeback_HRatio = 1.0,
+ .writeback_VRatio = 1.5,
+ .writeback_luma_HTaps = 8,
+ .writeback_luma_VTaps = 8,
+ .writeback_chroma_HTaps = 0,
+ .writeback_chroma_VTaps = 0,
+ .writeback_destination_width = 1333.56,
+ .HTotal = 1400,
+ .writeback_chroma_line_buffer_width = 5,
+ .calculate_write_back_DISPCLK = 0x1.717f8p+12,
+ },
+ {
+ .desc = "No Writeback to Luma Taps for 4:2:0 10-bit encoding",
+ .writeback_pixel_format = dm_420_10,
+ .pixel_clock = 1800.66,
+ .writeback_HRatio = 2.0,
+ .writeback_VRatio = 1.5,
+ .writeback_luma_HTaps = 0,
+ .writeback_luma_VTaps = 0,
+ .writeback_chroma_HTaps = 3,
+ .writeback_chroma_VTaps = 3,
+ .writeback_destination_width = 996.0,
+ .HTotal = 1400,
+ .writeback_chroma_line_buffer_width = 4,
+ .calculate_write_back_DISPCLK = 0x1.43767ep+10,
+ },
+ {
+ .desc = "Reduce numeric error by decreasing pixel clock for 4:4:4 16-bit encoding",
+ .writeback_pixel_format = dm_444_16,
+ .pixel_clock = 340.456,
+ .writeback_HRatio = 2.0,
+ .writeback_VRatio = 1.0,
+ .writeback_luma_HTaps = 5,
+ .writeback_luma_VTaps = 5,
+ .writeback_chroma_HTaps = 5,
+ .writeback_chroma_VTaps = 5,
+ .writeback_destination_width = 2400.0,
+ .HTotal = 1181,
+ .writeback_chroma_line_buffer_width = 3,
+ .calculate_write_back_DISPCLK = 0x1.067b3p+10,
+ },
+ {
+ .desc = "Increase numeric error by increasing pixel clock for 4:4:4 16-bit encoding",
+ .writeback_pixel_format = dm_444_16,
+ .pixel_clock = 4000.92,
+ .writeback_HRatio = 2.0,
+ .writeback_VRatio = 1.0,
+ .writeback_luma_HTaps = 3,
+ .writeback_luma_VTaps = 3,
+ .writeback_chroma_HTaps = 2,
+ .writeback_chroma_VTaps = 2,
+ .writeback_destination_width = 1686.7,
+ .HTotal = 1100,
+ .writeback_chroma_line_buffer_width = 2,
+ .calculate_write_back_DISPCLK = 0x1.84b5b8p+12,
+ },
+};
+
+static void pixel_clock_adjustment_for_progressive_to_interlace_unit_test_to_desc
+(const struct pixel_clock_adjustment_for_progressive_to_interlace_unit_test_case *t,
+ char *desc)
+{
+ strcpy(desc, t->desc);
+}
+
+KUNIT_ARRAY_PARAM(pixel_clock_adjustment_for_progressive_to_interlace_unit,
+ pixel_clock_adjustment_for_progressive_to_interlace_unit_cases,
+ pixel_clock_adjustment_for_progressive_to_interlace_unit_test_to_desc);
+
+static void calculate_256B_block_sizes_test_to_desc
+(const struct calculate_256B_block_sizes_test_case *t, char *desc)
+{
+ strcpy(desc, t->desc);
+}
+
+KUNIT_ARRAY_PARAM(calculate_256B_block_sizes, calculate_256B_block_sizes_cases,
+ calculate_256B_block_sizes_test_to_desc);
+
+static void calculate_write_back_DISPCLK_test_to_desc(const struct
+ calculate_write_back_DISPCLK_test_case * t, char *desc)
+{
+ strcpy(desc, t->desc);
+}
+
+KUNIT_ARRAY_PARAM(calculate_write_back_DISPCLK, calculate_write_back_DISPCLK_cases,
+ calculate_write_back_DISPCLK_test_to_desc);
+
+static struct kunit_case display_mode_vba_test_cases[] = {
+ KUNIT_CASE_PARAM(pclk_adjustment_for_progressive_to_interlace_unit_test,
+ pixel_clock_adjustment_for_progressive_to_interlace_unit_gen_params),
+ KUNIT_CASE_PARAM(calculate_256B_block_sizes_test,
+ calculate_256B_block_sizes_gen_params),
+ KUNIT_CASE(calculate_min_and_max_prefetch_mode_test),
+ KUNIT_CASE_PARAM(calculate_write_back_DISPCLK_test,
+ calculate_write_back_DISPCLK_gen_params),
+ {}
+};
+
+static struct kunit_suite display_mode_vba_test_suite = {
+ .name = "dml_display_mode_vba",
+ .test_cases = display_mode_vba_test_cases,
+};
+
+kunit_test_suite(display_mode_vba_test_suite);
--
2.37.0

Tales Aparecida

unread,
Aug 10, 2022, 8:40:51 PM8/10/22
to Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, kuni...@googlegroups.com, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, maira...@riseup.net, Isabella Basso, magali...@gmail.com, tales.a...@gmail.com
From: Maíra Canal <maira...@riseup.net>

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.

Signed-off-by: Maíra Canal <maira...@riseup.net>
Signed-off-by: Tales Aparecida <tales.a...@gmail.com>
---
.../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

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c b/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c
index d3b5b6fedf04..738d8c1f5def 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c
@@ -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
diff --git a/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_mode_vba_20_test.c b/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_mode_vba_20_test.c
new file mode 100644
index 000000000000..7abaf0a8d50a
--- /dev/null
+++ b/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_mode_vba_20_test.c
@@ -0,0 +1,227 @@
+// SPDX-License-Identifier: MIT
+/*
+ * KUnit tests for dml/dcn20/display_mode_vba_20.c
+ *
+ * Copyright (C) 2022, Maíra Canal <maira...@riseup.net>
+ */
+
+#include <kunit/test.h>
+#include "dml/display_mode_enums.h"
+
+static void DSC_compute_delay_test(struct kunit *test)
+{
+ /* 4:4:4 encoding */
+ KUNIT_EXPECT_EQ(test, dscComputeDelay(dm_444), 30);
+
+ /* 4:2:0 encoding */
+ KUNIT_EXPECT_EQ(test, dscComputeDelay(dm_420), 48);
+
+ /* 4:2:2 n-encoding */
+ KUNIT_EXPECT_EQ(test, dscComputeDelay(dm_n422), 49);
+
+ /* 4:2:2 s-encoding */
+ KUNIT_EXPECT_EQ(test, dscComputeDelay(dm_s422), 30);
+}
+
+static void calculate_TWait_test(struct kunit *test)
+{
+ /* Zeroed Prefetch Mode */
+
+ /* DRAMClockChangeLatency > UrgentLatencyPixelDataOnly > SREnterPlusExitTime*/
+ KUNIT_EXPECT_EQ(test, CalculateTWait(0, 1300000, 1200000, 1000000), 2500000);
+
+ /* DRAMClockChangeLatency > SREnterPlusExitTime > UrgentLatencyPixelDataOnly */
+ KUNIT_EXPECT_EQ(test, CalculateTWait(0, 1300000, 900000, 1200000), 2200000);
+
+ /* UrgentLatencyPixelDataOnly > DRAMClockChangeLatency > SREnterPlusExitTime */
+ KUNIT_EXPECT_EQ(test, CalculateTWait(0, 1000000, 2000000, 900000), 3000000);
+
+ /* UrgentLatencyPixelDataOnly > SREnterPlusExitTime > DRAMClockChangeLatency */
+ KUNIT_EXPECT_EQ(test, CalculateTWait(0, 1000000, 1200000, 1100000), 2200000);
+
+ /* SREnterPlusExitTime > DRAMClockChangeLatency > UrgentLatencyPixelDataOnly */
+ KUNIT_EXPECT_EQ(test, CalculateTWait(0, 1000000, 900000, 2000000), 2000000);
+
+ /* SREnterPlusExitTime > UrgentLatencyPixelDataOnly > DRAMClockChangeLatency */
+ KUNIT_EXPECT_EQ(test, CalculateTWait(0, 1000000, 1200000, 1300000), 2200000);
+
+ /* Prefetch Mode equals 1 */
+ KUNIT_EXPECT_EQ(test, CalculateTWait(1, 2500000, 2000000, 900000), 2000000);
+ KUNIT_EXPECT_EQ(test, CalculateTWait(1, 1300000, 900000, 1200000), 1200000);
+ KUNIT_EXPECT_EQ(test, CalculateTWait(1, 1100000, 1200000, 1000000), 1200000);
+ KUNIT_EXPECT_EQ(test, CalculateTWait(1, 1000000, 1200000, 1100000), 1200000);
+ KUNIT_EXPECT_EQ(test, CalculateTWait(1, 1000000, 900000, 2000000), 2000000);
+ KUNIT_EXPECT_EQ(test, CalculateTWait(1, 1000000, 1200000, 1300000), 1300000);
+
+ /* Prefetch Mode greater than 1 */
+ KUNIT_EXPECT_EQ(test, CalculateTWait(1, 2500000, 2000000, 900000), 2000000);
+ KUNIT_EXPECT_EQ(test, CalculateTWait(2, 2500000, 900000, 2000000), 900000);
+ KUNIT_EXPECT_EQ(test, CalculateTWait(5, 1100000, 1200000, 1000000), 1200000);
+ KUNIT_EXPECT_EQ(test, CalculateTWait(4, 1000000, 1300000, 1200000), 1300000);
+ KUNIT_EXPECT_EQ(test, CalculateTWait(6, 1000000, 900000, 2000000), 900000);
+ KUNIT_EXPECT_EQ(test, CalculateTWait(3, 1000000, 1200000, 1300000), 1200000);
+}
+
+static void trunc_to_valid_BPP_test(struct kunit *test)
+{
+ /* HDMI output for 4:2:0 encoding */
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(18.01, true, dm_hdmi, dm_420, 0), 18);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(18, true, dm_hdmi, dm_420, 10), 18);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(15.01, false, dm_hdmi, dm_420, 0), 15);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(15, false, dm_hdmi, dm_420, 8), 15);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(12.01, true, dm_hdmi, dm_420, 0), 12);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(12, true, dm_hdmi, dm_420, 5), 12);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(11.99, false, dm_hdmi, dm_420, 5), BPP_INVALID);
+
+ /* HDMI output for 4:2:0 encoding */
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(36.01, true, dm_hdmi, dm_444, 0), 36);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(36, true, dm_hdmi, dm_444, 10), 36);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(30.01, false, dm_hdmi, dm_444, 0), 30);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(30, false, dm_hdmi, dm_444, 8), 30);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(24.01, true, dm_hdmi, dm_444, 0), 24);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(24, true, dm_hdmi, dm_444, 5), 24);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(18.01, true, dm_hdmi, dm_444, 0), 18);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(18, true, dm_hdmi, dm_444, 5), 18);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.99, false, dm_hdmi, dm_444, 5), BPP_INVALID);
+
+ /* HDMI output for different encoding types */
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(36.01, true, dm_hdmi, dm_n422, 0), 24);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(36, true, dm_hdmi, dm_s422, 10), 24);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(30.01, false, dm_hdmi, dm_n422, 0), 20);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(30, false, dm_hdmi, dm_s422, 8), 20);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(24.01, true, dm_hdmi, dm_n422, 0), 16);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(24, true, dm_hdmi, dm_s422, 5), 16);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(15.99, false, dm_hdmi, dm_n422, 5), BPP_INVALID);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(-1, true, dm_hdmi, dm_s422, 0), BPP_INVALID);
+
+ /* Display Port output with DSC enabled and 4:2:0 encoding */
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(5.99, true, dm_dp, dm_420, 0), BPP_INVALID);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(-1, true, dm_dp, dm_420, 0), BPP_INVALID);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(12, true, dm_dp, dm_420, 8), 12);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(1.5 * 8 - 1 / (double)16, true, dm_dp, dm_420, 8), 11);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(7, true, dm_dp, dm_420, 3), 4);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(1.5 * 9 - 1 / (double)16, true, dm_dp, dm_420, 9), 13);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(6, true, dm_dp, dm_420, 8), 6);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(6.25, true, dm_dp, dm_420, 8), 6);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(6 + 1 / (double)3, true, dm_dp, dm_420, 8), 6);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(6.50, true, dm_dp, dm_420, 8), 6);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(6.75, true, dm_dp, dm_420, 8), 6);
+
+ /* Embedded Display Port output with DSC enabled and n-4:2:2 encoding */
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(6.99, true, dm_edp, dm_n422, 0), BPP_INVALID);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(-1, true, dm_edp, dm_n422, 0), BPP_INVALID);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(16, true, dm_edp, dm_n422, 7), 14);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(2 * 7 - 1 / (double)16, true, dm_edp, dm_n422, 7), 13);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(7, true, dm_edp, dm_n422, 3), 6);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(2 * 9 - 1 / (double)16, true, dm_edp, dm_n422, 9), 17);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(11, true, dm_edp, dm_n422, 8), 11);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(11 + 1 / (double)3, true, dm_edp, dm_n422, 8), 11);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(11.40, true, dm_edp, dm_n422, 8), 11);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(11.50, true, dm_edp, dm_n422, 8), 11);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(11.75, true, dm_edp, dm_n422, 8), 11);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(11.95, true, dm_edp, dm_n422, 8), 11);
+
+ /* Display Port 2.0 output with DSC enabled and 4:4:4 encoding */
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(7.99, true, dm_dp2p0, dm_444, 0), BPP_INVALID);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(-1, true, dm_dp2p0, dm_444, 0), BPP_INVALID);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(22, true, dm_dp2p0, dm_444, 11), 22);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(3 * 7 - 1 / (double)16, true, dm_dp2p0, dm_444, 7), 20);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(14, true, dm_dp2p0, dm_444, 3), 9);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(3 * 9 - 1 / (double)16, true, dm_dp2p0, dm_444, 9), 26);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17, true, dm_dp2p0, dm_444, 7), 17);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17 + 1 / (double)3, true, dm_dp2p0, dm_444, 7), 17);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.40, true, dm_dp2p0, dm_444, 7), 17);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.50, true, dm_dp2p0, dm_444, 7), 17);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.75, true, dm_dp2p0, dm_444, 7), 17);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.95, true, dm_dp2p0, dm_444, 7), 17);
+
+ /* WB output with DSC enabled and 4:2:2 s-encoding */
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(7.99, true, dm_wb, dm_s422, 0), BPP_INVALID);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(-1, true, dm_wb, dm_s422, 0), BPP_INVALID);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(22, true, dm_wb, dm_s422, 11), 22);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(3 * 7 - 1 / (double)16, true, dm_wb, dm_s422, 7), 20);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(18, true, dm_wb, dm_s422, 3), 9);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(3 * 9 - 1 / (double)16, true, dm_wb, dm_s422, 9), 26);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17, true, dm_wb, dm_s422, 7), 17);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17 + 1 / (double)3, true, dm_wb, dm_s422, 7), 17);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.40, true, dm_wb, dm_s422, 7), 17);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.50, true, dm_wb, dm_s422, 7), 17);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.75, true, dm_wb, dm_s422, 7), 17);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.95, true, dm_wb, dm_s422, 7), 17);
+
+ /* Display Port output with DSC disabled for 4:2:0 encoding */
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(18.01, false, dm_dp, dm_420, 0), 18);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(18, false, dm_dp, dm_420, 10), 18);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(15.01, false, dm_dp, dm_420, 0), 15);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(15, false, dm_dp, dm_420, 8), 15);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(12.01, false, dm_dp, dm_420, 0), 12);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(12, false, dm_dp, dm_420, 5), 12);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(11.99, false, dm_dp, dm_420, 5), BPP_INVALID);
+
+ /* Embedded Display Port output with DSC disabled for 4:2:2 encoding */
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(24.01, false, dm_edp, dm_s422, 0), 24);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(24, false, dm_edp, dm_n422, 10), 24);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(20.01, false, dm_edp, dm_s422, 0), 20);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(20, false, dm_edp, dm_n422, 8), 20);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(16.01, false, dm_edp, dm_s422, 0), 16);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(16, false, dm_edp, dm_n422, 5), 16);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(15.99, false, dm_edp, dm_s422, 5), BPP_INVALID);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(-1, false, dm_edp, dm_n422, 5), BPP_INVALID);
+
+ /* WB output with DSC disabled for 4:4:4 encoding */
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(36.01, false, dm_wb, dm_444, 0), 36);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(36, false, dm_wb, dm_444, 10), 36);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(30.01, false, dm_wb, dm_444, 0), 30);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(30, false, dm_wb, dm_444, 8), 30);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(24.01, false, dm_wb, dm_444, 0), 24);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(24, false, dm_wb, dm_444, 5), 24);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(18.01, false, dm_wb, dm_444, 0), 18);
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(18, false, dm_wb, dm_444, 5), 18);
+
+ KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.99, false, dm_wb, dm_444, 5), BPP_INVALID);
+}
+
+static struct kunit_case display_mode_vba_20_cases[] = {
+ KUNIT_CASE(DSC_compute_delay_test),
+ KUNIT_CASE(calculate_TWait_test),
+ KUNIT_CASE(trunc_to_valid_BPP_test),
+ { }
+};
+
+static struct kunit_suite display_mode_vba_20_suite = {
+ .name = "display_mode_vba_20",
+ .test_cases = display_mode_vba_20_cases,
+};
+
+kunit_test_suite(display_mode_vba_20_suite);
--
2.37.0

Tales Aparecida

unread,
Aug 10, 2022, 8:40:56 PM8/10/22
to Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, kuni...@googlegroups.com, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, maira...@riseup.net, Isabella Basso, magali...@gmail.com, tales.a...@gmail.com
From: Magali Lemes <magali...@gmail.com>

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

Signed-off-by: Magali Lemes <magali...@gmail.com>
Signed-off-by: Tales Aparecida <tales.a...@gmail.com>
---
.../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

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn20/dcn20_fpu.c b/drivers/gpu/drm/amd/display/dc/dml/dcn20/dcn20_fpu.c
index ca44df4fca74..ad30d6ef9603 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn20/dcn20_fpu.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn20/dcn20_fpu.c
@@ -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
diff --git a/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c b/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c
new file mode 100644
index 000000000000..71b1391cda91
--- /dev/null
+++ b/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c
@@ -0,0 +1,560 @@
+// SPDX-License-Identifier: MIT
+/*
+ * KUnit tests for dml/dcn20/dcn20_fpu.h
+ *
+ * Copyright (C) 2022, Magali Lemes <magali...@gmail.com>
+ */
+
+#include <kunit/test.h>
+
+#include "dc/inc/resource.h"
+#include "dc/inc/hw/clk_mgr.h"
+#include "dc/dcn21/dcn21_resource.h"
+
+#include "dml/dcn20/dcn20_fpu.h"
+
+/**
+ * DOC: Unit tests for AMDGPU DML dcn20/dcn20_fpu.h
+ */
+
+struct dcn20_cap_soc_clocks_test_case {
+ const char *desc;
+ struct _vcs_dpi_soc_bounding_box_st bb;
+ struct pp_smu_nv_clock_table max_clocks;
+ const int clock_states;
+ const struct _vcs_dpi_voltage_scaling_st expected_clock_limits[DC__VOLTAGE_STATES];
+};
+
+struct dcn21_update_bw_bounding_box_test_case {
+ const char *desc;
+ struct dc dc;
+ struct clk_bw_params bw_params;
+ const int clocks_to_compare;
+ const struct _vcs_dpi_voltage_scaling_st expected_clock_limits[DC__VOLTAGE_STATES];
+};
+
+struct dcn20_cap_soc_clocks_test_case dcn20_cap_soc_clocks_test_cases[] = {
+ {
+ .desc = "4-state bounding box clock limits ",
+ .bb = {
+ .clock_limits = {
+ {
+ .dcfclk_mhz = 506.0,
+ .fabricclk_mhz = 506.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 400.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 506.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 1600.0,
+ },
+ {
+ .dcfclk_mhz = 540.0,
+ .fabricclk_mhz = 540.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 1284.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 540.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 8000.0,
+ },
+ {
+ .dcfclk_mhz = 675.0,
+ .fabricclk_mhz = 675.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 1284.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 675.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 10000.0,
+ },
+ {
+ .dcfclk_mhz = 1265.0,
+ .fabricclk_mhz = 1266.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 1284.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 1266.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 15000.0,
+ },
+ },
+ .num_states = 4,
+ },
+ .max_clocks = {
+ .dcfClockInKhz = 1265000,
+ .uClockInKhz = 875000,
+ .fabricClockInKhz = 0,
+ .displayClockInKhz = 1284000,
+ .dppClockInKhz = 0,
+ .phyClockInKhz = 810000,
+ .socClockInKhz = 1266000,
+ .dscClockInKhz = 0,
+ },
+ .clock_states = 4,
+ .expected_clock_limits = {
+ {
+ .dcfclk_mhz = 506.0,
+ .fabricclk_mhz = 506.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 400.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 506.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 1600.0,
+ },
+ {
+ .dcfclk_mhz = 540.0,
+ .fabricclk_mhz = 540.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 1284.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 540.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 8000.0,
+ },
+ {
+ .dcfclk_mhz = 675.0,
+ .fabricclk_mhz = 675.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 1284.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 675.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 10000.0,
+ },
+ {
+ .dcfclk_mhz = 1265.0,
+ .fabricclk_mhz = 1266.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 1284.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 1266.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 14000.0,
+ },
+ },
+ },
+ {
+ .desc = "One duplicate clock state",
+ .bb = {
+ .clock_limits = {
+ {
+ .dcfclk_mhz = 506.0,
+ .fabricclk_mhz = 506.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 400.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 506.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 1600.0,
+ },
+ {
+ .dcfclk_mhz = 675.0,
+ .fabricclk_mhz = 675.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 1284.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 675.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 10000.0,
+ },
+ {
+ .dcfclk_mhz = 675.0,
+ .fabricclk_mhz = 675.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 1284.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 675.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 10000.0,
+ },
+ {
+ .dcfclk_mhz = 1265.0,
+ .fabricclk_mhz = 1266.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 1284.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 1266.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 15000.0,
+ },
+ },
+ .num_states = 4,
+ },
+ .max_clocks = {
+ .dcfClockInKhz = 1265000,
+ .uClockInKhz = 875000,
+ .fabricClockInKhz = 0,
+ .displayClockInKhz = 1284000,
+ .dppClockInKhz = 0,
+ .phyClockInKhz = 810000,
+ .socClockInKhz = 1266000,
+ .dscClockInKhz = 0,
+ },
+ .clock_states = 3,
+ .expected_clock_limits = {
+ {
+ .dcfclk_mhz = 506.0,
+ .fabricclk_mhz = 506.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 400.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 506.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 1600.0,
+ },
+ {
+ .dcfclk_mhz = 675.0,
+ .fabricclk_mhz = 675.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 1284.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 675.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 10000.0,
+ },
+ {
+ .dcfclk_mhz = 675.0,
+ .fabricclk_mhz = 675.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 1284.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 675.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 10000.0,
+ },
+ },
+ },
+ {
+ .desc = "Zeroed max clocks",
+ .bb = {
+ .clock_limits = {
+ {
+ .dcfclk_mhz = 506.0,
+ .fabricclk_mhz = 506.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 400.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 506.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 1600.0,
+ },
+ },
+ .num_states = 1,
+ },
+ .max_clocks = {
+ .dcfClockInKhz = 0,
+ .uClockInKhz = 0,
+ .fabricClockInKhz = 0,
+ .displayClockInKhz = 0,
+ .dppClockInKhz = 0,
+ .phyClockInKhz = 0,
+ .socClockInKhz = 0,
+ .dscClockInKhz = 0,
+ },
+ .clock_states = 1,
+ .expected_clock_limits = {
+ {
+ .dcfclk_mhz = 506.0,
+ .fabricclk_mhz = 506.0,
+ .dispclk_mhz = 1284.0,
+ .dppclk_mhz = 400.0,
+ .phyclk_mhz = 810.0,
+ .socclk_mhz = 506.0,
+ .dscclk_mhz = 428.0,
+ .dram_speed_mts = 1600.0,
+ },
+ },
+ },
+};
+
+struct dcn21_update_bw_bounding_box_test_case dcn21_update_bw_bounding_box_test_data[] = {
+ {
+ .desc = "5-entry bounding box clocks table",
+ .dc = {
+ .res_pool = &(struct resource_pool) {
+ .pipe_count = 2,
+ .res_cap = &(struct resource_caps) {
+ .num_timing_generator = 3
+ },
+ },
+ },
+ .bw_params = {
+ .num_channels = 1,
+ .clk_table = {
+ .entries = {
+ {
+ .voltage = 0,
+ .dcfclk_mhz = 200,
+ .fclk_mhz = 400,
+ .memclk_mhz = 800,
+ .socclk_mhz = 0,
+ },
+ {
+ .voltage = 0,
+ .dcfclk_mhz = 201,
+ .fclk_mhz = 800,
+ .memclk_mhz = 1600,
+ .socclk_mhz = 0,
+ },
+ {
+ .voltage = 0,
+ .dcfclk_mhz = 553,
+ .fclk_mhz = 1067,
+ .memclk_mhz = 1067,
+ .socclk_mhz = 0,
+ },
+ {
+ .voltage = 0,
+ .dcfclk_mhz = 602,
+ .fclk_mhz = 1333,
+ .memclk_mhz = 1600,
+ .socclk_mhz = 0,
+ },
+ {
+ .voltage = 0,
+ .dispclk_mhz = 1372,
+ .dppclk_mhz = 1372,
+ .phyclk_mhz = 810,
+ .phyclk_d18_mhz = 667,
+ .dtbclk_mhz = 600,
+ },
+ },
+
+ .num_entries = 5,
+ },
+ },
+ .expected_clock_limits = {
+ {
+ .state = 0,
+ .dcfclk_mhz = 200.0,
+ .fabricclk_mhz = 400.0,
+ .dispclk_mhz = 600.0,
+ .dppclk_mhz = 400.0,
+ .phyclk_mhz = 600.0,
+ .socclk_mhz = 0.0,
+ .dscclk_mhz = 205.67,
+ .dram_speed_mts = 1600.0,
+ },
+ {
+ .state = 1,
+ .dcfclk_mhz = 200.0,
+ .fabricclk_mhz = 400.0,
+ .dispclk_mhz = 600.0,
+ .dppclk_mhz = 400.0,
+ .phyclk_mhz = 600.0,
+ .socclk_mhz = 0.0,
+ .dscclk_mhz = 205.67,
+ .dram_speed_mts = 1600.0,
+ },
+ {
+ .state = 2,
+ .dcfclk_mhz = 201,
+ .fabricclk_mhz = 800.0,
+ .dispclk_mhz = 600.0,
+ .dppclk_mhz = 400.0,
+ .phyclk_mhz = 600.0,
+ .socclk_mhz = 0.0,
+ .dscclk_mhz = 205.67,
+ .dram_speed_mts = 3200.0,
+ },
+ {
+ .state = 3,
+ .dcfclk_mhz = 553.0,
+ .fabricclk_mhz = 1067.0,
+ .dispclk_mhz = 757.89,
+ .dppclk_mhz = 685.71,
+ .phyclk_mhz = 600.0,
+ .socclk_mhz = 0.0,
+ .dscclk_mhz = 287.67,
+ .dram_speed_mts = 2134.0,
+ },
+ {
+ .state = 4,
+ .dcfclk_mhz = 602.0,
+ .fabricclk_mhz = 1333.0,
+ .dispclk_mhz = 847.06,
+ .dppclk_mhz = 757.89,
+ .phyclk_mhz = 600.0,
+ .socclk_mhz = 0.0,
+ .dscclk_mhz = 318.334,
+ .dram_speed_mts = 3200.0,
+ },
+ {
+ .state = 5,
+ .dcfclk_mhz = 0.0,
+ .fabricclk_mhz = 0.0,
+ .dispclk_mhz = 600.0,
+ .dppclk_mhz = 400.0,
+ .phyclk_mhz = 600.0,
+ .socclk_mhz = 0.0,
+ .dscclk_mhz = 205.67,
+ .dram_speed_mts = 0.0,
+ },
+ {
+ .state = 6,
+ .dcfclk_mhz = 0.0,
+ .fabricclk_mhz = 0.0,
+ .dispclk_mhz = 600.0,
+ .dppclk_mhz = 400.0,
+ .phyclk_mhz = 600.0,
+ .socclk_mhz = 0.0,
+ .dscclk_mhz = 205.67,
+ .dram_speed_mts = 0.0,
+ },
+ },
+ .clocks_to_compare = 6,
+ },
+};
+
+/**
+ * dcn20_cap_soc_clocks_test - KUnit test for dcn20_cap_soc_clocks
+ * @test: represents a running instance of a test.
+ */
+static void dcn20_cap_soc_clocks_test(struct kunit *test)
+{
+ struct dcn20_cap_soc_clocks_test_case *test_param =
+ (struct dcn20_cap_soc_clocks_test_case *)test->param_value;
+ int i;
+
+ DC_FP_START();
+ dcn20_cap_soc_clocks(&test_param->bb, test_param->max_clocks);
+ DC_FP_END();
+
+ /* Check if no clock limit is higher than the specified maximum */
+ for (i = 0; i < test_param->bb.num_states; i++) {
+ KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].dcfclk_mhz,
+ test_param->expected_clock_limits[i].dcfclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].fabricclk_mhz,
+ test_param->expected_clock_limits[i].fabricclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].dispclk_mhz,
+ test_param->expected_clock_limits[i].dispclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].dppclk_mhz,
+ test_param->expected_clock_limits[i].dppclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].phyclk_mhz,
+ test_param->expected_clock_limits[i].phyclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].socclk_mhz,
+ test_param->expected_clock_limits[i].socclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].dscclk_mhz,
+ test_param->expected_clock_limits[i].dscclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].dram_speed_mts,
+ test_param->expected_clock_limits[i].dram_speed_mts);
+ }
+
+ KUNIT_EXPECT_EQ(test, test_param->clock_states, test_param->bb.num_states);
+}
+
+static struct _vcs_dpi_soc_bounding_box_st original_dcn2_1_soc;
+static struct _vcs_dpi_ip_params_st original_dcn2_1_ip;
+
+/**
+ * dcn20_fpu_dcn21_update_bw_bounding_box_test_init - Store backup copies of DCN global structures
+ * @test: represents a running instance of a test.
+ */
+int dcn20_fpu_dcn21_update_bw_bounding_box_test_init(struct kunit *test)
+{
+ memcpy(&original_dcn2_1_soc, &dcn2_1_soc, sizeof(struct _vcs_dpi_soc_bounding_box_st));
+ memcpy(&original_dcn2_1_ip, &dcn2_1_ip, sizeof(struct _vcs_dpi_ip_params_st));
+
+ return 0;
+}
+
+/**
+ * dcn20_fpu_dcn21_update_bw_bounding_box_test_exit - Restore original values
+ * of DCN global structures
+ * @test: represents a running instance of a test.
+ */
+static void dcn20_fpu_dcn21_update_bw_bounding_box_test_exit(struct kunit *test)
+{
+ memcpy(&dcn2_1_soc, &original_dcn2_1_soc, sizeof(struct _vcs_dpi_soc_bounding_box_st));
+ memcpy(&dcn2_1_ip, &original_dcn2_1_ip, sizeof(struct _vcs_dpi_ip_params_st));
+}
+
+/**
+ * dcn21_update_bw_bounding_box_test - KUnit test for dcn21_update_bw_bounding_box
+ * @test: represents a running instance of a test.
+ */
+static void dcn21_update_bw_bounding_box_test(struct kunit *test)
+{
+ struct dcn21_update_bw_bounding_box_test_case *test_param =
+ (struct dcn21_update_bw_bounding_box_test_case *)test->param_value;
+ int i;
+
+ DC_FP_START();
+ dcn21_update_bw_bounding_box(&test_param->dc, &test_param->bw_params);
+ DC_FP_END();
+
+ KUNIT_EXPECT_EQ(test, test_param->dc.res_pool->res_cap->num_timing_generator,
+ dcn2_1_ip.max_num_otg);
+ KUNIT_EXPECT_EQ(test, test_param->dc.res_pool->pipe_count, dcn2_1_ip.max_num_dpp);
+ KUNIT_EXPECT_EQ(test, test_param->bw_params.num_channels, dcn2_1_soc.num_chans);
+
+ for (i = 0; i <= test_param->clocks_to_compare; i++) {
+ KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].state,
+ dcn2_1_soc.clock_limits[i].state);
+ KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].dcfclk_mhz,
+ dcn2_1_soc.clock_limits[i].dcfclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].fabricclk_mhz,
+ dcn2_1_soc.clock_limits[i].fabricclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].dispclk_mhz,
+ dcn2_1_soc.clock_limits[i].dispclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].dppclk_mhz,
+ dcn2_1_soc.clock_limits[i].dppclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].phyclk_mhz,
+ dcn2_1_soc.clock_limits[i].phyclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].socclk_mhz,
+ dcn2_1_soc.clock_limits[i].socclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].dscclk_mhz,
+ dcn2_1_soc.clock_limits[i].dscclk_mhz);
+ KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].dram_speed_mts,
+ dcn2_1_soc.clock_limits[i].dram_speed_mts);
+ }
+
+ if (test_param->bw_params.clk_table.num_entries)
+ KUNIT_EXPECT_EQ(test, test_param->bw_params.clk_table.num_entries,
+ dcn2_1_soc.num_states);
+}
+
+static void dcn20_cap_soc_clocks_test_to_desc(struct dcn20_cap_soc_clocks_test_case *t, char *desc)
+{
+ strcpy(desc, t->desc);
+}
+
+static void dcn21_update_bw_bounding_box_test_to_desc(struct dcn21_update_bw_bounding_box_test_case *t, char *desc)
+{
+ strcpy(desc, t->desc);
+}
+
+KUNIT_ARRAY_PARAM(dcn20_cap_soc_clocks,
+ dcn20_cap_soc_clocks_test_cases,
+ dcn20_cap_soc_clocks_test_to_desc);
+
+static struct kunit_case dcn20_fpu_test_cases[] = {
+ KUNIT_CASE_PARAM(dcn20_cap_soc_clocks_test, dcn20_cap_soc_clocks_gen_params),
+ { }
+};
+
+static struct kunit_suite dcn20_fpu_test_suite = {
+ .name = "dml_dcn20_fpu",
+ .test_cases = dcn20_fpu_test_cases,
+};
+
+KUNIT_ARRAY_PARAM(dcn21_update_bw_bounding_box,
+ dcn21_update_bw_bounding_box_test_data,
+ dcn21_update_bw_bounding_box_test_to_desc);
+
+static struct kunit_case dcn20_fpu_dcn21_update_bw_bounding_box_test_cases[] = {
+ KUNIT_CASE_PARAM(dcn21_update_bw_bounding_box_test,
+ dcn21_update_bw_bounding_box_gen_params),
+ { }
+};
+
+static struct kunit_suite dcn21_update_bw_bounding_box_test_suite = {
+ .name = "dml_dcn20_fpu_dcn21_update_bw_bounding_box_test",
+ .init = dcn20_fpu_dcn21_update_bw_bounding_box_test_init,
+ .exit = dcn20_fpu_dcn21_update_bw_bounding_box_test_exit,
+ .test_cases = dcn20_fpu_dcn21_update_bw_bounding_box_test_cases,
+};
+
+kunit_test_suites(&dcn20_fpu_test_suite, &dcn21_update_bw_bounding_box_test_suite);
--
2.37.0

Tales Aparecida

unread,
Aug 10, 2022, 8:41:01 PM8/10/22
to Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, kuni...@googlegroups.com, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, maira...@riseup.net, Isabella Basso, magali...@gmail.com, tales.a...@gmail.com
From: Maíra Canal <maira...@riseup.net>

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

Signed-off-by: Maíra Canal <maira...@riseup.net>
Signed-off-by: Tales Aparecida <tales.a...@gmail.com>
---
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

diff --git a/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c b/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c
index 2d61c2a91cee..f5dd1f69840e 100644
--- a/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c
+++ b/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c
@@ -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
diff --git a/drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c b/drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c
new file mode 100644
index 000000000000..051079cbf65e
--- /dev/null
+++ b/drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c
@@ -0,0 +1,285 @@
+// SPDX-License-Identifier: MIT
+/*
+ * KUnit tests for dc_dmub_srv.c
+ *
+ * Copyright (C) 2022, Maíra Canal <maira...@riseup.net>
+ */
+
+#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)
+{
+ 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);
+
+ 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

Tales Aparecida

unread,
Aug 10, 2022, 8:41:06 PM8/10/22
to Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, kuni...@googlegroups.com, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, maira...@riseup.net, Isabella Basso, magali...@gmail.com, tales.a...@gmail.com
From: Maíra Canal <maira...@riseup.net>

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.

Signed-off-by: Maíra Canal <maira...@riseup.net>
Signed-off-by: Tales Aparecida <tales.a...@gmail.com>
---
.../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

diff --git a/Documentation/gpu/amdgpu/display/display-test.rst b/Documentation/gpu/amdgpu/display/display-test.rst
new file mode 100644
index 000000000000..f2eb8e3213ea
--- /dev/null
+++ b/Documentation/gpu/amdgpu/display/display-test.rst
@@ -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.
diff --git a/Documentation/gpu/amdgpu/display/index.rst b/Documentation/gpu/amdgpu/display/index.rst
index c1fb2fb3c710..4f4e72e3e75f 100644
--- a/Documentation/gpu/amdgpu/display/index.rst
+++ b/Documentation/gpu/amdgpu/display/index.rst
@@ -28,4 +28,5 @@ table of content:
display-manager.rst
dc-debug.rst
dcn-overview.rst
+ display-test.rst
dc-glossary.rst
--
2.37.0

Daniel Latypov

unread,
Aug 10, 2022, 11:05:05 PM8/10/22
to Tales Aparecida, Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, kuni...@googlegroups.com, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, maira...@riseup.net, Isabella Basso, magali...@gmail.com
On Wed, Aug 10, 2022 at 5:40 PM Tales Aparecida
<tales.a...@gmail.com> wrote:
>
> 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/

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

David Gow

unread,
Aug 11, 2022, 3:19:36 AM8/11/22
to Daniel Latypov, Tales Aparecida, Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, KUnit Development, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, Maíra Canal, Isabella Basso, magali...@gmail.com
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/20220218075727.2...@google.com/

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

David Gow

unread,
Aug 11, 2022, 3:35:02 AM8/11/22
to Tales Aparecida, Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, KUnit Development, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, Maíra Canal, Isabella Basso, magali...@gmail.com, Maíra Canal
On Thu, Aug 11, 2022 at 8:40 AM Tales Aparecida
<tales.a...@gmail.com> wrote:
>
> From: Maíra Canal <maira...@usp.br>
>
> 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/
>
> Signed-off-by: Maíra Canal <maira...@usp.br>
> Co-developed-by: Magali Lemes <magali...@gmail.com>
> Signed-off-by: Magali Lemes <magali...@gmail.com>
> Co-developed-by: Tales Aparecida <tales.a...@gmail.com>
> Signed-off-by: Tales Aparecida <tales.a...@gmail.com>
> ---

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 <davi...@google.com>
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.

Signed-off-by: David Gow <davi...@google.com>
---
drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c
b/drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c
index fbe8d0661396..3850f7f0f679 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/calcs/bw_fixed.c
@@ -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

David Gow

unread,
Aug 11, 2022, 3:37:27 AM8/11/22
to Tales Aparecida, Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, KUnit Development, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, Maíra Canal, Isabella Basso, magali...@gmail.com
On Thu, Aug 11, 2022 at 8:41 AM Tales Aparecida
<tales.a...@gmail.com> wrote:
>
> From: Maíra Canal <maira...@riseup.net>
>
> Add unit test to the SubVP feature in order to avoid possible
> regressions and assure the code robustness.
>
> Signed-off-by: Maíra Canal <maira...@riseup.net>
> Signed-off-by: Tales Aparecida <tales.a...@gmail.com>
> ---

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
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.
> --
> 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 kunit-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20220811004010.61299-8-tales.aparecida%40gmail.com.

Christian König

unread,
Aug 11, 2022, 7:22:23 AM8/11/22
to Tales Aparecida, Alex Deucher, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, kuni...@googlegroups.com, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, maira...@riseup.net, Isabella Basso, magali...@gmail.com


Am 11.08.22 um 02:40 schrieb Tales Aparecida:
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.
> 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

Maíra Canal

unread,
Aug 11, 2022, 9:10:12 AM8/11/22
to Christian König, Tales Aparecida, Alex Deucher, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, kuni...@googlegroups.com, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, Isabella Basso, magali...@gmail.com
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

Maíra Canal

unread,
Aug 11, 2022, 9:22:48 AM8/11/22
to David Gow, Daniel Latypov, Tales Aparecida, Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, KUnit Development, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, Isabella Basso, magali...@gmail.com
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?= <maira...@riseup.net>
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

Signed-off-by: Maíra Canal <maira...@riseup.net>
---
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(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
index a5409531a2fd..bbed3284e78e 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
index 25990bec600d..5f0e58c430a1 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
@@ -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;
diff --git a/drivers/gpu/drm/amd/display/Kconfig b/drivers/gpu/drm/amd/display/Kconfig
index 72e7a63da79f..d066af22ecea 100644
--- a/drivers/gpu/drm/amd/display/Kconfig
+++ b/drivers/gpu/drm/amd/display/Kconfig
@@ -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
diff --git a/drivers/gpu/drm/amd/display/dc/gpio/hw_gpio.c b/drivers/gpu/drm/amd/display/dc/gpio/hw_gpio.c
index 660510842ecf..a591090784ee 100644
--- a/drivers/gpu/drm/amd/display/dc/gpio/hw_gpio.c
+++ b/drivers/gpu/drm/amd/display/dc/gpio/hw_gpio.c
@@ -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;
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c
index e4fcbf8a7eb5..825b80590f1b 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c
@@ -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);
--
2.37.1
------

Best Regards,
- Maíra Canal

>
> Cheers,
> -- David

Maíra Canal

unread,
Aug 11, 2022, 9:38:41 AM8/11/22
to David Gow, Tales Aparecida, Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, KUnit Development, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, Isabella Basso, magali...@gmail.com
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

David Gow

unread,
Aug 11, 2022, 1:53:19 PM8/11/22
to Maíra Canal, Tales Aparecida, Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, KUnit Development, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, Isabella Basso, magali...@gmail.com
Fair enough: I definitely don't expect these all to work perfectly on
UML (particularly in v1).

> 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

Tales Lelo da Aparecida

unread,
Aug 11, 2022, 4:56:05 PM8/11/22
to David Gow, Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, KUnit Development, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, Maíra Canal, Isabella Basso, magali...@gmail.com, Maíra Canal
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/20220811204327.4117...@gmail.com/
Thanks for reviewing,
Tales

David Gow

unread,
Aug 12, 2022, 2:58:51 AM8/12/22
to Christian König, Tales Aparecida, Alex Deucher, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, KUnit Development, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, Maíra Canal, Isabella Basso, magali...@gmail.com
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-
> --
> 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 kunit-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/6d24ac92-7ea9-0c35-a97a-bfb53b84f655%40amd.com.

David Gow

unread,
Aug 13, 2022, 1:57:04 AM8/13/22
to Tales Aparecida, Alex Deucher, Christian König, Pan, Xinhui, David Airlie, Daniel Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jonathan Corbet, Harry Wentland, Leo Li, Rodrigo Siqueira, amd...@lists.freedesktop.org, KUnit Development, Trevor Woerner, siqueir...@riseup.net, mw...@igalia.com, andre...@riseup.net, Maíra Canal, Isabella Basso, magali...@gmail.com
On Thu, Aug 11, 2022 at 8:40 AM Tales Aparecida
<tales.a...@gmail.com> wrote:
>
> 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/
>
> Signed-off-by: Tales Aparecida <tales.a...@gmail.com>
> ---

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:
Reviewed-by: David Gow <davi...@google.com>

Cheers,
-- David

> 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
>
> diff --git a/drivers/gpu/drm/amd/display/Kconfig b/drivers/gpu/drm/amd/display/Kconfig
> index 96cbc87f7b6b..27981ccb7032 100644
> --- a/drivers/gpu/drm/amd/display/Kconfig
> +++ b/drivers/gpu/drm/amd/display/Kconfig
> @@ -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/20220810234056....@redhat.com/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.

> + 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.
These could be done as a parameterised test if you prefer, though it's
fine either way.
> --
> 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 kunit-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20220811004010.61299-2-tales.aparecida%40gmail.com.
Reply all
Reply to author
Forward
0 new messages