Testbench: Fix parameters passing within testbench

This patch fixes the use of private copies of the same header file
defined parameters in several C files that is not good practise to
do. They were not defined as proper global variables. Instead the
same parameters are now simply passed in function calls only to where
needed.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This commit is contained in:
Seppo Ingalsuo 2019-02-21 17:43:47 +02:00 committed by Liam Girdwood
parent e502f2286d
commit 957d3369f7
5 changed files with 92 additions and 89 deletions

View File

@ -76,8 +76,9 @@ int tb_pipeline_setup(struct sof *sof)
}
/* set up pcm params, prepare and trigger pipeline */
int tb_pipeline_start(struct ipc *ipc, int nch, char *bits_in,
struct sof_ipc_pipe_new *ipc_pipe)
int tb_pipeline_start(struct ipc *ipc, int nch,
struct sof_ipc_pipe_new *ipc_pipe,
struct testbench_prm *tp)
{
struct ipc_comp_dev *pcm_dev;
struct pipeline *p;
@ -85,7 +86,7 @@ int tb_pipeline_start(struct ipc *ipc, int nch, char *bits_in,
int ret;
/* set up pipeline params */
ret = tb_pipeline_params(ipc, nch, bits_in, ipc_pipe);
ret = tb_pipeline_params(ipc, nch, ipc_pipe, tp);
if (ret < 0) {
fprintf(stderr, "error: pipeline params\n");
return -EINVAL;
@ -114,30 +115,30 @@ int tb_pipeline_start(struct ipc *ipc, int nch, char *bits_in,
}
/* pipeline pcm params */
int tb_pipeline_params(struct ipc *ipc, int nch, char *bits_in,
struct sof_ipc_pipe_new *ipc_pipe)
int tb_pipeline_params(struct ipc *ipc, int nch,
struct sof_ipc_pipe_new *ipc_pipe,
struct testbench_prm *tp)
{
int fs_period, ret = 0;
struct ipc_comp_dev *pcm_dev;
struct pipeline *p;
struct comp_dev *cd;
struct sof_ipc_pcm_params params;
int deadline;
char message[DEBUG_MSG_LEN];
deadline = ipc_pipe->deadline;
int fs_period;
int deadline = ipc_pipe->deadline;
int ret = 0;
/* Compute period from sample rates */
fs_period = (int)(0.9999 + fs_in * deadline / 1e6);
fs_period = (int)(0.9999 + tp->fs_in * deadline / 1e6);
sprintf(message, "period sample count %d\n", fs_period);
debug_print(message);
/* set pcm params */
params.comp_id = ipc_pipe->comp_id;
params.params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED;
params.params.frame_fmt = find_format(bits_in);
params.params.frame_fmt = find_format(tp->bits_in);
params.params.direction = SOF_IPC_STREAM_PLAYBACK;
params.params.rate = fs_in;
params.params.rate = tp->fs_in;
params.params.channels = nch;
switch (params.params.frame_fmt) {
case(SOF_IPC_FRAME_S16_LE):
@ -250,4 +251,3 @@ void dma_sg_free(struct dma_sg_elem_array *elem_array)
void pipeline_xrun(struct pipeline *p, struct comp_dev *dev, int32_t bytes)
{
}

View File

@ -170,7 +170,7 @@ static int set_up_library_table(void)
return 0;
}
static void parse_input_args(int argc, char **argv)
static void parse_input_args(int argc, char **argv, struct testbench_prm *tp)
{
int option = 0;
@ -178,22 +178,22 @@ static void parse_input_args(int argc, char **argv)
switch (option) {
/* input sample file */
case 'i':
input_file = strdup(optarg);
tp->input_file = strdup(optarg);
break;
/* output sample file */
case 'o':
output_file = strdup(optarg);
tp->output_file = strdup(optarg);
break;
/* topology file */
case 't':
tplg_file = strdup(optarg);
tp->tplg_file = strdup(optarg);
break;
/* input samples bit format */
case 'b':
bits_in = strdup(optarg);
tp->bits_in = strdup(optarg);
break;
/* override default libraries */
@ -203,12 +203,12 @@ static void parse_input_args(int argc, char **argv)
/* input sample rate */
case 'r':
fs_in = atoi(optarg);
tp->fs_in = atoi(optarg);
break;
/* output sample rate */
case 'R':
fs_out = atoi(optarg);
tp->fs_out = atoi(optarg);
break;
/* enable debug prints */
@ -227,6 +227,7 @@ static void parse_input_args(int argc, char **argv)
int main(int argc, char **argv)
{
struct testbench_prm tp;
struct ipc_comp_dev *pcm_dev;
struct pipeline *p;
struct sof_ipc_pipe_new *ipc_pipe;
@ -239,8 +240,8 @@ int main(int argc, char **argv)
int i;
/* initialize input and output sample rates */
fs_in = 0;
fs_out = 0;
tp.fs_in = 0;
tp.fs_out = 0;
/* set up shared library look up table */
ret = set_up_library_table();
@ -250,10 +251,10 @@ int main(int argc, char **argv)
}
/* command line arguments*/
parse_input_args(argc, argv);
parse_input_args(argc, argv, &tp);
/* check args */
if (!tplg_file || !input_file || !output_file || !bits_in) {
if (!tp.tplg_file || !tp.input_file || !tp.output_file || !tp.bits_in) {
print_usage(argv[0]);
exit(EXIT_FAILURE);
}
@ -265,8 +266,8 @@ int main(int argc, char **argv)
}
/* parse topology file and create pipeline */
if (parse_topology(tplg_file, &sof, &fr_id, &fw_id, &sched_id, bits_in,
input_file, output_file, lib_table, pipeline) < 0) {
if (parse_topology(&sof, lib_table, &tp, &fr_id, &fw_id, &sched_id,
pipeline) < 0) {
fprintf(stderr, "error: parsing topology\n");
exit(EXIT_FAILURE);
}
@ -283,14 +284,14 @@ int main(int argc, char **argv)
ipc_pipe = &p->ipc_pipe;
/* input and output sample rate */
if (!fs_in)
fs_in = ipc_pipe->deadline * ipc_pipe->frames_per_sched;
if (!tp.fs_in)
tp.fs_in = ipc_pipe->deadline * ipc_pipe->frames_per_sched;
if (!fs_out)
fs_out = ipc_pipe->deadline * ipc_pipe->frames_per_sched;
if (!tp.fs_out)
tp.fs_out = 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) {
if (tb_pipeline_start(sof.ipc, TESTBENCH_NCH, ipc_pipe, &tp) < 0) {
fprintf(stderr, "error: pipeline params\n");
exit(EXIT_FAILURE);
}
@ -317,7 +318,7 @@ int main(int argc, char **argv)
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_out / t_exec;
c_realtime = (double)n_out / TESTBENCH_NCH / tp.fs_out / t_exec;
/* free all components/buffers in pipeline */
free_comps();
@ -328,20 +329,20 @@ int main(int argc, char **argv)
printf("==========================================================\n");
printf("Test Pipeline:\n");
printf("%s\n", pipeline);
printf("Input bit format: %s\n", bits_in);
printf("Input sample rate: %d\n", fs_in);
printf("Output sample rate: %d\n", fs_out);
printf("Output written to file: \"%s\"\n", output_file);
printf("Input bit format: %s\n", tp.bits_in);
printf("Input sample rate: %d\n", tp.fs_in);
printf("Output sample rate: %d\n", tp.fs_out);
printf("Output written to file: \"%s\"\n", tp.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);
/* free all other data */
free(bits_in);
free(input_file);
free(tplg_file);
free(output_file);
free(tp.bits_in);
free(tp.input_file);
free(tp.tplg_file);
free(tp.output_file);
/* close shared library objects */
for (i = 0; i < NUM_WIDGETS_SUPPORTED; i++) {

View File

@ -235,14 +235,15 @@ static int load_buffer(struct sof *sof, int comp_id, int pipeline_id, int size)
/* load fileread component */
static int load_fileread(struct sof *sof, int comp_id, int pipeline_id,
int size, char *bits_in, int *fr_id, int *sched_id)
int size, int *fr_id, int *sched_id,
struct testbench_prm *tp)
{
struct sof_ipc_comp_file fileread;
struct snd_soc_tplg_vendor_array *array = NULL;
size_t total_array_size = 0, read_size;
int ret = 0;
fileread.config.frame_fmt = find_format(bits_in);
fileread.config.frame_fmt = find_format(tp->bits_in);
/* allocate memory for vendor tuple array */
array = (struct snd_soc_tplg_vendor_array *)malloc(size);
@ -272,7 +273,7 @@ static int load_fileread(struct sof *sof, int comp_id, int pipeline_id,
}
/* configure fileread */
fileread.fn = strdup(input_file);
fileread.fn = strdup(tp->input_file);
fileread.mode = FILE_READ;
fileread.comp.id = comp_id;
@ -296,7 +297,7 @@ static int load_fileread(struct sof *sof, int comp_id, int pipeline_id,
/* load filewrite component */
static int load_filewrite(struct sof *sof, int comp_id, int pipeline_id,
int size, int *fw_id)
int size, int *fw_id, struct testbench_prm *tp)
{
struct sof_ipc_comp_file filewrite;
struct snd_soc_tplg_vendor_array *array = NULL;
@ -332,7 +333,7 @@ static int load_filewrite(struct sof *sof, int comp_id, int pipeline_id,
}
/* configure filewrite */
filewrite.fn = strdup(output_file);
filewrite.fn = strdup(tp->output_file);
filewrite.comp.id = comp_id;
filewrite.mode = FILE_WRITE;
*fw_id = comp_id;
@ -572,7 +573,7 @@ static int load_controls(struct sof *sof, int num_kcontrols)
/* load src dapm widget */
static int load_src(struct sof *sof, int comp_id, int pipeline_id,
int size)
int size, struct testbench_prm *tp)
{
struct sof_ipc_comp_src src = {0};
struct snd_soc_tplg_vendor_array *array = NULL;
@ -622,15 +623,15 @@ static int load_src(struct sof *sof, int comp_id, int pipeline_id,
array = (void *)array - size;
/* set testbench input and output sample rate from topology */
if (!fs_out) {
fs_out = src.sink_rate;
if (!tp->fs_out) {
tp->fs_out = src.sink_rate;
if (!fs_in)
fs_in = src.source_rate;
if (!tp->fs_in)
tp->fs_in = src.source_rate;
else
src.source_rate = fs_in;
src.source_rate = tp->fs_in;
} else {
src.sink_rate = fs_out;
src.sink_rate = tp->fs_out;
}
/* configure src */
@ -651,11 +652,11 @@ static int load_src(struct sof *sof, int comp_id, int pipeline_id,
}
/* load dapm widget */
static int load_widget(struct sof *sof, int *fr_id, int *fw_id,
int *sched_id, char *bits_in,
static int load_widget(struct sof *sof, int *fr_id, int *fw_id, int *sched_id,
struct comp_info *temp_comp_list,
struct sof_ipc_pipe_new *pipeline, int comp_id,
int comp_index, int pipeline_id)
int comp_index, int pipeline_id,
struct testbench_prm *tp)
{
struct snd_soc_tplg_dapm_widget *widget;
char message[DEBUG_MSG_LEN];
@ -708,8 +709,8 @@ static int load_widget(struct sof *sof, int *fr_id, int *fw_id,
/* replace pcm playback component with fileread in testbench */
case(SND_SOC_TPLG_DAPM_AIF_IN):
if (load_fileread(sof, temp_comp_list[comp_index].id,
pipeline_id, widget->priv.size, bits_in,
fr_id, sched_id) < 0) {
pipeline_id, widget->priv.size,
fr_id, sched_id, tp) < 0) {
fprintf(stderr, "error: load fileread\n");
return -EINVAL;
}
@ -719,7 +720,7 @@ static int load_widget(struct sof *sof, int *fr_id, int *fw_id,
case(SND_SOC_TPLG_DAPM_DAI_IN):
if (load_filewrite(sof, temp_comp_list[comp_index].id,
pipeline_id, widget->priv.size,
fw_id) < 0) {
fw_id, tp) < 0) {
fprintf(stderr, "error: load filewrite\n");
return -EINVAL;
}
@ -749,7 +750,7 @@ static int load_widget(struct sof *sof, int *fr_id, int *fw_id,
/* load src widget */
case(SND_SOC_TPLG_DAPM_SRC):
if (load_src(sof, temp_comp_list[comp_index].id,
pipeline_id, widget->priv.size) < 0) {
pipeline_id, widget->priv.size, tp) < 0) {
fprintf(stderr, "error: load src\n");
return -EINVAL;
}
@ -774,10 +775,9 @@ static int load_widget(struct sof *sof, int *fr_id, int *fw_id,
}
/* parse topology file and set up pipeline */
int parse_topology(char *filename, struct sof *sof, int *fr_id, int *fw_id,
int *sched_id, char *bits_in, char *in_file,
char *out_file, struct shared_lib_table *library_table,
char *pipeline_msg)
int parse_topology(struct sof *sof, struct shared_lib_table *library_table,
struct testbench_prm *tp, int *fr_id, int *fw_id,
int *sched_id, char *pipeline_msg)
{
struct snd_soc_tplg_hdr *hdr;
@ -789,9 +789,9 @@ int parse_topology(char *filename, struct sof *sof, int *fr_id, int *fw_id,
size_t file_size, size;
/* open topology file */
file = fopen(tplg_file, "rb");
file = fopen(tp->tplg_file, "rb");
if (!file) {
fprintf(stderr, "error: opening file %s\n", tplg_file);
fprintf(stderr, "error: opening file %s\n", tp->tplg_file);
return -EINVAL;
}
@ -834,9 +834,9 @@ int parse_topology(char *filename, struct sof *sof, int *fr_id, int *fw_id,
for (i = 0; i < hdr->count; i++)
load_widget(sof, fr_id, fw_id, sched_id,
bits_in, temp_comp_list,
temp_comp_list,
&pipeline, next_comp_id++,
i, hdr->index);
i, hdr->index, tp);
break;
/* set up component connections from pipeline graph */

View File

@ -41,26 +41,27 @@
#include <sof/audio/component.h>
#include <sof/audio/format.h>
/* common input parameters for the testbench */
char *tplg_file; /* topology file to use */
char *input_file; /* input file name */
char *output_file; /* output file name */
char *bits_in; /* input bit format */
/*
* input and output sample rate parameters
* By default, these are calculated from pipeline frames_per_sched and deadline
* But they can also be overridden via input arguments to the testbench
*/
uint32_t fs_in;
uint32_t fs_out;
#define DEBUG_MSG_LEN 256
#define MAX_LIB_NAME_LEN 256
/* number of widgets types supported in testbench */
#define NUM_WIDGETS_SUPPORTED 3
struct testbench_prm {
char *tplg_file; /* topology file to use */
char *input_file; /* input file name */
char *output_file; /* output file name */
char *bits_in; /* input bit format */
/*
* input and output sample rate parameters
* By default, these are calculated from pipeline frames_per_sched
* and deadline but they can also be overridden via input arguments
* to the testbench.
*/
uint32_t fs_in;
uint32_t fs_out;
};
struct shared_lib_table {
char *comp_name;
char library_name[MAX_LIB_NAME_LEN];
@ -80,11 +81,13 @@ void sys_comp_filewrite_init(void);
int tb_pipeline_setup(struct sof *sof);
int tb_pipeline_start(struct ipc *ipc, int nch, char *bits_in,
struct sof_ipc_pipe_new *ipc_pipe);
int tb_pipeline_start(struct ipc *ipc, int nch,
struct sof_ipc_pipe_new *ipc_pipe,
struct testbench_prm *tp);
int tb_pipeline_params(struct ipc *ipc, int nch, char *bits_in,
struct sof_ipc_pipe_new *ipc_pipe);
int tb_pipeline_params(struct ipc *ipc, int nch,
struct sof_ipc_pipe_new *ipc_pipe,
struct testbench_prm *tp);
void debug_print(char *message);

View File

@ -194,9 +194,8 @@ void sof_parse_word_tokens(void *object,
int count,
struct snd_soc_tplg_vendor_array *array);
int parse_topology(char *filename, struct sof *sof, int *fr_id, int *fw_id,
int *sched_id, char *bits_in, char *in_file,
char *out_file, struct shared_lib_table *library_table,
char *pipeline_msg);
int parse_topology(struct sof *sof, struct shared_lib_table *library_table,
struct testbench_prm *tp, int *fr_id, int *fw_id,
int *sched_id, char *pipeline_msg);
#endif