From patchwork Tue Sep 19 00:44:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 9957919 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 ECB3860385 for ; Tue, 19 Sep 2017 00:51:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB93728D2B for ; Tue, 19 Sep 2017 00:51:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D05A028DDA; Tue, 19 Sep 2017 00:51:54 +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=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F091D28D2B for ; Tue, 19 Sep 2017 00:51:53 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id DAF1326743C; Tue, 19 Sep 2017 02:45:06 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id BDE8926737E; Tue, 19 Sep 2017 02:44:51 +0200 (CEST) Received: from smtp-proxy004.phy.lolipop.jp (smtp-proxy004.phy.lolipop.jp [157.7.104.45]) by alsa0.perex.cz (Postfix) with ESMTP id CA661266E4C for ; Tue, 19 Sep 2017 02:44:31 +0200 (CEST) Received: from smtp-proxy004.phy.lolipop.lan (HELO smtp-proxy004.phy.lolipop.jp) (172.19.44.45) (smtp-auth username m12129643-o-takashi, mechanism plain) by smtp-proxy004.phy.lolipop.jp (qpsmtpd/0.82) with ESMTPA; Tue, 19 Sep 2017 09:44:31 +0900 Received: from 127.0.0.1 (127.0.0.1) by smtp-proxy004.phy.lolipop.jp (LOLIPOP-Fsecure); Tue, 19 Sep 2017 09:44:18 +0900 (JST) X-Virus-Status: clean(LOLIPOP-Fsecure) From: Takashi Sakamoto To: tiwai@suse.de Date: Tue, 19 Sep 2017 09:44:11 +0900 Message-Id: <20170919004418.24668-32-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170919004418.24668-1-o-takashi@sakamocchi.jp> References: <20170919004418.24668-1-o-takashi@sakamocchi.jp> Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [RFCv2][PATCH 31/38] axfer: add a unit test for vumeter calculation X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP In a previous commit, vumeter is implemented. This commit adds a simple unit test for the feature. This tests positive cases only. Signed-off-by: Takashi Sakamoto --- axfer/test/Makefile.am | 14 +++-- axfer/test/vumeter-test.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 axfer/test/vumeter-test.c diff --git a/axfer/test/Makefile.am b/axfer/test/Makefile.am index 76a93bfc..0e48b9f2 100644 --- a/axfer/test/Makefile.am +++ b/axfer/test/Makefile.am @@ -1,10 +1,12 @@ TESTS = \ - container-test \ - mapper-test + container-test \ + mapper-test \ + vumeter-test check_PROGRAMS = \ container-test \ - mapper-test + mapper-test \ + vumeter-test container_test_SOURCES = \ ../container.h \ @@ -29,3 +31,9 @@ mapper_test_SOURCES = \ ../mapper-multiple.c \ generator.c \ mapper-test.c + +vumeter_test_SOURCES = \ + ../vumeter.h \ + ../vumeter.c \ + generator.c \ + vumeter-test.c diff --git a/axfer/test/vumeter-test.c b/axfer/test/vumeter-test.c new file mode 100644 index 00000000..41a19b13 --- /dev/null +++ b/axfer/test/vumeter-test.c @@ -0,0 +1,128 @@ +/* + * test-vumeter.c - A unit test for Volume Unit meter. + * + * Copyright (c) 2017 Takashi Sakamoto + * + * Licensed under the terms of the GNU General Public License, version 2. + */ + +#include "../vumeter.h" +#include "../misc.h" + +#include "generator.h" + +#include + +static int callback(struct test_generator *gen, snd_pcm_access_t access, + snd_pcm_format_t sample_format, + unsigned int samples_per_frame, void *frame_buffer, + unsigned int frame_count) +{ + static const enum vumeter_mode modes[] = { + [0] = VUMETER_MODE_MONO, + [1] = VUMETER_MODE_STEREO, + }; + struct vumeter_context *vu = gen->private_data; + int i; + int err; + + for (i = 0; i < ARRAY_SIZE(modes); ++i) { + int j; + + memset(vu, 0, sizeof(*vu)); + err = vumeter_context_init(vu, modes[i], access, sample_format, + samples_per_frame, 4000); + if (err < 0) + break; + assert(vu->significant_bits_per_sample >= 0); + assert(vu->bytes_per_sample >= 0); + assert(vu->samples_per_frame >= 0); + assert(vu->frames_per_second >= 0); + assert(vu->max > 0); + assert(vu->peaks != NULL); + assert(vu->ratios != NULL); + assert(vu->max_ratios_in_second != NULL); + assert(vu->printer != NULL); + assert(vu->calculator != NULL); + + vumeter_context_prepare(vu); + for (j = 0; j < samples_per_frame; ++j) { + assert(vu->ratios[j] == 0); + assert(vu->max_ratios_in_second[j] == 0); + } + + vumeter_context_calculate(vu, frame_buffer, frame_count); + for (j = 0; j < samples_per_frame; ++j) { + assert(vu->peaks[j] <= vu->max); + assert(vu->max_ratios_in_second[j] <= vu->max); + assert(vu->max_ratios_in_second[j] <= 100); + } + + vumeter_context_destroy(vu); + assert(vu->ratios == NULL); + assert(vu->max_ratios_in_second == NULL); + assert(vu->peaks == NULL); + } + + return err; +} + +int main(int argc, const char *argv[]) +{ + struct test_generator gen = {0}; + uint64_t access_mask; + uint64_t sample_format_mask; + int err; + + access_mask = (1ul << SND_PCM_ACCESS_MMAP_INTERLEAVED) | + (1ul << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) | + (1ul << SND_PCM_ACCESS_RW_INTERLEAVED) | + (1ul << SND_PCM_ACCESS_RW_NONINTERLEAVED); + sample_format_mask = (1ul << SND_PCM_FORMAT_S8) | + (1ul << SND_PCM_FORMAT_U8) | + (1ul << SND_PCM_FORMAT_S16_LE) | + (1ul << SND_PCM_FORMAT_S16_BE) | + (1ul << SND_PCM_FORMAT_U16_LE) | + (1ul << SND_PCM_FORMAT_U16_BE) | + (1ul << SND_PCM_FORMAT_S24_LE) | + (1ul << SND_PCM_FORMAT_S24_BE) | + (1ul << SND_PCM_FORMAT_U24_LE) | + (1ul << SND_PCM_FORMAT_U24_BE) | + (1ul << SND_PCM_FORMAT_S32_LE) | + (1ul << SND_PCM_FORMAT_S32_BE) | + (1ul << SND_PCM_FORMAT_U32_LE) | + (1ul << SND_PCM_FORMAT_U32_BE) | + (1ul << SND_PCM_FORMAT_S24_3LE) | + (1ul << SND_PCM_FORMAT_S24_3BE) | + (1ul << SND_PCM_FORMAT_U24_3LE) | + (1ul << SND_PCM_FORMAT_U24_3BE) | + (1ul << SND_PCM_FORMAT_S24_3LE) | + (1ul << SND_PCM_FORMAT_S24_3BE) | + (1ul << SND_PCM_FORMAT_U24_3LE) | + (1ul << SND_PCM_FORMAT_U24_3BE) | + (1ul << SND_PCM_FORMAT_S20_3LE) | + (1ul << SND_PCM_FORMAT_S20_3BE) | + (1ul << SND_PCM_FORMAT_U20_3LE) | + (1ul << SND_PCM_FORMAT_U20_3BE) | + (1ul << SND_PCM_FORMAT_S18_3LE) | + (1ul << SND_PCM_FORMAT_S18_3BE) | + (1ul << SND_PCM_FORMAT_U18_3LE) | + (1ul << SND_PCM_FORMAT_U18_3BE); + + err = generator_context_init(&gen, access_mask, sample_format_mask, + 1, 128, 23, 4500, 1024, + sizeof(struct vumeter_context)); + if (err < 0) + return EXIT_FAILURE; + + err = generator_context_run(&gen, callback); + + generator_context_destroy(&gen); + + if (err < 0) { + printf("%s\n", strerror(-err)); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +}