From 0fab55dbc0ed91787fee14fe00376a6289dc7165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 24 Jun 2021 15:32:43 +0200 Subject: [PATCH] tests/kms/device: Add mode setting test Checks that the relevant device state is correct after mode setting. Part-of: --- src/backends/native/meta-kms-crtc.h | 3 ++ src/backends/native/meta-kms-device.h | 1 + src/tests/meson.build | 2 + src/tests/native-kms-device.c | 57 +++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/src/backends/native/meta-kms-crtc.h b/src/backends/native/meta-kms-crtc.h index 1a64eadf5..218bec9a1 100644 --- a/src/backends/native/meta-kms-crtc.h +++ b/src/backends/native/meta-kms-crtc.h @@ -63,12 +63,15 @@ G_DECLARE_FINAL_TYPE (MetaKmsCrtc, meta_kms_crtc, META_EXPORT_TEST MetaKmsDevice * meta_kms_crtc_get_device (MetaKmsCrtc *crtc); +META_EXPORT_TEST const MetaKmsCrtcState * meta_kms_crtc_get_current_state (MetaKmsCrtc *crtc); +META_EXPORT_TEST uint32_t meta_kms_crtc_get_id (MetaKmsCrtc *crtc); int meta_kms_crtc_get_idx (MetaKmsCrtc *crtc); +META_EXPORT_TEST gboolean meta_kms_crtc_is_active (MetaKmsCrtc *crtc); void meta_kms_crtc_gamma_free (MetaKmsCrtcGamma *gamma); diff --git a/src/backends/native/meta-kms-device.h b/src/backends/native/meta-kms-device.h index 026b7a270..288119fbb 100644 --- a/src/backends/native/meta-kms-device.h +++ b/src/backends/native/meta-kms-device.h @@ -72,6 +72,7 @@ MetaKmsPlane * meta_kms_device_get_cursor_plane_for (MetaKmsDevice *device, GList * meta_kms_device_get_fallback_modes (MetaKmsDevice *device); +META_EXPORT_TEST MetaKmsFeedback * meta_kms_device_process_update_sync (MetaKmsDevice *device, MetaKmsUpdate *update, MetaKmsUpdateFlag flags); diff --git a/src/tests/meson.build b/src/tests/meson.build index d07099844..6f1391453 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -300,6 +300,8 @@ if have_native_tests native_kms_device_tests = executable('mutter-native-kms-device', sources: [ + 'meta-kms-test-utils.c', + 'meta-kms-test-utils.h', 'native-kms-device.c', ], include_directories: tests_includes, diff --git a/src/tests/native-kms-device.c b/src/tests/native-kms-device.c index 55649ed6d..ef14e530c 100644 --- a/src/tests/native-kms-device.c +++ b/src/tests/native-kms-device.c @@ -25,8 +25,10 @@ #include "backends/native/meta-kms-crtc.h" #include "backends/native/meta-kms-device.h" #include "backends/native/meta-kms-plane.h" +#include "backends/native/meta-kms-update.h" #include "backends/native/meta-kms.h" #include "meta-test/meta-context-test.h" +#include "tests/meta-kms-test-utils.h" static MetaContext *test_context; @@ -86,11 +88,66 @@ meta_test_kms_device_sanity (void) META_KMS_PLANE_TYPE_CURSOR); } +static void +meta_test_kms_device_mode_set (void) +{ + MetaKmsDevice *device; + MetaKmsUpdate *update; + MetaKmsCrtc *crtc; + MetaKmsConnector *connector; + MetaKmsMode *mode; + MetaKmsPlane *primary_plane; + g_autoptr (MetaDrmBuffer) primary_buffer = NULL; + const MetaKmsCrtcState *crtc_state; + const MetaKmsConnectorState *connector_state; + MetaRectangle mode_rect; + + device = meta_get_test_kms_device (test_context); + crtc = meta_get_test_kms_crtc (device); + connector = meta_get_test_kms_connector (device); + mode = meta_kms_connector_get_preferred_mode (connector); + + update = meta_kms_update_new (device); + + meta_kms_update_mode_set (update, crtc, + g_list_append (NULL, connector), + mode); + + primary_buffer = meta_create_test_mode_dumb_buffer (device, mode); + + primary_plane = meta_kms_device_get_primary_plane_for (device, crtc); + meta_kms_update_assign_plane (update, + crtc, + primary_plane, + primary_buffer, + meta_get_mode_fixed_rect_16 (mode), + meta_get_mode_rect (mode), + META_KMS_ASSIGN_PLANE_FLAG_NONE); + meta_kms_device_process_update_sync (device, update, + META_KMS_UPDATE_FLAG_NONE); + meta_kms_update_free (update); + + crtc_state = meta_kms_crtc_get_current_state (crtc); + g_assert_nonnull (crtc_state); + g_assert_true (crtc_state->is_active); + g_assert_true (crtc_state->is_drm_mode_valid); + mode_rect = meta_get_mode_rect (mode); + g_assert (meta_rectangle_equal (&crtc_state->rect, &mode_rect)); + + connector_state = meta_kms_connector_get_current_state (connector); + g_assert_nonnull (connector_state); + g_assert_cmpuint (connector_state->current_crtc_id, + ==, + meta_kms_crtc_get_id (crtc)); +} + static void init_tests (void) { g_test_add_func ("/backends/native/kms/device/sanity", meta_test_kms_device_sanity); + g_test_add_func ("/backends/native/kms/device/mode-set", + meta_test_kms_device_mode_set); } int