2017-08-18 02:27:42 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2023-02-01 06:21:49 -05:00
|
|
|
#include "backends/meta-logical-monitor.h"
|
2017-08-18 02:27:42 -04:00
|
|
|
#include "backends/meta-monitor-manager-private.h"
|
2023-02-01 06:21:49 -05:00
|
|
|
#include "backends/native/meta-backend-native.h"
|
|
|
|
#include "backends/native/meta-udev.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "core/display-private.h"
|
2021-05-06 17:37:35 -04:00
|
|
|
#include "meta-test/meta-context-test.h"
|
2023-02-01 06:21:49 -05:00
|
|
|
#include "tests/drm-mock/drm-mock.h"
|
2017-08-18 02:27:42 -04:00
|
|
|
#include "tests/meta-monitor-manager-test.h"
|
|
|
|
|
2022-05-27 16:55:43 -04:00
|
|
|
static MetaContext *test_context;
|
|
|
|
|
2017-08-18 02:27:42 -04:00
|
|
|
static void
|
|
|
|
meta_test_headless_start (void)
|
|
|
|
{
|
2022-05-27 16:55:43 -04:00
|
|
|
MetaBackend *backend = meta_context_get_backend (test_context);
|
2017-08-18 02:27:42 -04:00
|
|
|
MetaMonitorManager *monitor_manager =
|
|
|
|
meta_backend_get_monitor_manager (backend);
|
2017-07-10 06:19:32 -04:00
|
|
|
GList *gpus;
|
|
|
|
MetaGpu *gpu;
|
2017-08-18 02:27:42 -04:00
|
|
|
|
2019-01-11 09:35:42 -05:00
|
|
|
gpus = meta_backend_get_gpus (backend);
|
2017-07-10 06:19:32 -04:00
|
|
|
g_assert_cmpint ((int) g_list_length (gpus), ==, 1);
|
|
|
|
|
|
|
|
gpu = gpus->data;
|
|
|
|
g_assert_null (meta_gpu_get_outputs (gpu));
|
2017-08-18 02:27:42 -04:00
|
|
|
g_assert_null (monitor_manager->monitors);
|
|
|
|
g_assert_null (monitor_manager->logical_monitors);
|
|
|
|
|
|
|
|
g_assert_cmpint (monitor_manager->screen_width,
|
|
|
|
==,
|
|
|
|
META_MONITOR_MANAGER_MIN_SCREEN_WIDTH);
|
|
|
|
g_assert_cmpint (monitor_manager->screen_height,
|
|
|
|
==,
|
|
|
|
META_MONITOR_MANAGER_MIN_SCREEN_HEIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_test_headless_monitor_getters (void)
|
|
|
|
{
|
|
|
|
MetaDisplay *display;
|
|
|
|
int index;
|
|
|
|
|
2022-05-27 16:55:43 -04:00
|
|
|
display = meta_context_get_display (test_context);
|
2017-08-18 02:27:42 -04:00
|
|
|
|
2017-08-26 15:22:34 -04:00
|
|
|
index = meta_display_get_monitor_index_for_rect (display,
|
2023-07-19 19:46:15 -04:00
|
|
|
&(MtkRectangle) { 0 });
|
2017-08-18 02:27:42 -04:00
|
|
|
g_assert_cmpint (index, ==, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_test_headless_monitor_connect (void)
|
|
|
|
{
|
2022-05-27 16:55:43 -04:00
|
|
|
MetaBackend *backend = meta_context_get_backend (test_context);
|
2023-02-01 06:21:49 -05:00
|
|
|
MetaUdev *udev = meta_backend_native_get_udev (META_BACKEND_NATIVE (backend));
|
2017-08-18 02:27:42 -04:00
|
|
|
MetaMonitorManager *monitor_manager =
|
|
|
|
meta_backend_get_monitor_manager (backend);
|
2023-02-01 06:21:49 -05:00
|
|
|
g_autolist (GObject) udev_devices = NULL;
|
2017-08-18 02:27:42 -04:00
|
|
|
GList *logical_monitors;
|
2023-02-01 06:21:49 -05:00
|
|
|
MetaLogicalMonitor *logical_monitor;
|
2023-07-19 19:46:15 -04:00
|
|
|
MtkRectangle monitor_layout;
|
2017-08-18 02:27:42 -04:00
|
|
|
ClutterActor *stage;
|
2023-02-01 06:21:49 -05:00
|
|
|
g_autoptr (GError) error = NULL;
|
2017-08-18 02:27:42 -04:00
|
|
|
|
2023-02-01 06:21:49 -05:00
|
|
|
drm_mock_unset_resource_filter (DRM_MOCK_CALL_FILTER_GET_CONNECTOR);
|
2020-02-26 03:45:07 -05:00
|
|
|
|
2023-02-01 06:21:49 -05:00
|
|
|
udev_devices = meta_udev_list_drm_devices (udev, &error);
|
|
|
|
g_assert_cmpuint (g_list_length (udev_devices), ==, 1);
|
|
|
|
g_signal_emit_by_name (udev, "hotplug", g_list_first (udev_devices)->data);
|
2017-08-18 02:27:42 -04:00
|
|
|
|
|
|
|
logical_monitors =
|
|
|
|
meta_monitor_manager_get_logical_monitors (monitor_manager);
|
|
|
|
g_assert_cmpint (g_list_length (logical_monitors), ==, 1);
|
2023-02-01 06:21:49 -05:00
|
|
|
logical_monitor = g_list_first (logical_monitors)->data;
|
|
|
|
monitor_layout = meta_logical_monitor_get_layout (logical_monitor);
|
2017-08-18 02:27:42 -04:00
|
|
|
|
2023-02-01 06:21:49 -05:00
|
|
|
g_assert_cmpint (monitor_manager->screen_width, ==, monitor_layout.width);
|
|
|
|
g_assert_cmpint (monitor_manager->screen_height, ==, monitor_layout.height);
|
2017-08-18 02:27:42 -04:00
|
|
|
|
|
|
|
stage = meta_backend_get_stage (backend);
|
2023-02-01 06:21:49 -05:00
|
|
|
g_assert_cmpint (clutter_actor_get_width (stage), ==, monitor_layout.width);
|
|
|
|
g_assert_cmpint (clutter_actor_get_height (stage), ==, monitor_layout.height);
|
2017-08-18 02:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static MetaMonitorTestSetup *
|
2022-01-28 10:28:32 -05:00
|
|
|
create_headless_test_setup (MetaBackend *backend)
|
2017-08-18 02:27:42 -04:00
|
|
|
{
|
|
|
|
return g_new0 (MetaMonitorTestSetup, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-03-02 13:51:54 -05:00
|
|
|
init_tests (void)
|
2017-08-18 02:27:42 -04:00
|
|
|
{
|
2022-01-28 10:28:32 -05:00
|
|
|
meta_init_monitor_test_setup (create_headless_test_setup);
|
2017-08-18 02:27:42 -04:00
|
|
|
|
|
|
|
g_test_add_func ("/headless-start/start", meta_test_headless_start);
|
|
|
|
g_test_add_func ("/headless-start/monitor-getters",
|
|
|
|
meta_test_headless_monitor_getters);
|
|
|
|
g_test_add_func ("/headless-start/connect",
|
|
|
|
meta_test_headless_monitor_connect);
|
|
|
|
}
|
|
|
|
|
2023-02-01 06:21:49 -05:00
|
|
|
static void
|
|
|
|
disconnect_connector_filter (gpointer resource,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
drmModeConnector *drm_connector = resource;
|
|
|
|
|
|
|
|
drm_connector->connection = DRM_MODE_DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
2017-08-18 02:27:42 -04:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2021-03-02 13:51:54 -05:00
|
|
|
g_autoptr (MetaContext) context = NULL;
|
2017-08-18 02:27:42 -04:00
|
|
|
|
2023-02-01 06:21:49 -05:00
|
|
|
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_VKMS,
|
2021-03-03 04:42:26 -05:00
|
|
|
META_CONTEXT_TEST_FLAG_NO_X11);
|
2021-03-02 13:51:54 -05:00
|
|
|
g_assert (meta_context_configure (context, &argc, &argv, NULL));
|
2017-08-18 02:27:42 -04:00
|
|
|
|
2021-03-02 13:51:54 -05:00
|
|
|
init_tests ();
|
2017-08-18 02:27:42 -04:00
|
|
|
|
2022-05-27 16:55:43 -04:00
|
|
|
test_context = context;
|
|
|
|
|
2023-02-01 06:21:49 -05:00
|
|
|
drm_mock_set_resource_filter (DRM_MOCK_CALL_FILTER_GET_CONNECTOR,
|
|
|
|
disconnect_connector_filter, NULL);
|
|
|
|
|
2021-05-17 06:12:49 -04:00
|
|
|
return meta_context_test_run_tests (META_CONTEXT_TEST (context),
|
2023-06-26 16:06:22 -04:00
|
|
|
META_TEST_RUN_FLAG_CAN_SKIP);
|
2017-08-18 02:27:42 -04:00
|
|
|
}
|