[igt-dev] [PATCH i-g-t 1/5] lib/igt_eld: introduce an ELD library
Martin Peres
martin.peres at linux.intel.com
Mon Jun 3 12:27:52 UTC 2019
On 31/05/2019 14:21, Simon Ser wrote:
> There are two reasons why I want to introduce this library:
>
> - I want to use it from the Chamelium tests for DisplayPort
> - I want to expand it to also check that audio parameters parsed by ALSA are
> correct (formats, sampling rates, sample sizes and so on)
>
> Signed-off-by: Simon Ser <simon.ser at intel.com>
> ---
> lib/igt_eld.c | 111 ++++++++++++++++++++++++++++++++++++++++
> lib/igt_eld.h | 35 +++++++++++++
> lib/meson.build | 1 +
> tests/kms_hdmi_inject.c | 80 ++---------------------------
> 4 files changed, 152 insertions(+), 75 deletions(-)
> create mode 100644 lib/igt_eld.c
> create mode 100644 lib/igt_eld.h
>
> diff --git a/lib/igt_eld.c b/lib/igt_eld.c
> new file mode 100644
> index 000000000000..8e0dcc306e85
> --- /dev/null
> +++ b/lib/igt_eld.c
> @@ -0,0 +1,111 @@
> +/*
> + * Copyright © 2019 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + *
> + * Authors: Simon Ser <simon.ser at intel.com>
> + */
> +
> +#include "config.h"
> +
> +#include <dirent.h>
> +#include <stdint.h>
> +#include <stdio.h>
> +#include <string.h>
> +
> +#include "igt_eld.h"
> +
> +/**
> + * EDID-Like Data (ELD) is metadata parsed and exposed by ALSA for HDMI and
> + * DisplayPort connectors supporting audio. This includes the monitor name and
> + * the supported audio parameters (formats, sampling rates, sample sizes and so
> + * on).
> + */
> +
> +/** eld_entry_is_igt: checks whether an ELD entry is mapped to the IGT EDID */
> +static bool eld_entry_is_igt(const char *path)
> +{
> + FILE *in;
> + char buf[1024];
> + uint8_t eld_valid = 0;
> + uint8_t mon_valid = 0;
> +
> + in = fopen(path, "r");
> + if (!in)
> + return false;
> +
> + memset(buf, 0, 1024);
> +
> + while ((fgets(buf, 1024, in)) != NULL) {
> + char *line = buf;
> +
> + if (!strncasecmp(line, "eld_valid", 9) &&
> + strstr(line, "1")) {
> + eld_valid++;
I understand that you are just copy-pasting the previous implementation,
but this is not exactly the nicest way of making a boolean. How about
just setting it to 1, to make it clear that we are not counting anything?
This could be done in another patch or merged in this one.
Reviewed-by: Martin Peres <martin.peres at linux.intel.com>
> + }
> +
> + if (!strncasecmp(line, "monitor_name", 12) &&
> + strstr(line, "IGT")) {
> + mon_valid++;
> + }
> + }
> +
> + fclose(in);
> + if (mon_valid && eld_valid)
> + return true;
> +
> + return false;
> +}
> +
> +/** eld_has_igt: check whether ALSA has detected the audio-capable IGT EDID by
> + * parsing ELD entries */
> +bool eld_has_igt(void)
> +{
> + DIR *dir;
> + struct dirent *snd_hda;
> + int i;
> +
> + for (i = 0; i < 8; i++) {
> + char cards[128];
> +
> + snprintf(cards, sizeof(cards), "/proc/asound/card%d", i);
> + dir = opendir(cards);
> + if (!dir)
> + continue;
> +
> + while ((snd_hda = readdir(dir))) {
> + char fpath[PATH_MAX];
> +
> + if (*snd_hda->d_name == '.' ||
> + strstr(snd_hda->d_name, "eld") == 0)
> + continue;
> +
> + snprintf(fpath, sizeof(fpath), "%s/%s", cards,
> + snd_hda->d_name);
> + if (eld_entry_is_igt(fpath)) {
> + closedir(dir);
> + return true;
> + }
> + }
> + closedir(dir);
> + }
> +
> + return false;
> +}
> diff --git a/lib/igt_eld.h b/lib/igt_eld.h
> new file mode 100644
> index 000000000000..27f876d9f631
> --- /dev/null
> +++ b/lib/igt_eld.h
> @@ -0,0 +1,35 @@
> +/*
> + * Copyright © 2019 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + *
> + * Authors: Simon Ser <simon.ser at intel.com>
> + */
> +
> +#ifndef IGT_ELD_H
> +#define IGT_ELD_H
> +
> +#include "config.h"
> +
> +#include <stdbool.h>
> +
> +bool eld_has_igt(void);
> +
> +#endif
> diff --git a/lib/meson.build b/lib/meson.build
> index cdb450e1e762..844e0abcd919 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -59,6 +59,7 @@ lib_sources = [
> 'igt_psr.c',
> 'igt_amd.c',
> 'igt_edid.c',
> + 'igt_eld.c',
> ]
>
> lib_deps = [
> diff --git a/tests/kms_hdmi_inject.c b/tests/kms_hdmi_inject.c
> index a24061042c20..eba25046cead 100644
> --- a/tests/kms_hdmi_inject.c
> +++ b/tests/kms_hdmi_inject.c
> @@ -22,8 +22,12 @@
> *
> */
>
> +#include "config.h"
> +
> #include <dirent.h>
> +
> #include "igt.h"
> +#include "igt_eld.h"
>
> #define HDISPLAY_4K 3840
> #define VDISPLAY_4K 2160
> @@ -134,80 +138,6 @@ hdmi_inject_4k(int drm_fd, drmModeConnector *connector)
> free(edid);
> }
>
> -/** eld_entry_is_igt: checks whether an ELD entry is mapped to the IGT EDID */
> -static bool
> -eld_entry_is_igt(const char* path)
> -{
> - FILE *in;
> - char buf[1024];
> - uint8_t eld_valid = 0;
> - uint8_t mon_valid = 0;
> -
> - in = fopen(path, "r");
> - if (!in)
> - return false;
> -
> - memset(buf, 0, 1024);
> -
> - while ((fgets(buf, 1024, in)) != NULL) {
> -
> - char *line = buf;
> -
> - if (!strncasecmp(line, "eld_valid", 9) &&
> - strstr(line, "1")) {
> - eld_valid++;
> - }
> -
> - if (!strncasecmp(line, "monitor_name", 12) &&
> - strstr(line, "IGT")) {
> - mon_valid++;
> - }
> - }
> -
> - fclose(in);
> - if (mon_valid && eld_valid)
> - return true;
> -
> - return false;
> -}
> -
> -/** eld_is_valid: check whether ALSA has detected the audio-capable IGT EDID by
> - * parsing ELD entries */
> -static bool
> -eld_is_valid(void)
> -{
> - DIR *dir;
> - struct dirent *snd_hda;
> - int i;
> -
> - for (i = 0; i < 8; i++) {
> - char cards[128];
> -
> - snprintf(cards, sizeof(cards), "/proc/asound/card%d", i);
> - dir = opendir(cards);
> - if (!dir)
> - continue;
> -
> - while ((snd_hda = readdir(dir))) {
> - char fpath[PATH_MAX];
> -
> - if (*snd_hda->d_name == '.' ||
> - strstr(snd_hda->d_name, "eld") == 0)
> - continue;
> -
> - snprintf(fpath, sizeof(fpath), "%s/%s", cards,
> - snd_hda->d_name);
> - if (eld_entry_is_igt(fpath)) {
> - closedir(dir);
> - return true;
> - }
> - }
> - closedir(dir);
> - }
> -
> - return false;
> -}
> -
> static void
> hdmi_inject_audio(int drm_fd, drmModeConnector *connector)
> {
> @@ -252,7 +182,7 @@ hdmi_inject_audio(int drm_fd, drmModeConnector *connector)
> * Test if we have /proc/asound/HDMI/eld#0.0 and is its contents are
> * valid.
> */
> - igt_assert(eld_is_valid());
> + igt_assert(eld_has_igt());
>
> igt_remove_fb(drm_fd, &fb);
>
>
More information about the igt-dev
mailing list