From patchwork Mon Aug 21 15:27:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Kocialkowki X-Patchwork-Id: 9913011 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 AC9AD602A0 for ; Mon, 21 Aug 2017 15:27:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A21E02817F for ; Mon, 21 Aug 2017 15:27:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96EDD28788; Mon, 21 Aug 2017 15:27:32 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 002642817F for ; Mon, 21 Aug 2017 15:27:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 409CC6E283; Mon, 21 Aug 2017 15:27:31 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id E249D6E283 for ; Mon, 21 Aug 2017 15:27:29 +0000 (UTC) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP; 21 Aug 2017 08:27:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,409,1498546800"; d="scan'208"; a="1208444706" Received: from linux.intel.com ([10.54.29.200]) by fmsmga002.fm.intel.com with ESMTP; 21 Aug 2017 08:27:29 -0700 Received: from workstation.fi.intel.com (workstation.fi.intel.com [10.237.68.31]) by linux.intel.com (Postfix) with ESMTP id 08A8C5803BE; Mon, 21 Aug 2017 08:27:27 -0700 (PDT) From: Paul Kocialkowski To: intel-gfx@lists.freedesktop.org Date: Mon, 21 Aug 2017 18:27:20 +0300 Message-Id: <20170821152720.5925-4-paul.kocialkowski@linux.intel.com> X-Mailer: git-send-email 2.14.0 In-Reply-To: <20170821152720.5925-1-paul.kocialkowski@linux.intel.com> References: <20170821152720.5925-1-paul.kocialkowski@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v2 3/3] tests: Introduce audio tests, starting with HDMI signal integrity 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 This introduces a new test for audio going through display connectors. It currently contains a single subtest for HDMI signal integrity, but other test cases will be added later on. The test setup consists in using an HDMI-VGA bridge that separates the audio out (via a 3.5 mm jack) and feeding this back to the DUT's line-in where it can be recorded by ALSA with controls correctly configured. The audio test makes use of the audio and ALSA igt libraries helpers. Signed-off-by: Paul Kocialkowski --- README | 6 ++ configure.ac | 18 ++++++ tests/Makefile.am | 12 ++++ tests/audio.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 210 insertions(+) create mode 100644 tests/audio.c diff --git a/README b/README index d1ea9529..c3ddf768 100644 --- a/README +++ b/README @@ -153,6 +153,12 @@ The following dependencies are required for building chamelium support libglib2.0-dev libgsl-dev +The following dependencies are requires for building audio support +(package names may vary): + + libasound2-dev + libgsl-dev + Releases for maintainers ------------------------ diff --git a/configure.ac b/configure.ac index e66273a4..41ec4d26 100644 --- a/configure.ac +++ b/configure.ac @@ -222,6 +222,23 @@ fi PKG_CHECK_MODULES(ALSA, [alsa], [alsa=yes], [alsa=no]) AM_CONDITIONAL(HAVE_ALSA, [test "x$alsa" = xyes]) +# for audio +AC_ARG_ENABLE(audio, AS_HELP_STRING([--enable-audio], + [Enable building of audio tests (default: no)]), + [if test x$enableval = xyes; then enable_audio=yes; fi], + [enable_audio=no]) +AM_CONDITIONAL(HAVE_AUDIO, [test "x$enable_audio" = xyes]) +if test "x$enable_audio" = xyes; then + if test x"$alsa" != xyes; then + AC_MSG_ERROR([Failed to find ALSA, required by audio.]) + fi + if test x"$gsl" != xyes; then + AC_MSG_ERROR([Failed to find gsl, required by audio.]) + fi + + AC_DEFINE(HAVE_AUDIO, 1, [Enable Audio support]) +fi + # ----------------------------------------------------------------------------- # Configuration options # ----------------------------------------------------------------------------- @@ -420,6 +437,7 @@ echo "" echo " • Tests:" echo " Build tests : ${BUILD_TESTS}" echo " Chamelium tests : ${enable_chamelium}" +echo " Audio tests : ${enable_audio}" echo " Compile prime tests: ${NOUVEAU}" echo " Print stack traces : ${with_libunwind}" echo " Debug flags : ${DEBUG_CFLAGS}" diff --git a/tests/Makefile.am b/tests/Makefile.am index f9d11e6c..471f3818 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -20,6 +20,15 @@ TESTS_progs += \ $(NULL) endif +if HAVE_ALSA +if HAVE_GSL +TESTS_progs += \ + audio \ + $(NULL) +endif +endif + + if BUILD_TESTS test-list.txt: Makefile.sources @echo TESTLIST > $@ @@ -134,6 +143,9 @@ vc4_wait_seqno_LDADD = $(LDADD) $(DRM_VC4_LIBS) chamelium_CFLAGS = $(AM_CFLAGS) $(XMLRPC_CFLAGS) $(LIBUDEV_CFLAGS) chamelium_LDADD = $(LDADD) $(XMLRPC_LIBS) $(LIBUDEV_LIBS) +audio_CFLAGS = $(AM_CFLAGS) $(ALSA_CFLAGS) +audio_LDADD = $(LDADD) $(ALSA_LIBS) + amdgpu_amd_basic_CFLAGS = $(AM_CFLAGS) $(DRM_AMDGPU_CFLAGS) amdgpu_amd_basic_LDADD = $(LDADD) $(DRM_AMDGPU_LIBS) amdgpu_amd_cs_nop_CFLAGS = $(AM_CFLAGS) $(DRM_AMDGPU_CFLAGS) diff --git a/tests/audio.c b/tests/audio.c new file mode 100644 index 00000000..7fb91c97 --- /dev/null +++ b/tests/audio.c @@ -0,0 +1,174 @@ +/* + * Copyright © 2017 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: + * Paul Kocialkowski + */ + +#include "config.h" +#include "igt.h" + +#define PLAYBACK_CHANNELS 2 +#define PLAYBACK_FRAMES 1024 + +#define CAPTURE_SAMPLE_RATE 48000 +#define CAPTURE_CHANNELS 2 +#define CAPTURE_DEVICE_NAME "default" +#define CAPTURE_FRAMES 2048 + +#define RUN_TIMEOUT 2000 + +struct test_data { + struct alsa *alsa; + struct audio_signal *signal; + + int streak; +}; + +static int sampling_rates[] = { + 32000, + 44100, + 48000, + 88200, + 96000, + 176400, + 192000, +}; + +static int sampling_rates_count = sizeof(sampling_rates) / sizeof(int); + +static int test_frequencies[] = { + 300, + 600, + 1200, + 80000, + 10000, +}; + +static int test_frequencies_count = sizeof(test_frequencies) / sizeof(int); + +static int output_callback(void *data, short *buffer, int frames) +{ + struct test_data *test_data = (struct test_data *) data; + + audio_signal_fill(test_data->signal, buffer, frames); + + return 0; +} + +static int input_callback(void *data, short *buffer, int frames) +{ + struct test_data *test_data = (struct test_data *) data; + bool detect; + + detect = audio_signal_detect(test_data->signal, CAPTURE_CHANNELS, + CAPTURE_SAMPLE_RATE, buffer, frames); + if (detect) + test_data->streak++; + else + test_data->streak = 0; + + /* A streak of 3 gives confidence that the signal is good. */ + if (test_data->streak == 3) + return 1; + + return 0; +} + +static void test_integrity(const char *device_name) +{ + struct test_data data; + int sampling_rate; + bool run = false; + bool test; + int i, j; + int ret; + + data.alsa = alsa_init(); + igt_assert(data.alsa); + + ret = alsa_open_input(data.alsa, CAPTURE_DEVICE_NAME); + igt_assert(ret >= 0); + + alsa_configure_input(data.alsa, CAPTURE_CHANNELS, + CAPTURE_SAMPLE_RATE); + + alsa_register_input_callback(data.alsa, input_callback, &data, + CAPTURE_FRAMES); + + for (i = 0; i < sampling_rates_count; i++) { + ret = alsa_open_output(data.alsa, device_name); + igt_assert(ret >= 0); + + sampling_rate = sampling_rates[i]; + + test = alsa_test_output_configuration(data.alsa, + PLAYBACK_CHANNELS, + sampling_rate); + if (!test) { + alsa_close_output(data.alsa); + continue; + } + + igt_debug("Testing with sampling rate %d\n", sampling_rate); + + alsa_configure_output(data.alsa, PLAYBACK_CHANNELS, + sampling_rate); + + data.signal = audio_signal_init(PLAYBACK_CHANNELS, + sampling_rate); + igt_assert(data.signal); + + for (j = 0; j < test_frequencies_count; j++) + audio_signal_add_frequency(data.signal, + test_frequencies[j]); + + audio_signal_synthesize(data.signal); + + alsa_register_output_callback(data.alsa, output_callback, + &data, PLAYBACK_FRAMES); + + data.streak = 0; + + ret = alsa_run(data.alsa, RUN_TIMEOUT); + igt_assert(ret > 0); + + audio_signal_clean(data.signal); + free(data.signal); + + alsa_close_output(data.alsa); + + run = true; + } + + /* Make sure we tested at least one frequency */ + igt_assert(run); + + alsa_close_input(data.alsa); + free(data.alsa); +} + +igt_main +{ + igt_subtest("hdmi-integrity") + test_integrity("HDMI"); +}