summaryrefslogtreecommitdiff
path: root/src/tests/headless-start-test.c
blob: 172a16544ad5f1e13fb61b8a46ecf3765287a623 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* -*- 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"

#include "backends/meta-monitor-manager-private.h"
#include "backends/meta-crtc.h"
#include "backends/meta-output.h"
#include "compositor/meta-plugin-manager.h"
#include "core/display-private.h"
#include "core/main-private.h"
#include "meta/main.h"
#include "tests/meta-backend-test.h"
#include "tests/meta-monitor-manager-test.h"
#include "tests/test-utils.h"
#include "wayland/meta-wayland.h"

#define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1)
#define FRAME_WARNING "Frame has assigned frame counter but no frame drawn time"

static gboolean
run_tests (gpointer data)
{
  MetaBackend *backend = meta_get_backend ();
  MetaSettings *settings = meta_backend_get_settings (backend);
  gboolean ret;

  g_test_log_set_fatal_handler (NULL, NULL);

  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 gboolean
ignore_frame_counter_warning (const gchar    *log_domain,
                              GLogLevelFlags  log_level,
                              const gchar    *message,
                              gpointer        user_data)
{
  if ((log_level & G_LOG_LEVEL_WARNING) &&
      g_strcmp0 (log_domain, "mutter") == 0 &&
      g_str_has_suffix (message, FRAME_WARNING))
    return FALSE;

  return TRUE;
}

static void
meta_test_headless_start (void)
{
  MetaBackend *backend = meta_get_backend ();
  MetaMonitorManager *monitor_manager =
    meta_backend_get_monitor_manager (backend);
  GList *gpus;
  MetaGpu *gpu;

  gpus = meta_monitor_manager_get_gpus (monitor_manager);
  g_assert_cmpint ((int) g_list_length (gpus), ==, 1);

  gpu = gpus->data;
  g_assert_null (meta_gpu_get_modes (gpu));
  g_assert_null (meta_gpu_get_outputs (gpu));
  g_assert_null (meta_gpu_get_crtcs (gpu));
  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;

  display = meta_get_display ();

  index = meta_display_get_monitor_index_for_rect (display,
                                                   &(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;
  MetaCrtcMode *crtc_mode;
  MetaCrtc *crtc;
  MetaCrtc **possible_crtcs;
  MetaOutput *output;
  GList *logical_monitors;
  ClutterActor *stage;

  test_setup = g_new0 (MetaMonitorTestSetup, 1);

  crtc_mode = g_object_new (META_TYPE_CRTC_MODE, NULL);
  crtc_mode->mode_id = 1;
  crtc_mode->width = 1024;
  crtc_mode->height = 768;
  crtc_mode->refresh_rate = 60.0;
  test_setup->modes = g_list_append (NULL, crtc_mode);

  crtc = g_object_new (META_TYPE_CRTC, NULL);
  crtc->crtc_id = 1;
  crtc->all_transforms = ALL_TRANSFORMS;
  test_setup->crtcs = g_list_append (NULL, crtc);

  modes = g_new0 (MetaCrtcMode *, 1);
  modes[0] = crtc_mode;

  possible_crtcs = g_new0 (MetaCrtc *, 1);
  possible_crtcs[0] = g_list_first (test_setup->crtcs)->data;

  output = g_object_new (META_TYPE_OUTPUT, NULL);
  output->winsys_id = 1;
  output->name = g_strdup ("DP-1");
  output->vendor = g_strdup ("MetaProduct's Inc.");
  output->product = g_strdup ("MetaMonitor");
  output->serial = g_strdup ("0x987654");
  output->preferred_mode = modes[0];
  output->n_modes = 1;
  output->modes = modes;
  output->n_possible_crtcs = 1;
  output->possible_crtcs = possible_crtcs;
  output->connector_type = META_CONNECTOR_TYPE_DisplayPort;
  test_setup->outputs = g_list_append (NULL, output);

  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)
{
  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[])
{
  test_init (&argc, &argv);
  init_tests (argc, argv);

  meta_plugin_manager_load (test_get_plugin_name ());

  meta_override_compositor_configuration (META_COMPOSITOR_TYPE_WAYLAND,
                                          META_TYPE_BACKEND_TEST);

  meta_init ();
  meta_register_with_session ();

  g_test_log_set_fatal_handler (ignore_frame_counter_warning, NULL);

  g_idle_add (run_tests, NULL);

  return meta_run ();
}