public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Martin Peres <martin.peres@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t 1/5] lib/igt_eld: introduce an ELD library
Date: Mon, 3 Jun 2019 15:27:52 +0300	[thread overview]
Message-ID: <6973e998-bf22-84b0-ad90-92a811e349ef@linux.intel.com> (raw)
In-Reply-To: <20190531112200.22403-2-simon.ser@intel.com>

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@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@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@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@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);
>  
> 
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2019-06-03 12:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-31 11:21 [igt-dev] [PATCH i-g-t 0/5] Add audio EDID tests to Chamelium Simon Ser
2019-05-31 11:21 ` [igt-dev] [PATCH i-g-t 1/5] lib/igt_eld: introduce an ELD library Simon Ser
2019-06-03 12:27   ` Martin Peres [this message]
2019-05-31 11:21 ` [igt-dev] [PATCH i-g-t 2/5] lib/igt_eld: consolidate ELD parsing Simon Ser
2019-06-03 12:42   ` Martin Peres
2019-06-03 14:34     ` Ser, Simon
2019-06-04  8:02       ` Peres, Martin
2019-05-31 11:21 ` [igt-dev] [PATCH i-g-t 3/5] lib/igt_eld: parse Short Audio Descriptors Simon Ser
2019-06-03 12:57   ` Martin Peres
2019-06-03 15:06     ` Ser, Simon
2019-05-31 11:21 ` [igt-dev] [PATCH i-g-t 4/5] lib/igt_eld: allow retrieving an ELD entry per monitor name Simon Ser
2019-06-03 13:04   ` Martin Peres
2019-06-03 15:10     ` Ser, Simon
2019-05-31 11:22 ` [igt-dev] [PATCH i-g-t 5/5] tests/kms_chamelium: add an audio EDID test Simon Ser
2019-05-31 13:18   ` Arkadiusz Hiler
2019-05-31 13:25     ` Arkadiusz Hiler
2019-05-31 14:06     ` Ser, Simon
2019-06-03 12:56     ` Ser, Simon
2019-05-31 16:02 ` [igt-dev] ✓ Fi.CI.BAT: success for Add audio EDID tests to Chamelium Patchwork
2019-06-01 18:54 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2019-06-03  6:38   ` Ser, Simon
2019-06-03 12:12     ` Peres, Martin
2019-06-03 12:17 ` [igt-dev] ✓ Fi.CI.IGT: success " Patchwork
2019-06-03 13:24 ` [igt-dev] ✓ Fi.CI.BAT: success for Add audio EDID tests to Chamelium (rev2) Patchwork
2019-06-03 19:53 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6973e998-bf22-84b0-ad90-92a811e349ef@linux.intel.com \
    --to=martin.peres@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox