From f3a65c9b32229d8b5d17968ca96394dd64cabfa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Fri, 8 May 2020 20:55:12 +0200 Subject: [PATCH 1/6] tests/monitor-test-utils: Remove unused function definition https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1243 --- src/tests/monitor-test-utils.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tests/monitor-test-utils.h b/src/tests/monitor-test-utils.h index 4b9b3f0c790..0b0dc6d7d9b 100644 --- a/src/tests/monitor-test-utils.h +++ b/src/tests/monitor-test-utils.h @@ -22,8 +22,6 @@ #include -gboolean is_using_monitor_config_manager (void); - void set_custom_monitor_config (const char *filename); char * read_file (const char *file_path); -- GitLab From 7cc604b9e598547f7b6c569ace96e3876eaa7711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Fri, 8 May 2020 21:03:47 +0200 Subject: [PATCH 2/6] tests/monitor-unit-tests: Use TestCaseSetup for building TestSetup We're going to move the functions for building MonitorTestSetups to the common monitor-test-utils.c file. To make building test setups a bit more straightforward in case no TestCaseExpect is wanted, change create_monitor_test_setup() to take a MonitorTestCaseSetup instead of a MonitorTestCase as an argument. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1243 --- src/tests/monitor-unit-tests.c | 156 ++++++++++++++++----------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c index 8e416624336..f639149fa24 100644 --- a/src/tests/monitor-unit-tests.c +++ b/src/tests/monitor-unit-tests.c @@ -866,8 +866,8 @@ meta_output_test_destroy_notify (MetaOutput *output) } static MetaMonitorTestSetup * -create_monitor_test_setup (MonitorTestCase *test_case, - MonitorTestFlag flags) +create_monitor_test_setup (MonitorTestCaseSetup *setup, + MonitorTestFlag flags) { MetaMonitorTestSetup *test_setup; int i; @@ -883,22 +883,22 @@ create_monitor_test_setup (MonitorTestCase *test_case, test_setup = g_new0 (MetaMonitorTestSetup, 1); test_setup->modes = NULL; - for (i = 0; i < test_case->setup.n_modes; i++) + for (i = 0; i < setup->n_modes; i++) { MetaCrtcMode *mode; mode = g_object_new (META_TYPE_CRTC_MODE, NULL); mode->mode_id = i; - mode->width = test_case->setup.modes[i].width; - mode->height = test_case->setup.modes[i].height; - mode->refresh_rate = test_case->setup.modes[i].refresh_rate; - mode->flags = test_case->setup.modes[i].flags; + mode->width = setup->modes[i].width; + mode->height = setup->modes[i].height; + mode->refresh_rate = setup->modes[i].refresh_rate; + mode->flags = setup->modes[i].flags; test_setup->modes = g_list_append (test_setup->modes, mode); } test_setup->crtcs = NULL; - for (i = 0; i < test_case->setup.n_crtcs; i++) + for (i = 0; i < setup->n_crtcs; i++) { MetaCrtc *crtc; @@ -910,7 +910,7 @@ create_monitor_test_setup (MonitorTestCase *test_case, } test_setup->outputs = NULL; - for (i = 0; i < test_case->setup.n_outputs; i++) + for (i = 0; i < setup->n_outputs; i++) { MetaOutput *output; MetaOutputTest *output_test; @@ -927,43 +927,43 @@ create_monitor_test_setup (MonitorTestCase *test_case, gboolean is_laptop_panel; const char *serial; - crtc_index = test_case->setup.outputs[i].crtc; + crtc_index = setup->outputs[i].crtc; if (crtc_index == -1) crtc = NULL; else crtc = g_list_nth_data (test_setup->crtcs, crtc_index); - preferred_mode_index = test_case->setup.outputs[i].preferred_mode; + preferred_mode_index = setup->outputs[i].preferred_mode; if (preferred_mode_index == -1) preferred_mode = NULL; else preferred_mode = g_list_nth_data (test_setup->modes, preferred_mode_index); - n_modes = test_case->setup.outputs[i].n_modes; + n_modes = setup->outputs[i].n_modes; modes = g_new0 (MetaCrtcMode *, n_modes); for (j = 0; j < n_modes; j++) { int mode_index; - mode_index = test_case->setup.outputs[i].modes[j]; + mode_index = setup->outputs[i].modes[j]; modes[j] = g_list_nth_data (test_setup->modes, mode_index); } - n_possible_crtcs = test_case->setup.outputs[i].n_possible_crtcs; + n_possible_crtcs = setup->outputs[i].n_possible_crtcs; possible_crtcs = g_new0 (MetaCrtc *, n_possible_crtcs); for (j = 0; j < n_possible_crtcs; j++) { int possible_crtc_index; - possible_crtc_index = test_case->setup.outputs[i].possible_crtcs[j]; + possible_crtc_index = setup->outputs[i].possible_crtcs[j]; possible_crtcs[j] = g_list_nth_data (test_setup->crtcs, possible_crtc_index); } output_test = g_new0 (MetaOutputTest, 1); - scale = test_case->setup.outputs[i].scale; + scale = setup->outputs[i].scale; if (scale < 1) scale = 1; @@ -971,9 +971,9 @@ create_monitor_test_setup (MonitorTestCase *test_case, .scale = scale }; - is_laptop_panel = test_case->setup.outputs[i].is_laptop_panel; + is_laptop_panel = setup->outputs[i].is_laptop_panel; - serial = test_case->setup.outputs[i].serial; + serial = setup->outputs[i].serial; if (!serial) serial = "0x123456"; @@ -992,8 +992,8 @@ create_monitor_test_setup (MonitorTestCase *test_case, output->suggested_x = -1; output->suggested_y = -1; output->hotplug_mode_update = hotplug_mode_update; - output->width_mm = test_case->setup.outputs[i].width_mm; - output->height_mm = test_case->setup.outputs[i].height_mm; + output->width_mm = setup->outputs[i].width_mm; + output->height_mm = setup->outputs[i].height_mm; output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN; output->preferred_mode = preferred_mode; output->n_modes = n_modes; @@ -1005,10 +1005,10 @@ create_monitor_test_setup (MonitorTestCase *test_case, output->backlight = -1; output->connector_type = (is_laptop_panel ? META_CONNECTOR_TYPE_eDP : META_CONNECTOR_TYPE_DisplayPort); - output->tile_info = test_case->setup.outputs[i].tile_info; - output->is_underscanning = test_case->setup.outputs[i].is_underscanning; + output->tile_info = setup->outputs[i].tile_info; + output->is_underscanning = setup->outputs[i].is_underscanning; output->panel_orientation_transform = - test_case->setup.outputs[i].panel_orientation_transform; + setup->outputs[i].panel_orientation_transform; output->driver_private = output_test; output->driver_notify = (GDestroyNotify) meta_output_test_destroy_notify; @@ -1094,7 +1094,7 @@ meta_test_monitor_one_disconnected_linear_config (void) .screen_height = 768 }; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -1212,7 +1212,7 @@ meta_test_monitor_one_off_linear_config (void) .screen_height = 768 }; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -1332,7 +1332,7 @@ meta_test_monitor_preferred_linear_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -1461,7 +1461,7 @@ meta_test_monitor_tiled_linear_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -1634,7 +1634,7 @@ meta_test_monitor_tiled_non_preferred_linear_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -1783,7 +1783,7 @@ meta_test_monitor_tiled_non_main_origin_linear_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -1929,7 +1929,7 @@ meta_test_monitor_hidpi_linear_config (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -2081,7 +2081,7 @@ meta_test_monitor_suggested_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); set_suggested_output_position (g_list_nth_data (test_setup->outputs, 0), @@ -2207,7 +2207,7 @@ meta_test_monitor_limited_crtcs (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, @@ -2350,7 +2350,7 @@ meta_test_monitor_lid_switch_config (void) MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -2523,7 +2523,7 @@ meta_test_monitor_lid_opened_config (void) MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); @@ -2629,7 +2629,7 @@ meta_test_monitor_lid_closed_no_external (void) MetaMonitorTestSetup *test_setup; MetaBackend *backend = meta_get_backend (); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); @@ -2772,7 +2772,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) * 3) Close lid */ - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); @@ -2789,7 +2789,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) test_case.expect.crtcs[1].x = 1024; test_case.expect.screen_width = 1024 * 2; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -2803,7 +2803,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) test_case.expect.crtcs[1].x = 0; test_case.expect.screen_width = 1024; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); emulate_hotplug (test_setup); @@ -2827,7 +2827,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) test_case.expect.crtcs[1].x = 1024; test_case.expect.screen_width = 1024 * 2; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); emulate_hotplug (test_setup); @@ -2842,7 +2842,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) test_case.expect.crtcs[1].current_mode = -1; test_case.expect.screen_width = 1024; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -2853,7 +2853,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) test_case.expect.n_logical_monitors = 1; test_case.expect.screen_width = 1024; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); emulate_hotplug (test_setup); @@ -2861,7 +2861,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) /* Lid opened */ - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); emulate_hotplug (test_setup); @@ -2961,7 +2961,7 @@ meta_test_monitor_lid_scaled_closed_opened (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("lid-scale.xml"); emulate_hotplug (test_setup); @@ -3002,7 +3002,7 @@ meta_test_monitor_no_outputs (void) MetaMonitorTestSetup *test_setup; GError *error = NULL; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); @@ -3023,7 +3023,7 @@ meta_test_monitor_no_outputs (void) check_monitor_test_clients_state (); /* Also check that we handle going headless -> headless */ - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); @@ -3114,7 +3114,7 @@ meta_test_monitor_underscanning_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -3209,7 +3209,7 @@ meta_test_monitor_preferred_non_first_mode (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -3242,7 +3242,7 @@ meta_test_monitor_non_upright_panel (void) test_case.expect.crtcs[0].current_mode = 1; test_case.expect.crtcs[0].transform = META_MONITOR_TRANSFORM_90; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -3380,7 +3380,7 @@ meta_test_monitor_custom_vertical_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("vertical.xml"); emulate_hotplug (test_setup); @@ -3520,7 +3520,7 @@ meta_test_monitor_custom_primary_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("primary.xml"); emulate_hotplug (test_setup); @@ -3612,7 +3612,7 @@ meta_test_monitor_custom_underscanning_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("underscanning.xml"); emulate_hotplug (test_setup); @@ -3709,7 +3709,7 @@ meta_test_monitor_custom_scale_config (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("scale.xml"); emulate_hotplug (test_setup); @@ -3806,7 +3806,7 @@ meta_test_monitor_custom_fractional_scale_config (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("fractional-scale.xml"); emulate_hotplug (test_setup); @@ -3903,7 +3903,7 @@ meta_test_monitor_custom_high_precision_fractional_scale_config (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("high-precision-fractional-scale.xml"); emulate_hotplug (test_setup); @@ -4040,7 +4040,7 @@ meta_test_monitor_custom_tiled_config (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("tiled.xml"); emulate_hotplug (test_setup); @@ -4197,7 +4197,7 @@ meta_test_monitor_custom_tiled_custom_resolution_config (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("tiled-custom-resolution.xml"); emulate_hotplug (test_setup); @@ -4371,7 +4371,7 @@ meta_test_monitor_custom_tiled_non_preferred_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("non-preferred-tiled-custom-resolution.xml"); emulate_hotplug (test_setup); @@ -4499,7 +4499,7 @@ meta_test_monitor_custom_mirrored_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("mirrored.xml"); emulate_hotplug (test_setup); @@ -4635,7 +4635,7 @@ meta_test_monitor_custom_first_rotated_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("first-rotated.xml"); emulate_hotplug (test_setup); @@ -4771,7 +4771,7 @@ meta_test_monitor_custom_second_rotated_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("second-rotated.xml"); emulate_hotplug (test_setup); @@ -4963,7 +4963,7 @@ meta_test_monitor_custom_second_rotated_tiled_config (void) meta_monitor_manager_test_set_handles_transforms (monitor_manager_test, TRUE); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("second-rotated-tiled.xml"); emulate_hotplug (test_setup); @@ -5155,7 +5155,7 @@ meta_test_monitor_custom_second_rotated_nonnative_tiled_config (void) meta_monitor_manager_test_set_handles_transforms (monitor_manager_test, FALSE); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("second-rotated-tiled.xml"); emulate_hotplug (test_setup); @@ -5305,7 +5305,7 @@ meta_test_monitor_custom_second_rotated_nonnative_config (void) meta_monitor_manager_test_set_handles_transforms (monitor_manager_test, FALSE); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("second-rotated.xml"); emulate_hotplug (test_setup); @@ -5414,7 +5414,7 @@ meta_test_monitor_custom_interlaced_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("interlaced.xml"); emulate_hotplug (test_setup); @@ -5543,7 +5543,7 @@ meta_test_monitor_custom_oneoff (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("oneoff.xml"); emulate_hotplug (test_setup); @@ -5680,7 +5680,7 @@ meta_test_monitor_custom_lid_switch_config (void) MetaMonitorTestSetup *test_setup; MetaBackend *backend = meta_get_backend (); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("lid-switch.xml"); emulate_hotplug (test_setup); @@ -5702,7 +5702,7 @@ meta_test_monitor_custom_lid_switch_config (void) test_case.expect.n_logical_monitors = 2; test_case.expect.screen_width = 1024 + 768; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -5721,7 +5721,7 @@ meta_test_monitor_custom_lid_switch_config (void) test_case.expect.screen_width = 768; meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -5743,7 +5743,7 @@ meta_test_monitor_custom_lid_switch_config (void) test_case.expect.screen_width = 1024 + 768; meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); emulate_hotplug (test_setup); check_monitor_configuration (&test_case); @@ -5847,7 +5847,7 @@ meta_test_monitor_migrated_rotated (void) g_autofree char *expected_data = NULL; g_autoptr (GFile) migrated_file = NULL; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); migrated_path = g_build_filename (g_get_tmp_dir (), @@ -5987,7 +5987,7 @@ meta_test_monitor_migrated_wiggle_discard (void) g_autofree char *expected_data = NULL; g_autoptr (GFile) migrated_file = NULL; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); migrated_path = g_build_filename (g_get_tmp_dir (), @@ -6086,7 +6086,7 @@ meta_test_monitor_wm_tiling (void) MetaMonitorTestSetup *test_setup; g_autoptr (GError) error = NULL; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); @@ -6120,11 +6120,11 @@ meta_test_monitor_wm_tiling (void) fprintf(stderr, ":::: %s:%d %s() - UNPLUGGING\n", __FILE__, __LINE__, __func__); test_case.setup.n_outputs = 0; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); test_case.setup.n_outputs = 1; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); @@ -6139,7 +6139,7 @@ meta_test_monitor_wm_tiling (void) */ test_case.setup.n_outputs = 2; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); @@ -6147,7 +6147,7 @@ meta_test_monitor_wm_tiling (void) meta_window_tile (test_window, META_TILE_NONE); test_case.setup.n_outputs = 1; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); @@ -6254,7 +6254,7 @@ meta_test_monitor_migrated_wiggle (void) g_autofree char *expected_data = NULL; g_autoptr (GFile) migrated_file = NULL; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); migrated_path = g_build_filename (g_get_tmp_dir (), @@ -6329,7 +6329,7 @@ init_monitor_tests (void) { MetaMonitorTestSetup *initial_test_setup; - initial_test_setup = create_monitor_test_setup (&initial_test_case, + initial_test_setup = create_monitor_test_setup (&initial_test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_monitor_manager_test_init_test_setup (initial_test_setup); -- GitLab From 531b0ab300368f3ffd15149b97484a9a0a839873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Fri, 8 May 2020 21:10:12 +0200 Subject: [PATCH 3/6] tests/monitor-unit-tests: Use TestCaseExpect for checking configuration Similar to the last commit, allow checking configurations without passing the whole MonitorTestCase, but instead only the MonitorTestCaseExpect object. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1243 --- src/tests/monitor-unit-tests.c | 175 ++++++++++++++++----------------- 1 file changed, 87 insertions(+), 88 deletions(-) diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c index f639149fa24..561aae4f711 100644 --- a/src/tests/monitor-unit-tests.c +++ b/src/tests/monitor-unit-tests.c @@ -550,8 +550,7 @@ logical_monitor_from_layout (MetaMonitorManager *monitor_manager, } static void -check_logical_monitor (MonitorTestCase *test_case, - MetaMonitorManager *monitor_manager, +check_logical_monitor (MetaMonitorManager *monitor_manager, MonitorTestCaseLogicalMonitor *test_logical_monitor) { MetaLogicalMonitor *logical_monitor; @@ -633,7 +632,7 @@ check_logical_monitor (MonitorTestCase *test_case, } static void -check_monitor_configuration (MonitorTestCase *test_case) +check_monitor_configuration (MonitorTestCaseExpect *expect) { MetaBackend *backend = meta_get_backend (); MetaMonitorManager *monitor_manager = @@ -650,27 +649,27 @@ check_monitor_configuration (MonitorTestCase *test_case) g_assert_cmpint (monitor_manager->screen_width, ==, - test_case->expect.screen_width); + expect->screen_width); g_assert_cmpint (monitor_manager->screen_height, ==, - test_case->expect.screen_height); + expect->screen_height); g_assert_cmpint ((int) g_list_length (meta_gpu_get_outputs (gpu)), ==, - test_case->expect.n_outputs); + expect->n_outputs); g_assert_cmpint ((int) g_list_length (meta_gpu_get_crtcs (gpu)), ==, - test_case->expect.n_crtcs); + expect->n_crtcs); tiled_monitor_count = meta_monitor_manager_test_get_tiled_monitor_count (monitor_manager_test); g_assert_cmpint (tiled_monitor_count, ==, - test_case->expect.n_tiled_monitors); + expect->n_tiled_monitors); monitors = meta_monitor_manager_get_monitors (monitor_manager); g_assert_cmpint ((int) g_list_length (monitors), ==, - test_case->expect.n_monitors); + expect->n_monitors); for (l = monitors, i = 0; l; l = l->next, i++) { MetaMonitor *monitor = l->data; @@ -688,15 +687,15 @@ check_monitor_configuration (MonitorTestCase *test_case) g_assert_cmpint ((int) g_list_length (outputs), ==, - test_case->expect.monitors[i].n_outputs); + expect->monitors[i].n_outputs); for (l_output = outputs, j = 0; l_output; l_output = l_output->next, j++) { MetaOutput *output = l_output->data; - uint64_t winsys_id = test_case->expect.monitors[i].outputs[j]; + uint64_t winsys_id = expect->monitors[i].outputs[j]; g_assert (output == output_from_winsys_id (backend, winsys_id)); - g_assert_cmpint (test_case->expect.monitors[i].is_underscanning, + g_assert_cmpint (expect->monitors[i].is_underscanning, ==, output->is_underscanning); } @@ -704,15 +703,15 @@ check_monitor_configuration (MonitorTestCase *test_case) meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm); g_assert_cmpint (width_mm, ==, - test_case->expect.monitors[i].width_mm); + expect->monitors[i].width_mm); g_assert_cmpint (height_mm, ==, - test_case->expect.monitors[i].height_mm); + expect->monitors[i].height_mm); modes = meta_monitor_get_modes (monitor); g_assert_cmpint (g_list_length (modes), ==, - test_case->expect.monitors[i].n_modes); + expect->monitors[i].n_modes); for (l_mode = modes, j = 0; l_mode; l_mode = l_mode->next, j++) { @@ -729,21 +728,21 @@ check_monitor_configuration (MonitorTestCase *test_case) g_assert_cmpint (width, ==, - test_case->expect.monitors[i].modes[j].width); + expect->monitors[i].modes[j].width); g_assert_cmpint (height, ==, - test_case->expect.monitors[i].modes[j].height); + expect->monitors[i].modes[j].height); g_assert_cmpfloat (refresh_rate, ==, - test_case->expect.monitors[i].modes[j].refresh_rate); + expect->monitors[i].modes[j].refresh_rate); g_assert_cmpint (flags, ==, - test_case->expect.monitors[i].modes[j].flags); + expect->monitors[i].modes[j].flags); data = (CheckMonitorModeData) { .backend = backend, .expect_crtc_mode_iter = - test_case->expect.monitors[i].modes[j].crtc_modes + expect->monitors[i].modes[j].crtc_modes }; meta_monitor_mode_foreach_output (monitor, mode, check_monitor_mode, @@ -752,7 +751,7 @@ check_monitor_configuration (MonitorTestCase *test_case) } current_mode = meta_monitor_get_current_mode (monitor); - expected_current_mode_index = test_case->expect.monitors[i].current_mode; + expected_current_mode_index = expect->monitors[i].current_mode; if (expected_current_mode_index == -1) expected_current_mode = NULL; else @@ -772,7 +771,7 @@ check_monitor_configuration (MonitorTestCase *test_case) data = (CheckMonitorModeData) { .backend = backend, .expect_crtc_mode_iter = - test_case->expect.monitors[i].modes[expected_current_mode_index].crtc_modes + expect->monitors[i].modes[expected_current_mode_index].crtc_modes }; meta_monitor_mode_foreach_output (monitor, expected_current_mode, check_current_monitor_mode, @@ -788,7 +787,7 @@ check_monitor_configuration (MonitorTestCase *test_case) meta_monitor_manager_get_num_logical_monitors (monitor_manager); g_assert_cmpint (n_logical_monitors, ==, - test_case->expect.n_logical_monitors); + expect->n_logical_monitors); /* * Check that we have a primary logical monitor (except for headless), @@ -796,7 +795,7 @@ check_monitor_configuration (MonitorTestCase *test_case) * that is marked as primary (further below). Note: outputs being primary or * not only matters on X11. */ - if (test_case->expect.primary_logical_monitor == -1) + if (expect->primary_logical_monitor == -1) { g_assert_null (monitor_manager->primary_logical_monitor); g_assert_null (monitor_manager->logical_monitors); @@ -804,7 +803,7 @@ check_monitor_configuration (MonitorTestCase *test_case) else { MonitorTestCaseLogicalMonitor *test_logical_monitor = - &test_case->expect.logical_monitors[test_case->expect.primary_logical_monitor]; + &expect->logical_monitors[expect->primary_logical_monitor]; MetaLogicalMonitor *logical_monitor; logical_monitor = @@ -813,12 +812,12 @@ check_monitor_configuration (MonitorTestCase *test_case) g_assert (logical_monitor == monitor_manager->primary_logical_monitor); } - for (i = 0; i < test_case->expect.n_logical_monitors; i++) + for (i = 0; i < expect->n_logical_monitors; i++) { MonitorTestCaseLogicalMonitor *test_logical_monitor = - &test_case->expect.logical_monitors[i]; + &expect->logical_monitors[i]; - check_logical_monitor (test_case, monitor_manager, test_logical_monitor); + check_logical_monitor (monitor_manager, test_logical_monitor); } g_assert_cmpint (n_logical_monitors, ==, i); @@ -828,7 +827,7 @@ check_monitor_configuration (MonitorTestCase *test_case) MetaCrtc *crtc = l->data; MetaCrtcConfig *crtc_config = crtc->config; - if (test_case->expect.crtcs[i].current_mode == -1) + if (expect->crtcs[i].current_mode == -1) { g_assert_null (crtc_config); } @@ -840,18 +839,18 @@ check_monitor_configuration (MonitorTestCase *test_case) expected_current_mode = g_list_nth_data (meta_gpu_get_modes (gpu), - test_case->expect.crtcs[i].current_mode); + expect->crtcs[i].current_mode); g_assert (crtc_config->mode == expected_current_mode); g_assert_cmpuint (crtc_config->transform, ==, - test_case->expect.crtcs[i].transform); + expect->crtcs[i].transform); g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.x, - test_case->expect.crtcs[i].x, + expect->crtcs[i].x, FLT_EPSILON); g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.y, - test_case->expect.crtcs[i].y, + expect->crtcs[i].y, FLT_EPSILON); } } @@ -1021,7 +1020,7 @@ create_monitor_test_setup (MonitorTestCaseSetup *setup, static void meta_test_monitor_initial_linear_config (void) { - check_monitor_configuration (&initial_test_case); + check_monitor_configuration (&initial_test_case.expect); } static void @@ -1097,7 +1096,7 @@ meta_test_monitor_one_disconnected_linear_config (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -1215,7 +1214,7 @@ meta_test_monitor_one_off_linear_config (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -1335,7 +1334,7 @@ meta_test_monitor_preferred_linear_config (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -1464,7 +1463,7 @@ meta_test_monitor_tiled_linear_config (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -1637,7 +1636,7 @@ meta_test_monitor_tiled_non_preferred_linear_config (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -1786,7 +1785,7 @@ meta_test_monitor_tiled_non_main_origin_linear_config (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -1932,7 +1931,7 @@ meta_test_monitor_hidpi_linear_config (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -2090,7 +2089,7 @@ meta_test_monitor_suggested_config (void) 0, 0); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -2216,7 +2215,7 @@ meta_test_monitor_limited_crtcs (void) emulate_hotplug (test_setup); g_test_assert_expected_messages (); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -2353,7 +2352,7 @@ meta_test_monitor_lid_switch_config (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); @@ -2370,7 +2369,7 @@ meta_test_monitor_lid_switch_config (void) test_case.expect.crtcs[0].current_mode = -1; test_case.expect.crtcs[1].x = 0; - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); @@ -2390,7 +2389,7 @@ meta_test_monitor_lid_switch_config (void) test_case.expect.crtcs[1].current_mode = 0; test_case.expect.crtcs[1].x = 1024; - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -2528,7 +2527,7 @@ meta_test_monitor_lid_opened_config (void) meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); @@ -2541,7 +2540,7 @@ meta_test_monitor_lid_opened_config (void) test_case.expect.crtcs[1].current_mode = 0; test_case.expect.crtcs[1].x = 0; - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -2634,7 +2633,7 @@ meta_test_monitor_lid_closed_no_external (void) meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -2777,7 +2776,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); /* External monitor connected */ @@ -2792,7 +2791,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); /* Lid closed */ @@ -2807,7 +2806,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); /* * The second part of this test emulate the following: @@ -2831,7 +2830,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); /* External monitor disconnected */ @@ -2845,7 +2844,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); /* Lid closed */ @@ -2857,7 +2856,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); /* Lid opened */ @@ -2865,7 +2864,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -2965,17 +2964,17 @@ meta_test_monitor_lid_scaled_closed_opened (void) MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("lid-scale.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -3006,7 +3005,7 @@ meta_test_monitor_no_outputs (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); if (!test_client_do (x11_monitor_test_client, &error, "resize", X11_TEST_CLIENT_WINDOW, @@ -3027,7 +3026,7 @@ meta_test_monitor_no_outputs (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -3117,7 +3116,7 @@ meta_test_monitor_underscanning_config (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -3212,7 +3211,7 @@ meta_test_monitor_preferred_non_first_mode (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -3245,7 +3244,7 @@ meta_test_monitor_non_upright_panel (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -3385,7 +3384,7 @@ meta_test_monitor_custom_vertical_config (void) set_custom_monitor_config ("vertical.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -3525,7 +3524,7 @@ meta_test_monitor_custom_primary_config (void) set_custom_monitor_config ("primary.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -3617,7 +3616,7 @@ meta_test_monitor_custom_underscanning_config (void) set_custom_monitor_config ("underscanning.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -3714,7 +3713,7 @@ meta_test_monitor_custom_scale_config (void) set_custom_monitor_config ("scale.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -3811,7 +3810,7 @@ meta_test_monitor_custom_fractional_scale_config (void) set_custom_monitor_config ("fractional-scale.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -3908,7 +3907,7 @@ meta_test_monitor_custom_high_precision_fractional_scale_config (void) set_custom_monitor_config ("high-precision-fractional-scale.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -4045,7 +4044,7 @@ meta_test_monitor_custom_tiled_config (void) set_custom_monitor_config ("tiled.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -4202,7 +4201,7 @@ meta_test_monitor_custom_tiled_custom_resolution_config (void) set_custom_monitor_config ("tiled-custom-resolution.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -4376,7 +4375,7 @@ meta_test_monitor_custom_tiled_non_preferred_config (void) set_custom_monitor_config ("non-preferred-tiled-custom-resolution.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -4504,7 +4503,7 @@ meta_test_monitor_custom_mirrored_config (void) set_custom_monitor_config ("mirrored.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -4639,7 +4638,7 @@ meta_test_monitor_custom_first_rotated_config (void) MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("first-rotated.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -4775,7 +4774,7 @@ meta_test_monitor_custom_second_rotated_config (void) MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("second-rotated.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -4967,7 +4966,7 @@ meta_test_monitor_custom_second_rotated_tiled_config (void) MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("second-rotated-tiled.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -5159,7 +5158,7 @@ meta_test_monitor_custom_second_rotated_nonnative_tiled_config (void) MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("second-rotated-tiled.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -5309,7 +5308,7 @@ meta_test_monitor_custom_second_rotated_nonnative_config (void) MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("second-rotated.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -5419,7 +5418,7 @@ meta_test_monitor_custom_interlaced_config (void) set_custom_monitor_config ("interlaced.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -5548,7 +5547,7 @@ meta_test_monitor_custom_oneoff (void) set_custom_monitor_config ("oneoff.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -5684,7 +5683,7 @@ meta_test_monitor_custom_lid_switch_config (void) MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("lid-switch.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); /* External monitor connected */ @@ -5705,7 +5704,7 @@ meta_test_monitor_custom_lid_switch_config (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); /* Lid was closed */ @@ -5724,7 +5723,7 @@ meta_test_monitor_custom_lid_switch_config (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); /* Lid was opened */ @@ -5746,7 +5745,7 @@ meta_test_monitor_custom_lid_switch_config (void) test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); } static void @@ -5871,7 +5870,7 @@ meta_test_monitor_migrated_rotated (void) emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration", @@ -6015,7 +6014,7 @@ meta_test_monitor_migrated_wiggle_discard (void) emulate_hotplug (test_setup); g_test_assert_expected_messages (); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration", @@ -6278,7 +6277,7 @@ meta_test_monitor_migrated_wiggle (void) emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration", -- GitLab From ae7cb7a3bfeea21fe9eb2a9f502e745dda862d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Fri, 8 May 2020 23:09:06 +0200 Subject: [PATCH 4/6] tests/monitor-unit-tests: Check test state outside of common function check_monitor_test_clients_state() is a function that's only meant to be used in the monitor-unit-tests, and since we're going to move the functions for creating MonitorTestSetups into a common file, this function is going to be in the way of that. So move the checking of the test client state outside of check_monitor_test_clients_state(). https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1243 --- src/tests/monitor-unit-tests.c | 57 ++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c index 561aae4f711..30f2bba88ec 100644 --- a/src/tests/monitor-unit-tests.c +++ b/src/tests/monitor-unit-tests.c @@ -854,8 +854,6 @@ check_monitor_configuration (MonitorTestCaseExpect *expect) FLT_EPSILON); } } - - check_monitor_test_clients_state (); } static void @@ -1021,6 +1019,7 @@ static void meta_test_monitor_initial_linear_config (void) { check_monitor_configuration (&initial_test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1097,6 +1096,7 @@ meta_test_monitor_one_disconnected_linear_config (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1215,6 +1215,7 @@ meta_test_monitor_one_off_linear_config (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1335,6 +1336,7 @@ meta_test_monitor_preferred_linear_config (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1464,6 +1466,7 @@ meta_test_monitor_tiled_linear_config (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1637,6 +1640,7 @@ meta_test_monitor_tiled_non_preferred_linear_config (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1786,6 +1790,7 @@ meta_test_monitor_tiled_non_main_origin_linear_config (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1932,6 +1937,7 @@ meta_test_monitor_hidpi_linear_config (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2090,6 +2096,7 @@ meta_test_monitor_suggested_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2216,6 +2223,7 @@ meta_test_monitor_limited_crtcs (void) g_test_assert_expected_messages (); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2353,6 +2361,7 @@ meta_test_monitor_lid_switch_config (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); @@ -2370,6 +2379,7 @@ meta_test_monitor_lid_switch_config (void) test_case.expect.crtcs[1].x = 0; check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); @@ -2390,6 +2400,7 @@ meta_test_monitor_lid_switch_config (void) test_case.expect.crtcs[1].x = 1024; check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2528,6 +2539,7 @@ meta_test_monitor_lid_opened_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); @@ -2541,6 +2553,7 @@ meta_test_monitor_lid_opened_config (void) test_case.expect.crtcs[1].x = 0; check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2634,6 +2647,7 @@ meta_test_monitor_lid_closed_no_external (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2777,6 +2791,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* External monitor connected */ @@ -2792,6 +2807,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* Lid closed */ @@ -2807,6 +2823,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* * The second part of this test emulate the following: @@ -2831,6 +2848,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* External monitor disconnected */ @@ -2845,6 +2863,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* Lid closed */ @@ -2857,6 +2876,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* Lid opened */ @@ -2865,6 +2885,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2965,16 +2986,19 @@ meta_test_monitor_lid_scaled_closed_opened (void) set_custom_monitor_config ("lid-scale.xml"); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3006,6 +3030,7 @@ meta_test_monitor_no_outputs (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); if (!test_client_do (x11_monitor_test_client, &error, "resize", X11_TEST_CLIENT_WINDOW, @@ -3027,6 +3052,7 @@ meta_test_monitor_no_outputs (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3117,6 +3143,7 @@ meta_test_monitor_underscanning_config (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3212,6 +3239,7 @@ meta_test_monitor_preferred_non_first_mode (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3245,6 +3273,7 @@ meta_test_monitor_non_upright_panel (void) MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3385,6 +3414,7 @@ meta_test_monitor_custom_vertical_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3525,6 +3555,7 @@ meta_test_monitor_custom_primary_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3617,6 +3648,7 @@ meta_test_monitor_custom_underscanning_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3714,6 +3746,7 @@ meta_test_monitor_custom_scale_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3811,6 +3844,7 @@ meta_test_monitor_custom_fractional_scale_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3908,6 +3942,7 @@ meta_test_monitor_custom_high_precision_fractional_scale_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4045,6 +4080,7 @@ meta_test_monitor_custom_tiled_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4202,6 +4238,7 @@ meta_test_monitor_custom_tiled_custom_resolution_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4376,6 +4413,7 @@ meta_test_monitor_custom_tiled_non_preferred_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4504,6 +4542,7 @@ meta_test_monitor_custom_mirrored_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4639,6 +4678,7 @@ meta_test_monitor_custom_first_rotated_config (void) set_custom_monitor_config ("first-rotated.xml"); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4775,6 +4815,7 @@ meta_test_monitor_custom_second_rotated_config (void) set_custom_monitor_config ("second-rotated.xml"); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4967,6 +5008,7 @@ meta_test_monitor_custom_second_rotated_tiled_config (void) set_custom_monitor_config ("second-rotated-tiled.xml"); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -5159,6 +5201,7 @@ meta_test_monitor_custom_second_rotated_nonnative_tiled_config (void) set_custom_monitor_config ("second-rotated-tiled.xml"); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -5309,6 +5352,7 @@ meta_test_monitor_custom_second_rotated_nonnative_config (void) set_custom_monitor_config ("second-rotated.xml"); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -5419,6 +5463,7 @@ meta_test_monitor_custom_interlaced_config (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -5548,6 +5593,7 @@ meta_test_monitor_custom_oneoff (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -5684,6 +5730,7 @@ meta_test_monitor_custom_lid_switch_config (void) set_custom_monitor_config ("lid-switch.xml"); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* External monitor connected */ @@ -5705,6 +5752,7 @@ meta_test_monitor_custom_lid_switch_config (void) MONITOR_TEST_FLAG_NONE); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* Lid was closed */ @@ -5724,6 +5772,7 @@ meta_test_monitor_custom_lid_switch_config (void) MONITOR_TEST_FLAG_NONE); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* Lid was opened */ @@ -5746,6 +5795,7 @@ meta_test_monitor_custom_lid_switch_config (void) MONITOR_TEST_FLAG_NONE); emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -5871,6 +5921,7 @@ meta_test_monitor_migrated_rotated (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration", @@ -6015,6 +6066,7 @@ meta_test_monitor_migrated_wiggle_discard (void) g_test_assert_expected_messages (); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration", @@ -6278,6 +6330,7 @@ meta_test_monitor_migrated_wiggle (void) emulate_hotplug (test_setup); check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration", -- GitLab From 3c35a78769a0daf23822a7cd3eb9e2c07a0d6f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Fri, 8 May 2020 22:46:54 +0200 Subject: [PATCH 5/6] tests/monitor-store-unit-tests: Rename some structs We're going to move some structs from monitor-unit-tests.c to monitor-test-utils.h and some names are currently clashing with the struct names here, so rename those to be specific to the MonitorStoreUnitTests. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1243 --- src/tests/monitor-store-unit-tests.c | 52 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/tests/monitor-store-unit-tests.c b/src/tests/monitor-store-unit-tests.c index 4a73d89db4c..b9d5622b7ae 100644 --- a/src/tests/monitor-store-unit-tests.c +++ b/src/tests/monitor-store-unit-tests.c @@ -31,38 +31,38 @@ #define MAX_N_LOGICAL_MONITORS 10 #define MAX_N_CONFIGURATIONS 10 -typedef struct _MonitorTestCaseMonitorMode +typedef struct _MonitorStoreTestCaseMonitorMode { int width; int height; float refresh_rate; MetaCrtcModeFlag flags; -} MonitorTestCaseMonitorMode; +} MonitorStoreTestCaseMonitorMode; -typedef struct _MonitorTestCaseMonitor +typedef struct _MonitorStoreTestCaseMonitor { const char *connector; const char *vendor; const char *product; const char *serial; - MonitorTestCaseMonitorMode mode; + MonitorStoreTestCaseMonitorMode mode; gboolean is_underscanning; -} MonitorTestCaseMonitor; +} MonitorStoreTestCaseMonitor; -typedef struct _MonitorTestCaseLogicalMonitor +typedef struct _MonitorStoreTestCaseLogicalMonitor { MetaRectangle layout; float scale; MetaMonitorTransform transform; gboolean is_primary; gboolean is_presentation; - MonitorTestCaseMonitor monitors[MAX_N_MONITORS]; + MonitorStoreTestCaseMonitor monitors[MAX_N_MONITORS]; int n_monitors; -} MonitorTestCaseLogicalMonitor; +} MonitorStoreTestCaseLogicalMonitor; typedef struct _MonitorStoreTestConfiguration { - MonitorTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS]; + MonitorStoreTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS]; int n_logical_monitors; } MonitorStoreTestConfiguration; @@ -87,7 +87,7 @@ create_config_key_from_expect (MonitorStoreTestConfiguration *expect_config) for (j = 0; j < expect_config->logical_monitors[i].n_monitors; j++) { MetaMonitorSpec *monitor_spec; - MonitorTestCaseMonitor *test_monitor = + MonitorStoreTestCaseMonitor *test_monitor = &expect_config->logical_monitors[i].monitors[j]; monitor_spec = g_new0 (MetaMonitorSpec, 1); @@ -115,8 +115,8 @@ create_config_key_from_expect (MonitorStoreTestConfiguration *expect_config) } static void -check_monitor_configuration (MetaMonitorConfigStore *config_store, - MonitorStoreTestConfiguration *config_expect) +check_monitor_store_configuration (MetaMonitorConfigStore *config_store, + MonitorStoreTestConfiguration *config_expect) { MetaMonitorsConfigKey *config_key; MetaMonitorsConfig *config; @@ -164,7 +164,7 @@ check_monitor_configuration (MetaMonitorConfigStore *config_store, k = k->next, j++) { MetaMonitorConfig *monitor_config = k->data; - MonitorTestCaseMonitor *test_monitor = + MonitorStoreTestCaseMonitor *test_monitor = &config_expect->logical_monitors[i].monitors[j]; g_assert_cmpstr (monitor_config->monitor_spec->connector, @@ -200,7 +200,7 @@ check_monitor_configuration (MetaMonitorConfigStore *config_store, } static void -check_monitor_configurations (MonitorStoreTestExpect *expect) +check_monitor_store_configurations (MonitorStoreTestExpect *expect) { MetaBackend *backend = meta_get_backend (); MetaMonitorManager *monitor_manager = @@ -215,7 +215,7 @@ check_monitor_configurations (MonitorStoreTestExpect *expect) expect->n_configurations); for (i = 0; i < expect->n_configurations; i++) - check_monitor_configuration (config_store, &expect->configurations[i]); + check_monitor_store_configuration (config_store, &expect->configurations[i]); } static void @@ -259,7 +259,7 @@ meta_test_monitor_store_single (void) set_custom_monitor_config ("single.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -328,7 +328,7 @@ meta_test_monitor_store_vertical (void) set_custom_monitor_config ("vertical.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -397,7 +397,7 @@ meta_test_monitor_store_primary (void) set_custom_monitor_config ("primary.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -442,7 +442,7 @@ meta_test_monitor_store_underscanning (void) set_custom_monitor_config ("underscanning.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -492,7 +492,7 @@ meta_test_monitor_store_scale (void) set_custom_monitor_config ("scale.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -542,7 +542,7 @@ meta_test_monitor_store_fractional_scale (void) set_custom_monitor_config ("fractional-scale.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -592,7 +592,7 @@ meta_test_monitor_store_high_precision_fractional_scale (void) set_custom_monitor_config ("high-precision-fractional-scale.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -646,7 +646,7 @@ meta_test_monitor_store_mirrored (void) set_custom_monitor_config ("mirrored.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -717,7 +717,7 @@ meta_test_monitor_store_first_rotated (void) set_custom_monitor_config ("first-rotated.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -788,7 +788,7 @@ meta_test_monitor_store_second_rotated (void) set_custom_monitor_config ("second-rotated.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -833,7 +833,7 @@ meta_test_monitor_store_interlaced (void) set_custom_monitor_config ("interlaced.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } void -- GitLab From a51807fc1ee246bb0ffcc5c8dedea000b1616587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Fri, 8 May 2020 23:05:35 +0200 Subject: [PATCH 6/6] tests: Move monitor test functions into common utils It's very useful to have common functions for easily creating a monitor test setup for all kinds of tests, so move create_monitor_test_setup() and check_monitor_configuration() and all the structs those are using to monitor-test-utils. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1243 --- src/tests/monitor-test-utils.c | 601 ++++++++++++++++++++++++++ src/tests/monitor-test-utils.h | 174 ++++++++ src/tests/monitor-unit-tests.c | 762 --------------------------------- 3 files changed, 775 insertions(+), 762 deletions(-) diff --git a/src/tests/monitor-test-utils.c b/src/tests/monitor-test-utils.c index 54881569102..6de2682bba2 100644 --- a/src/tests/monitor-test-utils.c +++ b/src/tests/monitor-test-utils.c @@ -22,8 +22,12 @@ #include "tests/monitor-test-utils.h" #include "backends/meta-backend-private.h" +#include "backends/meta-crtc.h" +#include "backends/meta-logical-monitor.h" #include "backends/meta-monitor-config-manager.h" #include "backends/meta-monitor-config-store.h" +#include "backends/meta-output.h" +#include "meta-backend-test.h" void set_custom_monitor_config (const char *filename) @@ -79,3 +83,600 @@ read_file (const char *file_path) return g_steal_pointer (&buffer); } + +static MetaOutput * +output_from_winsys_id (MetaBackend *backend, + uint64_t winsys_id) +{ + MetaGpu *gpu = meta_backend_test_get_gpu (META_BACKEND_TEST (backend)); + GList *l; + + for (l = meta_gpu_get_outputs (gpu); l; l = l->next) + { + MetaOutput *output = l->data; + + if (output->winsys_id == winsys_id) + return output; + } + + return NULL; +} + +typedef struct _CheckMonitorModeData +{ + MetaBackend *backend; + MetaTestCaseMonitorCrtcMode *expect_crtc_mode_iter; +} CheckMonitorModeData; + +static gboolean +check_monitor_mode (MetaMonitor *monitor, + MetaMonitorMode *mode, + MetaMonitorCrtcMode *monitor_crtc_mode, + gpointer user_data, + GError **error) +{ + CheckMonitorModeData *data = user_data; + MetaBackend *backend = data->backend; + MetaOutput *output; + MetaCrtcMode *crtc_mode; + int expect_crtc_mode_index; + + output = output_from_winsys_id (backend, + data->expect_crtc_mode_iter->output); + g_assert (monitor_crtc_mode->output == output); + + expect_crtc_mode_index = data->expect_crtc_mode_iter->crtc_mode; + if (expect_crtc_mode_index == -1) + { + crtc_mode = NULL; + } + else + { + MetaGpu *gpu = meta_output_get_gpu (output); + + crtc_mode = g_list_nth_data (meta_gpu_get_modes (gpu), + expect_crtc_mode_index); + } + g_assert (monitor_crtc_mode->crtc_mode == crtc_mode); + + if (crtc_mode) + { + float refresh_rate; + MetaCrtcModeFlag flags; + + refresh_rate = meta_monitor_mode_get_refresh_rate (mode); + flags = meta_monitor_mode_get_flags (mode); + + g_assert_cmpfloat (refresh_rate, ==, crtc_mode->refresh_rate); + g_assert_cmpint (flags, ==, (crtc_mode->flags & HANDLED_CRTC_MODE_FLAGS)); + } + + data->expect_crtc_mode_iter++; + + return TRUE; +} + +static gboolean +check_current_monitor_mode (MetaMonitor *monitor, + MetaMonitorMode *mode, + MetaMonitorCrtcMode *monitor_crtc_mode, + gpointer user_data, + GError **error) +{ + CheckMonitorModeData *data = user_data; + MetaBackend *backend = data->backend; + MetaOutput *output; + MetaCrtc *crtc; + + output = output_from_winsys_id (backend, + data->expect_crtc_mode_iter->output); + crtc = meta_output_get_assigned_crtc (output); + + if (data->expect_crtc_mode_iter->crtc_mode == -1) + { + g_assert_null (crtc); + } + else + { + MetaCrtcConfig *crtc_config; + MetaLogicalMonitor *logical_monitor; + + g_assert_nonnull (crtc); + + crtc_config = crtc->config; + g_assert_nonnull (crtc_config); + + g_assert (monitor_crtc_mode->crtc_mode == crtc_config->mode); + + logical_monitor = meta_monitor_get_logical_monitor (monitor); + g_assert_nonnull (logical_monitor); + } + + + data->expect_crtc_mode_iter++; + + return TRUE; +} + +static MetaLogicalMonitor * +logical_monitor_from_layout (MetaMonitorManager *monitor_manager, + MetaRectangle *layout) +{ + GList *l; + + for (l = monitor_manager->logical_monitors; l; l = l->next) + { + MetaLogicalMonitor *logical_monitor = l->data; + + if (meta_rectangle_equal (layout, &logical_monitor->rect)) + return logical_monitor; + } + + return NULL; +} + +static void +check_logical_monitor (MetaMonitorManager *monitor_manager, + MonitorTestCaseLogicalMonitor *test_logical_monitor) +{ + MetaLogicalMonitor *logical_monitor; + MetaOutput *primary_output; + GList *monitors; + GList *l; + int i; + + logical_monitor = logical_monitor_from_layout (monitor_manager, + &test_logical_monitor->layout); + g_assert_nonnull (logical_monitor); + + g_assert_cmpint (logical_monitor->rect.x, + ==, + test_logical_monitor->layout.x); + g_assert_cmpint (logical_monitor->rect.y, + ==, + test_logical_monitor->layout.y); + g_assert_cmpint (logical_monitor->rect.width, + ==, + test_logical_monitor->layout.width); + g_assert_cmpint (logical_monitor->rect.height, + ==, + test_logical_monitor->layout.height); + g_assert_cmpfloat (logical_monitor->scale, + ==, + test_logical_monitor->scale); + g_assert_cmpuint (logical_monitor->transform, + ==, + test_logical_monitor->transform); + + if (logical_monitor == monitor_manager->primary_logical_monitor) + g_assert (meta_logical_monitor_is_primary (logical_monitor)); + + primary_output = NULL; + monitors = meta_logical_monitor_get_monitors (logical_monitor); + g_assert_cmpint ((int) g_list_length (monitors), + ==, + test_logical_monitor->n_monitors); + + for (i = 0; i < test_logical_monitor->n_monitors; i++) + { + MetaMonitor *monitor = + g_list_nth (monitor_manager->monitors, + test_logical_monitor->monitors[i])->data; + + g_assert_nonnull (g_list_find (monitors, monitor)); + } + + for (l = monitors; l; l = l->next) + { + MetaMonitor *monitor = l->data; + GList *outputs; + GList *l_output; + + outputs = meta_monitor_get_outputs (monitor); + for (l_output = outputs; l_output; l_output = l_output->next) + { + MetaOutput *output = l_output->data; + MetaCrtc *crtc; + + if (output->is_primary) + { + g_assert_null (primary_output); + primary_output = output; + } + + crtc = meta_output_get_assigned_crtc (output); + g_assert (!crtc || + meta_monitor_get_logical_monitor (monitor) == logical_monitor); + g_assert_cmpint (logical_monitor->is_presentation, + ==, + output->is_presentation); + } + } + + if (logical_monitor == monitor_manager->primary_logical_monitor) + g_assert_nonnull (primary_output); +} + +void +check_monitor_configuration (MonitorTestCaseExpect *expect) +{ + MetaBackend *backend = meta_get_backend (); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + MetaMonitorManagerTest *monitor_manager_test = + META_MONITOR_MANAGER_TEST (monitor_manager); + MetaGpu *gpu = meta_backend_test_get_gpu (META_BACKEND_TEST (backend)); + int tiled_monitor_count; + GList *monitors; + GList *crtcs; + int n_logical_monitors; + GList *l; + int i; + + g_assert_cmpint (monitor_manager->screen_width, + ==, + expect->screen_width); + g_assert_cmpint (monitor_manager->screen_height, + ==, + expect->screen_height); + g_assert_cmpint ((int) g_list_length (meta_gpu_get_outputs (gpu)), + ==, + expect->n_outputs); + g_assert_cmpint ((int) g_list_length (meta_gpu_get_crtcs (gpu)), + ==, + expect->n_crtcs); + + tiled_monitor_count = + meta_monitor_manager_test_get_tiled_monitor_count (monitor_manager_test); + g_assert_cmpint (tiled_monitor_count, + ==, + expect->n_tiled_monitors); + + monitors = meta_monitor_manager_get_monitors (monitor_manager); + g_assert_cmpint ((int) g_list_length (monitors), + ==, + expect->n_monitors); + for (l = monitors, i = 0; l; l = l->next, i++) + { + MetaMonitor *monitor = l->data; + GList *outputs; + GList *l_output; + int j; + int width_mm, height_mm; + GList *modes; + GList *l_mode; + MetaMonitorMode *current_mode; + int expected_current_mode_index; + MetaMonitorMode *expected_current_mode; + + outputs = meta_monitor_get_outputs (monitor); + + g_assert_cmpint ((int) g_list_length (outputs), + ==, + expect->monitors[i].n_outputs); + + for (l_output = outputs, j = 0; l_output; l_output = l_output->next, j++) + { + MetaOutput *output = l_output->data; + uint64_t winsys_id = expect->monitors[i].outputs[j]; + + g_assert (output == output_from_winsys_id (backend, winsys_id)); + g_assert_cmpint (expect->monitors[i].is_underscanning, + ==, + output->is_underscanning); + } + + meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm); + g_assert_cmpint (width_mm, + ==, + expect->monitors[i].width_mm); + g_assert_cmpint (height_mm, + ==, + expect->monitors[i].height_mm); + + modes = meta_monitor_get_modes (monitor); + g_assert_cmpint (g_list_length (modes), + ==, + expect->monitors[i].n_modes); + + for (l_mode = modes, j = 0; l_mode; l_mode = l_mode->next, j++) + { + MetaMonitorMode *mode = l_mode->data; + int width; + int height; + float refresh_rate; + MetaCrtcModeFlag flags; + CheckMonitorModeData data; + + meta_monitor_mode_get_resolution (mode, &width, &height); + refresh_rate = meta_monitor_mode_get_refresh_rate (mode); + flags = meta_monitor_mode_get_flags (mode); + + g_assert_cmpint (width, + ==, + expect->monitors[i].modes[j].width); + g_assert_cmpint (height, + ==, + expect->monitors[i].modes[j].height); + g_assert_cmpfloat (refresh_rate, + ==, + expect->monitors[i].modes[j].refresh_rate); + g_assert_cmpint (flags, + ==, + expect->monitors[i].modes[j].flags); + + data = (CheckMonitorModeData) { + .backend = backend, + .expect_crtc_mode_iter = + expect->monitors[i].modes[j].crtc_modes + }; + meta_monitor_mode_foreach_output (monitor, mode, + check_monitor_mode, + &data, + NULL); + } + + current_mode = meta_monitor_get_current_mode (monitor); + expected_current_mode_index = expect->monitors[i].current_mode; + if (expected_current_mode_index == -1) + expected_current_mode = NULL; + else + expected_current_mode = g_list_nth (modes, + expected_current_mode_index)->data; + + g_assert (current_mode == expected_current_mode); + if (current_mode) + g_assert (meta_monitor_is_active (monitor)); + else + g_assert (!meta_monitor_is_active (monitor)); + + if (current_mode) + { + CheckMonitorModeData data; + + data = (CheckMonitorModeData) { + .backend = backend, + .expect_crtc_mode_iter = + expect->monitors[i].modes[expected_current_mode_index].crtc_modes + }; + meta_monitor_mode_foreach_output (monitor, expected_current_mode, + check_current_monitor_mode, + &data, + NULL); + } + + meta_monitor_derive_current_mode (monitor); + g_assert (current_mode == meta_monitor_get_current_mode (monitor)); + } + + n_logical_monitors = + meta_monitor_manager_get_num_logical_monitors (monitor_manager); + g_assert_cmpint (n_logical_monitors, + ==, + expect->n_logical_monitors); + + /* + * Check that we have a primary logical monitor (except for headless), + * and that the main output of the first monitor is the only output + * that is marked as primary (further below). Note: outputs being primary or + * not only matters on X11. + */ + if (expect->primary_logical_monitor == -1) + { + g_assert_null (monitor_manager->primary_logical_monitor); + g_assert_null (monitor_manager->logical_monitors); + } + else + { + MonitorTestCaseLogicalMonitor *test_logical_monitor = + &expect->logical_monitors[expect->primary_logical_monitor]; + MetaLogicalMonitor *logical_monitor; + + logical_monitor = + logical_monitor_from_layout (monitor_manager, + &test_logical_monitor->layout); + g_assert (logical_monitor == monitor_manager->primary_logical_monitor); + } + + for (i = 0; i < expect->n_logical_monitors; i++) + { + MonitorTestCaseLogicalMonitor *test_logical_monitor = + &expect->logical_monitors[i]; + + check_logical_monitor (monitor_manager, test_logical_monitor); + } + g_assert_cmpint (n_logical_monitors, ==, i); + + crtcs = meta_gpu_get_crtcs (gpu); + for (l = crtcs, i = 0; l; l = l->next, i++) + { + MetaCrtc *crtc = l->data; + MetaCrtcConfig *crtc_config = crtc->config; + + if (expect->crtcs[i].current_mode == -1) + { + g_assert_null (crtc_config); + } + else + { + MetaCrtcMode *expected_current_mode; + + g_assert_nonnull (crtc_config); + + expected_current_mode = + g_list_nth_data (meta_gpu_get_modes (gpu), + expect->crtcs[i].current_mode); + g_assert (crtc_config->mode == expected_current_mode); + + g_assert_cmpuint (crtc_config->transform, + ==, + expect->crtcs[i].transform); + + g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.x, + expect->crtcs[i].x, + FLT_EPSILON); + g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.y, + expect->crtcs[i].y, + FLT_EPSILON); + } + } +} + +static void +meta_output_test_destroy_notify (MetaOutput *output) +{ + g_clear_pointer (&output->driver_private, g_free); +} + +MetaMonitorTestSetup * +create_monitor_test_setup (MonitorTestCaseSetup *setup, + MonitorTestFlag flags) +{ + MetaMonitorTestSetup *test_setup; + int i; + int n_laptop_panels = 0; + int n_normal_panels = 0; + gboolean hotplug_mode_update; + + if (flags & MONITOR_TEST_FLAG_NO_STORED) + hotplug_mode_update = TRUE; + else + hotplug_mode_update = FALSE; + + test_setup = g_new0 (MetaMonitorTestSetup, 1); + + test_setup->modes = NULL; + for (i = 0; i < setup->n_modes; i++) + { + MetaCrtcMode *mode; + + mode = g_object_new (META_TYPE_CRTC_MODE, NULL); + mode->mode_id = i; + mode->width = setup->modes[i].width; + mode->height = setup->modes[i].height; + mode->refresh_rate = setup->modes[i].refresh_rate; + mode->flags = setup->modes[i].flags; + + test_setup->modes = g_list_append (test_setup->modes, mode); + } + + test_setup->crtcs = NULL; + for (i = 0; i < setup->n_crtcs; i++) + { + MetaCrtc *crtc; + + crtc = g_object_new (META_TYPE_CRTC, NULL); + crtc->crtc_id = i + 1; + crtc->all_transforms = ALL_TRANSFORMS; + + test_setup->crtcs = g_list_append (test_setup->crtcs, crtc); + } + + test_setup->outputs = NULL; + for (i = 0; i < setup->n_outputs; i++) + { + MetaOutput *output; + MetaOutputTest *output_test; + int crtc_index; + MetaCrtc *crtc; + int preferred_mode_index; + MetaCrtcMode *preferred_mode; + MetaCrtcMode **modes; + int n_modes; + int j; + MetaCrtc **possible_crtcs; + int n_possible_crtcs; + int scale; + gboolean is_laptop_panel; + const char *serial; + + crtc_index = setup->outputs[i].crtc; + if (crtc_index == -1) + crtc = NULL; + else + crtc = g_list_nth_data (test_setup->crtcs, crtc_index); + + preferred_mode_index = setup->outputs[i].preferred_mode; + if (preferred_mode_index == -1) + preferred_mode = NULL; + else + preferred_mode = g_list_nth_data (test_setup->modes, + preferred_mode_index); + + n_modes = setup->outputs[i].n_modes; + modes = g_new0 (MetaCrtcMode *, n_modes); + for (j = 0; j < n_modes; j++) + { + int mode_index; + + mode_index = setup->outputs[i].modes[j]; + modes[j] = g_list_nth_data (test_setup->modes, mode_index); + } + + n_possible_crtcs = setup->outputs[i].n_possible_crtcs; + possible_crtcs = g_new0 (MetaCrtc *, n_possible_crtcs); + for (j = 0; j < n_possible_crtcs; j++) + { + int possible_crtc_index; + + possible_crtc_index = setup->outputs[i].possible_crtcs[j]; + possible_crtcs[j] = g_list_nth_data (test_setup->crtcs, + possible_crtc_index); + } + + output_test = g_new0 (MetaOutputTest, 1); + + scale = setup->outputs[i].scale; + if (scale < 1) + scale = 1; + + *output_test = (MetaOutputTest) { + .scale = scale + }; + + is_laptop_panel = setup->outputs[i].is_laptop_panel; + + serial = setup->outputs[i].serial; + if (!serial) + serial = "0x123456"; + + output = g_object_new (META_TYPE_OUTPUT, NULL); + + if (crtc) + meta_output_assign_crtc (output, crtc); + output->winsys_id = i; + output->name = (is_laptop_panel ? g_strdup_printf ("eDP-%d", + ++n_laptop_panels) + : g_strdup_printf ("DP-%d", + ++n_normal_panels)); + output->vendor = g_strdup ("MetaProduct's Inc."); + output->product = g_strdup ("MetaMonitor"); + output->serial = g_strdup (serial); + output->suggested_x = -1; + output->suggested_y = -1; + output->hotplug_mode_update = hotplug_mode_update; + output->width_mm = setup->outputs[i].width_mm; + output->height_mm = setup->outputs[i].height_mm; + output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN; + output->preferred_mode = preferred_mode; + output->n_modes = n_modes; + output->modes = modes; + output->n_possible_crtcs = n_possible_crtcs; + output->possible_crtcs = possible_crtcs; + output->n_possible_clones = 0; + output->possible_clones = NULL; + output->backlight = -1; + output->connector_type = (is_laptop_panel ? META_CONNECTOR_TYPE_eDP + : META_CONNECTOR_TYPE_DisplayPort); + output->tile_info = setup->outputs[i].tile_info; + output->is_underscanning = setup->outputs[i].is_underscanning; + output->panel_orientation_transform = + setup->outputs[i].panel_orientation_transform; + output->driver_private = output_test; + output->driver_notify = (GDestroyNotify) meta_output_test_destroy_notify; + + test_setup->outputs = g_list_append (test_setup->outputs, output); + } + + return test_setup; +} diff --git a/src/tests/monitor-test-utils.h b/src/tests/monitor-test-utils.h index 0b0dc6d7d9b..e99799861cd 100644 --- a/src/tests/monitor-test-utils.h +++ b/src/tests/monitor-test-utils.h @@ -22,8 +22,182 @@ #include +#include "tests/meta-monitor-manager-test.h" +#include "backends/meta-crtc.h" +#include "backends/meta-output.h" + +#define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1) + +#define MAX_N_MODES 10 +#define MAX_N_OUTPUTS 10 +#define MAX_N_CRTCS 10 +#define MAX_N_MONITORS 10 +#define MAX_N_LOGICAL_MONITORS 10 + +/* + * The following structures are used to define test cases. + * + * Each test case consists of a test case setup and a test case expectaction. + * and a expected result, consisting + * of an array of monitors, logical monitors and a screen size. + * + * TEST CASE SETUP: + * + * A test case setup consists of an array of modes, an array of outputs and an + * array of CRTCs. + * + * A mode has a width and height in pixels, and a refresh rate in updates per + * second. + * + * An output has an array of available modes, and a preferred mode. Modes are + * defined as indices into the modes array of the test case setup. + * + * It also has CRTc and an array of possible CRTCs. Crtcs are defined as indices + * into the CRTC array. The CRTC value -1 means no CRTC. + * + * It also has various meta data, such as physical dimension, tile info and + * scale. + * + * A CRTC only has a current mode. A mode is defined as an index into the modes + * array. + * + * + * TEST CASE EXPECTS: + * + * A test case expects consists of an array of monitors, an array of logical + * monitors, a output and crtc count, and a screen width. + * + * A monitor represents a physical monitor (such as an external monitor, or a + * laptop panel etc). A monitor consists of an array of outputs, defined by + * indices into the setup output array, an array of monitor modes, and the + * current mode, defined by an index into the monitor modes array, and the + * physical dimensions. + * + * A logical monitor represents a region of the total screen area. It contains + * the expected layout and a scale. + */ + +typedef enum _MonitorTestFlag +{ + MONITOR_TEST_FLAG_NONE, + MONITOR_TEST_FLAG_NO_STORED +} MonitorTestFlag; + +typedef struct _MonitorTestCaseMode +{ + int width; + int height; + float refresh_rate; + MetaCrtcModeFlag flags; +} MonitorTestCaseMode; + +typedef struct _MonitorTestCaseOutput +{ + int crtc; + int modes[MAX_N_MODES]; + int n_modes; + int preferred_mode; + int possible_crtcs[MAX_N_CRTCS]; + int n_possible_crtcs; + int width_mm; + int height_mm; + MetaTileInfo tile_info; + float scale; + gboolean is_laptop_panel; + gboolean is_underscanning; + const char *serial; + MetaMonitorTransform panel_orientation_transform; +} MonitorTestCaseOutput; + +typedef struct _MonitorTestCaseCrtc +{ + int current_mode; +} MonitorTestCaseCrtc; + +typedef struct _MonitorTestCaseSetup +{ + MonitorTestCaseMode modes[MAX_N_MODES]; + int n_modes; + + MonitorTestCaseOutput outputs[MAX_N_OUTPUTS]; + int n_outputs; + + MonitorTestCaseCrtc crtcs[MAX_N_CRTCS]; + int n_crtcs; +} MonitorTestCaseSetup; + +typedef struct _MonitorTestCaseMonitorCrtcMode +{ + uint64_t output; + int crtc_mode; +} MetaTestCaseMonitorCrtcMode; + +typedef struct _MonitorTestCaseMonitorMode +{ + int width; + int height; + float refresh_rate; + MetaCrtcModeFlag flags; + MetaTestCaseMonitorCrtcMode crtc_modes[MAX_N_CRTCS]; +} MetaMonitorTestCaseMonitorMode; + +typedef struct _MonitorTestCaseMonitor +{ + uint64_t outputs[MAX_N_OUTPUTS]; + int n_outputs; + MetaMonitorTestCaseMonitorMode modes[MAX_N_MODES]; + int n_modes; + int current_mode; + int width_mm; + int height_mm; + gboolean is_underscanning; +} MonitorTestCaseMonitor; + +typedef struct _MonitorTestCaseLogicalMonitor +{ + MetaRectangle layout; + float scale; + int monitors[MAX_N_MONITORS]; + int n_monitors; + MetaMonitorTransform transform; +} MonitorTestCaseLogicalMonitor; + +typedef struct _MonitorTestCaseCrtcExpect +{ + MetaMonitorTransform transform; + int current_mode; + float x; + float y; +} MonitorTestCaseCrtcExpect; + +typedef struct _MonitorTestCaseExpect +{ + MonitorTestCaseMonitor monitors[MAX_N_MONITORS]; + int n_monitors; + MonitorTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS]; + int n_logical_monitors; + int primary_logical_monitor; + int n_outputs; + MonitorTestCaseCrtcExpect crtcs[MAX_N_CRTCS]; + int n_crtcs; + int n_tiled_monitors; + int screen_width; + int screen_height; +} MonitorTestCaseExpect; + +typedef struct _MonitorTestCase +{ + MonitorTestCaseSetup setup; + MonitorTestCaseExpect expect; +} MonitorTestCase; + void set_custom_monitor_config (const char *filename); char * read_file (const char *file_path); +void check_monitor_configuration (MonitorTestCaseExpect *expect); + +MetaMonitorTestSetup * create_monitor_test_setup (MonitorTestCaseSetup *setup, + MonitorTestFlag flags); + #endif /* MONITOR_TEST_UTILS_H */ diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c index 30f2bba88ec..975c9970c3c 100644 --- a/src/tests/monitor-unit-tests.c +++ b/src/tests/monitor-unit-tests.c @@ -35,171 +35,6 @@ #include "tests/test-utils.h" #include "x11/meta-x11-display-private.h" -#define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1) - -#define MAX_N_MODES 10 -#define MAX_N_OUTPUTS 10 -#define MAX_N_CRTCS 10 -#define MAX_N_MONITORS 10 -#define MAX_N_LOGICAL_MONITORS 10 - -/* - * The following structures are used to define test cases. - * - * Each test case consists of a test case setup and a test case expectaction. - * and a expected result, consisting - * of an array of monitors, logical monitors and a screen size. - * - * TEST CASE SETUP: - * - * A test case setup consists of an array of modes, an array of outputs and an - * array of CRTCs. - * - * A mode has a width and height in pixels, and a refresh rate in updates per - * second. - * - * An output has an array of available modes, and a preferred mode. Modes are - * defined as indices into the modes array of the test case setup. - * - * It also has CRTc and an array of possible CRTCs. Crtcs are defined as indices - * into the CRTC array. The CRTC value -1 means no CRTC. - * - * It also has various meta data, such as physical dimension, tile info and - * scale. - * - * A CRTC only has a current mode. A mode is defined as an index into the modes - * array. - * - * - * TEST CASE EXPECTS: - * - * A test case expects consists of an array of monitors, an array of logical - * monitors, a output and crtc count, and a screen width. - * - * A monitor represents a physical monitor (such as an external monitor, or a - * laptop panel etc). A monitor consists of an array of outputs, defined by - * indices into the setup output array, an array of monitor modes, and the - * current mode, defined by an index into the monitor modes array, and the - * physical dimensions. - * - * A logical monitor represents a region of the total screen area. It contains - * the expected layout and a scale. - */ - -typedef enum _MonitorTestFlag -{ - MONITOR_TEST_FLAG_NONE, - MONITOR_TEST_FLAG_NO_STORED -} MonitorTestFlag; - -typedef struct _MonitorTestCaseMode -{ - int width; - int height; - float refresh_rate; - MetaCrtcModeFlag flags; -} MonitorTestCaseMode; - -typedef struct _MonitorTestCaseOutput -{ - int crtc; - int modes[MAX_N_MODES]; - int n_modes; - int preferred_mode; - int possible_crtcs[MAX_N_CRTCS]; - int n_possible_crtcs; - int width_mm; - int height_mm; - MetaTileInfo tile_info; - float scale; - gboolean is_laptop_panel; - gboolean is_underscanning; - const char *serial; - MetaMonitorTransform panel_orientation_transform; -} MonitorTestCaseOutput; - -typedef struct _MonitorTestCaseCrtc -{ - int current_mode; -} MonitorTestCaseCrtc; - -typedef struct _MonitorTestCaseSetup -{ - MonitorTestCaseMode modes[MAX_N_MODES]; - int n_modes; - - MonitorTestCaseOutput outputs[MAX_N_OUTPUTS]; - int n_outputs; - - MonitorTestCaseCrtc crtcs[MAX_N_CRTCS]; - int n_crtcs; -} MonitorTestCaseSetup; - -typedef struct _MonitorTestCaseMonitorCrtcMode -{ - uint64_t output; - int crtc_mode; -} MetaTestCaseMonitorCrtcMode; - -typedef struct _MonitorTestCaseMonitorMode -{ - int width; - int height; - float refresh_rate; - MetaCrtcModeFlag flags; - MetaTestCaseMonitorCrtcMode crtc_modes[MAX_N_CRTCS]; -} MetaMonitorTestCaseMonitorMode; - -typedef struct _MonitorTestCaseMonitor -{ - uint64_t outputs[MAX_N_OUTPUTS]; - int n_outputs; - MetaMonitorTestCaseMonitorMode modes[MAX_N_MODES]; - int n_modes; - int current_mode; - int width_mm; - int height_mm; - gboolean is_underscanning; -} MonitorTestCaseMonitor; - -typedef struct _MonitorTestCaseLogicalMonitor -{ - MetaRectangle layout; - float scale; - int monitors[MAX_N_MONITORS]; - int n_monitors; - MetaMonitorTransform transform; -} MonitorTestCaseLogicalMonitor; - -typedef struct _MonitorTestCaseCrtcExpect -{ - MetaMonitorTransform transform; - int current_mode; - float x; - float y; -} MonitorTestCaseCrtcExpect; - -typedef struct _MonitorTestCaseExpect -{ - MonitorTestCaseMonitor monitors[MAX_N_MONITORS]; - int n_monitors; - MonitorTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS]; - int n_logical_monitors; - int primary_logical_monitor; - int n_outputs; - MonitorTestCaseCrtcExpect crtcs[MAX_N_CRTCS]; - int n_crtcs; - int n_tiled_monitors; - int screen_width; - int screen_height; -} MonitorTestCaseExpect; - -typedef struct _MonitorTestCase -{ - MonitorTestCaseSetup setup; - MonitorTestCaseExpect expect; -} MonitorTestCase; - static MonitorTestCase initial_test_case = { .setup = { .modes = { @@ -418,603 +253,6 @@ destroy_monitor_test_clients (void) NULL, NULL); } -static MetaOutput * -output_from_winsys_id (MetaBackend *backend, - uint64_t winsys_id) -{ - MetaGpu *gpu = meta_backend_test_get_gpu (META_BACKEND_TEST (backend)); - GList *l; - - for (l = meta_gpu_get_outputs (gpu); l; l = l->next) - { - MetaOutput *output = l->data; - - if (output->winsys_id == winsys_id) - return output; - } - - return NULL; -} - -typedef struct _CheckMonitorModeData -{ - MetaBackend *backend; - MetaTestCaseMonitorCrtcMode *expect_crtc_mode_iter; -} CheckMonitorModeData; - -static gboolean -check_monitor_mode (MetaMonitor *monitor, - MetaMonitorMode *mode, - MetaMonitorCrtcMode *monitor_crtc_mode, - gpointer user_data, - GError **error) -{ - CheckMonitorModeData *data = user_data; - MetaBackend *backend = data->backend; - MetaOutput *output; - MetaCrtcMode *crtc_mode; - int expect_crtc_mode_index; - - output = output_from_winsys_id (backend, - data->expect_crtc_mode_iter->output); - g_assert (monitor_crtc_mode->output == output); - - expect_crtc_mode_index = data->expect_crtc_mode_iter->crtc_mode; - if (expect_crtc_mode_index == -1) - { - crtc_mode = NULL; - } - else - { - MetaGpu *gpu = meta_output_get_gpu (output); - - crtc_mode = g_list_nth_data (meta_gpu_get_modes (gpu), - expect_crtc_mode_index); - } - g_assert (monitor_crtc_mode->crtc_mode == crtc_mode); - - if (crtc_mode) - { - float refresh_rate; - MetaCrtcModeFlag flags; - - refresh_rate = meta_monitor_mode_get_refresh_rate (mode); - flags = meta_monitor_mode_get_flags (mode); - - g_assert_cmpfloat (refresh_rate, ==, crtc_mode->refresh_rate); - g_assert_cmpint (flags, ==, (crtc_mode->flags & HANDLED_CRTC_MODE_FLAGS)); - } - - data->expect_crtc_mode_iter++; - - return TRUE; -} - -static gboolean -check_current_monitor_mode (MetaMonitor *monitor, - MetaMonitorMode *mode, - MetaMonitorCrtcMode *monitor_crtc_mode, - gpointer user_data, - GError **error) -{ - CheckMonitorModeData *data = user_data; - MetaBackend *backend = data->backend; - MetaOutput *output; - MetaCrtc *crtc; - - output = output_from_winsys_id (backend, - data->expect_crtc_mode_iter->output); - crtc = meta_output_get_assigned_crtc (output); - - if (data->expect_crtc_mode_iter->crtc_mode == -1) - { - g_assert_null (crtc); - } - else - { - MetaCrtcConfig *crtc_config; - MetaLogicalMonitor *logical_monitor; - - g_assert_nonnull (crtc); - - crtc_config = crtc->config; - g_assert_nonnull (crtc_config); - - g_assert (monitor_crtc_mode->crtc_mode == crtc_config->mode); - - logical_monitor = meta_monitor_get_logical_monitor (monitor); - g_assert_nonnull (logical_monitor); - } - - - data->expect_crtc_mode_iter++; - - return TRUE; -} - -static MetaLogicalMonitor * -logical_monitor_from_layout (MetaMonitorManager *monitor_manager, - MetaRectangle *layout) -{ - GList *l; - - for (l = monitor_manager->logical_monitors; l; l = l->next) - { - MetaLogicalMonitor *logical_monitor = l->data; - - if (meta_rectangle_equal (layout, &logical_monitor->rect)) - return logical_monitor; - } - - return NULL; -} - -static void -check_logical_monitor (MetaMonitorManager *monitor_manager, - MonitorTestCaseLogicalMonitor *test_logical_monitor) -{ - MetaLogicalMonitor *logical_monitor; - MetaOutput *primary_output; - GList *monitors; - GList *l; - int i; - - logical_monitor = logical_monitor_from_layout (monitor_manager, - &test_logical_monitor->layout); - g_assert_nonnull (logical_monitor); - - g_assert_cmpint (logical_monitor->rect.x, - ==, - test_logical_monitor->layout.x); - g_assert_cmpint (logical_monitor->rect.y, - ==, - test_logical_monitor->layout.y); - g_assert_cmpint (logical_monitor->rect.width, - ==, - test_logical_monitor->layout.width); - g_assert_cmpint (logical_monitor->rect.height, - ==, - test_logical_monitor->layout.height); - g_assert_cmpfloat (logical_monitor->scale, - ==, - test_logical_monitor->scale); - g_assert_cmpuint (logical_monitor->transform, - ==, - test_logical_monitor->transform); - - if (logical_monitor == monitor_manager->primary_logical_monitor) - g_assert (meta_logical_monitor_is_primary (logical_monitor)); - - primary_output = NULL; - monitors = meta_logical_monitor_get_monitors (logical_monitor); - g_assert_cmpint ((int) g_list_length (monitors), - ==, - test_logical_monitor->n_monitors); - - for (i = 0; i < test_logical_monitor->n_monitors; i++) - { - MetaMonitor *monitor = - g_list_nth (monitor_manager->monitors, - test_logical_monitor->monitors[i])->data; - - g_assert_nonnull (g_list_find (monitors, monitor)); - } - - for (l = monitors; l; l = l->next) - { - MetaMonitor *monitor = l->data; - GList *outputs; - GList *l_output; - - outputs = meta_monitor_get_outputs (monitor); - for (l_output = outputs; l_output; l_output = l_output->next) - { - MetaOutput *output = l_output->data; - MetaCrtc *crtc; - - if (output->is_primary) - { - g_assert_null (primary_output); - primary_output = output; - } - - crtc = meta_output_get_assigned_crtc (output); - g_assert (!crtc || - meta_monitor_get_logical_monitor (monitor) == logical_monitor); - g_assert_cmpint (logical_monitor->is_presentation, - ==, - output->is_presentation); - } - } - - if (logical_monitor == monitor_manager->primary_logical_monitor) - g_assert_nonnull (primary_output); -} - -static void -check_monitor_configuration (MonitorTestCaseExpect *expect) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - MetaGpu *gpu = meta_backend_test_get_gpu (META_BACKEND_TEST (backend)); - int tiled_monitor_count; - GList *monitors; - GList *crtcs; - int n_logical_monitors; - GList *l; - int i; - - g_assert_cmpint (monitor_manager->screen_width, - ==, - expect->screen_width); - g_assert_cmpint (monitor_manager->screen_height, - ==, - expect->screen_height); - g_assert_cmpint ((int) g_list_length (meta_gpu_get_outputs (gpu)), - ==, - expect->n_outputs); - g_assert_cmpint ((int) g_list_length (meta_gpu_get_crtcs (gpu)), - ==, - expect->n_crtcs); - - tiled_monitor_count = - meta_monitor_manager_test_get_tiled_monitor_count (monitor_manager_test); - g_assert_cmpint (tiled_monitor_count, - ==, - expect->n_tiled_monitors); - - monitors = meta_monitor_manager_get_monitors (monitor_manager); - g_assert_cmpint ((int) g_list_length (monitors), - ==, - expect->n_monitors); - for (l = monitors, i = 0; l; l = l->next, i++) - { - MetaMonitor *monitor = l->data; - GList *outputs; - GList *l_output; - int j; - int width_mm, height_mm; - GList *modes; - GList *l_mode; - MetaMonitorMode *current_mode; - int expected_current_mode_index; - MetaMonitorMode *expected_current_mode; - - outputs = meta_monitor_get_outputs (monitor); - - g_assert_cmpint ((int) g_list_length (outputs), - ==, - expect->monitors[i].n_outputs); - - for (l_output = outputs, j = 0; l_output; l_output = l_output->next, j++) - { - MetaOutput *output = l_output->data; - uint64_t winsys_id = expect->monitors[i].outputs[j]; - - g_assert (output == output_from_winsys_id (backend, winsys_id)); - g_assert_cmpint (expect->monitors[i].is_underscanning, - ==, - output->is_underscanning); - } - - meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm); - g_assert_cmpint (width_mm, - ==, - expect->monitors[i].width_mm); - g_assert_cmpint (height_mm, - ==, - expect->monitors[i].height_mm); - - modes = meta_monitor_get_modes (monitor); - g_assert_cmpint (g_list_length (modes), - ==, - expect->monitors[i].n_modes); - - for (l_mode = modes, j = 0; l_mode; l_mode = l_mode->next, j++) - { - MetaMonitorMode *mode = l_mode->data; - int width; - int height; - float refresh_rate; - MetaCrtcModeFlag flags; - CheckMonitorModeData data; - - meta_monitor_mode_get_resolution (mode, &width, &height); - refresh_rate = meta_monitor_mode_get_refresh_rate (mode); - flags = meta_monitor_mode_get_flags (mode); - - g_assert_cmpint (width, - ==, - expect->monitors[i].modes[j].width); - g_assert_cmpint (height, - ==, - expect->monitors[i].modes[j].height); - g_assert_cmpfloat (refresh_rate, - ==, - expect->monitors[i].modes[j].refresh_rate); - g_assert_cmpint (flags, - ==, - expect->monitors[i].modes[j].flags); - - data = (CheckMonitorModeData) { - .backend = backend, - .expect_crtc_mode_iter = - expect->monitors[i].modes[j].crtc_modes - }; - meta_monitor_mode_foreach_output (monitor, mode, - check_monitor_mode, - &data, - NULL); - } - - current_mode = meta_monitor_get_current_mode (monitor); - expected_current_mode_index = expect->monitors[i].current_mode; - if (expected_current_mode_index == -1) - expected_current_mode = NULL; - else - expected_current_mode = g_list_nth (modes, - expected_current_mode_index)->data; - - g_assert (current_mode == expected_current_mode); - if (current_mode) - g_assert (meta_monitor_is_active (monitor)); - else - g_assert (!meta_monitor_is_active (monitor)); - - if (current_mode) - { - CheckMonitorModeData data; - - data = (CheckMonitorModeData) { - .backend = backend, - .expect_crtc_mode_iter = - expect->monitors[i].modes[expected_current_mode_index].crtc_modes - }; - meta_monitor_mode_foreach_output (monitor, expected_current_mode, - check_current_monitor_mode, - &data, - NULL); - } - - meta_monitor_derive_current_mode (monitor); - g_assert (current_mode == meta_monitor_get_current_mode (monitor)); - } - - n_logical_monitors = - meta_monitor_manager_get_num_logical_monitors (monitor_manager); - g_assert_cmpint (n_logical_monitors, - ==, - expect->n_logical_monitors); - - /* - * Check that we have a primary logical monitor (except for headless), - * and that the main output of the first monitor is the only output - * that is marked as primary (further below). Note: outputs being primary or - * not only matters on X11. - */ - if (expect->primary_logical_monitor == -1) - { - g_assert_null (monitor_manager->primary_logical_monitor); - g_assert_null (monitor_manager->logical_monitors); - } - else - { - MonitorTestCaseLogicalMonitor *test_logical_monitor = - &expect->logical_monitors[expect->primary_logical_monitor]; - MetaLogicalMonitor *logical_monitor; - - logical_monitor = - logical_monitor_from_layout (monitor_manager, - &test_logical_monitor->layout); - g_assert (logical_monitor == monitor_manager->primary_logical_monitor); - } - - for (i = 0; i < expect->n_logical_monitors; i++) - { - MonitorTestCaseLogicalMonitor *test_logical_monitor = - &expect->logical_monitors[i]; - - check_logical_monitor (monitor_manager, test_logical_monitor); - } - g_assert_cmpint (n_logical_monitors, ==, i); - - crtcs = meta_gpu_get_crtcs (gpu); - for (l = crtcs, i = 0; l; l = l->next, i++) - { - MetaCrtc *crtc = l->data; - MetaCrtcConfig *crtc_config = crtc->config; - - if (expect->crtcs[i].current_mode == -1) - { - g_assert_null (crtc_config); - } - else - { - MetaCrtcMode *expected_current_mode; - - g_assert_nonnull (crtc_config); - - expected_current_mode = - g_list_nth_data (meta_gpu_get_modes (gpu), - expect->crtcs[i].current_mode); - g_assert (crtc_config->mode == expected_current_mode); - - g_assert_cmpuint (crtc_config->transform, - ==, - expect->crtcs[i].transform); - - g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.x, - expect->crtcs[i].x, - FLT_EPSILON); - g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.y, - expect->crtcs[i].y, - FLT_EPSILON); - } - } -} - -static void -meta_output_test_destroy_notify (MetaOutput *output) -{ - g_clear_pointer (&output->driver_private, g_free); -} - -static MetaMonitorTestSetup * -create_monitor_test_setup (MonitorTestCaseSetup *setup, - MonitorTestFlag flags) -{ - MetaMonitorTestSetup *test_setup; - int i; - int n_laptop_panels = 0; - int n_normal_panels = 0; - gboolean hotplug_mode_update; - - if (flags & MONITOR_TEST_FLAG_NO_STORED) - hotplug_mode_update = TRUE; - else - hotplug_mode_update = FALSE; - - test_setup = g_new0 (MetaMonitorTestSetup, 1); - - test_setup->modes = NULL; - for (i = 0; i < setup->n_modes; i++) - { - MetaCrtcMode *mode; - - mode = g_object_new (META_TYPE_CRTC_MODE, NULL); - mode->mode_id = i; - mode->width = setup->modes[i].width; - mode->height = setup->modes[i].height; - mode->refresh_rate = setup->modes[i].refresh_rate; - mode->flags = setup->modes[i].flags; - - test_setup->modes = g_list_append (test_setup->modes, mode); - } - - test_setup->crtcs = NULL; - for (i = 0; i < setup->n_crtcs; i++) - { - MetaCrtc *crtc; - - crtc = g_object_new (META_TYPE_CRTC, NULL); - crtc->crtc_id = i + 1; - crtc->all_transforms = ALL_TRANSFORMS; - - test_setup->crtcs = g_list_append (test_setup->crtcs, crtc); - } - - test_setup->outputs = NULL; - for (i = 0; i < setup->n_outputs; i++) - { - MetaOutput *output; - MetaOutputTest *output_test; - int crtc_index; - MetaCrtc *crtc; - int preferred_mode_index; - MetaCrtcMode *preferred_mode; - MetaCrtcMode **modes; - int n_modes; - int j; - MetaCrtc **possible_crtcs; - int n_possible_crtcs; - int scale; - gboolean is_laptop_panel; - const char *serial; - - crtc_index = setup->outputs[i].crtc; - if (crtc_index == -1) - crtc = NULL; - else - crtc = g_list_nth_data (test_setup->crtcs, crtc_index); - - preferred_mode_index = setup->outputs[i].preferred_mode; - if (preferred_mode_index == -1) - preferred_mode = NULL; - else - preferred_mode = g_list_nth_data (test_setup->modes, - preferred_mode_index); - - n_modes = setup->outputs[i].n_modes; - modes = g_new0 (MetaCrtcMode *, n_modes); - for (j = 0; j < n_modes; j++) - { - int mode_index; - - mode_index = setup->outputs[i].modes[j]; - modes[j] = g_list_nth_data (test_setup->modes, mode_index); - } - - n_possible_crtcs = setup->outputs[i].n_possible_crtcs; - possible_crtcs = g_new0 (MetaCrtc *, n_possible_crtcs); - for (j = 0; j < n_possible_crtcs; j++) - { - int possible_crtc_index; - - possible_crtc_index = setup->outputs[i].possible_crtcs[j]; - possible_crtcs[j] = g_list_nth_data (test_setup->crtcs, - possible_crtc_index); - } - - output_test = g_new0 (MetaOutputTest, 1); - - scale = setup->outputs[i].scale; - if (scale < 1) - scale = 1; - - *output_test = (MetaOutputTest) { - .scale = scale - }; - - is_laptop_panel = setup->outputs[i].is_laptop_panel; - - serial = setup->outputs[i].serial; - if (!serial) - serial = "0x123456"; - - output = g_object_new (META_TYPE_OUTPUT, NULL); - - if (crtc) - meta_output_assign_crtc (output, crtc); - output->winsys_id = i; - output->name = (is_laptop_panel ? g_strdup_printf ("eDP-%d", - ++n_laptop_panels) - : g_strdup_printf ("DP-%d", - ++n_normal_panels)); - output->vendor = g_strdup ("MetaProduct's Inc."); - output->product = g_strdup ("MetaMonitor"); - output->serial = g_strdup (serial); - output->suggested_x = -1; - output->suggested_y = -1; - output->hotplug_mode_update = hotplug_mode_update; - output->width_mm = setup->outputs[i].width_mm; - output->height_mm = setup->outputs[i].height_mm; - output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN; - output->preferred_mode = preferred_mode; - output->n_modes = n_modes; - output->modes = modes; - output->n_possible_crtcs = n_possible_crtcs; - output->possible_crtcs = possible_crtcs; - output->n_possible_clones = 0; - output->possible_clones = NULL; - output->backlight = -1; - output->connector_type = (is_laptop_panel ? META_CONNECTOR_TYPE_eDP - : META_CONNECTOR_TYPE_DisplayPort); - output->tile_info = setup->outputs[i].tile_info; - output->is_underscanning = setup->outputs[i].is_underscanning; - output->panel_orientation_transform = - setup->outputs[i].panel_orientation_transform; - output->driver_private = output_test; - output->driver_notify = (GDestroyNotify) meta_output_test_destroy_notify; - - test_setup->outputs = g_list_append (test_setup->outputs, output); - } - - return test_setup; -} - static void meta_test_monitor_initial_linear_config (void) { -- GitLab