From f729a2023ea4233b95ae271d2ef6ebc9ee66dd8d Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Fri, 3 Mar 2023 16:37:34 +0100 Subject: [PATCH] tests: Add tests for HDR Static Metadata encoding/decoding and equality We have the drm/InfoFrame encoding and our MetaOutputHdrMetadata encoding. Check that we can correctly convert between each other by doing a encode/decode and decode/encode roundtrip and then checking for equality. Part-of: --- .../native/meta-kms-connector-private.h | 9 ++ src/backends/native/meta-kms-connector.c | 4 +- src/tests/hdr-metadata-unit-tests.c | 107 ++++++++++++++++++ src/tests/hdr-metadata-unit-tests.h | 26 +++++ src/tests/meson.build | 1 + src/tests/unit-tests.c | 2 + 6 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 src/tests/hdr-metadata-unit-tests.c create mode 100644 src/tests/hdr-metadata-unit-tests.h diff --git a/src/backends/native/meta-kms-connector-private.h b/src/backends/native/meta-kms-connector-private.h index 1e58c0ba2..b720c8623 100644 --- a/src/backends/native/meta-kms-connector-private.h +++ b/src/backends/native/meta-kms-connector-private.h @@ -142,7 +142,16 @@ MetaKmsConnector * meta_kms_connector_new (MetaKmsImplDevice *impl_device, gboolean meta_kms_connector_is_same_as (MetaKmsConnector *connector, drmModeConnector *drm_connector); +META_EXPORT_TEST void meta_set_drm_hdr_metadata (MetaOutputHdrMetadata *metadata, struct hdr_output_metadata *drm_metadata); +META_EXPORT_TEST +gboolean set_output_hdr_metadata (struct hdr_output_metadata *drm_metadata, + MetaOutputHdrMetadata *metadata); + +META_EXPORT_TEST +gboolean hdr_metadata_equal (MetaOutputHdrMetadata *metadata, + MetaOutputHdrMetadata *other_metadata); + #endif /* META_KMS_CONNECTOR_PRIVATE_H */ diff --git a/src/backends/native/meta-kms-connector.c b/src/backends/native/meta-kms-connector.c index 7cd2b66e6..5c2e563cc 100644 --- a/src/backends/native/meta-kms-connector.c +++ b/src/backends/native/meta-kms-connector.c @@ -504,7 +504,7 @@ decode_u16_min_luminance (uint16_t value) return value * 0.0001; } -static gboolean +gboolean set_output_hdr_metadata (struct hdr_output_metadata *drm_metadata, MetaOutputHdrMetadata *metadata) { @@ -887,7 +887,7 @@ hdr_min_luminance_equal (double x1, double x2) return fabs (x1 - x2) < (0.0001 - DBL_EPSILON); } -static gboolean +gboolean hdr_metadata_equal (MetaOutputHdrMetadata *metadata, MetaOutputHdrMetadata *other_metadata) { diff --git a/src/tests/hdr-metadata-unit-tests.c b/src/tests/hdr-metadata-unit-tests.c new file mode 100644 index 000000000..177008dcb --- /dev/null +++ b/src/tests/hdr-metadata-unit-tests.c @@ -0,0 +1,107 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright (C) 2023 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * Author: Sebastian Wick + */ + +#include "hdr-metadata-unit-tests.h" + +#include "tests/meta-monitor-test-utils.h" + +#include "backends/native/meta-kms-connector-private.h" + +static void +meta_test_hdr_metadata_equality1 (void) +{ + struct hdr_output_metadata drm_metadata_in, drm_metadata_out; + MetaOutputHdrMetadata metadata; + + memset (&drm_metadata_in, 0, sizeof (drm_metadata_in)); + memset (&drm_metadata_out, 0, sizeof (drm_metadata_out)); + + drm_metadata_in = (struct hdr_output_metadata) { + .metadata_type = 0, + .hdmi_metadata_type1 = { + .eotf = 2, + .metadata_type = 0, + .display_primaries[0].x = 27, + .display_primaries[0].y = 53, + .display_primaries[1].x = 111, + .display_primaries[1].y = 43, + .display_primaries[2].x = 633, + .display_primaries[2].y = 2, + .white_point.x = 27, + .white_point.y = 53, + .max_display_mastering_luminance = 3333, + .min_display_mastering_luminance = 1000, + .max_cll = 392, + .max_fall = 2, + }, + }; + + g_assert_true (set_output_hdr_metadata (&drm_metadata_in, &metadata)); + meta_set_drm_hdr_metadata (&metadata, &drm_metadata_out); + + g_assert_cmpint (memcmp (&drm_metadata_in, + &drm_metadata_out, + sizeof (struct hdr_output_metadata)), ==, 0); +} + +static void +meta_test_hdr_metadata_equality2 (void) +{ + struct hdr_output_metadata drm_metadata; + MetaOutputHdrMetadata metadata_in, metadata_out; + + memset (&metadata_in, 0, sizeof (metadata_in)); + memset (&metadata_out, 0, sizeof (metadata_out)); + + metadata_in = (MetaOutputHdrMetadata) { + .active = true, + .eotf = META_OUTPUT_HDR_METADATA_EOTF_PQ, + .mastering_display_primaries[0].x = 0.2384, + .mastering_display_primaries[0].y = 1.0000, + .mastering_display_primaries[1].x = 0.4, + .mastering_display_primaries[1].y = 0.002, + .mastering_display_primaries[2].x = 0.3, + .mastering_display_primaries[2].y = 0.333, + .mastering_display_white_point.x = 0.0001, + .mastering_display_white_point.y = 0.999, + .mastering_display_max_luminance = 22.22, + .max_cll = 50.5, + .max_fall = 12.0, + }; + + meta_set_drm_hdr_metadata (&metadata_in, &drm_metadata); + g_assert_true (set_output_hdr_metadata (&drm_metadata, &metadata_out)); + metadata_out.active = TRUE; + + g_assert_cmpint (memcmp (&metadata_in, + &metadata_out, + sizeof (MetaOutputHdrMetadata)), !=, 0); + + g_assert_true (hdr_metadata_equal (&metadata_in, &metadata_out)); +} + +void +init_hdr_metadata_tests (void) +{ + g_test_add_func ("/backends/native/hdr-metadata-equality1", + meta_test_hdr_metadata_equality1); + g_test_add_func ("/backends/native/hdr-metadata-equality2", + meta_test_hdr_metadata_equality2); +} diff --git a/src/tests/hdr-metadata-unit-tests.h b/src/tests/hdr-metadata-unit-tests.h new file mode 100644 index 000000000..feee8209d --- /dev/null +++ b/src/tests/hdr-metadata-unit-tests.h @@ -0,0 +1,26 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright (C) 2023 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * Author: Sebastian Wick + */ + +#ifndef HDR_METADATA_UNIT_TESTS_H +#define HDR_METADATA_UNIT_TESTS_H + +void init_hdr_metadata_tests (void); + +#endif /* HDR_METADATA_UNIT_TESTS_H */ diff --git a/src/tests/meson.build b/src/tests/meson.build index f1eb1d220..6e94eb751 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -235,6 +235,7 @@ test_cases += [ 'monitor-transform-tests.c', 'monitor-transform-tests.h', 'orientation-manager-unit-tests.c', + 'hdr-metadata-unit-tests.c', ], }, { diff --git a/src/tests/unit-tests.c b/src/tests/unit-tests.c index 75c65b21f..ff0516fe6 100644 --- a/src/tests/unit-tests.c +++ b/src/tests/unit-tests.c @@ -38,6 +38,7 @@ #include "tests/monitor-transform-tests.h" #include "tests/meta-test-utils.h" #include "tests/orientation-manager-unit-tests.h" +#include "tests/hdr-metadata-unit-tests.h" MetaContext *test_context; @@ -242,6 +243,7 @@ init_tests (void) init_boxes_tests (); init_monitor_transform_tests (); init_orientation_manager_tests (); + init_hdr_metadata_tests (); } int