From: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx> Test the basics of drm_atomic_set_mode_for_crtc(), and in particular verify that the function doesn't take the shortcut incorrectly. Cc: Daniel Vetter <daniel@xxxxxxxx> Signed-off-by: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx> --- drivers/gpu/drm/selftests/Makefile | 3 +- .../gpu/drm/selftests/drm_modeset_selftests.h | 2 + .../gpu/drm/selftests/test-drm_atomic_uapi.c | 110 ++++++++++++++++++ .../drm/selftests/test-drm_modeset_common.h | 2 + 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/selftests/test-drm_atomic_uapi.c diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile index d2137342b371..a5adc25bd345 100644 --- a/drivers/gpu/drm/selftests/Makefile +++ b/drivers/gpu/drm/selftests/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only test-drm_modeset-y := 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_damage_helper.o test-drm_dp_mst_helper.o \ + test-drm_atomic_uapi.o obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o test-drm_cmdline_parser.o diff --git a/drivers/gpu/drm/selftests/drm_modeset_selftests.h b/drivers/gpu/drm/selftests/drm_modeset_selftests.h index 1898de0b4a4d..2cc4e2f43286 100644 --- a/drivers/gpu/drm/selftests/drm_modeset_selftests.h +++ b/drivers/gpu/drm/selftests/drm_modeset_selftests.h @@ -6,6 +6,8 @@ * * Tests are executed in order by igt/drm_selftests_helper */ +selftest(atomic_set_mode_for_crtc, igt_atomic_set_mode_for_crtc) +selftest(atomic_set_zeroed_mode_for_crtc, igt_atomic_set_zeroed_mode_for_crtc) 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) diff --git a/drivers/gpu/drm/selftests/test-drm_atomic_uapi.c b/drivers/gpu/drm/selftests/test-drm_atomic_uapi.c new file mode 100644 index 000000000000..0f9a4d0d2541 --- /dev/null +++ b/drivers/gpu/drm/selftests/test-drm_atomic_uapi.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Test cases for the drm_atomic_uapi functions + */ + +#define pr_fmt(fmt) "drm_atomic_uapi: " fmt + +#include <drm/drm_atomic_uapi.h> +#include <drm/drm_drv.h> +#include <drm/drm_crtc.h> +#include <drm/drm_modes.h> + +#include "test-drm_modeset_common.h" + +static const struct drm_display_mode zeroed_mode; + +static struct drm_driver mock_driver; +static struct drm_device mock_device; +static struct drm_crtc mock_crtc; + +static void init(void) +{ + memset(&mock_driver, 0, sizeof(mock_driver)); + memset(&mock_device, 0, sizeof(mock_device)); + memset(&mock_crtc, 0, sizeof(mock_crtc)); + + mock_device.driver = &mock_driver; + mock_crtc.dev = &mock_device; + + drm_mode_config_init(&mock_device); +} + +static void cleanup(void) +{ + drm_mode_config_cleanup(&mock_device); +} + +int igt_atomic_set_mode_for_crtc(void *ignored) +{ + static const struct drm_display_mode mode1 = { + DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, + 640, 656, 752, 800, 0, 480, 490, 492, 525, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) + }; + static const struct drm_display_mode mode2 = { + DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, + 1024, 1048, 1184, 1344, 0, 768, 771, 777, 806, 0, + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) + }; + struct drm_crtc_state crtc_state = { + .crtc = &mock_crtc, + }; + int ret; + + init(); + + /* + * Make sure drm_atomic_set_mode_for_crtc() + * updates the crtc state correctly. + */ + ret = drm_atomic_set_mode_for_crtc(&crtc_state, &mode1); + FAIL(ret < 0, "Unable to set mode on crtc\n"); + FAIL_ON(!crtc_state.enable); + FAIL_ON(memcmp(&crtc_state.mode, &mode1, sizeof(mode1))); + + ret = drm_atomic_set_mode_for_crtc(&crtc_state, &mode2); + FAIL(ret < 0, "Unable to set mode on crtc\n"); + FAIL_ON(!crtc_state.enable); + FAIL_ON(memcmp(&crtc_state.mode, &mode2, sizeof(mode2))); + + ret = drm_atomic_set_mode_for_crtc(&crtc_state, NULL); + FAIL(ret < 0, "Unable to unset mode on crtc\n"); + FAIL_ON(crtc_state.enable); + FAIL_ON(memcmp(&crtc_state.mode, &zeroed_mode, sizeof(zeroed_mode))); + + cleanup(); + + return 0; +} + +int igt_atomic_set_zeroed_mode_for_crtc(void *ignored) +{ + struct drm_crtc_state crtc_state = { + .crtc = &mock_crtc, + }; + int ret; + + init(); + + /* + * Make sure drm_atomic_set_mode_for_crtc() doesn't + * take the shortcut and fail to update crtc_state.enable + * when passed a zeroed mode (which is technically not + * valid, but as drm_atomic_set_mode_for_crtc() does no + * mode validation it should still work). + */ + ret = drm_atomic_set_mode_for_crtc(&crtc_state, &zeroed_mode); + FAIL(ret < 0, "Unable to set mode on crtc\n"); + FAIL_ON(!crtc_state.enable); + FAIL_ON(memcmp(&crtc_state.mode, &zeroed_mode, sizeof(zeroed_mode))); + + ret = drm_atomic_set_mode_for_crtc(&crtc_state, NULL); + FAIL(ret < 0, "Unable to unset mode on crtc\n"); + FAIL_ON(crtc_state.enable); + FAIL_ON(memcmp(&crtc_state.mode, &zeroed_mode, sizeof(zeroed_mode))); + + cleanup(); + + return 0; +} diff --git a/drivers/gpu/drm/selftests/test-drm_modeset_common.h b/drivers/gpu/drm/selftests/test-drm_modeset_common.h index 0fcb8bbc6a1b..a1248abf86f9 100644 --- a/drivers/gpu/drm/selftests/test-drm_modeset_common.h +++ b/drivers/gpu/drm/selftests/test-drm_modeset_common.h @@ -13,6 +13,8 @@ #define FAIL_ON(x) FAIL((x), "%s", "FAIL_ON(" __stringify(x) ")\n") +int igt_atomic_set_mode_for_crtc(void *ignored); +int igt_atomic_set_zeroed_mode_for_crtc(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); -- 2.23.0 _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel