From patchwork Wed Mar 15 11:41:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Abdiel Janulgue X-Patchwork-Id: 9625445 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4F9A26048C for ; Wed, 15 Mar 2017 11:43:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BA5628343 for ; Wed, 15 Mar 2017 11:43:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3066D2860B; Wed, 15 Mar 2017 11:43:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AAA4E28343 for ; Wed, 15 Mar 2017 11:43:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 00CD86E891; Wed, 15 Mar 2017 11:43:48 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id C9FD66E891 for ; Wed, 15 Mar 2017 11:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489578225; x=1521114225; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MaARNe6DUVNHdyTqFVfGp7ruCfq48GmAxRGVSTIPjW8=; b=ab4wTmMmIQPX7HGZaMJ04Je7RH5hLgfpzubmPKI9fpvtxq/VEhqDsxpn Ofc95iIilaK6yRGHRMd6mgQCX3j8WA==; Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Mar 2017 04:43:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,168,1486454400"; d="scan'208";a="60639467" Received: from skylake-nuc.fi.intel.com ([10.237.72.145]) by orsmga002.jf.intel.com with ESMTP; 15 Mar 2017 04:43:43 -0700 From: Abdiel Janulgue To: intel-gfx@lists.freedesktop.org Date: Wed, 15 Mar 2017 13:41:01 +0200 Message-Id: <1489578061-11427-2-git-send-email-abdiel.janulgue@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1489578061-11427-1-git-send-email-abdiel.janulgue@linux.intel.com> References: <1489578061-11427-1-git-send-email-abdiel.janulgue@linux.intel.com> MIME-Version: 1.0 Cc: Marius Vlad Subject: [Intel-gfx] [i-g-t PATCH v3 2/2] tests/kms_hdmi_inject: Test to make use of HDMI injection capabilities. X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Marius Vlad v3: Make audio injection work Signed-off-by: Marius Vlad Signed-off-by: Abdiel Janulgue --- tests/Makefile.sources | 1 + tests/kms_hdmi_inject.c | 272 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 273 insertions(+) create mode 100644 tests/kms_hdmi_inject.c diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 1763b67..07d7158 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -222,6 +222,7 @@ TESTS_progs = \ gen3_render_tiledx_blits \ gen3_render_tiledy_blits \ gen7_forcewake_mt \ + kms_hdmi_inject \ kms_3d \ kms_fence_pin_leak \ kms_force_connector_basic \ diff --git a/tests/kms_hdmi_inject.c b/tests/kms_hdmi_inject.c new file mode 100644 index 0000000..a3e0248 --- /dev/null +++ b/tests/kms_hdmi_inject.c @@ -0,0 +1,272 @@ +/* + * Copyright © 2016 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. + * + */ + +#include +#include "igt.h" + +#define HDISPLAY_4K 3840 +#define VDISPLAY_4K 2160 + +IGT_TEST_DESCRIPTION("Tests 4K and audio HDMI injection."); + +static drmModeConnector * +get_connector(int drm_fd, drmModeRes *res) +{ + int i; + drmModeConnector *connector; + + for (i = 0; i < res->count_connectors; i++) { + + connector = + drmModeGetConnectorCurrent(drm_fd, res->connectors[i]); + + if (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA && + connector->connection == DRM_MODE_DISCONNECTED) + break; + + drmModeFreeConnector(connector); + connector = NULL; + } + + return connector; +} + +static void +hdmi_inject_4k(int drm_fd, drmModeConnector *connector) +{ + unsigned char *edid; + size_t length; + struct kmstest_connector_config config; + int ret, cid, i, crtc_mask = -1; + int fb_id; + struct igt_fb fb; + uint8_t found_4k_mode = 0; + uint32_t devid; + + devid = intel_get_drm_devid(drm_fd); + + /* 4K requires at least HSW */ + igt_require(IS_HASWELL(devid) || intel_gen(devid) >= 8); + + kmstest_edid_add_4k(igt_kms_get_base_edid(), EDID_LENGTH, &edid, + &length); + + kmstest_force_edid(drm_fd, connector, edid, length); + + if (!kmstest_force_connector(drm_fd, connector, FORCE_CONNECTOR_ON)) + igt_skip("Could not force connector on\n"); + + cid = connector->connector_id; + + connector = drmModeGetConnectorCurrent(drm_fd, cid); + + for (i = 0; i < connector->count_modes; i++) { + if (connector->modes[i].hdisplay == HDISPLAY_4K && + connector->modes[i].vdisplay == VDISPLAY_4K) { + found_4k_mode++; + break; + } + } + + igt_assert(found_4k_mode); + + /* create a configuration */ + ret = kmstest_get_connector_config(drm_fd, cid, crtc_mask, &config); + igt_assert(ret); + + igt_info(" "); + kmstest_dump_mode(&connector->modes[i]); + + /* create framebuffer */ + fb_id = igt_create_fb(drm_fd, connector->modes[i].hdisplay, + connector->modes[i].vdisplay, + DRM_FORMAT_XRGB8888, + LOCAL_DRM_FORMAT_MOD_NONE, &fb); + + ret = drmModeSetCrtc(drm_fd, config.crtc->crtc_id, fb_id, 0, 0, + &connector->connector_id, 1, + &connector->modes[i]); + + igt_assert(ret == 0); + + igt_remove_fb(drm_fd, &fb); + + kmstest_force_connector(drm_fd, connector, FORCE_CONNECTOR_UNSPECIFIED); + kmstest_force_edid(drm_fd, connector, NULL, 0); + + free(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; +} + +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[128]; + + 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) +{ + unsigned char *edid; + size_t length; + int fb_id, cid, ret, crtc_mask = -1; + struct igt_fb fb; + struct kmstest_connector_config config; + + kmstest_edid_add_audio(igt_kms_get_base_edid(), EDID_LENGTH, &edid, + &length); + + kmstest_force_edid(drm_fd, connector, edid, length); + + if (!kmstest_force_connector(drm_fd, connector, FORCE_CONNECTOR_ON)) + igt_skip("Could not force connector on\n"); + + cid = connector->connector_id; + connector = drmModeGetConnectorCurrent(drm_fd, cid); + + /* create a configuration */ + ret = kmstest_get_connector_config(drm_fd, cid, crtc_mask, &config); + igt_assert(ret); + + /* + * Create a framebuffer as to allow the kernel to enable the pipe and + * enable the audio encoder. + */ + fb_id = igt_create_fb(drm_fd, connector->modes[0].hdisplay, + connector->modes[0].vdisplay, + DRM_FORMAT_XRGB8888, + LOCAL_DRM_FORMAT_MOD_NONE, &fb); + + ret = drmModeSetCrtc(drm_fd, config.crtc->crtc_id, fb_id, 0, 0, + &connector->connector_id, 1, + &connector->modes[0]); + + + igt_assert(ret == 0); + + /* + * Test if we have /proc/asound/HDMI/eld#0.0 and is its contents are + * valid. + */ + igt_assert(eld_is_valid()); + + igt_remove_fb(drm_fd, &fb); + + igt_info(" "); + kmstest_dump_mode(&connector->modes[0]); + + kmstest_force_connector(drm_fd, connector, FORCE_CONNECTOR_UNSPECIFIED); + kmstest_force_edid(drm_fd, connector, NULL, 0); + + free(edid); +} + +igt_main +{ + int drm_fd; + drmModeRes *res; + drmModeConnector *connector; + + igt_fixture { + drm_fd = drm_open_driver_master(DRIVER_INTEL); + res = drmModeGetResources(drm_fd); + + connector = get_connector(drm_fd, res); + igt_require(connector); + } + + igt_subtest("inject-4k") + hdmi_inject_4k(drm_fd, connector); + + igt_subtest("inject-audio") + hdmi_inject_audio(drm_fd, connector); + + igt_fixture { + drmModeFreeConnector(connector); + } +}