[Sound-open-firmware] [PATCH v2 3/3] tune: add testbench for volume comp

Liam Girdwood liam.r.girdwood at linux.intel.com
Thu May 10 17:52:15 CEST 2018


On Wed, 2018-05-09 at 15:59 -0700, Ranjani Sridharan wrote:
> This patch adds a volume testbench that enable reading samples from
> an input file, processing them through a volume pipeline and
> writing the processed samples to the output file.
> 

This is looking very good and useful ! Just some mostly minor comments below. 

Do we need to call this volume test now it can load any shared object component
(created by the host build target) ?

> Signed-off-by: Ranjani Sridharan <ranjani.sridharan at linux.intel.com>
> ---
>  configure.ac            |   1 +
>  tune/Makefile.am        |   2 +-
>  tune/test/Makefile.am   |  16 ++++
>  tune/test/volume_test.c | 221
> ++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 239 insertions(+), 1 deletion(-)
>  create mode 100644 tune/test/Makefile.am
>  create mode 100644 tune/test/volume_test.c
> 
> diff --git a/configure.ac b/configure.ac
> index 30ec1c7..0764374 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -24,6 +24,7 @@ AC_OUTPUT([
>  	topology/test/Makefile
>  	tune/Makefile
>  	tune/src/Makefile
> +	tune/test/Makefile
>  ])
>  
>  echo "
> diff --git a/tune/Makefile.am b/tune/Makefile.am
> index af437a6..b4b5bc3 100644
> --- a/tune/Makefile.am
> +++ b/tune/Makefile.am
> @@ -1 +1 @@
> -SUBDIRS = src
> +SUBDIRS = src test
> diff --git a/tune/test/Makefile.am b/tune/test/Makefile.am
> new file mode 100644
> index 0000000..6399566
> --- /dev/null
> +++ b/tune/test/Makefile.am
> @@ -0,0 +1,16 @@
> +AUTOMAKE_OPTIONS = subdir-objects
> +
> +INCDIR1 = ../include
> +INCDIR2 = $(prefix)/include/sof
> +INCLUDE = -I$(INCDIR1) -I$(INCDIR2)
> +
> +AM_CPPFLAGS = $(INCLUDE)
> +AM_CFLAGS = -g -Wall
> +LDADD = \
> +	-ldl -lm -lsof -lsof_ipc \
> +	../src/libtb_common.a
> +
> +bin_PROGRAMS = volume_test
> +
> +volume_test_SOURCES = \
> +	volume_test.c
> diff --git a/tune/test/volume_test.c b/tune/test/volume_test.c
> new file mode 100644
> index 0000000..e74fea5
> --- /dev/null
> +++ b/tune/test/volume_test.c
> @@ -0,0 +1,221 @@
> +/*
> + * Copyright (c) 2018, Intel Corporation
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions are
> met:
> + *   * Redistributions of source code must retain the above copyright
> + *     notice, this list of conditions and the following disclaimer.
> + *   * Redistributions in binary form must reproduce the above copyright
> + *     notice, this list of conditions and the following disclaimer in the
> + *     documentation and/or other materials provided with the distribution.
> + *   * Neither the name of the Intel Corporation nor the
> + *     names of its contributors may be used to endorse or promote products
> + *     derived from this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
> IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + *
> + * Author: Seppo Ingalsuo <seppo.ingalsuo at linux.intel.com>
> + *	   Ranjani Sridharan <ranjani.sridharan at linux.intel.com>
> + */
> +
> +#include <sof/ipc.h>
> +#include <getopt.h>
> +#include <dlfcn.h>
> +#include "common_test.h"
> +#include "topology.h"
> +#include "trace.h"
> +#include "file.h"
> +
> +#define TESTBENCH_NCH 2 /* Stereo */
> +
> +/* main firmware context */
> +static struct sof sof;
> +static int fr_id; /* comp id for fileread */
> +static int fw_id; /* comp id for filewrite */
> +static int sched_id; /* comp id for scheduling comp */
> +
> +/*
> + * Parse shared library from user input
> + * Currently only handles volume comp

Why can we only load volume comp ?

> + */
> +static void parse_libraries(char *libs, void *handle)

comments and newlines needed in this code too.

> +{
> +	char *lib_token, *comp_token;
> +	char *token = strtok_r(libs, ",", &lib_token);
> +
> +	while (token != NULL) {
> +		char *token1 = strtok_r(token, "=", &comp_token);
> +		/* parse shared library for volume component */
> +		if (strcmp(token1, "vol") == 0) {
> +			while (token1 != NULL) {
> +				token1 = strtok_r(NULL, "=", &comp_token);
> +				if (!token1)
> +					return;
> +				if (handle)
> +					dlclose(handle);
> +				/* open volume shared library */
> +				handle = dlopen(token1, RTLD_LAZY);
> +				if (!handle) {
> +					printf("error: %s\n", dlerror());
> +					exit(EXIT_FAILURE);
> +				}
> +				printf("debug: opening volume shared library
> %s\n",
> +				       token1);
> +			}
> +		}
> +		token = strtok_r(NULL, ",", &lib_token);
> +	}
> +}
> +
> +/* print usage for testbench */
> +static void print_usage(char *executable)
> +{
> +	printf("Usage: %s -i <input_file> -o <output_file> -t <tplg_file> -b
> <input_format> -a <comp1=comp1_library,comp2=comp2_library>\n",
> +	       executable);
> +	printf("input_format should be S16_LE, S32_LE, S24_LE or
> FLOAT_LE\n");
> +	printf("Example Usage:\n");
> +	printf("%s -i in.txt -o out.txt -t test.tplg -b S16_LE -a
> vol=libsof_volume.so\n",
> +	       executable);
> +}
> +
> +int main(int argc, char **argv)
> +{
> +	struct ipc_comp_dev *pcm_dev;
> +	struct pipeline *p;
> +	struct sof_ipc_pipe_new *ipc_pipe;
> +	struct comp_dev *cd;
> +	struct file_comp_data *frcd, *fwcd;
> +	char *tplg_file = NULL, *input_file = NULL;
> +	char *output_file = NULL, *bits_in = NULL;
> +	clock_t tic, toc;
> +	double c_realtime, t_exec;
> +	int fs, n_in, n_out, ret;
> +	int option = 0;
> +	/* volume component share library handle */
> +	void *vol_handle = NULL;
> +
> +	/*set up default volume shared library */
> +	if (!vol_handle) {
> +		vol_handle = dlopen("libsof_volume.so", RTLD_LAZY);

It's probably worth having a table above that converts the topology component
names/IDs to the library names. i.e.

{vol_widget?, "libsof_volume"},

That way you could load them as you parsed topology (unless overridden from cmd
line).

> +		if (!vol_handle) {
> +			printf("error: %s\n", dlerror());
> +			exit(EXIT_FAILURE);
> +		}
> +	}
> +
> +
> +	/* command line arguments*/
> +	while ((option = getopt(argc, argv, "hi:o:t:b:a:")) != -1) {
> +		switch (option) {
> +		case 'i':
> +			/* input sample file */
> +			input_file = strdup(optarg);
> +			break;
> +		case 'o':
> +			/* output sample file */
> +			output_file = strdup(optarg);
> +			break;
> +		case 't':
> +			/* topology file */
> +			tplg_file = strdup(optarg);
> +			break;
> +		case 'b':
> +			/* input samples bit format */
> +			bits_in = strdup(optarg);
> +			break;
> +		case 'a':
> +			/* override default libraries */
> +			parse_libraries(optarg, vol_handle);
> +			break;
> +		case 'h':
> +		default:
> +			print_usage(argv[0]);
> +			exit(EXIT_FAILURE);
> +		}
> +	}
> +
> +	/* check args */
> +	if (!bits_in || !tplg_file || !input_file || !output_file) {
> +		print_usage(argv[0]);
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	/* initialize ipc, pipeline and scheduler */
> +	if (tb_pipeline_setup(&sof) < 0) {
> +		printf("error: pipeline init\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	/* parse topology file and create pipeline */
> +	if (parse_topology(tplg_file, &sof, &fr_id, &fw_id, &sched_id,
> bits_in,
> +		       input_file, output_file, vol_handle) < 0) {
> +		printf("error: parsing topology\n");
> +		exit(EXIT_FAILURE);
> +	}
> +
> +	/* Get pointers to fileread and filewrite */
> +	pcm_dev = ipc_get_comp(sof.ipc, fw_id);
> +	fwcd = comp_get_drvdata(pcm_dev->cd);
> +	pcm_dev = ipc_get_comp(sof.ipc, fr_id);
> +	frcd = comp_get_drvdata(pcm_dev->cd);
> +
> +	/* Run pipeline until EOF from fileread */
> +	pcm_dev = ipc_get_comp(sof.ipc, sched_id);
> +	p = pcm_dev->cd->pipeline;
> +	ipc_pipe = &p->ipc_pipe;
> +
> +	fs = ipc_pipe->deadline * ipc_pipe->frames_per_sched;
> +
> +	/* set pipeline params and trigger start */
> +	if (tb_pipeline_start(sof.ipc, TESTBENCH_NCH, bits_in, ipc_pipe) < 0)
> {
> +		printf("error: pipeline params\n");
> +		exit(EXIT_FAILURE);
> +	}
> +	cd = pcm_dev->cd;
> +	tb_disable_trace(); /* Reduce print output */
> +	tic = clock();
> +
> +	while (frcd->fs.reached_eof == 0)
> +		pipeline_schedule_copy(p, 0);
> +
> +	/* reset and free pipeline */
> +	toc = clock();
> +	tb_enable_trace();
> +	ret = pipeline_reset(p, cd);
> +	if (ret < 0) {
> +		printf("error: pipeline reset\n");
> +		exit(EXIT_FAILURE);
> +	}
> +	pipeline_free(p);
> +
> +	n_in = frcd->fs.n;
> +	n_out = fwcd->fs.n;
> +	t_exec = (double) (toc - tic) / CLOCKS_PER_SEC;
> +	c_realtime = (double) n_out / TESTBENCH_NCH / fs / t_exec;
> +	/* print test summary */
> +	printf("==============================================\n");
> +	printf("		Test Summary\n");
> +	printf("==============================================\n");
> +	printf("Output written to file \"%s\"\n", output_file);
> +	printf("Input sample count: %d\n", n_in);
> +	printf("Output sample count: %d\n", n_out);
> +	printf("Total execution time: %.2f us, %.2f x realtime\n",
> +	       1e3 * t_exec, c_realtime);
> +
> +	/* close shared library object */
> +	if (vol_handle)
> +		dlclose(vol_handle);
> +
> +	return EXIT_SUCCESS;
> +}


More information about the Sound-open-firmware mailing list