tests: Add monitor config migration tests

So far some basic testing, including:

 * Test that the migrated configuration is applicable
 * Test that a monitors.xml with multiple configurations are translated
 * Test rotation
 * Test tiled monitor discovery (well, test a made up tiled monitor
   configuration since I don't have a real one)

https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
Jonas Ådahl 2017-08-10 17:12:39 +08:00
parent bc3162460f
commit 61950755ec
14 changed files with 606 additions and 0 deletions

View File

@ -38,6 +38,8 @@ mutter_test_unit_tests_SOURCES = \
tests/meta-backend-test.h \
tests/meta-monitor-manager-test.c \
tests/meta-monitor-manager-test.h \
tests/monitor-config-migration-unit-tests.c \
tests/monitor-config-migration-unit-tests.h \
tests/monitor-store-unit-tests.c \
tests/monitor-store-unit-tests.h \
tests/monitor-test-utils.c \

View File

@ -0,0 +1,78 @@
<monitors version="2">
<configuration>
<migrated/>
<logicalmonitor>
<x>0</x>
<y>0</y>
<monitor>
<monitorspec>
<connector>HDMI-1</connector>
<vendor>DEL</vendor>
<product>DELL P2415Q</product>
<serial>GTTPW67P0WFB</serial>
</monitorspec>
<mode>
<width>3840</width>
<height>2160</height>
<rate>29.981103897094727</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>3840</x>
<y>0</y>
<primary>yes</primary>
<monitor>
<monitorspec>
<connector>eDP-1</connector>
<vendor>AUO</vendor>
<product>0x123d</product>
<serial>0x00000000</serial>
</monitorspec>
<mode>
<width>1920</width>
<height>1080</height>
<rate>60.049972534179688</rate>
</mode>
</monitor>
</logicalmonitor>
</configuration>
<configuration>
<migrated/>
<logicalmonitor>
<x>1920</x>
<y>0</y>
<monitor>
<monitorspec>
<connector>DP-2</connector>
<vendor>ACI</vendor>
<product>VX239</product>
<serial>ECLMRS004144</serial>
</monitorspec>
<mode>
<width>1920</width>
<height>1080</height>
<rate>60</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>0</x>
<y>0</y>
<primary>yes</primary>
<monitor>
<monitorspec>
<connector>eDP-1</connector>
<vendor>AUO</vendor>
<product>0x123d</product>
<serial>0x00000000</serial>
</monitorspec>
<mode>
<width>1920</width>
<height>1080</height>
<rate>60.049468994140625</rate>
</mode>
</monitor>
</logicalmonitor>
</configuration>
</monitors>

View File

@ -0,0 +1,72 @@
<monitors version="1">
<configuration>
<clone>no</clone>
<output name="HDMI-1">
<vendor>DEL</vendor>
<product>DELL P2415Q</product>
<serial>GTTPW67P0WFB</serial>
<width>3840</width>
<height>2160</height>
<rate>29.981103897094727</rate>
<x>0</x>
<y>0</y>
<rotation>normal</rotation>
<reflect_x>no</reflect_x>
<reflect_y>no</reflect_y>
<primary>no</primary>
<presentation>no</presentation>
<underscanning>no</underscanning>
</output>
<output name="eDP-1">
<vendor>AUO</vendor>
<product>0x123d</product>
<serial>0x00000000</serial>
<width>1920</width>
<height>1080</height>
<rate>60.049972534179688</rate>
<x>3840</x>
<y>0</y>
<rotation>normal</rotation>
<reflect_x>no</reflect_x>
<reflect_y>no</reflect_y>
<primary>yes</primary>
<presentation>no</presentation>
<underscanning>no</underscanning>
</output>
</configuration>
<configuration>
<clone>no</clone>
<output name="DP-2">
<vendor>ACI</vendor>
<product>VX239</product>
<serial>ECLMRS004144</serial>
<width>1920</width>
<height>1080</height>
<rate>60</rate>
<x>1920</x>
<y>0</y>
<rotation>normal</rotation>
<reflect_x>no</reflect_x>
<reflect_y>no</reflect_y>
<primary>no</primary>
<presentation>no</presentation>
<underscanning>no</underscanning>
</output>
<output name="eDP-1">
<vendor>AUO</vendor>
<product>0x123d</product>
<serial>0x00000000</serial>
<width>1920</width>
<height>1080</height>
<rate>60.049468994140625</rate>
<x>0</x>
<y>0</y>
<rotation>normal</rotation>
<reflect_x>no</reflect_x>
<reflect_y>no</reflect_y>
<primary>yes</primary>
<presentation>no</presentation>
<underscanning>no</underscanning>
</output>
</configuration>
</monitors>

View File

@ -0,0 +1,27 @@
<monitors version="2">
<configuration>
<logicalmonitor>
<x>0</x>
<y>0</y>
<scale>1</scale>
<primary>yes</primary>
<transform>
<rotation>right</rotation>
<flipped>no</flipped>
</transform>
<monitor>
<monitorspec>
<connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60</rate>
</mode>
</monitor>
</logicalmonitor>
</configuration>
</monitors>

View File

@ -0,0 +1,27 @@
<monitors version="2">
<configuration>
<migrated/>
<logicalmonitor>
<x>0</x>
<y>0</y>
<primary>yes</primary>
<transform>
<rotation>right</rotation>
<flipped>no</flipped>
</transform>
<monitor>
<monitorspec>
<connector>DP-1</connector>
<vendor>MetaProduct's Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60</rate>
</mode>
</monitor>
</logicalmonitor>
</configuration>
</monitors>

View File

@ -0,0 +1,21 @@
<monitors version="1">
<configuration>
<clone>no</clone>
<output name="DP-1">
<vendor>MetaProduct's Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456</serial>
<width>600</width>
<height>800</height>
<rate>60</rate>
<x>0</x>
<y>0</y>
<rotation>right</rotation>
<reflect_x>no</reflect_x>
<reflect_y>no</reflect_y>
<primary>yes</primary>
<presentation>no</presentation>
<underscanning>no</underscanning>
</output>
</configuration>
</monitors>

View File

@ -0,0 +1,23 @@
<monitors version="2">
<configuration>
<migrated/>
<logicalmonitor>
<x>0</x>
<y>0</y>
<primary>yes</primary>
<monitor>
<monitorspec>
<connector>DP-1</connector>
<vendor>DEL</vendor>
<product>DELL P2415Q</product>
<serial>GTTPW67P0WFB</serial>
</monitorspec>
<mode>
<width>3840</width>
<height>2160</height>
<rate>60</rate>
</mode>
</monitor>
</logicalmonitor>
</configuration>
</monitors>

View File

@ -0,0 +1,37 @@
<monitors version="1">
<configuration>
<clone>no</clone>
<output name="DP-1">
<vendor>DEL</vendor>
<product>DELL P2415Q</product>
<serial>GTTPW67P0WFB</serial>
<width>1920</width>
<height>2160</height>
<rate>60</rate>
<x>0</x>
<y>0</y>
<rotation>normal</rotation>
<reflect_x>no</reflect_x>
<reflect_y>no</reflect_y>
<primary>yes</primary>
<presentation>no</presentation>
<underscanning>no</underscanning>
</output>
<output name="DP-2">
<vendor>DEL</vendor>
<product>DELL P2415Q</product>
<serial>GTTPW67P0WFB</serial>
<width>1920</width>
<height>2160</height>
<rate>60</rate>
<x>1920</x>
<y>0</y>
<rotation>normal</rotation>
<reflect_x>no</reflect_x>
<reflect_y>no</reflect_y>
<primary>yes</primary>
<presentation>no</presentation>
<underscanning>no</underscanning>
</output>
</configuration>
</monitors>

View File

@ -0,0 +1,112 @@
/* -*- 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 "tests/monitor-config-migration-unit-tests.h"
#include <glib.h>
#include <gio/gio.h>
#include "backends/meta-backend-private.h"
#include "backends/meta-monitor-config-manager.h"
#include "backends/meta-monitor-config-store.h"
#include "backends/meta-monitor-manager-private.h"
#include "backends/meta-monitor-config-migration.h"
#include "tests/monitor-test-utils.h"
static void
test_migration (const char *old_config,
const char *new_config)
{
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaMonitorConfigManager *config_manager = monitor_manager->config_manager;
MetaMonitorConfigStore *config_store =
meta_monitor_config_manager_get_store (config_manager);
GError *error = NULL;
const char *old_config_path;
g_autoptr (GFile) old_config_file = NULL;
g_autofree char *migrated_path = NULL;
const char *expected_path;
g_autofree char *migrated_data = NULL;
g_autofree char *expected_data = NULL;
g_autoptr (GFile) migrated_file = NULL;
migrated_path = g_build_filename (g_get_tmp_dir (),
"test-migrated-monitors.xml",
NULL);
if (!meta_monitor_config_store_set_custom (config_store, "/dev/null",
migrated_path,
&error))
g_error ("Failed to set custom config store: %s", error->message);
old_config_path = g_test_get_filename (G_TEST_DIST, "tests", "migration",
old_config, NULL);
old_config_file = g_file_new_for_path (old_config_path);
if (!meta_migrate_old_monitors_config (config_store,
old_config_file,
&error))
g_error ("Failed to migrate config: %s", error->message);
expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration",
new_config, NULL);
expected_data = read_file (expected_path);
migrated_data = read_file (migrated_path);
g_assert_nonnull (expected_data);
g_assert_nonnull (migrated_data);
g_assert (strcmp (expected_data, migrated_data) == 0);
migrated_file = g_file_new_for_path (migrated_path);
if (!g_file_delete (migrated_file, NULL, &error))
g_error ("Failed to remove test data output file: %s", error->message);
}
static void
meta_test_monitor_config_migration_basic (void)
{
test_migration ("basic-old.xml", "basic-new.xml");
}
static void
meta_test_monitor_config_migration_rotated (void)
{
test_migration ("rotated-old.xml", "rotated-new.xml");
}
static void
meta_test_monitor_config_migration_tiled (void)
{
test_migration ("tiled-old.xml", "tiled-new.xml");
}
void
init_monitor_config_migration_tests (void)
{
g_test_add_func ("/backends/monitor-config-migration/basic",
meta_test_monitor_config_migration_basic);
g_test_add_func ("/backends/monitor-config-migration/rotated",
meta_test_monitor_config_migration_rotated);
g_test_add_func ("/backends/monitor-config-migration/tiled",
meta_test_monitor_config_migration_tiled);
}

View File

@ -0,0 +1,25 @@
/* -*- 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/>.
*/
#ifndef MONITOR_CONFIG_MIGRATION_UNIT_TESTS_H
#define MONITOR_CONFIG_MIGRATION_UNIT_TESTS_H
void init_monitor_config_migration_tests (void);
#endif /* MONITOR_CONFIG_MIGRATION_UNIT_TESTS_H */

View File

@ -46,3 +46,36 @@ set_custom_monitor_config (const char *filename)
&error))
g_error ("Failed to set custom config: %s", error->message);
}
char *
read_file (const char *file_path)
{
g_autoptr (GFile) file = NULL;
g_autoptr (GFileInputStream) input_stream = NULL;
g_autoptr (GFileInfo) file_info = NULL;
goffset file_size;
gsize bytes_read;
g_autofree char *buffer = NULL;
GError *error = NULL;
file = g_file_new_for_path (file_path);
input_stream = g_file_read (file, NULL, &error);
if (!input_stream)
g_error ("Failed to read migrated config file: %s", error->message);
file_info = g_file_input_stream_query_info (input_stream,
G_FILE_ATTRIBUTE_STANDARD_SIZE,
NULL, &error);
if (!file_info)
g_error ("Failed to read file info: %s", error->message);
file_size = g_file_info_get_size (file_info);
buffer = g_malloc0 (file_size + 1);
if (!g_input_stream_read_all (G_INPUT_STREAM (input_stream),
buffer, file_size, &bytes_read, NULL, &error))
g_error ("Failed to read file content: %s", error->message);
g_assert_cmpint ((goffset) bytes_read, ==, file_size);
return g_steal_pointer (&buffer);
}

View File

@ -26,4 +26,6 @@ gboolean is_using_monitor_config_manager (void);
void set_custom_monitor_config (const char *filename);
char * read_file (const char *file_path);
#endif /* MONITOR_TEST_UTILS_H */

View File

@ -24,6 +24,8 @@
#include "backends/meta-backend-private.h"
#include "backends/meta-logical-monitor.h"
#include "backends/meta-monitor.h"
#include "backends/meta-monitor-config-migration.h"
#include "backends/meta-monitor-config-store.h"
#include "tests/meta-monitor-manager-test.h"
#include "tests/monitor-test-utils.h"
@ -4650,6 +4652,146 @@ meta_test_monitor_custom_interlaced_config (void)
check_monitor_configuration (&test_case);
}
static void
meta_test_monitor_migrated_rotated (void)
{
MonitorTestCase test_case = {
.setup = {
.modes = {
{
.width = 800,
.height = 600,
.refresh_rate = 60.0
}
},
.n_modes = 1,
.outputs = {
{
.crtc = -1,
.modes = { 0 },
.n_modes = 1,
.preferred_mode = 0,
.possible_crtcs = { 0 },
.n_possible_crtcs = 1,
.width_mm = 222,
.height_mm = 125
}
},
.n_outputs = 1,
.crtcs = {
{
.current_mode = -1
}
},
.n_crtcs = 1
},
.expect = {
.monitors = {
{
.outputs = { 0 },
.n_outputs = 1,
.modes = {
{
.width = 800,
.height = 600,
.refresh_rate = 60.0,
.crtc_modes = {
{
.output = 0,
.crtc_mode = 0
}
}
}
},
.n_modes = 1,
.current_mode = 0,
.width_mm = 222,
.height_mm = 125
}
},
.n_monitors = 1,
.logical_monitors = {
{
.monitors = { 0 },
.n_monitors = 1,
.layout = { .x = 0, .y = 0, .width = 600, .height = 800 },
.scale = 1,
.transform = META_MONITOR_TRANSFORM_270
},
},
.n_logical_monitors = 1,
.primary_logical_monitor = 0,
.n_outputs = 1,
.crtcs = {
{
.current_mode = 0,
}
},
.n_crtcs = 1,
.screen_width = 600,
.screen_height = 800,
}
};
MetaMonitorTestSetup *test_setup;
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaMonitorConfigManager *config_manager = monitor_manager->config_manager;
MetaMonitorConfigStore *config_store =
meta_monitor_config_manager_get_store (config_manager);
g_autofree char *migrated_path = NULL;
const char *old_config_path;
g_autoptr (GFile) old_config_file = NULL;
GError *error = NULL;
const char *expected_path;
g_autofree char *migrated_data = NULL;
g_autofree char *expected_data = NULL;
g_autoptr (GFile) migrated_file = NULL;
test_setup = create_monitor_test_setup (&test_case,
MONITOR_TEST_FLAG_NONE);
migrated_path = g_build_filename (g_get_tmp_dir (),
"test-finished-migrated-monitors.xml",
NULL);
if (!meta_monitor_config_store_set_custom (config_store,
"/dev/null",
migrated_path,
&error))
g_error ("Failed to set custom config store files: %s", error->message);
old_config_path = g_test_get_filename (G_TEST_DIST,
"tests", "migration",
"rotated-old.xml",
NULL);
old_config_file = g_file_new_for_path (old_config_path);
if (!meta_migrate_old_monitors_config (config_store,
old_config_file,
&error))
g_error ("Failed to migrated config: %s", error->message);
emulate_hotplug (test_setup);
check_monitor_configuration (&test_case);
expected_path = g_test_get_filename (G_TEST_DIST,
"tests", "migration",
"rotated-new-finished.xml",
NULL);
expected_data = read_file (expected_path);
migrated_data = read_file (migrated_path);
g_assert_nonnull (expected_data);
g_assert_nonnull (migrated_data);
g_assert (strcmp (expected_data, migrated_data) == 0);
migrated_file = g_file_new_for_path (migrated_path);
if (!g_file_delete (migrated_file, NULL, &error))
g_error ("Failed to remove test data output file: %s", error->message);
}
void
init_monitor_tests (void)
{
@ -4720,4 +4862,7 @@ init_monitor_tests (void)
meta_test_monitor_custom_second_rotated_nonnative_config);
g_test_add_func ("/backends/monitor/custom/interlaced-config",
meta_test_monitor_custom_interlaced_config);
g_test_add_func ("/backends/monitor/migrated/rotated",
meta_test_monitor_migrated_rotated);
}

View File

@ -29,6 +29,7 @@
#include "core/boxes-private.h"
#include "core/main-private.h"
#include "tests/meta-backend-test.h"
#include "tests/monitor-config-migration-unit-tests.h"
#include "tests/monitor-unit-tests.h"
#include "tests/monitor-store-unit-tests.h"
#include "wayland/meta-wayland.h"
@ -244,6 +245,7 @@ init_tests (int argc, char **argv)
g_test_add_func ("/core/boxes/adjecent-to", meta_test_adjecent_to);
init_monitor_store_tests ();
init_monitor_config_migration_tests ();
init_monitor_tests ();
}