1
0
Fork 0

tests/monitor-unit: Add layout mode migration tests

Let's add a bunch of tests for the newly introduced monitor config
migration code. We're verifying that:

- monitor configs get migrated and monitors.xml is updated on startup

- existing monitor configs in LOGICAL layout mode (ie.
"scale-monitor-framebuffers" was enabled before updating mutter) get
migrated

- the migration of various more complex monitor layouts from PHYSICAL
to LOGICAL layout mode works

- for monitor layouts where conversion to LOGICAL fails, the PHYSICAL
layout mode still is migrated, while for LOGICAL at least primary
monitor and disabled monitors are preserved

- simple monitor configurations (with no scaled monitors, or with only
"irrelevant" scaled monitors at the end of the layout) do not go through
the conversion code paths

- monitor configs in PHYSICAL layout mode with integer scale factors
which will result in non-integer logical monitor sizes get converted
to the closest fractional scale factor

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3596>
This commit is contained in:
Jonas Dreßler 2024-02-17 01:13:45 +01:00 committed by Marge Bot
parent 05cc8a56e1
commit 4175a37e4c
5 changed files with 937 additions and 0 deletions

View file

@ -0,0 +1,154 @@
<monitors version="2">
<configuration>
<layout_mode>logical</layout_mode>
<logicalmonitor>
<x>0</x>
<y>150</y>
<scale>2</scale>
<monitor>
<monitorspec>
<connector>DP-1</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456a</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>400</x>
<y>0</y>
<scale>1</scale>
<monitor>
<monitorspec>
<connector>DP-2</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456b</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>1200</x>
<y>199</y>
<scale>2.985074520111084</scale>
<primary>yes</primary>
<monitor>
<monitorspec>
<connector>DP-3</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456c</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>1468</x>
<y>0</y>
<scale>1</scale>
<monitor>
<monitorspec>
<connector>DP-4</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456d</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
</configuration>
<configuration>
<layout_mode>physical</layout_mode>
<logicalmonitor>
<x>0</x>
<y>0</y>
<scale>2</scale>
<monitor>
<monitorspec>
<connector>DP-1</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456a</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>800</x>
<y>550</y>
<scale>1</scale>
<monitor>
<monitorspec>
<connector>DP-2</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456b</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>1600</x>
<y>550</y>
<scale>3</scale>
<primary>yes</primary>
<monitor>
<monitorspec>
<connector>DP-3</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456c</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>2400</x>
<y>900</y>
<scale>1</scale>
<monitor>
<monitorspec>
<connector>DP-4</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456d</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
</configuration>
</monitors>

View file

@ -0,0 +1,77 @@
<monitors version="2">
<configuration>
<logicalmonitor>
<x>0</x>
<y>0</y>
<scale>2</scale>
<monitor>
<monitorspec>
<connector>DP-1</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456a</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>800</x>
<y>550</y>
<scale>1</scale>
<monitor>
<monitorspec>
<connector>DP-2</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456b</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>1600</x>
<y>550</y>
<scale>3</scale>
<primary>yes</primary>
<monitor>
<monitorspec>
<connector>DP-3</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456c</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>2400</x>
<y>900</y>
<scale>1</scale>
<monitor>
<monitorspec>
<connector>DP-4</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456d</serial>
</monitorspec>
<mode>
<width>800</width>
<height>600</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
</configuration>
</monitors>

View file

@ -0,0 +1,126 @@
<monitors version="2">
<configuration>
<layout_mode>logical</layout_mode>
<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&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456a</serial>
</monitorspec>
<mode>
<width>1920</width>
<height>1080</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>1080</x>
<y>0</y>
<scale>2</scale>
<monitor>
<monitorspec>
<connector>DP-2</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456b</serial>
</monitorspec>
<mode>
<width>1920</width>
<height>1080</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>600</x>
<y>1920</y>
<scale>1</scale>
<monitor>
<monitorspec>
<connector>DP-3</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456c</serial>
</monitorspec>
<mode>
<width>1920</width>
<height>1080</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
</configuration>
<configuration>
<layout_mode>physical</layout_mode>
<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&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456a</serial>
</monitorspec>
<mode>
<width>1920</width>
<height>1080</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>1080</x>
<y>0</y>
<scale>2</scale>
<monitor>
<monitorspec>
<connector>DP-2</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456b</serial>
</monitorspec>
<mode>
<width>1920</width>
<height>1080</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>600</x>
<y>1920</y>
<scale>1</scale>
<monitor>
<monitorspec>
<connector>DP-3</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456c</serial>
</monitorspec>
<mode>
<width>1920</width>
<height>1080</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
</configuration>
</monitors>

View file

@ -0,0 +1,63 @@
<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&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456a</serial>
</monitorspec>
<mode>
<width>1920</width>
<height>1080</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>1080</x>
<y>0</y>
<scale>2</scale>
<monitor>
<monitorspec>
<connector>DP-2</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456b</serial>
</monitorspec>
<mode>
<width>1920</width>
<height>1080</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
<logicalmonitor>
<x>600</x>
<y>1920</y>
<scale>1</scale>
<monitor>
<monitorspec>
<connector>DP-3</connector>
<vendor>MetaProduct&apos;s Inc.</vendor>
<product>MetaMonitor</product>
<serial>0x123456c</serial>
</monitorspec>
<mode>
<width>1920</width>
<height>1080</height>
<rate>60.000</rate>
</mode>
</monitor>
</logicalmonitor>
</configuration>
</monitors>

View file

@ -8417,6 +8417,518 @@ meta_test_monitor_custom_lid_switch_config (void)
check_monitor_test_clients_state ();
}
static void
meta_test_monitor_migrated_rotated (void)
{
MonitorTestCase test_case = {
.setup = {
.modes = {
{
.width = 1920,
.height = 1080,
.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,
.serial = "0x123456a",
},
{
.crtc = -1,
.modes = { 0 },
.n_modes = 1,
.preferred_mode = 0,
.possible_crtcs = { 1 },
.n_possible_crtcs = 1,
.width_mm = 222,
.height_mm = 125,
.serial = "0x123456b",
},
{
.crtc = -1,
.modes = { 0 },
.n_modes = 1,
.preferred_mode = 0,
.possible_crtcs = { 2 },
.n_possible_crtcs = 1,
.width_mm = 222,
.height_mm = 125,
.serial = "0x123456c",
}
},
.n_outputs = 3,
.crtcs = {
{
.current_mode = 0
},
{
.current_mode = 0
},
{
.current_mode = 0
}
},
.n_crtcs = 3
},
.expect = {
.monitors = {
{
.outputs = { 0 },
.n_outputs = 1,
.modes = {
{
.width = 1920,
.height = 1080,
.refresh_rate = 60.0,
.crtc_modes = {
{
.output = 0,
.crtc_mode = 0
}
}
}
},
.n_modes = 1,
.current_mode = 0,
.width_mm = 222,
.height_mm = 125
},
{
.outputs = { 1 },
.n_outputs = 1,
.modes = {
{
.width = 1920,
.height = 1080,
.refresh_rate = 60.0,
.crtc_modes = {
{
.output = 1,
.crtc_mode = 0
}
}
}
},
.n_modes = 1,
.current_mode = 0,
.width_mm = 222,
.height_mm = 125
},
{
.outputs = { 2 },
.n_outputs = 1,
.modes = {
{
.width = 1920,
.height = 1080,
.refresh_rate = 60.0,
.crtc_modes = {
{
.output = 2,
.crtc_mode = 0
}
}
}
},
.n_modes = 1,
.current_mode = 0,
.width_mm = 222,
.height_mm = 125
}
},
.n_monitors = 3,
.logical_monitors = {
{
.monitors = { 0 },
.n_monitors = 1,
.layout = { .x = 0, .y = 0, .width = 1080, .height = 1920 },
.scale = 1,
.transform = MTK_MONITOR_TRANSFORM_270
},
{
.monitors = { 1 },
.n_monitors = 1,
.layout = { .x = 1080, .y = 0, .width = 960, .height = 540 },
.scale = 2
},
{
.monitors = { 2 },
.n_monitors = 1,
.layout = { .x = 600, .y = 1920, .width = 1920, .height = 1080 },
.scale = 1
}
},
.n_logical_monitors = 3,
.primary_logical_monitor = 0,
.n_outputs = 3,
.crtcs = {
{
.current_mode = 0,
.transform = MTK_MONITOR_TRANSFORM_270
},
{
.current_mode = 0,
.x = 1080
},
{
.current_mode = 0,
.x = 600,
.y = 1920
}
},
.n_crtcs = 3,
.screen_width = 2520,
.screen_height = 3000,
}
};
MetaMonitorTestSetup *test_setup;
MetaBackend *backend = meta_context_get_backend (test_context);
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;
g_autofree char *old_config_path = NULL;
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 = meta_create_monitor_test_setup (test_backend,
&test_case.setup,
MONITOR_TEST_FLAG_NONE);
old_config_path = g_test_build_filename (G_TEST_DIST,
"tests", "migration",
"rotated.xml",
NULL);
migrated_path = g_build_filename (g_get_tmp_dir (),
"test-finished-migrated-monitors.xml",
NULL);
if (!meta_monitor_config_store_set_custom (config_store,
old_config_path,
migrated_path,
META_MONITORS_CONFIG_FLAG_NONE,
&error))
g_error ("Failed to set custom config store files: %s", error->message);
emulate_hotplug (test_setup);
META_TEST_LOG_CALL ("Checking monitor configuration",
meta_check_monitor_configuration (test_context,
&test_case.expect));
check_monitor_test_clients_state ();
expected_path = g_test_get_filename (G_TEST_DIST,
"tests", "migration",
"rotated-finished.xml",
NULL);
expected_data = meta_read_file (expected_path);
migrated_data = meta_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_migrated_horizontal_strip (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,
.serial = "0x123456a",
},
{
.crtc = -1,
.modes = { 0 },
.n_modes = 1,
.preferred_mode = 0,
.possible_crtcs = { 1 },
.n_possible_crtcs = 1,
.width_mm = 222,
.height_mm = 125,
.serial = "0x123456b",
},
{
.crtc = -1,
.modes = { 0 },
.n_modes = 1,
.preferred_mode = 0,
.possible_crtcs = { 2 },
.n_possible_crtcs = 1,
.width_mm = 222,
.height_mm = 125,
.serial = "0x123456c",
},
{
.crtc = -1,
.modes = { 0 },
.n_modes = 1,
.preferred_mode = 0,
.possible_crtcs = { 3 },
.n_possible_crtcs = 1,
.width_mm = 222,
.height_mm = 125,
.serial = "0x123456d",
}
},
.n_outputs = 4,
.crtcs = {
{
.current_mode = 0
},
{
.current_mode = 0
},
{
.current_mode = 0
},
{
.current_mode = 0
}
},
.n_crtcs = 4
},
.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
},
{
.outputs = { 1 },
.n_outputs = 1,
.modes = {
{
.width = 800,
.height = 600,
.refresh_rate = 60.0,
.crtc_modes = {
{
.output = 1,
.crtc_mode = 0
}
}
}
},
.n_modes = 1,
.current_mode = 0,
.width_mm = 222,
.height_mm = 125
},
{
.outputs = { 2 },
.n_outputs = 1,
.modes = {
{
.width = 800,
.height = 600,
.refresh_rate = 60.0,
.crtc_modes = {
{
.output = 2,
.crtc_mode = 0
}
}
}
},
.n_modes = 1,
.current_mode = 0,
.width_mm = 222,
.height_mm = 125
},
{
.outputs = { 3 },
.n_outputs = 1,
.modes = {
{
.width = 800,
.height = 600,
.refresh_rate = 60.0,
.crtc_modes = {
{
.output = 3,
.crtc_mode = 0
}
}
}
},
.n_modes = 1,
.current_mode = 0,
.width_mm = 222,
.height_mm = 125
}
},
.n_monitors = 4,
.logical_monitors = {
{
.monitors = { 0 },
.n_monitors = 1,
.layout = { .x = 0, .y = 150, .width = 400, .height = 300 },
.scale = 2
},
{
.monitors = { 1 },
.n_monitors = 1,
.layout = { .x = 400, .y = 0, .width = 800, .height = 600 },
.scale = 1
},
{
.monitors = { 2 },
.n_monitors = 1,
.layout = { .x = 1200, .y = 199, .width = 268, .height = 201 },
.scale = 2.985074520111084
},
{
.monitors = { 3 },
.n_monitors = 1,
.layout = { .x = 1468, .y = 0, .width = 800, .height = 600 },
.scale = 1
}
},
.n_logical_monitors = 4,
.primary_logical_monitor = 2,
.n_outputs = 4,
.crtcs = {
{
.current_mode = 0,
.y = 150
},
{
.current_mode = 0,
.x = 400
},
{
.current_mode = 0,
.x = 1200,
.y = 199
},
{
.current_mode = 0,
.x = 1468
}
},
.n_crtcs = 4,
.screen_width = 2268,
.screen_height = 600,
}
};
MetaMonitorTestSetup *test_setup;
MetaBackend *backend = meta_context_get_backend (test_context);
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;
g_autofree char *old_config_path = NULL;
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 = meta_create_monitor_test_setup (test_backend,
&test_case.setup,
MONITOR_TEST_FLAG_NONE);
old_config_path = g_test_build_filename (G_TEST_DIST,
"tests", "migration",
"horizontal-strip.xml",
NULL);
migrated_path = g_build_filename (g_get_tmp_dir (),
"test-finished-migrated-monitors.xml",
NULL);
if (!meta_monitor_config_store_set_custom (config_store,
old_config_path,
migrated_path,
META_MONITORS_CONFIG_FLAG_NONE,
&error))
g_error ("Failed to set custom config store files: %s", error->message);
emulate_hotplug (test_setup);
META_TEST_LOG_CALL ("Checking monitor configuration",
meta_check_monitor_configuration (test_context,
&test_case.expect));
check_monitor_test_clients_state ();
expected_path = g_test_get_filename (G_TEST_DIST,
"tests", "migration",
"horizontal-strip-finished.xml",
NULL);
expected_data = meta_read_file (expected_path);
migrated_data = meta_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_custom_detached_groups (void)
{
@ -9660,6 +10172,11 @@ init_monitor_tests (void)
add_monitor_test ("/backends/monitor/custom/detached-groups",
meta_test_monitor_custom_detached_groups);
add_monitor_test ("/backends/monitor/migrated/rotated",
meta_test_monitor_migrated_rotated);
add_monitor_test ("/backends/monitor/migrated/horizontal-strip",
meta_test_monitor_migrated_horizontal_strip);
add_monitor_test ("/backends/monitor/wm/tiling",
meta_test_monitor_wm_tiling);