Skip to content

Conversation

@singalsu
Copy link
Collaborator

Adds support for command line, e.g.

tools/testbench/build_testbench/install/bin/sof-testbench4 -r 48000 -c 2 -b S32_LE   -p 1,2 \
 -t tools/build_tools/topology/topology2/production/sof-hda-generic.tplg \
-i in.raw -o out.raw -s controls.sh

Where controls.sh script can be e.g. similar as control for a real device:

#!/bin/sh

# Example test sequence for DRC and volume components

amixer -c0 cset name='Post Mixer Analog Playback DRC switch' off
amixer -c0 cset name='Post Mixer Analog Playback Volume' 20,30
sleep 1
amixer -c0 cset name='Post Mixer Analog Playback Volume' 0
sleep 1
amixer -c0 cset name='Post Mixer Analog Playback Volume' 45

In the above, the comments are ignored. Only the amixer and sleep commands are parsed. For sleep the numerical argument, and for amixer the cset name='' part and the arguments after.

@singalsu singalsu force-pushed the testbench_control_script branch from 8ab6f9a to 3e8aa01 Compare March 21, 2025 14:55
@singalsu
Copy link
Collaborator Author

singalsu commented Mar 26, 2025

Seems to be a bug in testbench, the end of component configuration blob becomes corrupt with this PR... finding out why.

Found, there's no check in testbench for bytes control data vs. allocated max size.

@singalsu singalsu force-pushed the testbench_control_script branch 2 times, most recently from 6271a95 to bc41954 Compare March 27, 2025 17:13
@singalsu singalsu marked this pull request as ready for review March 27, 2025 17:21
Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some comment/questions inline, please check

return 0;

raw_line = malloc(TB_MAX_CMD_CHARS);
if (!raw_line)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just assert on alloc error and not deal with memory handling.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK


line = malloc(TB_MAX_CMD_CHARS);
if (!line)
return -ENOMEM;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do check for alloc errors, then you'd need to free "raw_line" here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert() then for simplicity, not expecting to run out memory in this.

fprintf(stderr, "error: failed parse of sleep command.\n");
break;
}
break;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function tb_read_controls() should return and continue pipelines scheduling when sleep is encountered and be called back after nanoseconds if simulated time.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, this is the main purpose of "sleep". Sorry my bad. I guess a comment might help to explain why we need to return to main loop after "sleep", but not after other commands.

memcpy(control_name, name_str + find_len, len);

line_end = line + strlen(line);
len = line_end - end_str - find_end_len; // Todo rememove linefeed from end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo still valid (rememove?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line feeds were handled, just remove comment.

The non-threaded version of testbench no more support these
features so, they are removed to simplify the code. The
removed command line switches are -D for pipeline duration
and -T tick duration.

The cleanup is done to ease adding support for simulated
run-time ALSA controls into pipelines schedule loop.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
The stream parameters channels count and sample rate are moved
into the struct file state that is monitored by testbench
pipelines schedule loop. The simulated "time" can be derived
from file state samples count when the parameters are known.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This patch adds to testbench command line option -s <controls file>.
The controls file can contain comments with line starting with #,
empty lines, amixer cset name= commands and sleep n commands.

The script format is similar to what can be applied to a real
SOF device running Linux OS. E.g.

amixer -c0 cset name='Post Mixer Analog Playback DRC switch' off
amixer -c0 cset name='Post Mixer Analog Playback Volume' 42,43
sleep 0.5
amixer -c0 cset name='Post Mixer Analog Playback Volume' 45

The result simulated waveform would show in the beginning left
channel set to gain value 42, and right channel to gain value 43.
After processing 0.5 seconds of audio both left and right
channel gains are set to 45.

The supported controls types are mixer, switch and enum.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
The added example generates a sine wave file and processed
it with various stereo mixer control settings. Since the
example topology contains also a DRC it is switched off as
demo with switch control.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This patch adds check for bytes data control size into
sof-testbench4 for topology embedded control data. Also the
missing error handling is added to the topology parser.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
The max size is increased to 8 kB. Instead of copying the data
from topology to controls array the data can be referenced
with a pointer.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
@singalsu singalsu force-pushed the testbench_control_script branch from bc41954 to bf04b74 Compare March 31, 2025 12:27
@singalsu singalsu requested a review from kv2019i March 31, 2025 12:28
fprintf(stderr, "error: failed parse of sleep command.\n");
break;
}
break;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, this is the main purpose of "sleep". Sorry my bad. I guess a comment might help to explain why we need to return to main loop after "sleep", but not after other commands.

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can deal with the comment in the next PR as I know there is more work to come here.

@lgirdwood lgirdwood merged commit fc9edf7 into thesofproject:main Apr 2, 2025
43 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants