From 23b30267b5312742c86fef48118bc8a02cb356c6 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 17 Jan 2024 17:25:06 +0100 Subject: [PATCH] monitor-unit-tests: Add basic tests for RGB range Part-of: --- src/backends/meta-output.h | 1 + src/tests/meta-monitor-test-utils.c | 6 ++ src/tests/meta-monitor-test-utils.h | 2 + src/tests/monitor-configs/rgb-range.xml | 23 ++++++ src/tests/monitor-store-unit-tests.c | 105 ++++++++++++++++++++---- src/tests/monitor-unit-tests.c | 96 ++++++++++++++++++++++ 6 files changed, 215 insertions(+), 18 deletions(-) create mode 100644 src/tests/monitor-configs/rgb-range.xml diff --git a/src/backends/meta-output.h b/src/backends/meta-output.h index 075c22d6a..ca0124154 100644 --- a/src/backends/meta-output.h +++ b/src/backends/meta-output.h @@ -271,6 +271,7 @@ void meta_output_set_hdr_metadata (MetaOutput *output, MetaOutputHdrMetadata * meta_output_peek_hdr_metadata (MetaOutput *output); +META_EXPORT_TEST MetaOutputRGBRange meta_output_peek_rgb_range (MetaOutput *output); void meta_output_add_possible_clone (MetaOutput *output, diff --git a/src/tests/meta-monitor-test-utils.c b/src/tests/meta-monitor-test-utils.c index 1555a5f87..440536daa 100644 --- a/src/tests/meta-monitor-test-utils.c +++ b/src/tests/meta-monitor-test-utils.c @@ -388,6 +388,7 @@ meta_check_monitor_configuration (MetaContext *context, MetaOutput *output = l_output->data; uint64_t winsys_id = expect->monitors[i].outputs[j]; unsigned int output_max_bpc; + MetaOutputRGBRange rgb_range = META_OUTPUT_RGB_RANGE_AUTO; g_assert (output == output_from_winsys_id (backend, winsys_id)); g_assert_cmpint (expect->monitors[i].is_underscanning, @@ -398,6 +399,10 @@ meta_check_monitor_configuration (MetaContext *context, output_max_bpc = 0; g_assert_cmpint (expect->monitors[i].max_bpc, ==, output_max_bpc); + + if (expect->monitors[i].rgb_range) + rgb_range = expect->monitors[i].rgb_range; + g_assert_cmpint (rgb_range, ==, meta_output_peek_rgb_range (output)); } meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm); @@ -798,6 +803,7 @@ meta_create_monitor_test_setup (MetaBackend *backend, .is_underscanning = setup->outputs[i].is_underscanning, .has_max_bpc = !!setup->outputs[i].max_bpc, .max_bpc = setup->outputs[i].max_bpc, + .rgb_range = setup->outputs[i].rgb_range, }; meta_output_assign_crtc (output, crtc, &output_assignment); } diff --git a/src/tests/meta-monitor-test-utils.h b/src/tests/meta-monitor-test-utils.h index 6d2c00189..6e4937542 100644 --- a/src/tests/meta-monitor-test-utils.h +++ b/src/tests/meta-monitor-test-utils.h @@ -106,6 +106,7 @@ typedef struct _MonitorTestCaseOutput gboolean is_laptop_panel; gboolean is_underscanning; unsigned int max_bpc; + MetaOutputRGBRange rgb_range; const char *serial; MetaMonitorTransform panel_orientation_transform; gboolean hotplug_mode; @@ -161,6 +162,7 @@ typedef struct _MonitorTestCaseMonitor int height_mm; gboolean is_underscanning; unsigned int max_bpc; + MetaOutputRGBRange rgb_range; } MonitorTestCaseMonitor; typedef struct _MonitorTestCaseLogicalMonitor diff --git a/src/tests/monitor-configs/rgb-range.xml b/src/tests/monitor-configs/rgb-range.xml new file mode 100644 index 000000000..f3ab9731b --- /dev/null +++ b/src/tests/monitor-configs/rgb-range.xml @@ -0,0 +1,23 @@ + + + + 0 + 0 + yes + + + DP-1 + MetaProduct's Inc. + MetaMonitor + 0x123456 + + + 1024 + 768 + 60.000495910644531 + + limited + + + + diff --git a/src/tests/monitor-store-unit-tests.c b/src/tests/monitor-store-unit-tests.c index d6ed7665c..872a8bf0f 100644 --- a/src/tests/monitor-store-unit-tests.c +++ b/src/tests/monitor-store-unit-tests.c @@ -49,6 +49,7 @@ typedef struct _MonitorStoreTestCaseMonitor MonitorStoreTestCaseMonitorMode mode; gboolean is_underscanning; unsigned int max_bpc; + MetaOutputRGBRange rgb_range; } MonitorStoreTestCaseMonitor; typedef struct _MonitorStoreTestCaseLogicalMonitor @@ -203,6 +204,9 @@ check_monitor_store_configuration (MetaMonitorConfigStore *config_store, g_assert_cmpint (monitor_config->max_bpc, ==, test_monitor->max_bpc); + g_assert_cmpint (monitor_config->rgb_range, + ==, + test_monitor->rgb_range); } } } @@ -253,7 +257,8 @@ meta_test_monitor_store_single (void) .width = 1920, .height = 1080, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -297,7 +302,8 @@ meta_test_monitor_store_vertical (void) .width = 1024, .height = 768, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -322,7 +328,8 @@ meta_test_monitor_store_vertical (void) .width = 800, .height = 600, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -366,7 +373,8 @@ meta_test_monitor_store_primary (void) .width = 1024, .height = 768, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -391,7 +399,8 @@ meta_test_monitor_store_primary (void) .width = 800, .height = 600, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -436,7 +445,8 @@ meta_test_monitor_store_underscanning (void) .width = 1024, .height = 768, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -481,7 +491,8 @@ meta_test_monitor_store_max_bpc (void) .width = 1024, .height = 768, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -498,6 +509,51 @@ meta_test_monitor_store_max_bpc (void) check_monitor_store_configurations (&expect); } +static void +meta_test_monitor_store_rgb_range (void) +{ + MonitorStoreTestExpect expect = { + .configurations = { + { + .logical_monitors = { + { + .layout = { + .x = 0, + .y = 0, + .width = 1024, + .height = 768 + }, + .scale = 1, + .is_primary = TRUE, + .is_presentation = FALSE, + .monitors = { + { + .connector = "DP-1", + .vendor = "MetaProduct's Inc.", + .product = "MetaMonitor", + .serial = "0x123456", + .mode = { + .width = 1024, + .height = 768, + .refresh_rate = 60.000495910644531 + }, + .rgb_range = META_OUTPUT_RGB_RANGE_LIMITED, + } + }, + .n_monitors = 1, + }, + }, + .n_logical_monitors = 1 + } + }, + .n_configurations = 1 + }; + + meta_set_custom_monitor_config (test_context, "rgb-range.xml"); + + check_monitor_store_configurations (&expect); +} + static void meta_test_monitor_store_scale (void) { @@ -525,7 +581,8 @@ meta_test_monitor_store_scale (void) .width = 1920, .height = 1080, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -569,7 +626,8 @@ meta_test_monitor_store_fractional_scale (void) .width = 1200, .height = 900, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -613,7 +671,8 @@ meta_test_monitor_store_high_precision_fractional_scale (void) .width = 1024, .height = 768, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -656,7 +715,8 @@ meta_test_monitor_store_mirrored (void) .width = 800, .height = 600, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, }, { .connector = "DP-2", @@ -667,7 +727,8 @@ meta_test_monitor_store_mirrored (void) .width = 800, .height = 600, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 2, @@ -712,7 +773,8 @@ meta_test_monitor_store_first_rotated (void) .width = 1024, .height = 768, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -738,7 +800,8 @@ meta_test_monitor_store_first_rotated (void) .width = 1024, .height = 768, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -783,7 +846,8 @@ meta_test_monitor_store_second_rotated (void) .width = 1024, .height = 768, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -809,7 +873,8 @@ meta_test_monitor_store_second_rotated (void) .width = 1024, .height = 768, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -854,7 +919,8 @@ meta_test_monitor_store_interlaced (void) .height = 768, .refresh_rate = 60.000495910644531, .flags = META_CRTC_MODE_FLAG_INTERLACE, - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -898,7 +964,8 @@ meta_test_monitor_store_unknown_elements (void) .width = 1920, .height = 1080, .refresh_rate = 60.000495910644531 - } + }, + .rgb_range = META_OUTPUT_RGB_RANGE_AUTO, } }, .n_monitors = 1, @@ -1049,6 +1116,8 @@ init_monitor_store_tests (void) meta_test_monitor_store_underscanning); g_test_add_func ("/backends/monitor-store/max-bpc", meta_test_monitor_store_max_bpc); + g_test_add_func ("/backends/monitor-store/rgb-range", + meta_test_monitor_store_rgb_range); g_test_add_func ("/backends/monitor-store/scale", meta_test_monitor_store_scale); g_test_add_func ("/backends/monitor-store/fractional-scale", diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c index e0d8605d6..3a1dd3cc1 100644 --- a/src/tests/monitor-unit-tests.c +++ b/src/tests/monitor-unit-tests.c @@ -3348,6 +3348,100 @@ meta_test_monitor_max_bpc_config (void) check_monitor_test_clients_state (); } +static void +meta_test_monitor_rgb_range_config (void) +{ + MonitorTestCase test_case = { + .setup = { + .modes = { + { + .width = 1024, + .height = 768, + .refresh_rate = 60.0 + } + }, + .n_modes = 1, + .outputs = { + { + .crtc = 0, + .modes = { 0 }, + .n_modes = 1, + .preferred_mode = 0, + .possible_crtcs = { 0 }, + .n_possible_crtcs = 1, + .width_mm = 222, + .height_mm = 125, + .rgb_range = META_OUTPUT_RGB_RANGE_FULL, + } + }, + .n_outputs = 1, + .crtcs = { + { + .current_mode = 0 + } + }, + .n_crtcs = 1 + }, + + .expect = { + .monitors = { + { + .outputs = { 0 }, + .n_outputs = 1, + .modes = { + { + .width = 1024, + .height = 768, + .refresh_rate = 60.0, + .crtc_modes = { + { + .output = 0, + .crtc_mode = 0 + } + } + } + }, + .n_modes = 1, + .current_mode = 0, + .width_mm = 222, + .height_mm = 125, + .rgb_range = META_OUTPUT_RGB_RANGE_FULL, + } + }, + .n_monitors = 1, + .logical_monitors = { + { + .monitors = { 0 }, + .n_monitors = 1, + .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, + .scale = 1 + } + }, + .n_logical_monitors = 1, + .primary_logical_monitor = 0, + .n_outputs = 1, + .crtcs = { + { + .current_mode = 0, + } + }, + .n_crtcs = 1, + .screen_width = 1024, + .screen_height = 768 + } + }; + MetaMonitorTestSetup *test_setup; + + test_setup = meta_create_monitor_test_setup (test_backend, + &test_case.setup, + MONITOR_TEST_FLAG_NO_STORED); + emulate_hotplug (test_setup); + META_TEST_LOG_CALL ("Checking monitor configuration", + meta_check_monitor_configuration (test_context, + &test_case.expect)); + check_monitor_test_clients_state (); +} + static void meta_test_monitor_preferred_non_first_mode (void) { @@ -9626,6 +9720,8 @@ init_monitor_tests (void) meta_test_monitor_underscanning_config); add_monitor_test ("/backends/monitor/max-bpc-config", meta_test_monitor_max_bpc_config); + add_monitor_test ("/backends/monitor/rgb-range-config", + meta_test_monitor_rgb_range_config); add_monitor_test ("/backends/monitor/preferred-non-first-mode", meta_test_monitor_preferred_non_first_mode); add_monitor_test ("/backends/monitor/non-upright-panel",