From 3f6a2d02fd5af6da4cc65f6dfbaf38498aeed189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 18 Aug 2017 14:27:42 +0800 Subject: [PATCH] tests: Add headless start test case Test that mutter starts properly when there are no monitors connected yet, and that things work when a monitor is eventually connected. https://bugzilla.gnome.org/show_bug.cgi?id=730551 --- .gitignore | 1 + src/Makefile-tests.am | 28 +++- src/tests/headless-start-test.c | 203 ++++++++++++++++++++++++++ src/tests/meta-monitor-manager-test.c | 5 +- 4 files changed, 232 insertions(+), 5 deletions(-) create mode 100644 src/tests/headless-start-test.c diff --git a/.gitignore b/.gitignore index 321d7732f..4d3737de3 100644 --- a/.gitignore +++ b/.gitignore @@ -55,6 +55,7 @@ mutter-restart-helper mutter-test-client mutter-test-runner mutter-test-unit-tests +mutter-test-headless-start-test mutter-all.test org.gnome.mutter.gschema.valid org.gnome.mutter.gschema.xml diff --git a/src/Makefile-tests.am b/src/Makefile-tests.am index 40370def6..3d8683c08 100644 --- a/src/Makefile-tests.am +++ b/src/Makefile-tests.am @@ -2,6 +2,13 @@ if HAVE_WAYLAND +test_programs = \ + mutter-test-client \ + mutter-test-runner \ + mutter-test-unit-tests \ + mutter-test-headless-start-test \ + $(NULL) + if BUILDOPT_INSTALL_TESTS stackingdir = $(pkgdatadir)/tests/stacking dist_stacking_DATA = \ @@ -19,9 +26,9 @@ installedtestsdir = $(datadir)/installed-tests/mutter installedtests_DATA = mutter-all.test installedtestsbindir = $(libexecdir)/installed-tests/mutter -installedtestsbin_PROGRAMS = mutter-test-client mutter-test-runner mutter-test-unit-tests +installedtestsbin_PROGRAMS = $(test_programs) else -noinst_PROGRAMS += mutter-test-client mutter-test-runner mutter-test-unit-tests +noinst_PROGRAMS += $(test_programs) endif EXTRA_DIST += tests/mutter-all.test.in @@ -52,7 +59,17 @@ mutter_test_unit_tests_SOURCES = \ $(NULL) mutter_test_unit_tests_LDADD = $(MUTTER_LIBS) libmutter-$(LIBMUTTER_API_VERSION).la -.PHONY: run-tests run-test-runner-tests run-unit-tests +mutter_test_headless_start_test_SOURCES = \ + tests/headless-start-test.c \ + tests/headless-start-test.h \ + tests/meta-backend-test.c \ + tests/meta-backend-test.h \ + tests/meta-monitor-manager-test.c \ + tests/meta-monitor-manager-test.h \ + $(NULL) +mutter_test_headless_start_test_LDADD = $(MUTTER_LIBS) libmutter-$(LIBMUTTER_API_VERSION).la + +.PHONY: run-tests run-test-runner-tests run-unit-tests run-headless-start-test run-test-runner-tests: mutter-test-client mutter-test-runner ./mutter-test-runner $(dist_stacking_DATA) @@ -60,7 +77,10 @@ run-test-runner-tests: mutter-test-client mutter-test-runner run-unit-tests: mutter-test-unit-tests ./mutter-test-unit-tests -run-tests: run-test-runner-tests run-unit-tests +run-headless-start-test: mutter-test-headless-start-test + ./mutter-test-headless-start-test + +run-tests: run-test-runner-tests run-unit-tests run-headless-start-test endif diff --git a/src/tests/headless-start-test.c b/src/tests/headless-start-test.c new file mode 100644 index 000000000..f2fb70cfe --- /dev/null +++ b/src/tests/headless-start-test.c @@ -0,0 +1,203 @@ +/* -*- 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 . + */ + +#include "config.h" + +#include "backends/meta-monitor-manager-private.h" +#include "compositor/meta-plugin-manager.h" +#include "core/main-private.h" +#include "meta/main.h" +#include "tests/meta-backend-test.h" +#include "tests/meta-monitor-manager-test.h" +#include "wayland/meta-wayland.h" + +#define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1) + +static gboolean +run_tests (gpointer data) +{ + MetaBackend *backend = meta_get_backend (); + MetaSettings *settings = meta_backend_get_settings (backend); + gboolean ret; + + meta_settings_override_experimental_features (settings); + + meta_settings_enable_experimental_feature ( + settings, + META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER); + + ret = g_test_run (); + + meta_quit (ret != 0); + + return FALSE; +} + +static void +meta_test_headless_start (void) +{ + MetaBackend *backend = meta_get_backend (); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + + g_assert_cmpint ((int) monitor_manager->n_modes, + ==, + 0); + g_assert_cmpint ((int) monitor_manager->n_outputs, + ==, + 0); + g_assert_cmpint ((int) monitor_manager->n_crtcs, + ==, + 0); + 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; + MetaScreen *screen; + int index; + + display = meta_get_display (); + screen = display->screen; + + index = meta_screen_get_monitor_index_for_rect (screen, + &(MetaRectangle) { 0 }); + g_assert_cmpint (index, ==, -1); +} + +static void +meta_test_headless_monitor_connect (void) +{ + MetaBackend *backend = meta_get_backend (); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + MetaMonitorManagerTest *monitor_manager_test = + META_MONITOR_MANAGER_TEST (monitor_manager); + MetaMonitorTestSetup *test_setup; + MetaCrtcMode **modes; + MetaCrtc **possible_crtcs; + GList *logical_monitors; + ClutterActor *stage; + + test_setup = g_new0 (MetaMonitorTestSetup, 1); + test_setup->n_modes = 1; + test_setup->modes = g_new0 (MetaCrtcMode, test_setup->n_modes); + test_setup->modes[0] = (MetaCrtcMode) { + .mode_id = 1, + .width = 1024, + .height = 768, + .refresh_rate = 60.0 + }; + + test_setup->n_crtcs = 1; + test_setup->crtcs = g_new0 (MetaCrtc, test_setup->n_crtcs); + test_setup->crtcs[0] = (MetaCrtc) { + .crtc_id = 1, + .all_transforms = ALL_TRANSFORMS + }; + + modes = g_new0 (MetaCrtcMode *, 1); + modes[0] = &test_setup->modes[0]; + + possible_crtcs = g_new0 (MetaCrtc *, 1); + possible_crtcs[0] = &test_setup->crtcs[0]; + + test_setup->n_outputs = 1; + test_setup->outputs = g_new0 (MetaOutput, test_setup->n_outputs); + test_setup->outputs[0] = (MetaOutput) { + .winsys_id = 1, + .name = g_strdup ("DP-1"), + .vendor = g_strdup ("MetaProduct's Inc."), + .product = g_strdup ("MetaMonitor"), + .serial = g_strdup ("0x987654"), + .preferred_mode = modes[0], + .n_modes = 1, + .modes = modes, + .n_possible_crtcs = 1, + .possible_crtcs = possible_crtcs, + .backlight = -1, + .connector_type = META_CONNECTOR_TYPE_DisplayPort + }; + + meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); + + logical_monitors = + meta_monitor_manager_get_logical_monitors (monitor_manager); + g_assert_cmpint (g_list_length (logical_monitors), ==, 1); + + g_assert_cmpint (monitor_manager->screen_width, ==, 1024); + g_assert_cmpint (monitor_manager->screen_height, ==, 768); + + stage = meta_backend_get_stage (backend); + g_assert_cmpint (clutter_actor_get_width (stage), ==, 1024); + g_assert_cmpint (clutter_actor_get_height (stage), ==, 768); +} + +static MetaMonitorTestSetup * +create_headless_test_setup (void) +{ + return g_new0 (MetaMonitorTestSetup, 1); +} + +static void +init_tests (int argc, char **argv) +{ + g_test_init (&argc, &argv, NULL); + g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id="); + + MetaMonitorTestSetup *initial_test_setup; + + initial_test_setup = create_headless_test_setup (); + meta_monitor_manager_test_init_test_setup (initial_test_setup); + + 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); +} + +int +main (int argc, char *argv[]) +{ + init_tests (argc, argv); + + meta_plugin_manager_load ("default"); + + meta_override_compositor_configuration (META_COMPOSITOR_TYPE_WAYLAND, + META_TYPE_BACKEND_TEST); + meta_wayland_override_display_name ("mutter-test-display"); + + meta_init (); + meta_register_with_session (); + + g_idle_add (run_tests, NULL); + + return meta_run (); +} diff --git a/src/tests/meta-monitor-manager-test.c b/src/tests/meta-monitor-manager-test.c index 4b0634e68..3e105de11 100644 --- a/src/tests/meta-monitor-manager-test.c +++ b/src/tests/meta-monitor-manager-test.c @@ -372,7 +372,10 @@ meta_monitor_manager_test_calculate_monitor_mode_scale (MetaMonitorManager *mana output = meta_monitor_get_main_output (monitor); output_test = output->driver_private; - return output_test->scale; + if (output_test) + return output_test->scale; + else + return 1; } static float *