drm: selftests: Convert to KUnit
Subsystems (5)
cover drm: selftests: Convert to KUnit
KUnit unifies the test structure and provides helper tools that simplify the development. Basic use case allows running tests as regular processes, leveraging User Mode Linux.
For example, to execute all DRM unit tests:./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm (the tool also allows using QEMU instead of UML by adding e.g. --arch=x86_64)
For developers - it means that it's easier to run unit tests on the development machine, tightening the feedback loop. When using UML, it also simplifies using gdb for debug (since the kernel is just a regular process).
For CI systems - DRM tests can be moved from being executed on device under test (that's also running IGTs and so on) to being executed on buildsystem during build (just like checkpatch.pl).
All tests were renamed - IGT prefix is no longer used.
Compared to selftests executed by CI using IGT, there's one functional regression - KUnit test runner is not catching WARNs.
To solve this, we could either go in the similar direction that UBSAN went in:
1195505 ("kunit: ubsan integration")
Or we could expand the test runner to catch WARN signature in dmesg.
Pastebin to preview the output and execution times:
https://gitlab.freedesktop.org/-/snippets/4139
-Michał
Michał Winiarski (10):
drm: test-drm_cmdline_parser: Convert to KUnit
drm: test-drm_plane_helper: Convert to KUnit
drm: test-drm_format: Convert to KUnit
drm: test-drm_framebuffer: Convert to KUnit
drm: test-drm_damage_helper: Convert to KUnit
drm: test-drm_dp_mst_helper: Convert to KUnit
drm: test-drm_rect: Convert to KUnit
drm: test-drm_mm: Convert to KUnit
drm: selftests: Convert to KUnit
drm: test: Simplify testing on UML with kunit.py
drivers/gpu/drm/.kunitconfig | 3 +
drivers/gpu/drm/Kconfig | 22 +-
drivers/gpu/drm/Makefile | 2 +-
drivers/gpu/drm/i915/Kconfig.debug | 1 -
drivers/gpu/drm/selftests/Makefile | 7 -
.../gpu/drm/selftests/drm_cmdline_selftests.h | 68 -
drivers/gpu/drm/selftests/drm_mm_selftests.h | 28 -
.../gpu/drm/selftests/drm_modeset_selftests.h | 40 -
drivers/gpu/drm/selftests/drm_selftest.c | 109 -
drivers/gpu/drm/selftests/drm_selftest.h | 41 -
.../drm/selftests/test-drm_cmdline_parser.c | 1141 --------
.../drm/selftests/test-drm_damage_helper.c | 667 -----
.../drm/selftests/test-drm_dp_mst_helper.c | 273 --
drivers/gpu/drm/selftests/test-drm_format.c | 280 --
drivers/gpu/drm/selftests/test-drm_mm.c | 2487 -----------------
.../drm/selftests/test-drm_modeset_common.c | 32 -
.../drm/selftests/test-drm_modeset_common.h | 52 -
.../gpu/drm/selftests/test-drm_plane_helper.c | 223 --
drivers/gpu/drm/selftests/test-drm_rect.c | 223 --
drivers/gpu/drm/test/Makefile | 7 +
.../gpu/drm/test/test-drm_cmdline_parser.c | 1027 +++++++
drivers/gpu/drm/test/test-drm_damage_helper.c | 667 +++++
drivers/gpu/drm/test/test-drm_dp_mst_helper.c | 429 +++
drivers/gpu/drm/test/test-drm_format.c | 356 +++
.../test-drm_framebuffer.c | 109 +-
drivers/gpu/drm/test/test-drm_mm.c | 2426 ++++++++++++++++
drivers/gpu/drm/test/test-drm_plane_helper.c | 312 +++
drivers/gpu/drm/test/test-drm_rect.c | 249 ++
drivers/video/Kconfig | 4 +
29 files changed, 5558 insertions(+), 5727 deletions(-)
create mode 100644 drivers/gpu/drm/.kunitconfig
delete mode 100644 drivers/gpu/drm/selftests/Makefile
delete mode 100644 drivers/gpu/drm/selftests/drm_cmdline_selftests.h
delete mode 100644 drivers/gpu/drm/selftests/drm_mm_selftests.h
delete mode 100644 drivers/gpu/drm/selftests/drm_modeset_selftests.h
delete mode 100644 drivers/gpu/drm/selftests/drm_selftest.c
delete mode 100644 drivers/gpu/drm/selftests/drm_selftest.h
delete mode 100644 drivers/gpu/drm/selftests/test-drm_cmdline_parser.c
delete mode 100644 drivers/gpu/drm/selftests/test-drm_damage_helper.c
delete mode 100644 drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c
delete mode 100644 drivers/gpu/drm/selftests/test-drm_format.c
delete mode 100644 drivers/gpu/drm/selftests/test-drm_mm.c
delete mode 100644 drivers/gpu/drm/selftests/test-drm_modeset_common.c
delete mode 100644 drivers/gpu/drm/selftests/test-drm_modeset_common.h
delete mode 100644 drivers/gpu/drm/selftests/test-drm_plane_helper.c
delete mode 100644 drivers/gpu/drm/selftests/test-drm_rect.c
create mode 100644 drivers/gpu/drm/test/Makefile
create mode 100644 drivers/gpu/drm/test/test-drm_cmdline_parser.c
create mode 100644 drivers/gpu/drm/test/test-drm_damage_helper.c
create mode 100644 drivers/gpu/drm/test/test-drm_dp_mst_helper.c
create mode 100644 drivers/gpu/drm/test/test-drm_format.c
rename drivers/gpu/drm/{selftests => test}/test-drm_framebuffer.c (91%)
create mode 100644 drivers/gpu/drm/test/test-drm_mm.c
create mode 100644 drivers/gpu/drm/test/test-drm_plane_helper.c
create mode 100644 drivers/gpu/drm/test/test-drm_rect.cSignature · 1 line
2.34.1
RFC 1/10 drm: test-drm_cmdline_parser: Convert to KUnit
One-to-one conversion, no functional changes. Negative tests were merged into single parameterized test case.
--- drivers/gpu/drm/Kconfig | 12 + drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/selftests/Makefile | 8 +- .../gpu/drm/selftests/drm_cmdline_selftests.h | 68 - .../drm/selftests/test-drm_cmdline_parser.c | 1680 ++++++++--------- 5 files changed, 802 insertions(+), 968 deletions(-) delete mode 100644 drivers/gpu/drm/selftests/drm_cmdline_selftests.h
drivers/gpu/drm/Kconfig +12 -0
@@ -80,6 +80,18 @@ config DRM_DEBUG_SELFTEST If in doubt, say "N". +config DRM_KUNIT_TEST + bool "DRM tests" if !KUNIT_ALL_TESTS + depends on DRM=y && KUNIT=y + default KUNIT_ALL_TESTS + help + Enables unit tests for DRM. 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 DRM_KMS_HELPER tristate depends on DRM
drivers/gpu/drm/Makefile +1 -1
@@ -65,7 +65,7 @@ drm_kms_helper-$(CONFIG_DRM_DP_AUX_CHARDEV) += drm_dp_aux_dev.o drm_kms_helper-$(CONFIG_DRM_DP_CEC) += drm_dp_cec.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o -obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/ +obj-y += selftests/ obj-$(CONFIG_DRM) += drm.o obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o
drivers/gpu/drm/selftests/Makefile +6 -2
@@ -1,7 +1,11 @@ # SPDX-License-Identifier: GPL-2.0-only -test-drm_modeset-y := test-drm_modeset_common.o test-drm_plane_helper.o \ +test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ + test-drm_modeset_common.o test-drm_plane_helper.o \ test-drm_format.o test-drm_framebuffer.o \ test-drm_damage_helper.o test-drm_dp_mst_helper.o \ test-drm_rect.o -obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o test-drm_cmdline_parser.o +obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o + +obj-$(CONFIG_DRM_KUNIT_TEST) := \ + test-drm_cmdline_parser.o
drivers/gpu/drm/selftests/drm_cmdline_selftests.h deleted +0 -68
68 lines not on this page · raw message
drivers/gpu/drm/selftests/test-drm_cmdline_parser.c +783 -897
1,922 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC 2/10 drm: test-drm_plane_helper: Convert to KUnit
In reply to Michał WiniarskiTests were converted into parameterized test cases. Negative tests were separated. Mocking was moved to test->init(). No functional changes.
--- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/selftests/Makefile | 4 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 1 - .../drm/selftests/test-drm_modeset_common.h | 1 - .../gpu/drm/selftests/test-drm_plane_helper.c | 483 +++++++++++------- 5 files changed, 289 insertions(+), 201 deletions(-)
drivers/gpu/drm/Kconfig +1 -0
@@ -83,6 +83,7 @@ config DRM_DEBUG_SELFTEST config DRM_KUNIT_TEST bool "DRM tests" if !KUNIT_ALL_TESTS depends on DRM=y && KUNIT=y + select DRM_KMS_HELPER default KUNIT_ALL_TESTS help Enables unit tests for DRM. Only useful for kernel devs running KUnit.
drivers/gpu/drm/selftests/Makefile +2 -2
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ - test-drm_modeset_common.o test-drm_plane_helper.o \ + test-drm_modeset_common.o \ test-drm_format.o test-drm_framebuffer.o \ test-drm_damage_helper.o test-drm_dp_mst_helper.o \ test-drm_rect.o
@@ -8,4 +8,4 @@ test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ - test-drm_cmdline_parser.o + test-drm_cmdline_parser.o test-drm_plane_helper.o
drivers/gpu/drm/selftests/drm_modeset_selftests.h +0 -1
@@ -10,7 +10,6 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped) selftest(drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) -selftest(check_plane_state, igt_check_plane_state) selftest(check_drm_format_block_width, igt_check_drm_format_block_width) selftest(check_drm_format_block_height, igt_check_drm_format_block_height)selftest (check_drm_format_min_pitch, igt_check_drm_format_min_pitch)
drivers/gpu/drm/selftests/test-drm_modeset_common.h +0 -1
@@ -20,7 +20,6 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored);int igt_drm_rect_clip_scaled_not_clipped (void *ignored);int igt_drm_rect_clip_scaled_clipped (void *ignored);int igt_drm_rect_clip_scaled_signed_vs_unsigned (void *ignored); -int igt_check_plane_state (void *ignored);int igt_check_drm_format_block_width (void *ignored);int igt_check_drm_format_block_height (void *ignored);int igt_check_drm_format_min_pitch (void *ignored);
drivers/gpu/drm/selftests/test-drm_plane_helper.c +286 -197
507 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC 3/10 drm: test-drm_format: Convert to KUnit
In reply to Michał WiniarskiOne-to-one conversion, no functional changes.
--- drivers/gpu/drm/selftests/Makefile | 5 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 3 - drivers/gpu/drm/selftests/test-drm_format.c | 538 ++++++++++-------- .../drm/selftests/test-drm_modeset_common.h | 3 - 4 files changed, 310 insertions(+), 239 deletions(-)
drivers/gpu/drm/selftests/Makefile +3 -2
@@ -1,11 +1,12 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ test-drm_modeset_common.o \ - test-drm_format.o test-drm_framebuffer.o \ + test-drm_framebuffer.o \ test-drm_damage_helper.o test-drm_dp_mst_helper.o \ test-drm_rect.o obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ - test-drm_cmdline_parser.o test-drm_plane_helper.o + test-drm_cmdline_parser.o test-drm_plane_helper.o \ + test-drm_format.o
drivers/gpu/drm/selftests/drm_modeset_selftests.h +0 -3
@@ -10,9 +10,6 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped) selftest(drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) -selftest(check_drm_format_block_width, igt_check_drm_format_block_width) -selftest(check_drm_format_block_height, igt_check_drm_format_block_height) -selftest(check_drm_format_min_pitch, igt_check_drm_format_min_pitch) selftest(check_drm_framebuffer_create, igt_check_drm_framebuffer_create) selftest(damage_iter_no_damage, igt_damage_iter_no_damage)selftest (damage_iter_no_damage_fractional_src, igt_damage_iter_no_damage_fractional_src)
drivers/gpu/drm/selftests/test-drm_format.c +307 -231
585 lines not on this page · raw message
drivers/gpu/drm/selftests/test-drm_modeset_common.h +0 -3
@@ -20,9 +20,6 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored);int igt_drm_rect_clip_scaled_not_clipped (void *ignored);int igt_drm_rect_clip_scaled_clipped (void *ignored);int igt_drm_rect_clip_scaled_signed_vs_unsigned (void *ignored); -int igt_check_drm_format_block_width (void *ignored); -int igt_check_drm_format_block_height (void *ignored); -int igt_check_drm_format_min_pitch (void *ignored);int igt_check_drm_framebuffer_create (void *ignored);int igt_damage_iter_no_damage (void *ignored);int igt_damage_iter_no_damage_fractional_src (void *ignored);
Signature · 1 line
2.34.1
RFC 4/10 drm: test-drm_framebuffer: Convert to KUnit
In reply to Michał WiniarskiMocking was moved to .init() in order to separate it from test logic. No functional changes.
--- drivers/gpu/drm/selftests/Makefile | 3 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 1 - .../gpu/drm/selftests/test-drm_framebuffer.c | 109 +++++++++++------- .../drm/selftests/test-drm_modeset_common.h | 1 - 4 files changed, 68 insertions(+), 46 deletions(-)
drivers/gpu/drm/selftests/Makefile +1 -2
@@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ test-drm_modeset_common.o \ - test-drm_framebuffer.o \ test-drm_damage_helper.o test-drm_dp_mst_helper.o \ test-drm_rect.o
@@ -9,4 +8,4 @@ obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ test-drm_cmdline_parser.o test-drm_plane_helper.o \ - test-drm_format.o + test-drm_format.o test-drm_framebuffer.o
drivers/gpu/drm/selftests/drm_modeset_selftests.h +0 -1
@@ -10,7 +10,6 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped) selftest(drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) -selftest(check_drm_framebuffer_create, igt_check_drm_framebuffer_create) selftest(damage_iter_no_damage, igt_damage_iter_no_damage) selftest(damage_iter_no_damage_fractional_src, igt_damage_iter_no_damage_fractional_src)selftest (damage_iter_no_damage_src_moved, igt_damage_iter_no_damage_src_moved)
drivers/gpu/drm/selftests/test-drm_framebuffer.c +67 -42
141 lines not on this page · raw message
drivers/gpu/drm/selftests/test-drm_modeset_common.h +0 -1
@@ -20,7 +20,6 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored);int igt_drm_rect_clip_scaled_not_clipped (void *ignored);int igt_drm_rect_clip_scaled_clipped (void *ignored);int igt_drm_rect_clip_scaled_signed_vs_unsigned (void *ignored); -int igt_check_drm_framebuffer_create (void *ignored);int igt_damage_iter_no_damage (void *ignored);int igt_damage_iter_no_damage_fractional_src (void *ignored);int igt_damage_iter_no_damage_src_moved (void *ignored);
Signature · 1 line
2.34.1
RFC 5/10 drm: test-drm_damage_helper: Convert to KUnit
In reply to Michał WiniarskiMocking was moved to .init() in order to separate it from test logic. No functional changes.
--- drivers/gpu/drm/selftests/Makefile | 5 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 21 - .../drm/selftests/test-drm_damage_helper.c | 570 +++++++++--------- .../drm/selftests/test-drm_modeset_common.h | 21 - 4 files changed, 288 insertions(+), 329 deletions(-)
drivers/gpu/drm/selftests/Makefile +3 -2
@@ -1,11 +1,12 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ test-drm_modeset_common.o \ - test-drm_damage_helper.o test-drm_dp_mst_helper.o \ + test-drm_dp_mst_helper.o \ test-drm_rect.o obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ test-drm_cmdline_parser.o test-drm_plane_helper.o \ - test-drm_format.o test-drm_framebuffer.o + test-drm_format.o test-drm_framebuffer.o \ + test-drm_damage_helper.o
drivers/gpu/drm/selftests/drm_modeset_selftests.h +0 -21
@@ -10,26 +10,5 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped) selftest(drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) -selftest(damage_iter_no_damage, igt_damage_iter_no_damage) -selftest(damage_iter_no_damage_fractional_src, igt_damage_iter_no_damage_fractional_src) -selftest(damage_iter_no_damage_src_moved, igt_damage_iter_no_damage_src_moved) -selftest(damage_iter_no_damage_fractional_src_moved, igt_damage_iter_no_damage_fractional_src_moved) -selftest(damage_iter_no_damage_not_visible, igt_damage_iter_no_damage_not_visible) -selftest(damage_iter_no_damage_no_crtc, igt_damage_iter_no_damage_no_crtc) -selftest(damage_iter_no_damage_no_fb, igt_damage_iter_no_damage_no_fb) -selftest(damage_iter_simple_damage, igt_damage_iter_simple_damage) -selftest(damage_iter_single_damage, igt_damage_iter_single_damage) -selftest(damage_iter_single_damage_intersect_src, igt_damage_iter_single_damage_intersect_src) -selftest(damage_iter_single_damage_outside_src, igt_damage_iter_single_damage_outside_src) -selftest(damage_iter_single_damage_fractional_src, igt_damage_iter_single_damage_fractional_src) -selftest(damage_iter_single_damage_intersect_fractional_src, igt_damage_iter_single_damage_intersect_fractional_src) -selftest(damage_iter_single_damage_outside_fractional_src, igt_damage_iter_single_damage_outside_fractional_src) -selftest(damage_iter_single_damage_src_moved, igt_damage_iter_single_damage_src_moved) -selftest(damage_iter_single_damage_fractional_src_moved, igt_damage_iter_single_damage_fractional_src_moved) -selftest(damage_iter_damage, igt_damage_iter_damage) -selftest(damage_iter_damage_one_intersect, igt_damage_iter_damage_one_intersect) -selftest(damage_iter_damage_one_outside, igt_damage_iter_damage_one_outside) -selftest(damage_iter_damage_src_moved, igt_damage_iter_damage_src_moved) -selftest(damage_iter_damage_not_visible, igt_damage_iter_damage_not_visible) selftest(dp_mst_calc_pbn_mode, igt_dp_mst_calc_pbn_mode)selftest (dp_mst_sideband_msg_req_decode, igt_dp_mst_sideband_msg_req_decode)
drivers/gpu/drm/selftests/test-drm_damage_helper.c +285 -285
919 lines not on this page · raw message
drivers/gpu/drm/selftests/test-drm_modeset_common.h +0 -21
@@ -20,27 +20,6 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored);int igt_drm_rect_clip_scaled_not_clipped (void *ignored);int igt_drm_rect_clip_scaled_clipped (void *ignored);int igt_drm_rect_clip_scaled_signed_vs_unsigned (void *ignored); -int igt_damage_iter_no_damage (void *ignored); -int igt_damage_iter_no_damage_fractional_src (void *ignored); -int igt_damage_iter_no_damage_src_moved (void *ignored); -int igt_damage_iter_no_damage_fractional_src_moved (void *ignored); -int igt_damage_iter_no_damage_not_visible (void *ignored); -int igt_damage_iter_no_damage_no_crtc (void *ignored); -int igt_damage_iter_no_damage_no_fb (void *ignored); -int igt_damage_iter_simple_damage (void *ignored); -int igt_damage_iter_single_damage (void *ignored); -int igt_damage_iter_single_damage_intersect_src (void *ignored); -int igt_damage_iter_single_damage_outside_src (void *ignored); -int igt_damage_iter_single_damage_fractional_src (void *ignored); -int igt_damage_iter_single_damage_intersect_fractional_src (void *ignored); -int igt_damage_iter_single_damage_outside_fractional_src (void *ignored); -int igt_damage_iter_single_damage_src_moved (void *ignored); -int igt_damage_iter_single_damage_fractional_src_moved (void *ignored); -int igt_damage_iter_damage (void *ignored); -int igt_damage_iter_damage_one_intersect (void *ignored); -int igt_damage_iter_damage_one_outside (void *ignored); -int igt_damage_iter_damage_src_moved (void *ignored); -int igt_damage_iter_damage_not_visible (void *ignored);int igt_dp_mst_calc_pbn_mode (void *ignored);int igt_dp_mst_sideband_msg_req_decode (void *ignored);
Signature · 1 line
2.34.1
RFC 6/10 drm: test-drm_dp_mst_helper: Convert to KUnit
In reply to Michał Winiarskiigt_dp_mst_calc_pbn_mode was converted one-to-one, igt_dp_mst_sideband_msg_req_decode was refactored to parameterized test.
--- drivers/gpu/drm/selftests/Makefile | 3 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 2 - .../drm/selftests/test-drm_dp_mst_helper.c | 502 ++++++++++++------ .../drm/selftests/test-drm_modeset_common.h | 2 - 4 files changed, 330 insertions(+), 179 deletions(-)
drivers/gpu/drm/selftests/Makefile +1 -2
@@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ test-drm_modeset_common.o \ - test-drm_dp_mst_helper.o \ test-drm_rect.o obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o
@@ -9,4 +8,4 @@ obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ test-drm_cmdline_parser.o test-drm_plane_helper.o \ test-drm_format.o test-drm_framebuffer.o \ - test-drm_damage_helper.o + test-drm_damage_helper.o test-drm_dp_mst_helper.o
drivers/gpu/drm/selftests/drm_modeset_selftests.h +0 -2
@@ -10,5 +10,3 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped)selftest (drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) -selftest(dp_mst_calc_pbn_mode, igt_dp_mst_calc_pbn_mode) -selftest (dp_mst_sideband_msg_req_decode, igt_dp_mst_sideband_msg_req_decode)
drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c +329 -173
575 lines not on this page · raw message
drivers/gpu/drm/selftests/test-drm_modeset_common.h +0 -2
@@ -20,7 +20,5 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored);int igt_drm_rect_clip_scaled_not_clipped (void *ignored);int igt_drm_rect_clip_scaled_clipped (void *ignored);int igt_drm_rect_clip_scaled_signed_vs_unsigned (void *ignored); -int igt_dp_mst_calc_pbn_mode (void *ignored); -int igt_dp_mst_sideband_msg_req_decode (void *ignored);#endif
Signature · 1 line
2.34.1
Re: [RFC 06/10] drm: test-drm_dp_mst_helper: Convert to KUnit
Quoted 160 lines · Michał Winiarski
igt_dp_mst_calc_pbn_modewas converted one-to-one,igt_dp_mst_sideband_msg_req_decodewas refactored to parameterized test.Signed-off-by Michał Winiarski <[email protected]>--- drivers/gpu/drm/selftests/Makefile | 3 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 2 - .../drm/selftests/test-drm_dp_mst_helper.c | 502 ++++++++++++------ .../drm/selftests/test-drm_modeset_common.h | 2 - 4 files changed, 330 insertions(+), 179 deletions(-)drivers/gpu/drm/selftests/Makefile +1
-2@@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ test-drm_modeset_common.o \ - test-drm_dp_mst_helper.o \ test-drm_rect.o obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o@@ -9,4 +8,4 @@ obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ test-drm_cmdline_parser.o test-drm_plane_helper.o \ test-drm_format.o test-drm_framebuffer.o \ - test-drm_damage_helper.o + test-drm_damage_helper.o test-drm_dp_mst_helper.odrivers/gpu/drm/selftests/drm_modeset_selftests.h +0
-2@@ -10,5 +10,3 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped)selftest (drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) -selftest(dp_mst_calc_pbn_mode, igt_dp_mst_calc_pbn_mode) -selftest (dp_mst_sideband_msg_req_decode, igt_dp_mst_sideband_msg_req_decode)drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c +69
-30@@ -3,54 +3,97 @@* Test cases for for the DRM DP MST helpers */ -#define PREFIX_STR "[drm_dp_mst_helper]" - +#include <kunit/test.h> #include <linux/random.h> #include <drm/drm_dp_mst_helper.h> #include <drm/drm_print.h> #include "../drm_dp_mst_topology_internal.h" -#include "test-drm_modeset_common.h" -int igt_dp_mst_calc_pbn_mode (void *ignored) +struct dp_mst_calc_pbn_mode_test { +int rate; +int bpp; +int expected; +bool dsc; +}; + +static void dp_mst_calc_pbn_mode (struct kunit *test) { -int pbn, i; -const struct { -int rate; -int bpp; -int expected; -bool dsc; - } test_params[] = { - {154000 ,30 ,689 , false }, - {234000 ,30 ,1047 , false }, - {297000 ,24 ,1063 , false }, - {332880 ,24 ,50 , true }, - {324540 ,24 ,49 , true }, - }; +const struct dp_mst_calc_pbn_mode_test *params = test->param_value; +int pbn; -for (i =0 ; i <ARRAY_SIZE (test_params); i++) { - pbn =drm_dp_calc_pbn_mode (test_params[i].rate, - test_params[i].bpp, - test_params[i].dsc); -FAIL (pbn != test_params[i].expected, -"Expected PBN %d for clock %d bpp %d, got %d\n" , - test_params[i].expected, test_params[i].rate, - test_params[i].bpp, pbn); - } + pbn =drm_dp_calc_pbn_mode (params->rate, + params->bpp, + params->dsc); + +KUNIT_EXPECT_EQ (test, pbn, params->expected); +} -return 0 ; +static const struct dp_mst_calc_pbn_mode_test dp_mst_calc_pbn_mode_tests[] = { + { + .rate =154000 , + .bpp =30 , + .expected =689 , + .dsc = false, + }, + { + .rate =234000 , + .bpp =30 , + .expected =1047 , + .dsc = false, + }, + { + .rate =297000 , + .bpp =24 , + .expected =1063 , + .dsc = false, + }, + { + .rate =332880 , + .bpp =24 , + .expected =50 , + .dsc = true, + }, + { + .rate =324540 , + .bpp =24 , + .expected =49 , + .dsc = true, + }, +}; + +static void dp_mst_calc_pbn_mode_desc (const struct dp_mst_calc_pbn_mode_test *t, +char *desc) +{ +sprintf (desc,"rate = %d, bpp = %d, dsc = %s" , + t->rate, t->bpp, t->dsc ?"true" :"false" ); } -static bool -sideband_msg_req_equal (const struct drm_dp_sideband_msg_req_body *in, -const struct drm_dp_sideband_msg_req_body *out) +KUNIT_ARRAY_PARAM (dp_mst_calc_pbn_mode, dp_mst_calc_pbn_mode_tests, dp_mst_calc_pbn_mode_desc); + +static void +drm_dp_mst_helper_printfn (struct drm_printer *p,struct va_format *vaf) +{ +struct kunit *test = p->arg; + +kunit_err (test,"%pV" , vaf); +} + +static void +expect_sideband_msg_req_equal (struct kunit *test, +const struct drm_dp_sideband_msg_req_body *in, +const struct drm_dp_sideband_msg_req_body *out) {
drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c line 96
Quoted 10 lines
drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c +5
-1const struct drm_dp_remote_i2c_read_tx *txin, *txout; +struct drm_printer p = { + .printfn = drm_dp_mst_helper_printfn, + .arg = test + };int i;if (in->req_type != out->req_type) -return false; + goto fail;
Briefly skimming over this code, it looks like it'd be simpler to have this function remain unchanged.
There's only the one caller.
It could take on the responsibility of creating the drm_printer and redirect the printfn to kunit_err, afaik.
Passing in test would be useful if we were generating custom error messages for each of the return false lines, which I assume was the original motivation for doing so?
But looking at this, I'd agree it seems like too much work.
Tangent:
It might have been easier to do that if the kunit assertions returned pass/fail. E.g. instead of having to do
if (!<long-condition>) {
KUNIT_FAIL("<long-condition> not met");
return;
}
if we could do
if(!KUNIT_EXPECT_TRUE(long-condition))
return;
or if there was a new macro type
KUNIT_EXPECT_RET_TRUE(long-condition); // like ASSERT, but just return from this func on failure
Quoted 470 lines
drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c +255
-142switch (in->req_type) {/* @@ -65,7 +108,7 @@ sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in,IN .num_transactions !=OUT .num_transactions ||IN .port_number !=OUT .port_number || IN.read_i2c_device_id != OUT.read_i2c_device_id) - return false; + goto fail;for (i =0 ; i <IN .num_transactions; i++) { txin = &IN .transactions[i];@@ -76,11 +119,11 @@ sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in, txin->num_bytes != txout->num_bytes || txin->i2c_transaction_delay != txout->i2c_transaction_delay) - return false; + goto fail;if (memcmp (txin->bytes, txout->bytes, txin->num_bytes) !=0 ) -return false; + goto fail; }break ;#undef IN@@ -92,9 +135,12 @@ sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in,if (IN .dpcd_address !=OUT .dpcd_address ||IN .num_bytes !=OUT .num_bytes ||IN .port_number !=OUT .port_number) -return false; + goto fail; -return memcmp (IN .bytes,OUT .bytes,IN .num_bytes) ==0 ; +if (memcmp (IN .bytes,OUT .bytes,IN .num_bytes) !=0 ) + goto fail; + +break ;#undef IN#undef OUT@@ -104,55 +150,65 @@ sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in,if (IN .port_number !=OUT .port_number ||IN .write_i2c_device_id !=OUT .write_i2c_device_id ||IN .num_bytes !=OUT .num_bytes) -return false; + goto fail; -return memcmp (IN .bytes,OUT .bytes,IN .num_bytes) ==0 ; +if (memcmp (IN .bytes,OUT .bytes,IN .num_bytes) !=0 ) + goto fail; + +break ;#undef IN#undef OUTdefault : -return memcmp (in, out,sizeof (*in)) ==0 ; +if (memcmp (in, out,sizeof (*in)) !=0 ) + goto fail; } -return true; +return ; + +fail: +drm_printf (&p,"Expected:\n" ); +drm_dp_dump_sideband_msg_req_body (in,1 , &p); +drm_printf (&p,"Got:\n" ); +drm_dp_dump_sideband_msg_req_body (out,1 , &p); +KUNIT_FAIL (test,"Encode/decode failed" ); +} + +struct dp_mst_sideband_msg_req_decode_test { +const struct drm_dp_sideband_msg_req_body req; +const struct drm_dp_sideband_msg_req_body + (*f)(const struct drm_dp_sideband_msg_req_body *in); +}; + +const struct drm_dp_sideband_msg_req_body +param_to_dp_mst_sideband_msg_req_body (const struct dp_mst_sideband_msg_req_decode_test *t) +{ +if (t->f) +return t->f (&t->req); + +return t->req; } -static bool -sideband_msg_req_encode_decode (struct drm_dp_sideband_msg_req_body *in) +static void dp_mst_sideband_msg_req_decode (struct kunit *test) { +const struct drm_dp_sideband_msg_req_body in = +param_to_dp_mst_sideband_msg_req_body (test->param_value);struct drm_dp_sideband_msg_req_body *out; -struct drm_printer p =drm_err_printer (PREFIX_STR );struct drm_dp_sideband_msg_tx *txmsg; -int i, ret; -bool result = true; - - out =kzalloc (sizeof (*out),GFP_KERNEL ); -if (!out) -return false; - - txmsg =kzalloc (sizeof (*txmsg),GFP_KERNEL ); -if (!txmsg) -return false; - -drm_dp_encode_sideband_req (in, txmsg); - ret =drm_dp_decode_sideband_req (txmsg, out); -if (ret <0 ) { -drm_printf (&p,"Failed to decode sideband request: %d\n" , - ret); - result = false; - goto out; - } +int i; -if (!sideband_msg_req_equal (in, out)) { -drm_printf (&p,"Encode/decode failed, expected:\n" ); -drm_dp_dump_sideband_msg_req_body (in,1 , &p); -drm_printf (&p,"Got:\n" ); -drm_dp_dump_sideband_msg_req_body (out,1 , &p); - result = false; - goto out; - } + out =kunit_kzalloc (test,sizeof (*out),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, out); -switch (in->req_type) { + txmsg =kunit_kzalloc (test,sizeof (*txmsg),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, txmsg); + +drm_dp_encode_sideband_req (&in, txmsg); +KUNIT_ASSERT_EQ (test,drm_dp_decode_sideband_req (txmsg, out),0 ); + +expect_sideband_msg_req_equal (test, &in, out); + +switch (in.req_type) {case DP_REMOTE_DPCD_WRITE :kfree (out->u.dpcd_write.bytes);break ;@@ -164,110 +220,210 @@ sideband_msg_req_encode_decode(struct drm_dp_sideband_msg_req_body *in)kfree (out->u.i2c_write.bytes);break ; } - -/* Clear everything but the req_type for the input */ -memset (&in->u,0 ,sizeof (in->u)); - -out: -kfree (out); -kfree (txmsg); -return result; } -int igt_dp_mst_sideband_msg_req_decode (void *unused) +static u8 data[] = {0xff ,0x0 ,0xdd }; + +const struct drm_dp_sideband_msg_req_body +random_dp_query_enc_client_id (const struct drm_dp_sideband_msg_req_body *in) { -struct drm_dp_sideband_msg_req_body in = {0 }; -u8 data[] = {0xff ,0x0 ,0xdd }; -int i; +struct drm_dp_query_stream_enc_status enc_status = { }; -#define DO_TEST () FAIL_ON(!sideband_msg_req_encode_decode(&in)) - - in.req_type =DP_ENUM_PATH_RESOURCES ; - in.u.port_num.port_number =5 ; -DO_TEST (); - - in.req_type =DP_POWER_UP_PHY ; - in.u.port_num.port_number =5 ; -DO_TEST (); - - in.req_type =DP_POWER_DOWN_PHY ; - in.u.port_num.port_number =5 ; -DO_TEST (); - - in.req_type =DP_ALLOCATE_PAYLOAD ; - in.u.allocate_payload.number_sdp_streams =3 ; -for (i =0 ; i < in.u.allocate_payload.number_sdp_streams; i++) - in.u.allocate_payload.sdp_stream_sink[i] = i +1 ; -DO_TEST (); - in.u.allocate_payload.port_number =0xf ; -DO_TEST (); - in.u.allocate_payload.vcpi =0x7f ; -DO_TEST (); - in.u.allocate_payload.pbn =U16_MAX ; -DO_TEST (); - - in.req_type =DP_QUERY_PAYLOAD ; - in.u.query_payload.port_number =0xf ; -DO_TEST (); - in.u.query_payload.vcpi =0x7f ; -DO_TEST (); - - in.req_type =DP_REMOTE_DPCD_READ ; - in.u.dpcd_read.port_number =0xf ; -DO_TEST (); - in.u.dpcd_read.dpcd_address =0xfedcb ; -DO_TEST (); - in.u.dpcd_read.num_bytes =U8_MAX ; -DO_TEST (); - - in.req_type =DP_REMOTE_DPCD_WRITE ; - in.u.dpcd_write.port_number =0xf ; -DO_TEST (); - in.u.dpcd_write.dpcd_address =0xfedcb ; -DO_TEST (); - in.u.dpcd_write.num_bytes =ARRAY_SIZE (data); - in.u.dpcd_write.bytes = data; -DO_TEST (); - - in.req_type =DP_REMOTE_I2C_READ ; - in.u.i2c_read.port_number =0xf ; -DO_TEST (); - in.u.i2c_read.read_i2c_device_id =0x7f ; -DO_TEST (); - in.u.i2c_read.num_transactions =3 ; - in.u.i2c_read.num_bytes_read =ARRAY_SIZE (data) *3 ; -for (i =0 ; i < in.u.i2c_read.num_transactions; i++) { - in.u.i2c_read.transactions[i].bytes = data; - in.u.i2c_read.transactions[i].num_bytes =ARRAY_SIZE (data); - in.u.i2c_read.transactions[i].i2c_dev_id =0x7f & ~i; - in.u.i2c_read.transactions[i].i2c_transaction_delay =0xf & ~i; - } -DO_TEST (); - - in.req_type =DP_REMOTE_I2C_WRITE ; - in.u.i2c_write.port_number =0xf ; -DO_TEST (); - in.u.i2c_write.write_i2c_device_id =0x7f ; -DO_TEST (); - in.u.i2c_write.num_bytes =ARRAY_SIZE (data); - in.u.i2c_write.bytes = data; -DO_TEST (); - - in.req_type =DP_QUERY_STREAM_ENC_STATUS ; - in.u.enc_status.stream_id =1 ; -DO_TEST (); -get_random_bytes (in.u.enc_status.client_id, -sizeof (in.u.enc_status.client_id)); -DO_TEST (); - in.u.enc_status.stream_event =3 ; -DO_TEST (); - in.u.enc_status.valid_stream_event =0 ; -DO_TEST (); - in.u.enc_status.stream_behavior =3 ; -DO_TEST (); - in.u.enc_status.valid_stream_behavior =1 ; -DO_TEST (); - -#undef DO_TEST -return 0 ; +get_random_bytes (enc_status.client_id,sizeof (enc_status.client_id)); + +return (const struct drm_dp_sideband_msg_req_body ) { .req_type = in->req_type, + .u.enc_status = enc_status + }; } + +static const struct dp_mst_sideband_msg_req_decode_test dp_msg_sideband_msg_req_decode_tests[] = { + { + .req = { + .req_type =DP_ENUM_PATH_RESOURCES , + .u.port_num.port_number =5 , + }, + }, + { + .req = { + .req_type =DP_POWER_UP_PHY , + .u.port_num.port_number =5 , + }, + }, + { + .req = { + .req_type =DP_POWER_DOWN_PHY , + .u.port_num.port_number =5 , + }, + }, + { + .req = { + .req_type =DP_ALLOCATE_PAYLOAD , + .u.allocate_payload.number_sdp_streams =3 , + .u.allocate_payload.sdp_stream_sink = {1 ,2 ,3 }, + }, + }, + { + .req = { + .req_type =DP_ALLOCATE_PAYLOAD , + .u.allocate_payload.port_number =0xf , + }, + }, + { + .req = { + .req_type =DP_ALLOCATE_PAYLOAD , + .u.allocate_payload.vcpi =0x7f , + }, + }, + { + .req = { + .req_type =DP_ALLOCATE_PAYLOAD , + .u.allocate_payload.pbn =U16_MAX , + }, + }, + { + .req = { + .req_type =DP_QUERY_PAYLOAD , + .u.query_payload.port_number =0xf , + }, + }, + { + .req = { + .req_type =DP_QUERY_PAYLOAD , + .u.query_payload.vcpi =0x7f , + }, + }, + { + .req = { + .req_type =DP_REMOTE_DPCD_READ , + .u.dpcd_read.port_number =0xf , + }, + }, + { + .req = { + .req_type =DP_REMOTE_DPCD_READ , + .u.dpcd_read.dpcd_address =0xfedcb , + }, + }, + { + .req = { + .req_type =DP_REMOTE_DPCD_READ , + .u.dpcd_read.num_bytes =U8_MAX , + }, + }, + { + .req = { + .req_type =DP_REMOTE_DPCD_WRITE , + .u.dpcd_write.port_number =0xf , + }, + }, + { + .req = { + .req_type =DP_REMOTE_DPCD_WRITE , + .u.dpcd_write.dpcd_address =0xfedcb , + }, + }, + { + .req = { + .req_type =DP_REMOTE_DPCD_WRITE , + .u.dpcd_write.num_bytes =ARRAY_SIZE (data), + .u.dpcd_write.bytes = data, + }, + }, + { + .req = { + .req_type =DP_REMOTE_I2C_READ , + .u.i2c_read.port_number =0xf , + }, + }, + { + .req = { + .req_type =DP_REMOTE_I2C_READ , + .u.i2c_read.read_i2c_device_id =0x7f , + }, + }, + { + .req = { + .req_type =DP_REMOTE_I2C_READ , + .u.i2c_read.num_transactions =3 , + .u.i2c_read.num_bytes_read =ARRAY_SIZE (data) *3 , + .u.i2c_read.transactions = { + { .bytes = data, .num_bytes =ARRAY_SIZE (data), + .i2c_dev_id =0x7f , .i2c_transaction_delay =0xf , }, + { .bytes = data, .num_bytes =ARRAY_SIZE (data), + .i2c_dev_id =0x7e , .i2c_transaction_delay =0xe , }, + { .bytes = data, .num_bytes =ARRAY_SIZE (data), + .i2c_dev_id =0x7d , .i2c_transaction_delay =0xd , }, + }, + }, + }, + { + .req = { + .req_type =DP_REMOTE_I2C_WRITE , + .u.i2c_write.port_number =0xf , + }, + }, + { + .req = { + .req_type =DP_REMOTE_I2C_WRITE , + .u.i2c_write.write_i2c_device_id =0x7f , + }, + }, + { + .req = { + .req_type =DP_REMOTE_I2C_WRITE , + .u.i2c_write.num_bytes =ARRAY_SIZE (data), + .u.i2c_write.bytes = data, + }, + }, + { + .req = { + .req_type =DP_QUERY_STREAM_ENC_STATUS , + .u.enc_status.stream_id =1 , + }, + }, + { + .req = { + .req_type =DP_QUERY_STREAM_ENC_STATUS , + }, + .f = random_dp_query_enc_client_id, + }, + { + .req = { + .req_type =DP_QUERY_STREAM_ENC_STATUS , + .u.enc_status.stream_event =3 , + }, + }, + { + .req = { + .req_type =DP_QUERY_STREAM_ENC_STATUS , + .u.enc_status.valid_stream_event =0 , + }, + }, + { + .req = { + .req_type =DP_QUERY_STREAM_ENC_STATUS , + .u.enc_status.stream_behavior =3 , + }, + }, + { + .req = { + .req_type =DP_QUERY_STREAM_ENC_STATUS , + .u.enc_status.valid_stream_behavior =1 , + }, + }, +}; + +KUNIT_ARRAY_PARAM (dp_mst_sideband_msg_req, dp_msg_sideband_msg_req_decode_tests,NULL ); + +static struct kunit_case drm_dp_mst_helper_tests[] = { +KUNIT_CASE_PARAM (dp_mst_calc_pbn_mode, dp_mst_calc_pbn_mode_gen_params), +KUNIT_CASE_PARAM (dp_mst_sideband_msg_req_decode, dp_mst_sideband_msg_req_gen_params), + {} +}; + +static struct kunit_suite drm_dp_mst_helper_test_suite = { + .name ="drm_dp_mst_helper_tests" , + .test_cases = drm_dp_mst_helper_tests, +}; + +kunit_test_suite (drm_dp_mst_helper_test_suite);drivers/gpu/drm/selftests/test-drm_modeset_common.h +0
-3@@ -20,7 +20,5 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored);int igt_drm_rect_clip_scaled_not_clipped (void *ignored);int igt_drm_rect_clip_scaled_clipped (void *ignored);int igt_drm_rect_clip_scaled_signed_vs_unsigned (void *ignored); -int igt_dp_mst_calc_pbn_mode (void *ignored); -int igt_dp_mst_sideband_msg_req_decode (void *ignored);#endif --2.34.1
Re: [RFC 06/10] drm: test-drm_dp_mst_helper: Convert to KUnit
Quoted 179 lines · Daniel Latypov
Quoted 160 lines · Michał Winiarski
igt_dp_mst_calc_pbn_modewas converted one-to-one,igt_dp_mst_sideband_msg_req_decodewas refactored to parameterized test.Signed-off-by Michał Winiarski <[email protected]>--- drivers/gpu/drm/selftests/Makefile | 3 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 2 - .../drm/selftests/test-drm_dp_mst_helper.c | 502 ++++++++++++------ .../drm/selftests/test-drm_modeset_common.h | 2 - 4 files changed, 330 insertions(+), 179 deletions(-)drivers/gpu/drm/selftests/Makefile +1
-2@@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ test-drm_modeset_common.o \ - test-drm_dp_mst_helper.o \ test-drm_rect.o obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o@@ -9,4 +8,4 @@ obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ test-drm_cmdline_parser.o test-drm_plane_helper.o \ test-drm_format.o test-drm_framebuffer.o \ - test-drm_damage_helper.o + test-drm_damage_helper.o test-drm_dp_mst_helper.odrivers/gpu/drm/selftests/drm_modeset_selftests.h +0
-2@@ -10,5 +10,3 @@ selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped)selftest (drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned) -selftest(dp_mst_calc_pbn_mode, igt_dp_mst_calc_pbn_mode) -selftest (dp_mst_sideband_msg_req_decode, igt_dp_mst_sideband_msg_req_decode)drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c +69
-30@@ -3,54 +3,97 @@* Test cases for for the DRM DP MST helpers */ -#define PREFIX_STR "[drm_dp_mst_helper]" - +#include <kunit/test.h> #include <linux/random.h> #include <drm/drm_dp_mst_helper.h> #include <drm/drm_print.h> #include "../drm_dp_mst_topology_internal.h" -#include "test-drm_modeset_common.h" -int igt_dp_mst_calc_pbn_mode (void *ignored) +struct dp_mst_calc_pbn_mode_test { +int rate; +int bpp; +int expected; +bool dsc; +}; + +static void dp_mst_calc_pbn_mode (struct kunit *test) { -int pbn, i; -const struct { -int rate; -int bpp; -int expected; -bool dsc; - } test_params[] = { - {154000 ,30 ,689 , false }, - {234000 ,30 ,1047 , false }, - {297000 ,24 ,1063 , false }, - {332880 ,24 ,50 , true }, - {324540 ,24 ,49 , true }, - }; +const struct dp_mst_calc_pbn_mode_test *params = test->param_value; +int pbn; -for (i =0 ; i <ARRAY_SIZE (test_params); i++) { - pbn =drm_dp_calc_pbn_mode (test_params[i].rate, - test_params[i].bpp, - test_params[i].dsc); -FAIL (pbn != test_params[i].expected, -"Expected PBN %d for clock %d bpp %d, got %d\n" , - test_params[i].expected, test_params[i].rate, - test_params[i].bpp, pbn); - } + pbn =drm_dp_calc_pbn_mode (params->rate, + params->bpp, + params->dsc); + +KUNIT_EXPECT_EQ (test, pbn, params->expected); +} -return 0 ; +static const struct dp_mst_calc_pbn_mode_test dp_mst_calc_pbn_mode_tests[] = { + { + .rate =154000 , + .bpp =30 , + .expected =689 , + .dsc = false, + }, + { + .rate =234000 , + .bpp =30 , + .expected =1047 , + .dsc = false, + }, + { + .rate =297000 , + .bpp =24 , + .expected =1063 , + .dsc = false, + }, + { + .rate =332880 , + .bpp =24 , + .expected =50 , + .dsc = true, + }, + { + .rate =324540 , + .bpp =24 , + .expected =49 , + .dsc = true, + }, +}; + +static void dp_mst_calc_pbn_mode_desc (const struct dp_mst_calc_pbn_mode_test *t, +char *desc) +{ +sprintf (desc,"rate = %d, bpp = %d, dsc = %s" , + t->rate, t->bpp, t->dsc ?"true" :"false" ); } -static bool -sideband_msg_req_equal (const struct drm_dp_sideband_msg_req_body *in, -const struct drm_dp_sideband_msg_req_body *out) +KUNIT_ARRAY_PARAM (dp_mst_calc_pbn_mode, dp_mst_calc_pbn_mode_tests, dp_mst_calc_pbn_mode_desc); + +static void +drm_dp_mst_helper_printfn (struct drm_printer *p,struct va_format *vaf) +{ +struct kunit *test = p->arg; + +kunit_err (test,"%pV" , vaf); +} + +static void +expect_sideband_msg_req_equal (struct kunit *test, +const struct drm_dp_sideband_msg_req_body *in, +const struct drm_dp_sideband_msg_req_body *out) {drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c line 96
Quoted 10 lines
drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c +5
-1const struct drm_dp_remote_i2c_read_tx *txin, *txout; +struct drm_printer p = { + .printfn = drm_dp_mst_helper_printfn, + .arg = test + };int i;if (in->req_type != out->req_type) -return false; + goto fail;Briefly skimming over this code, it looks like it'd be simpler to have this function remain unchanged.
There's only the one caller.
It could take on the responsibility of creating thedrm_printerand redirect the printfn tokunit_err, afaik.
Quoted 4 lines
Passing in
testwould be useful if we were generating custom error messages for each of thereturn falselines, which I assume was the original motivation for doing so?
But looking at this, I'd agree it seems like too much work.
Yes, that was the original motivation, but eventually I went back to the original code, leaving drm_printer behind. I agree - I'll leave the function intact.
Quoted 12 lines
Tangent:
It might have been easier to do that if the kunit assertions returned pass/fail. E.g. instead of having to doif (!<long-condition>) { KUNIT_FAIL("<long-condition> not met"); return; }if we could do
Quoted 7 lines
if(!KUNIT_EXPECT_TRUE(long-condition))
return;or if there was a new macro type
KUNIT_EXPECT_RET_TRUE(long-condition); // like ASSERT, but just return from this func on failure
This would simplify a bunch of other tests as well.
On the other hand - EXPECT_TRUE returning a value is not something I would expect :)
Thanks!
-Michał
Quoted 472 lines
Quoted 472 lines
drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c +255
-142switch (in->req_type) {/* @@ -65,7 +108,7 @@ sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in,IN .num_transactions !=OUT .num_transactions ||IN .port_number !=OUT .port_number || IN.read_i2c_device_id != OUT.read_i2c_device_id) - return false; + goto fail;for (i =0 ; i <IN .num_transactions; i++) { txin = &IN .transactions[i];@@ -76,11 +119,11 @@ sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in, txin->num_bytes != txout->num_bytes || txin->i2c_transaction_delay != txout->i2c_transaction_delay) - return false; + goto fail;if (memcmp (txin->bytes, txout->bytes, txin->num_bytes) !=0 ) -return false; + goto fail; }break ;#undef IN@@ -92,9 +135,12 @@ sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in,if (IN .dpcd_address !=OUT .dpcd_address ||IN .num_bytes !=OUT .num_bytes ||IN .port_number !=OUT .port_number) -return false; + goto fail; -return memcmp (IN .bytes,OUT .bytes,IN .num_bytes) ==0 ; +if (memcmp (IN .bytes,OUT .bytes,IN .num_bytes) !=0 ) + goto fail; + +break ;#undef IN#undef OUT@@ -104,55 +150,65 @@ sideband_msg_req_equal(const struct drm_dp_sideband_msg_req_body *in,if (IN .port_number !=OUT .port_number ||IN .write_i2c_device_id !=OUT .write_i2c_device_id ||IN .num_bytes !=OUT .num_bytes) -return false; + goto fail; -return memcmp (IN .bytes,OUT .bytes,IN .num_bytes) ==0 ; +if (memcmp (IN .bytes,OUT .bytes,IN .num_bytes) !=0 ) + goto fail; + +break ;#undef IN#undef OUTdefault : -return memcmp (in, out,sizeof (*in)) ==0 ; +if (memcmp (in, out,sizeof (*in)) !=0 ) + goto fail; } -return true; +return ; + +fail: +drm_printf (&p,"Expected:\n" ); +drm_dp_dump_sideband_msg_req_body (in,1 , &p); +drm_printf (&p,"Got:\n" ); +drm_dp_dump_sideband_msg_req_body (out,1 , &p); +KUNIT_FAIL (test,"Encode/decode failed" ); +} + +struct dp_mst_sideband_msg_req_decode_test { +const struct drm_dp_sideband_msg_req_body req; +const struct drm_dp_sideband_msg_req_body + (*f)(const struct drm_dp_sideband_msg_req_body *in); +}; + +const struct drm_dp_sideband_msg_req_body +param_to_dp_mst_sideband_msg_req_body (const struct dp_mst_sideband_msg_req_decode_test *t) +{ +if (t->f) +return t->f (&t->req); + +return t->req; } -static bool -sideband_msg_req_encode_decode (struct drm_dp_sideband_msg_req_body *in) +static void dp_mst_sideband_msg_req_decode (struct kunit *test) { +const struct drm_dp_sideband_msg_req_body in = +param_to_dp_mst_sideband_msg_req_body (test->param_value);struct drm_dp_sideband_msg_req_body *out; -struct drm_printer p =drm_err_printer (PREFIX_STR );struct drm_dp_sideband_msg_tx *txmsg; -int i, ret; -bool result = true; - - out =kzalloc (sizeof (*out),GFP_KERNEL ); -if (!out) -return false; - - txmsg =kzalloc (sizeof (*txmsg),GFP_KERNEL ); -if (!txmsg) -return false; - -drm_dp_encode_sideband_req (in, txmsg); - ret =drm_dp_decode_sideband_req (txmsg, out); -if (ret <0 ) { -drm_printf (&p,"Failed to decode sideband request: %d\n" , - ret); - result = false; - goto out; - } +int i; -if (!sideband_msg_req_equal (in, out)) { -drm_printf (&p,"Encode/decode failed, expected:\n" ); -drm_dp_dump_sideband_msg_req_body (in,1 , &p); -drm_printf (&p,"Got:\n" ); -drm_dp_dump_sideband_msg_req_body (out,1 , &p); - result = false; - goto out; - } + out =kunit_kzalloc (test,sizeof (*out),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, out); -switch (in->req_type) { + txmsg =kunit_kzalloc (test,sizeof (*txmsg),GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, txmsg); + +drm_dp_encode_sideband_req (&in, txmsg); +KUNIT_ASSERT_EQ (test,drm_dp_decode_sideband_req (txmsg, out),0 ); + +expect_sideband_msg_req_equal (test, &in, out); + +switch (in.req_type) {case DP_REMOTE_DPCD_WRITE :kfree (out->u.dpcd_write.bytes);break ;@@ -164,110 +220,210 @@ sideband_msg_req_encode_decode(struct drm_dp_sideband_msg_req_body *in)kfree (out->u.i2c_write.bytes);break ; } - -/* Clear everything but the req_type for the input */ -memset (&in->u,0 ,sizeof (in->u)); - -out: -kfree (out); -kfree (txmsg); -return result; } -int igt_dp_mst_sideband_msg_req_decode (void *unused) +static u8 data[] = {0xff ,0x0 ,0xdd }; + +const struct drm_dp_sideband_msg_req_body +random_dp_query_enc_client_id (const struct drm_dp_sideband_msg_req_body *in) { -struct drm_dp_sideband_msg_req_body in = {0 }; -u8 data[] = {0xff ,0x0 ,0xdd }; -int i; +struct drm_dp_query_stream_enc_status enc_status = { }; -#define DO_TEST () FAIL_ON(!sideband_msg_req_encode_decode(&in)) - - in.req_type =DP_ENUM_PATH_RESOURCES ; - in.u.port_num.port_number =5 ; -DO_TEST (); - - in.req_type =DP_POWER_UP_PHY ; - in.u.port_num.port_number =5 ; -DO_TEST (); - - in.req_type =DP_POWER_DOWN_PHY ; - in.u.port_num.port_number =5 ; -DO_TEST (); - - in.req_type =DP_ALLOCATE_PAYLOAD ; - in.u.allocate_payload.number_sdp_streams =3 ; -for (i =0 ; i < in.u.allocate_payload.number_sdp_streams; i++) - in.u.allocate_payload.sdp_stream_sink[i] = i +1 ; -DO_TEST (); - in.u.allocate_payload.port_number =0xf ; -DO_TEST (); - in.u.allocate_payload.vcpi =0x7f ; -DO_TEST (); - in.u.allocate_payload.pbn =U16_MAX ; -DO_TEST (); - - in.req_type =DP_QUERY_PAYLOAD ; - in.u.query_payload.port_number =0xf ; -DO_TEST (); - in.u.query_payload.vcpi =0x7f ; -DO_TEST (); - - in.req_type =DP_REMOTE_DPCD_READ ; - in.u.dpcd_read.port_number =0xf ; -DO_TEST (); - in.u.dpcd_read.dpcd_address =0xfedcb ; -DO_TEST (); - in.u.dpcd_read.num_bytes =U8_MAX ; -DO_TEST (); - - in.req_type =DP_REMOTE_DPCD_WRITE ; - in.u.dpcd_write.port_number =0xf ; -DO_TEST (); - in.u.dpcd_write.dpcd_address =0xfedcb ; -DO_TEST (); - in.u.dpcd_write.num_bytes =ARRAY_SIZE (data); - in.u.dpcd_write.bytes = data; -DO_TEST (); - - in.req_type =DP_REMOTE_I2C_READ ; - in.u.i2c_read.port_number =0xf ; -DO_TEST (); - in.u.i2c_read.read_i2c_device_id =0x7f ; -DO_TEST (); - in.u.i2c_read.num_transactions =3 ; - in.u.i2c_read.num_bytes_read =ARRAY_SIZE (data) *3 ; -for (i =0 ; i < in.u.i2c_read.num_transactions; i++) { - in.u.i2c_read.transactions[i].bytes = data; - in.u.i2c_read.transactions[i].num_bytes =ARRAY_SIZE (data); - in.u.i2c_read.transactions[i].i2c_dev_id =0x7f & ~i; - in.u.i2c_read.transactions[i].i2c_transaction_delay =0xf & ~i; - } -DO_TEST (); - - in.req_type =DP_REMOTE_I2C_WRITE ; - in.u.i2c_write.port_number =0xf ; -DO_TEST (); - in.u.i2c_write.write_i2c_device_id =0x7f ; -DO_TEST (); - in.u.i2c_write.num_bytes =ARRAY_SIZE (data); - in.u.i2c_write.bytes = data; -DO_TEST (); - - in.req_type =DP_QUERY_STREAM_ENC_STATUS ; - in.u.enc_status.stream_id =1 ; -DO_TEST (); -get_random_bytes (in.u.enc_status.client_id, -sizeof (in.u.enc_status.client_id)); -DO_TEST (); - in.u.enc_status.stream_event =3 ; -DO_TEST (); - in.u.enc_status.valid_stream_event =0 ; -DO_TEST (); - in.u.enc_status.stream_behavior =3 ; -DO_TEST (); - in.u.enc_status.valid_stream_behavior =1 ; -DO_TEST (); - -#undef DO_TEST -return 0 ; +get_random_bytes (enc_status.client_id,sizeof (enc_status.client_id)); + +return (const struct drm_dp_sideband_msg_req_body ) { .req_type = in->req_type, + .u.enc_status = enc_status + }; } + +static const struct dp_mst_sideband_msg_req_decode_test dp_msg_sideband_msg_req_decode_tests[] = { + { + .req = { + .req_type =DP_ENUM_PATH_RESOURCES , + .u.port_num.port_number =5 , + }, + }, + { + .req = { + .req_type =DP_POWER_UP_PHY , + .u.port_num.port_number =5 , + }, + }, + { + .req = { + .req_type =DP_POWER_DOWN_PHY , + .u.port_num.port_number =5 , + }, + }, + { + .req = { + .req_type =DP_ALLOCATE_PAYLOAD , + .u.allocate_payload.number_sdp_streams =3 , + .u.allocate_payload.sdp_stream_sink = {1 ,2 ,3 }, + }, + }, + { + .req = { + .req_type =DP_ALLOCATE_PAYLOAD , + .u.allocate_payload.port_number =0xf , + }, + }, + { + .req = { + .req_type =DP_ALLOCATE_PAYLOAD , + .u.allocate_payload.vcpi =0x7f , + }, + }, + { + .req = { + .req_type =DP_ALLOCATE_PAYLOAD , + .u.allocate_payload.pbn =U16_MAX , + }, + }, + { + .req = { + .req_type =DP_QUERY_PAYLOAD , + .u.query_payload.port_number =0xf , + }, + }, + { + .req = { + .req_type =DP_QUERY_PAYLOAD , + .u.query_payload.vcpi =0x7f , + }, + }, + { + .req = { + .req_type =DP_REMOTE_DPCD_READ , + .u.dpcd_read.port_number =0xf , + }, + }, + { + .req = { + .req_type =DP_REMOTE_DPCD_READ , + .u.dpcd_read.dpcd_address =0xfedcb , + }, + }, + { + .req = { + .req_type =DP_REMOTE_DPCD_READ , + .u.dpcd_read.num_bytes =U8_MAX , + }, + }, + { + .req = { + .req_type =DP_REMOTE_DPCD_WRITE , + .u.dpcd_write.port_number =0xf , + }, + }, + { + .req = { + .req_type =DP_REMOTE_DPCD_WRITE , + .u.dpcd_write.dpcd_address =0xfedcb , + }, + }, + { + .req = { + .req_type =DP_REMOTE_DPCD_WRITE , + .u.dpcd_write.num_bytes =ARRAY_SIZE (data), + .u.dpcd_write.bytes = data, + }, + }, + { + .req = { + .req_type =DP_REMOTE_I2C_READ , + .u.i2c_read.port_number =0xf , + }, + }, + { + .req = { + .req_type =DP_REMOTE_I2C_READ , + .u.i2c_read.read_i2c_device_id =0x7f , + }, + }, + { + .req = { + .req_type =DP_REMOTE_I2C_READ , + .u.i2c_read.num_transactions =3 , + .u.i2c_read.num_bytes_read =ARRAY_SIZE (data) *3 , + .u.i2c_read.transactions = { + { .bytes = data, .num_bytes =ARRAY_SIZE (data), + .i2c_dev_id =0x7f , .i2c_transaction_delay =0xf , }, + { .bytes = data, .num_bytes =ARRAY_SIZE (data), + .i2c_dev_id =0x7e , .i2c_transaction_delay =0xe , }, + { .bytes = data, .num_bytes =ARRAY_SIZE (data), + .i2c_dev_id =0x7d , .i2c_transaction_delay =0xd , }, + }, + }, + }, + { + .req = { + .req_type =DP_REMOTE_I2C_WRITE , + .u.i2c_write.port_number =0xf , + }, + }, + { + .req = { + .req_type =DP_REMOTE_I2C_WRITE , + .u.i2c_write.write_i2c_device_id =0x7f , + }, + }, + { + .req = { + .req_type =DP_REMOTE_I2C_WRITE , + .u.i2c_write.num_bytes =ARRAY_SIZE (data), + .u.i2c_write.bytes = data, + }, + }, + { + .req = { + .req_type =DP_QUERY_STREAM_ENC_STATUS , + .u.enc_status.stream_id =1 , + }, + }, + { + .req = { + .req_type =DP_QUERY_STREAM_ENC_STATUS , + }, + .f = random_dp_query_enc_client_id, + }, + { + .req = { + .req_type =DP_QUERY_STREAM_ENC_STATUS , + .u.enc_status.stream_event =3 , + }, + }, + { + .req = { + .req_type =DP_QUERY_STREAM_ENC_STATUS , + .u.enc_status.valid_stream_event =0 , + }, + }, + { + .req = { + .req_type =DP_QUERY_STREAM_ENC_STATUS , + .u.enc_status.stream_behavior =3 , + }, + }, + { + .req = { + .req_type =DP_QUERY_STREAM_ENC_STATUS , + .u.enc_status.valid_stream_behavior =1 , + }, + }, +}; + +KUNIT_ARRAY_PARAM (dp_mst_sideband_msg_req, dp_msg_sideband_msg_req_decode_tests,NULL ); + +static struct kunit_case drm_dp_mst_helper_tests[] = { +KUNIT_CASE_PARAM (dp_mst_calc_pbn_mode, dp_mst_calc_pbn_mode_gen_params), +KUNIT_CASE_PARAM (dp_mst_sideband_msg_req_decode, dp_mst_sideband_msg_req_gen_params), + {} +}; + +static struct kunit_suite drm_dp_mst_helper_test_suite = { + .name ="drm_dp_mst_helper_tests" , + .test_cases = drm_dp_mst_helper_tests, +}; + +kunit_test_suite (drm_dp_mst_helper_test_suite);drivers/gpu/drm/selftests/test-drm_modeset_common.h +0
-3@@ -20,7 +20,5 @@ int igt_drm_rect_clip_scaled_div_by_zero(void *ignored);int igt_drm_rect_clip_scaled_not_clipped (void *ignored);int igt_drm_rect_clip_scaled_clipped (void *ignored);int igt_drm_rect_clip_scaled_signed_vs_unsigned (void *ignored); -int igt_dp_mst_calc_pbn_mode (void *ignored); -int igt_dp_mst_sideband_msg_req_decode (void *ignored);#endif --2.34.1
Re: [RFC 06/10] drm: test-drm_dp_mst_helper: Convert to KUnit
Quoted 14 lines · Michał Winiarski
Quoted 14 lines
Tangent:
It might have been easier to do that if the kunit assertions returned pass/fail. E.g. instead of having to doif (!<long-condition>) { KUNIT_FAIL("<long-condition> not met"); return; }if we could do
if(!KUNIT_EXPECT_TRUE(long-condition))
return;
Quoted 8 lines
Quoted 4 lines
or if there was a new macro type
KUNIT_EXPECT_RET_TRUE(long-condition); // like ASSERT, but just return from this func on failureThis would simplify a bunch of other tests as well.
On the other hand -EXPECT_TRUEreturning a value is not something I would expect :)
Yeah.
It felt painful to type that out :)
But I felt the same need when looking at converting some other selftests over. It definitely feels like there's room to make these sorts of helper functions better.
KTF solved these by allowing asserts to goto or break, e.g.
https://github.com/oracle/ktf/blob/63c19dead80de9cd654b08120d28a04f24174f4b/kernel/ktf.h#L560
I had floated the idea of KUnit having a KUNIT_ASSERT_GOTO/KUNIT_ASSERT_RET (return)
macro, but these would add yet another dimension to the macros (EXPECT vs ASSERT, _MSG vs no _MSG).
But I have some patches out that delete hundreds of lines from the assert macros along with some others I haven't sent out publicly yet. Maybe such a thing would be more palatable after those land?
But for now, I think they can either just print enough debug info so that the failures are obvious (like this does), or they can use kunit_err() to print out additional info (like you do in other patches in this series).
Quoted 3 lines
Thanks!
-Michał
RFC 7/10 drm: test-drm_rect: Convert to KUnit
In reply to Michał WiniarskiOne-to-one conversion, no functional changes.
Now that all of the modeset selftests were converted, remove the helpers that are no longer used.
--- drivers/gpu/drm/selftests/Makefile | 8 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 12 - .../drm/selftests/test-drm_modeset_common.c | 32 --- .../drm/selftests/test-drm_modeset_common.h | 24 -- drivers/gpu/drm/selftests/test-drm_rect.c | 212 ++++++++++-------- 5 files changed, 122 insertions(+), 166 deletions(-) delete mode 100644 drivers/gpu/drm/selftests/drm_modeset_selftests.h delete mode 100644 drivers/gpu/drm/selftests/test-drm_modeset_common.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_modeset_common.h
drivers/gpu/drm/selftests/Makefile +3 -5
@@ -1,11 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only -test-drm_modeset-$(CONFIG_DRM_DEBUG_SELFTEST) := \ - test-drm_modeset_common.o \ - test-drm_rect.o -obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o +obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o obj-$(CONFIG_DRM_KUNIT_TEST) := \ test-drm_cmdline_parser.o test-drm_plane_helper.o \ test-drm_format.o test-drm_framebuffer.o \ - test-drm_damage_helper.o test-drm_dp_mst_helper.o + test-drm_damage_helper.o test-drm_dp_mst_helper.o \ + test-drm_rect.o
drivers/gpu/drm/selftests/drm_modeset_selftests.h deleted +0 -12
@@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* List each unit test as selftest(name, function) -* -* The name is used as both an enum and expanded as igt__name to create -* a module parameter. It must be unique and legal for a C identifier. -* -* Tests are executed in order by igt/drm_selftests_helper -*/ -selftest(drm_rect_clip_scaled_div_by_zero, igt_drm_rect_clip_scaled_div_by_zero) -selftest(drm_rect_clip_scaled_not_clipped, igt_drm_rect_clip_scaled_not_clipped) -selftest(drm_rect_clip_scaled_clipped, igt_drm_rect_clip_scaled_clipped) -selftest (drm_rect_clip_scaled_signed_vs_unsigned, igt_drm_rect_clip_scaled_signed_vs_unsigned)
drivers/gpu/drm/selftests/test-drm_modeset_common.c deleted +0 -32
@@ -1,32 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* Common file for modeset selftests. -*/ - -#include <linux/module.h> - -#include "test-drm_modeset_common.h" - -#define TESTS "drm_modeset_selftests.h" -#include "drm_selftest.h" - -#include "drm_selftest.c" - -static int __init test_drm_modeset_init (void ) -{ -int err; - - err =run_selftests (selftests,ARRAY_SIZE (selftests),NULL ); - -return err >0 ?0 : err; -} - -static void __exit test_drm_modeset_exit(void) -{ -} - -module_init (test_drm_modeset_init); -module_exit (test_drm_modeset_exit); - -MODULE_AUTHOR ("Intel Corporation" ); -MODULE_LICENSE ("GPL" );
drivers/gpu/drm/selftests/test-drm_modeset_common.h deleted +0 -24
@@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ - -#ifndef __TEST_DRM_MODESET_COMMON_H__ -#define __TEST_DRM_MODESET_COMMON_H__ - -#include <linux/errno.h> -#include <linux/printk.h> - -#define FAIL (test, msg, ...) \ - do { \ - if (test) { \ - pr_err("%s/%u: " msg, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ - return -EINVAL; \ - } \ - } while (0) - -#define FAIL_ON (x) FAIL((x), "%s", "FAIL_ON(" __stringify(x) ")\n") - -int igt_drm_rect_clip_scaled_div_by_zero (void *ignored); -int igt_drm_rect_clip_scaled_not_clipped (void *ignored); -int igt_drm_rect_clip_scaled_clipped (void *ignored); -int igt_drm_rect_clip_scaled_signed_vs_unsigned (void *ignored); - -#endif
drivers/gpu/drm/selftests/test-drm_rect.c +119 -93
299 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC 8/10 drm: test-drm_mm: Convert to KUnit
In reply to Michał WiniarskiTests that were looping over param (or combination of params) were converted to parameterized test cases.
While the conversion should be roughly functionally equivalent, there are changes in the test content and organization:
* sanitycheck was dropped (as it was only testing the test framework)
* both evict and color got a "sanitycheck" extracted as a separate test
* insert_outside_range was extracted as a separate test
* evict_range and color_evict_range were removed and expressed as input parameters to evict and color_evict
It's still possible to use modparams to change the number of iterations, or force specific seed e.g. by passing the following to kunit.py:
--kernel_args 'test_drm_mm.random_seed=X'
--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/selftests/Makefile | 4 +- drivers/gpu/drm/selftests/drm_mm_selftests.h | 28 - drivers/gpu/drm/selftests/test-drm_mm.c | 3187 +++++++++--------- 4 files changed, 1566 insertions(+), 1655 deletions(-) delete mode 100644 drivers/gpu/drm/selftests/drm_mm_selftests.h
drivers/gpu/drm/Kconfig +2 -0
@@ -84,6 +84,8 @@ config DRM_KUNIT_TEST bool "DRM tests" if !KUNIT_ALL_TESTS depends on DRM=y && KUNIT=y select DRM_KMS_HELPER + select PRIME_NUMBERS + select DRM_LIB_RANDOM default KUNIT_ALL_TESTS help Enables unit tests for DRM. Only useful for kernel devs running KUnit.
drivers/gpu/drm/selftests/Makefile +1 -3
@@ -1,9 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o - obj-$(CONFIG_DRM_KUNIT_TEST) := \ test-drm_cmdline_parser.o test-drm_plane_helper.o \ test-drm_format.o test-drm_framebuffer.o \ test-drm_damage_helper.o test-drm_dp_mst_helper.o \ - test-drm_rect.o + test-drm_rect.o test-drm_mm.o
drivers/gpu/drm/selftests/drm_mm_selftests.h deleted +0 -28
@@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* List each unit test as selftest(name, function) -* -* The name is used as both an enum and expanded as igt__name to create -* a module parameter. It must be unique and legal for a C identifier. -* -* Tests are executed in order by igt/drm_mm -*/ -selftest(sanitycheck, igt_sanitycheck) /* keep first (selfcheck for igt) */ -selftest(init, igt_init) -selftest(debug, igt_debug) -selftest(reserve, igt_reserve) -selftest(insert, igt_insert) -selftest(replace, igt_replace) -selftest(insert_range, igt_insert_range) -selftest(align, igt_align) -selftest(frag, igt_frag) -selftest(align32, igt_align32) -selftest(align64, igt_align64) -selftest(evict, igt_evict) -selftest(evict_range, igt_evict_range) -selftest(bottomup, igt_bottomup) -selftest(lowest, igt_lowest) -selftest(topdown, igt_topdown) -selftest(highest, igt_highest) -selftest(color, igt_color) -selftest(color_evict, igt_color_evict) -selftest (color_evict_range, igt_color_evict_range)
drivers/gpu/drm/selftests/test-drm_mm.c +1563 -1624
2,954 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
RFC 9/10 drm: selftests: Convert to KUnit
In reply to Michał WiniarskiNow that all tests were converted, remove the content that's no longer used and rename the directory to "test".
---
drivers/gpu/drm/Kconfig | 17 ---
drivers/gpu/drm/Makefile | 2 +-
drivers/gpu/drm/i915/Kconfig.debug | 1 -
drivers/gpu/drm/selftests/drm_selftest.c | 109 ------------------
drivers/gpu/drm/selftests/drm_selftest.h | 41 -------
drivers/gpu/drm/{selftests => test}/Makefile | 0
.../test-drm_cmdline_parser.c | 0
.../test-drm_damage_helper.c | 0
.../test-drm_dp_mst_helper.c | 0
.../drm/{selftests => test}/test-drm_format.c | 0
.../test-drm_framebuffer.c | 0
.../gpu/drm/{selftests => test}/test-drm_mm.c | 0
.../test-drm_plane_helper.c | 0
.../drm/{selftests => test}/test-drm_rect.c | 0
14 files changed, 1 insertion(+), 169 deletions(-)
delete mode 100644 drivers/gpu/drm/selftests/drm_selftest.c
delete mode 100644 drivers/gpu/drm/selftests/drm_selftest.h
rename drivers/gpu/drm/{selftests => test}/Makefile (100%)
rename drivers/gpu/drm/{selftests => test}/test-drm_cmdline_parser.c (100%)
rename drivers/gpu/drm/{selftests => test}/test-drm_damage_helper.c (100%)
rename drivers/gpu/drm/{selftests => test}/test-drm_dp_mst_helper.c (100%)
rename drivers/gpu/drm/{selftests => test}/test-drm_format.c (100%)
rename drivers/gpu/drm/{selftests => test}/test-drm_framebuffer.c (100%)
rename drivers/gpu/drm/{selftests => test}/test-drm_mm.c (100%)
rename drivers/gpu/drm/{selftests => test}/test-drm_plane_helper.c (100%)
rename drivers/gpu/drm/{selftests => test}/test-drm_rect.c (100%)drivers/gpu/drm/Kconfig +0 -17
@@ -63,23 +63,6 @@ config DRM_DEBUG_MM If in doubt, say "N". -config DRM_DEBUG_SELFTEST - tristate "kselftests for DRM" - depends on DRM - depends on DEBUG_KERNEL - select PRIME_NUMBERS - select DRM_LIB_RANDOM - select DRM_KMS_HELPER - select DRM_EXPORT_FOR_TESTS if m - default n - help - This option provides kernel modules that can be used to run - various selftests on parts of the DRM api. This option is not - useful for distributions or general kernels, but only for kernel - developers working on DRM and associated drivers. - - If in doubt, say "N". - config DRM_KUNIT_TEST bool "DRM tests" if !KUNIT_ALL_TESTS depends on DRM=y && KUNIT=y
drivers/gpu/drm/Makefile +1 -1
@@ -65,7 +65,7 @@ drm_kms_helper-$(CONFIG_DRM_DP_AUX_CHARDEV) += drm_dp_aux_dev.o drm_kms_helper-$(CONFIG_DRM_DP_CEC) += drm_dp_cec.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o -obj-y += selftests/ +obj-y += test/ obj-$(CONFIG_DRM) += drm.o obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o
drivers/gpu/drm/i915/Kconfig.debug +0 -1
@@ -38,7 +38,6 @@ config DRM_I915_DEBUG select DRM_VGEM # used by igt/prime_vgem (dmabuf interop checks) select DRM_DEBUG_MM if DRM=y select DRM_EXPORT_FOR_TESTS if m - select DRM_DEBUG_SELFTEST select DMABUF_SELFTESTS select SW_SYNC # signaling validation framework (igt/syncobj*) select DRM_I915_WERROR
drivers/gpu/drm/selftests/drm_selftest.c deleted +0 -109
109 lines not on this page · raw message
drivers/gpu/drm/selftests/drm_selftest.h deleted +0 -41
41 lines not on this page · raw message
drivers/gpu/drm/test/Makefile renamed from drivers/gpu/drm/selftests/Makefile +0 -0
drivers/gpu/drm/test/test-drm_cmdline_parser.c renamed from drivers/gpu/drm/selftests/test-drm_cmdline_parser.c +0 -0
drivers/gpu/drm/test/test-drm_damage_helper.c renamed from drivers/gpu/drm/selftests/test-drm_damage_helper.c +0 -0
drivers/gpu/drm/test/test-drm_dp_mst_helper.c renamed from drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c +0 -0
drivers/gpu/drm/test/test-drm_format.c renamed from drivers/gpu/drm/selftests/test-drm_format.c +0 -0
drivers/gpu/drm/test/test-drm_framebuffer.c renamed from drivers/gpu/drm/selftests/test-drm_framebuffer.c +0 -0
drivers/gpu/drm/test/test-drm_mm.c renamed from drivers/gpu/drm/selftests/test-drm_mm.c +0 -0
drivers/gpu/drm/test/test-drm_plane_helper.c renamed from drivers/gpu/drm/selftests/test-drm_plane_helper.c +0 -0
drivers/gpu/drm/test/test-drm_rect.c renamed from drivers/gpu/drm/selftests/test-drm_rect.c +0 -0
Signature · 1 line
2.34.1
RFC 10/10 drm: test: Simplify testing on UML with kunit.py
In reply to Michał WiniarskiDRM depends on IOMEM and DMA, introduce an additional Kconfig to pull in IOMEM and DMA emulation on UML.
Also, add .kunitconfig to simplify running DRM tests with:./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm
--- drivers/gpu/drm/.kunitconfig | 3 +++ drivers/video/Kconfig | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 drivers/gpu/drm/.kunitconfig
drivers/gpu/drm/.kunitconfig new file +3 -0
@@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_KUNIT_TEST=y
drivers/video/Kconfig +4 -0
@@ -46,5 +46,9 @@ if FB || SGI_NEWPORT_CONSOLE endif +config DRM_UML_IO_EMULATION + def_bool y if UML && KUNIT + select UML_DMA_EMULATION + select UML_IOMEM_EMULATION endmenu
Signature · 1 line
2.34.1
change
Quoted 10 lines · Michał Winiarski
KUnit unifies the test structure and provides helper tools that simplify the development. Basic use case allows running tests as regular processes, leveraging User Mode Linux.
For example, to execute all DRM unit tests:./tools/testing/kunit/kunit.pyrun --kunitconfig=drivers/gpu/drm (the tool also allows using QEMU instead of UML by adding e.g. --arch=x86_64)For developers - it means that it's easier to run unit tests on the development machine, tightening the feedback loop. When using UML, it also simplifies using
Nice, it's neat to see --kunitconfig being useful for having one-liners for running tests.
Quoted 1 line
gdb for debug (since the kernel is just a regular process).
Anecdotally, I hear from [email protected] that using gdb and UML together isn't the nicest experience because of all the SIGSEGV flying around when emulating paging.
So I'm a bit doubtful about this particular statement, but if you have tried it out and it works well, then that's good too.
I just think the primary benefit of UML is faster compilation and it being somewhat lighter than bringing up a VM.
Quoted 10 lines
For CI systems - DRM tests can be moved from being executed on device under test (that's also running IGTs and so on) to being executed on buildsystem during build (just like checkpatch.pl).
All tests were renamed - IGT prefix is no longer used.
Compared to selftests executed by CI using IGT, there's one functional regression - KUnit test runner is not catching WARNs.
To solve this, we could either go in the similar direction that UBSAN went in:
1195505 ("kunit: ubsan integration")
Is the suggestion that all WARN's fail the current KUnit test? I don't think we can do that.
Some KUnit tests will explicitly want to trigger error paths, so we could have a lot of false positives.
An alternative is that we can apply the 1195505 to the code paths we're interested in, e.g.
#include <kunit/test-bug.h>
if (bad_thing()) {
kunit_fail_current_test("bad_thing happened");
}
I don't have the context to know how cumbersome this would be for the DRM tests though.
If the answer is we want to catch any and all warnings, then we'd perhaps want to add something to the tests themselves. And maybe we should implement that as a KUnit library helper function so that other tests can use it as well.
Quoted 1 line
Or we could expand the test runner to catch WARN signature in dmesg.
Ditto from the above, I think we'd wrongly mark some tests as failed for intentional warnings.
Quoted 3 lines
Pastebin to preview the output and execution times:
https://gitlab.freedesktop.org/-/snippets/4139
I see these take 17-18s to exec the tests in the example snippets. FYI, if you're not already trying this on top of 5.16, there's recent changes to make the parsed output more fully realtime as well.
So hopefully that should increase the usability of these tests a bit further.
I only mention that since I wasn't able to apply this series without conflicts on top of v5.16.
Quoted 74 lines
-Michał
Michał Winiarski (10):
drm: test-drm_cmdline_parser: Convert to KUnit
drm: test-drm_plane_helper: Convert to KUnit
drm: test-drm_format: Convert to KUnit
drm: test-drm_framebuffer: Convert to KUnit
drm: test-drm_damage_helper: Convert to KUnit
drm: test-drm_dp_mst_helper: Convert to KUnit
drm: test-drm_rect: Convert to KUnit
drm: test-drm_mm: Convert to KUnit
drm: selftests: Convert to KUnit
drm: test: Simplify testing on UML withkunit.pydrivers/gpu/drm/.kunitconfig | 3 + drivers/gpu/drm/Kconfig | 22 +- drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/i915/Kconfig.debug | 1 - drivers/gpu/drm/selftests/Makefile | 7 - .../gpu/drm/selftests/drm_cmdline_selftests.h | 68 - drivers/gpu/drm/selftests/drm_mm_selftests.h | 28 - .../gpu/drm/selftests/drm_modeset_selftests.h | 40 - drivers/gpu/drm/selftests/drm_selftest.c | 109 - drivers/gpu/drm/selftests/drm_selftest.h | 41 - .../drm/selftests/test-drm_cmdline_parser.c | 1141 -------- .../drm/selftests/test-drm_damage_helper.c | 667 ----- .../drm/selftests/test-drm_dp_mst_helper.c | 273 -- drivers/gpu/drm/selftests/test-drm_format.c | 280 -- drivers/gpu/drm/selftests/test-drm_mm.c | 2487 ----------------- .../drm/selftests/test-drm_modeset_common.c | 32 - .../drm/selftests/test-drm_modeset_common.h | 52 - .../gpu/drm/selftests/test-drm_plane_helper.c | 223 -- drivers/gpu/drm/selftests/test-drm_rect.c | 223 -- drivers/gpu/drm/test/Makefile | 7 + .../gpu/drm/test/test-drm_cmdline_parser.c | 1027 +++++++ drivers/gpu/drm/test/test-drm_damage_helper.c | 667 +++++ drivers/gpu/drm/test/test-drm_dp_mst_helper.c | 429 +++ drivers/gpu/drm/test/test-drm_format.c | 356 +++ .../test-drm_framebuffer.c | 109 +- drivers/gpu/drm/test/test-drm_mm.c | 2426 ++++++++++++++++ drivers/gpu/drm/test/test-drm_plane_helper.c | 312 +++ drivers/gpu/drm/test/test-drm_rect.c | 249 ++ drivers/video/Kconfig | 4 + 29 files changed, 5558 insertions(+), 5727 deletions(-) create mode 100644 drivers/gpu/drm/.kunitconfig delete mode 100644 drivers/gpu/drm/selftests/Makefile delete mode 100644 drivers/gpu/drm/selftests/drm_cmdline_selftests.h delete mode 100644 drivers/gpu/drm/selftests/drm_mm_selftests.h delete mode 100644 drivers/gpu/drm/selftests/drm_modeset_selftests.h delete mode 100644 drivers/gpu/drm/selftests/drm_selftest.c delete mode 100644 drivers/gpu/drm/selftests/drm_selftest.h delete mode 100644 drivers/gpu/drm/selftests/test-drm_cmdline_parser.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_damage_helper.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_format.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_mm.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_modeset_common.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_modeset_common.h delete mode 100644 drivers/gpu/drm/selftests/test-drm_plane_helper.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_rect.c create mode 100644 drivers/gpu/drm/test/Makefile create mode 100644 drivers/gpu/drm/test/test-drm_cmdline_parser.c create mode 100644 drivers/gpu/drm/test/test-drm_damage_helper.c create mode 100644 drivers/gpu/drm/test/test-drm_dp_mst_helper.c create mode 100644 drivers/gpu/drm/test/test-drm_format.c rename drivers/gpu/drm/{selftests => test}/test-drm_framebuffer.c (91%) create mode 100644 drivers/gpu/drm/test/test-drm_mm.c create mode 100644 drivers/gpu/drm/test/test-drm_plane_helper.c create mode 100644 drivers/gpu/drm/test/test-drm_rect.c--
2.34.1
Quoted 19 lines · Daniel Latypov
change
Quoted 10 lines · Michał Winiarski
KUnit unifies the test structure and provides helper tools that simplify the development. Basic use case allows running tests as regular processes, leveraging User Mode Linux.
For example, to execute all DRM unit tests:./tools/testing/kunit/kunit.pyrun --kunitconfig=drivers/gpu/drm (the tool also allows using QEMU instead of UML by adding e.g. --arch=x86_64)For developers - it means that it's easier to run unit tests on the development machine, tightening the feedback loop. When using UML, it also simplifies using
Nice, it's neat to see --kunitconfig being useful for having one-liners for running tests.
Quoted 1 line
gdb for debug (since the kernel is just a regular process).
Quoted 8 lines
Anecdotally, I hear from [email protected] that using gdb and UML together isn't the nicest experience because of all the SIGSEGV flying around when emulating paging.
So I'm a bit doubtful about this particular statement, but if you have tried it out and it works well, then that's good too.I just think the primary benefit of UML is faster compilation and it being somewhat lighter than bringing up a VM.
It was good enough to debug any problems that I accidentally introduced during the conversion, but perhaps that was simple enough usecase to not encounter SIGSEGVs.
Quoted 7 lines
Quoted 7 lines
For CI systems - DRM tests can be moved from being executed on device under test (that's also running IGTs and so on) to being executed on buildsystem during build (just like checkpatch.pl).
All tests were renamed - IGT prefix is no longer used.
Quoted 7 lines
Quoted 4 lines
Compared to selftests executed by CI using IGT, there's one functional regression - KUnit test runner is not catching WARNs.
To solve this, we could either go in the similar direction that UBSAN went in:
1195505 ("kunit: ubsan integration")Is the suggestion that all WARN's fail the current KUnit test? I don't think we can do that.
Yes - that's the suggestion.
The CI used for DRM has a separate "WARN" test state, even if the test is PASSing, any WARNs cause the test to end up in this state. For example:
https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11112/bat-adlp-4/igt@[email protected]
Quoted 13 lines
Some KUnit tests will explicitly want to trigger error paths, so we could have a lot of false positives.
An alternative is that we can apply the 1195505 to the code paths we're interested in, e.g.
#include <
kunit/test-bug.h>if (bad_thing()) { kunit_fail_current_test("bad_thing happened"); }
Quoted 6 lines
I don't have the context to know how cumbersome this would be for the DRM tests though.
If the answer is we want to catch any and all warnings, then we'd perhaps want to add something to the tests themselves. And maybe we should implement that as a KUnit library helper function so that other tests can use it as well.
I don't thing that would work. IIUC, currently the runner is operating on taint - there's a subset of taints that it considers "fatal" (including TAINT_WARN).
If we have tests that WARN, perhaps we could introduce extra flag to the test state on per-test or per-testsuite level, to mark that the test wants to fail-on-warn? Then we would only fail if the test opted in (or other way around? if opt-out makes more sense and we have more tests that actually don't WARN as part of their normal test logic).
Quoted 10 lines
Quoted 2 lines
Or we could expand the test runner to catch WARN signature in dmesg.
Ditto from the above, I think we'd wrongly mark some tests as failed for intentional warnings.
Quoted 3 lines
Pastebin to preview the output and execution times:
https://gitlab.freedesktop.org/-/snippets/4139
Quoted 7 lines
I see these take 17-18s to exec the tests in the example snippets. FYI, if you're not already trying this on top of 5.16, there's recent changes to make the parsed output more fully realtime as well.
So hopefully that should increase the usability of these tests a bit further.I only mention that since I wasn't able to apply this series without conflicts on top of v5.16.
It's applied on top of DRM subsystem integration tree (drm-tip):
https://cgit.freedesktop.org/drm-tip
At that time it was already based on v5.16.
Most of that 17-18s is taken by two subtest of drm_mm_tests:
[22:17:19] ============================================================ [22:17:19] ================= drm_mm_tests (1 subtest) ================= [22:17:27] [PASSED] test_insert
[22:17:27] ================== [PASSED] drm_mm_tests =================== [22:17:27] ============================================================ [22:17:27] Testing complete. Passed: 1, Failed: 0, Crashed: 0, Skipped: 0, Errors: 0 [22:17:27] Elapsed time: 10.400s total, 0.001s configuring, 2.419s building, 7.947s running
[22:17:42] ============================================================ [22:17:42] ================= drm_mm_tests (1 subtest) ================= [22:17:50] [PASSED] test_replace
[22:17:50] ================== [PASSED] drm_mm_tests =================== [22:17:50] ============================================================ [22:17:50] Testing complete. Passed: 1, Failed: 0, Crashed: 0, Skipped: 0, Errors: 0 [22:17:50] Elapsed time: 10.272s total, 0.001s configuring, 2.492s building, 7.776s running
Their runtime can be controlled with max_prime and max_iterations modparams - I left the default values intact, but we can tweak them to speed things up if needed.
Thanks!
-Michał
Quoted 75 lines
Quoted 75 lines
-Michał
Michał Winiarski (10):
drm: test-drm_cmdline_parser: Convert to KUnit
drm: test-drm_plane_helper: Convert to KUnit
drm: test-drm_format: Convert to KUnit
drm: test-drm_framebuffer: Convert to KUnit
drm: test-drm_damage_helper: Convert to KUnit
drm: test-drm_dp_mst_helper: Convert to KUnit
drm: test-drm_rect: Convert to KUnit
drm: test-drm_mm: Convert to KUnit
drm: selftests: Convert to KUnit
drm: test: Simplify testing on UML withkunit.pydrivers/gpu/drm/.kunitconfig | 3 + drivers/gpu/drm/Kconfig | 22 +- drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/i915/Kconfig.debug | 1 - drivers/gpu/drm/selftests/Makefile | 7 - .../gpu/drm/selftests/drm_cmdline_selftests.h | 68 - drivers/gpu/drm/selftests/drm_mm_selftests.h | 28 - .../gpu/drm/selftests/drm_modeset_selftests.h | 40 - drivers/gpu/drm/selftests/drm_selftest.c | 109 - drivers/gpu/drm/selftests/drm_selftest.h | 41 - .../drm/selftests/test-drm_cmdline_parser.c | 1141 -------- .../drm/selftests/test-drm_damage_helper.c | 667 ----- .../drm/selftests/test-drm_dp_mst_helper.c | 273 -- drivers/gpu/drm/selftests/test-drm_format.c | 280 -- drivers/gpu/drm/selftests/test-drm_mm.c | 2487 ----------------- .../drm/selftests/test-drm_modeset_common.c | 32 - .../drm/selftests/test-drm_modeset_common.h | 52 - .../gpu/drm/selftests/test-drm_plane_helper.c | 223 -- drivers/gpu/drm/selftests/test-drm_rect.c | 223 -- drivers/gpu/drm/test/Makefile | 7 + .../gpu/drm/test/test-drm_cmdline_parser.c | 1027 +++++++ drivers/gpu/drm/test/test-drm_damage_helper.c | 667 +++++ drivers/gpu/drm/test/test-drm_dp_mst_helper.c | 429 +++ drivers/gpu/drm/test/test-drm_format.c | 356 +++ .../test-drm_framebuffer.c | 109 +- drivers/gpu/drm/test/test-drm_mm.c | 2426 ++++++++++++++++ drivers/gpu/drm/test/test-drm_plane_helper.c | 312 +++ drivers/gpu/drm/test/test-drm_rect.c | 249 ++ drivers/video/Kconfig | 4 + 29 files changed, 5558 insertions(+), 5727 deletions(-)create mode 100644
drivers/gpu/drm/.kunitconfig
delete mode 100644drivers/gpu/drm/selftests/Makefiledelete mode 100644drivers/gpu/drm/selftests/drm_cmdline_selftests.hdelete mode 100644drivers/gpu/drm/selftests/drm_mm_selftests.hdelete mode 100644drivers/gpu/drm/selftests/drm_modeset_selftests.hdelete mode 100644drivers/gpu/drm/selftests/drm_selftest.cdelete mode 100644drivers/gpu/drm/selftests/drm_selftest.hdelete mode 100644drivers/gpu/drm/selftests/test-drm_cmdline_parser.cdelete mode 100644drivers/gpu/drm/selftests/test-drm_damage_helper.cdelete mode 100644drivers/gpu/drm/selftests/test-drm_dp_mst_helper.cdelete mode 100644drivers/gpu/drm/selftests/test-drm_format.cdelete mode 100644drivers/gpu/drm/selftests/test-drm_mm.cdelete mode 100644drivers/gpu/drm/selftests/test-drm_modeset_common.cdelete mode 100644drivers/gpu/drm/selftests/test-drm_modeset_common.hdelete mode 100644drivers/gpu/drm/selftests/test-drm_plane_helper.cdelete mode 100644drivers/gpu/drm/selftests/test-drm_rect.ccreate mode 100644drivers/gpu/drm/test/Makefile
create mode 100644drivers/gpu/drm/test/test-drm_cmdline_parser.ccreate mode 100644drivers/gpu/drm/test/test-drm_damage_helper.ccreate mode 100644drivers/gpu/drm/test/test-drm_dp_mst_helper.ccreate mode 100644drivers/gpu/drm/test/test-drm_format.crenamedrivers/gpu/drm/{selftests=>test}/test-drm_framebuffer.c(91%) create mode 100644drivers/gpu/drm/test/test-drm_mm.ccreate mode 100644drivers/gpu/drm/test/test-drm_plane_helper.ccreate mode 100644drivers/gpu/drm/test/test-drm_rect.c--
2.34.1
Quoted 9 lines · Michał Winiarski
Quoted 5 lines
So I'm a bit doubtful about this particular statement, but if you have tried it out and it works well, then that's good too.
I just think the primary benefit of UML is faster compilation and it being somewhat lighter than bringing up a VM.
It was good enough to debug any problems that I accidentally introduced during the conversion, but perhaps that was simple enough usecase to not encounter SIGSEGVs.
Ah, that's good to know.
Quoted 11 lines
I don't thing that would work. IIUC, currently the runner is operating on taint - there's a subset of taints that it considers "fatal" (including
TAINT_WARN).If we have tests that WARN, perhaps we could introduce extra flag to the test state on per-test or per-testsuite level, to mark that the test wants to fail-on-warn?
Then we would only fail if the test opted in (or other way around? if opt-out makes more sense and we have more tests that actually don't WARN as part of their normal test logic).
Yeah, I think this would work.
I chatted with Brendan and David about this and suggested this approach.
This definitely seems useful, so I definitely think we should keep it in mind, even if we don't get an implementation done in the near future.
Quoted 4 lines
It's applied on top of DRM subsystem integration tree (drm-tip):
https://cgit.freedesktop.org/drm-tip
At that time it was already based on v5.16.
Ack, thanks!
I might take another stab at applying the patches locally, but based on my brief skim over them, everything seemed fine from a KUnit point of view. It's quite clear you've read over KUnit pretty thoroughly (e.g. figured out how to create new managed resources, etc.). So I probably won't have any feedback to give.
Quoted 23 lines
Most of that 17-18s is taken by two subtest of
drm_mm_tests:[22:17:19] ============================================================ [22:17:19] =================
drm_mm_tests(1 subtest) ================= [22:17:27] [PASSED]test_insert
[22:17:27] ================== [PASSED]drm_mm_tests=================== [22:17:27] ============================================================ [22:17:27] Testing complete. Passed: 1, Failed: 0, Crashed: 0, Skipped:
0, Errors: 0
[22:17:27] Elapsed time: 10.400s total, 0.001s configuring, 2.419s building, 7.947s running[22:17:42] ============================================================ [22:17:42] =================
drm_mm_tests(1 subtest) ================= [22:17:50] [PASSED]test_replace
[22:17:50] ================== [PASSED]drm_mm_tests=================== [22:17:50] ============================================================ [22:17:50] Testing complete. Passed: 1, Failed: 0, Crashed: 0, Skipped:
0, Errors: 0
[22:17:50] Elapsed time: 10.272s total, 0.001s configuring, 2.492s building, 7.776s running
Quoted 3 lines
Their runtime can be controlled with
max_primeandmax_iterationsmodparams - I left the default values intact, but we can tweak them to speed things up if needed.
Ah, I was not concerned about test runtime at all.
I was just suggesting that real-time output would be useful if you didn't have it already.
Quoted 14 lines · Michał Winiarski
KUnit unifies the test structure and provides helper tools that simplify the development. Basic use case allows running tests as regular processes, leveraging User Mode Linux.
For example, to execute all DRM unit tests:./tools/testing/kunit/kunit.pyrun --kunitconfig=drivers/gpu/drm (the tool also allows using QEMU instead of UML by adding e.g. --arch=x86_64)For developers - it means that it's easier to run unit tests on the development machine, tightening the feedback loop. When using UML, it also simplifies using gdb for debug (since the kernel is just a regular process).
For CI systems - DRM tests can be moved from being executed on device under test (that's also running IGTs and so on) to being executed on buildsystem during build (just like checkpatch.pl).
Quoted 7 lines
All tests were renamed - IGT prefix is no longer used.
Compared to selftests executed by CI using IGT, there's one functional regression - KUnit test runner is not catching WARNs.
To solve this, we could either go in the similar direction that UBSAN went in:
1195505 ("kunit: ubsan integration")
Or we could expand the test runner to catch WARN signature in dmesg.
I think catching WARN signature in dmesg makes sense, assuming Kunit has a standard WARN format. It would be nice to be consistent here.
I haven't looked at any details, but yes so much I want to see this done. I'll cc a bunch of people I've talked with about this conversion, hopefully I got them all. Maybe they can help with review and getting this all landed!
Cheers, Daniel
Quoted 76 lines
Pastebin to preview the output and execution times:
https://gitlab.freedesktop.org/-/snippets/4139-Michał
Michał Winiarski (10):
drm: test-drm_cmdline_parser: Convert to KUnit
drm: test-drm_plane_helper: Convert to KUnit
drm: test-drm_format: Convert to KUnit
drm: test-drm_framebuffer: Convert to KUnit
drm: test-drm_damage_helper: Convert to KUnit
drm: test-drm_dp_mst_helper: Convert to KUnit
drm: test-drm_rect: Convert to KUnit
drm: test-drm_mm: Convert to KUnit
drm: selftests: Convert to KUnit
drm: test: Simplify testing on UML withkunit.pydrivers/gpu/drm/.kunitconfig | 3 + drivers/gpu/drm/Kconfig | 22 +- drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/i915/Kconfig.debug | 1 - drivers/gpu/drm/selftests/Makefile | 7 - .../gpu/drm/selftests/drm_cmdline_selftests.h | 68 - drivers/gpu/drm/selftests/drm_mm_selftests.h | 28 - .../gpu/drm/selftests/drm_modeset_selftests.h | 40 - drivers/gpu/drm/selftests/drm_selftest.c | 109 - drivers/gpu/drm/selftests/drm_selftest.h | 41 - .../drm/selftests/test-drm_cmdline_parser.c | 1141 -------- .../drm/selftests/test-drm_damage_helper.c | 667 ----- .../drm/selftests/test-drm_dp_mst_helper.c | 273 -- drivers/gpu/drm/selftests/test-drm_format.c | 280 -- drivers/gpu/drm/selftests/test-drm_mm.c | 2487 ----------------- .../drm/selftests/test-drm_modeset_common.c | 32 - .../drm/selftests/test-drm_modeset_common.h | 52 - .../gpu/drm/selftests/test-drm_plane_helper.c | 223 -- drivers/gpu/drm/selftests/test-drm_rect.c | 223 -- drivers/gpu/drm/test/Makefile | 7 + .../gpu/drm/test/test-drm_cmdline_parser.c | 1027 +++++++ drivers/gpu/drm/test/test-drm_damage_helper.c | 667 +++++ drivers/gpu/drm/test/test-drm_dp_mst_helper.c | 429 +++ drivers/gpu/drm/test/test-drm_format.c | 356 +++ .../test-drm_framebuffer.c | 109 +- drivers/gpu/drm/test/test-drm_mm.c | 2426 ++++++++++++++++ drivers/gpu/drm/test/test-drm_plane_helper.c | 312 +++ drivers/gpu/drm/test/test-drm_rect.c | 249 ++ drivers/video/Kconfig | 4 + 29 files changed, 5558 insertions(+), 5727 deletions(-) create mode 100644 drivers/gpu/drm/.kunitconfig delete mode 100644 drivers/gpu/drm/selftests/Makefile delete mode 100644 drivers/gpu/drm/selftests/drm_cmdline_selftests.h delete mode 100644 drivers/gpu/drm/selftests/drm_mm_selftests.h delete mode 100644 drivers/gpu/drm/selftests/drm_modeset_selftests.h delete mode 100644 drivers/gpu/drm/selftests/drm_selftest.c delete mode 100644 drivers/gpu/drm/selftests/drm_selftest.h delete mode 100644 drivers/gpu/drm/selftests/test-drm_cmdline_parser.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_damage_helper.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_format.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_mm.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_modeset_common.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_modeset_common.h delete mode 100644 drivers/gpu/drm/selftests/test-drm_plane_helper.c delete mode 100644 drivers/gpu/drm/selftests/test-drm_rect.c create mode 100644 drivers/gpu/drm/test/Makefile create mode 100644 drivers/gpu/drm/test/test-drm_cmdline_parser.c create mode 100644 drivers/gpu/drm/test/test-drm_damage_helper.c create mode 100644 drivers/gpu/drm/test/test-drm_dp_mst_helper.c create mode 100644 drivers/gpu/drm/test/test-drm_format.c rename drivers/gpu/drm/{selftests => test}/test-drm_framebuffer.c (91%) create mode 100644 drivers/gpu/drm/test/test-drm_mm.c create mode 100644 drivers/gpu/drm/test/test-drm_plane_helper.c create mode 100644 drivers/gpu/drm/test/test-drm_rect.cSignature · 1 line
2.34.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch