Skip to content

Conversation

@singalsu
Copy link
Collaborator

@singalsu singalsu commented May 8, 2025

With this change sof-ctl commands can be executed during sof-testbench4 simulation, e.g.

sof-ctl -c name='Post Mixer Analog Playback IIR Eq bytes' \ -s tools/ctl/ipc4/eq_iir/loudness.txt

No other than switches -c and -s are supported for simulated sof-ctl. The blob file must be in normal comma separated ASCII uint32_t numbers format with nothing else in it.

With this change the SOF processing components can be tested extensively for their controls during simulated audio streaming.

@kv2019i kv2019i requested a review from Copilot May 9, 2025 07:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds simulation support for sof-ctl commands in the testbench, allowing simulated execution of sof-ctl control commands by reading blob files with comma‐separated ASCII numbers.

  • Introduces tb_set_bytes_control in utils_ipc4.c to handle bytes control transfers.
  • Implements tb_parse_sofctl and updates tb_read_controls in utils.c to parse and process new sof-ctl commands.
  • Updates the header file to define new constants and declare the new function.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tools/testbench/utils_ipc4.c Adds function to send bytes control data during simulation.
tools/testbench/utils.c Implements a new parser for sof-ctl commands and updates the control parser logic.
tools/testbench/include/testbench/utils.h Adds new macros for blob file handling and declares tb_set_bytes_control.

@singalsu singalsu force-pushed the testbench_add_sofctl branch from 6e7a254 to 2bf86c9 Compare May 9, 2025 09:05
@singalsu singalsu marked this pull request as ready for review May 9, 2025 09:25
@singalsu singalsu requested a review from Copilot May 9, 2025 09:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends the sof-testbench by adding simulation support for sof-ctl commands to manipulate bytes controls during audio streaming tests.

  • Added new functions tb_set_bytes_control in both IPC4 (actual implementation) and IPC3 (stub) modules.
  • Implemented a new command parser (tb_parse_sofctl) in utils.c to handle sof-ctl control commands.
  • Updated header definitions and README documentation to support and illustrate the new sof-ctl simulation feature.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tools/testbench/utils_ipc4.c Adds tb_set_bytes_control to send bytes control using IPC4 semantics.
tools/testbench/utils_ipc3.c Adds a stub tb_set_bytes_control for IPC3 compatibility.
tools/testbench/utils.c Implements tb_parse_sofctl and updates tb_read_controls to process sof-ctl commands.
tools/testbench/include/testbench/utils.h Declares constants and tb_set_bytes_control function prototype.
tools/testbench/README.md Updates documentation/example scripts for using sof-ctl simulation.

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.

Looks like a good feature for v2.13

@singalsu singalsu force-pushed the testbench_add_sofctl branch from 2bf86c9 to 576685a Compare May 12, 2025 08:40
@singalsu singalsu requested review from Copilot and lyakh May 12, 2025 10:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for executing sof-ctl commands during SOF testbench4 simulations, specifically enabling bytes control for IIR and FIR equalizers. Key changes include:

  • Adding new functions tb_set_bytes_control in both IPC3 and IPC4 code paths.
  • Implementing a new command parser tb_parse_sofctl in utils.c to process sof-ctl commands.
  • Updating the testbench header and README documentation to support and illustrate the new sof-ctl simulation commands.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/testbench/utils_ipc4.c Implements tb_set_bytes_control by invoking tb_send_bytes_data.
tools/testbench/utils_ipc3.c Adds a stub for tb_set_bytes_control for IPC3 simulation.
tools/testbench/utils.c Introduces tb_parse_sofctl to process sof-ctl command lines.
tools/testbench/include/testbench/utils.h Declares TB_MAX_BLOB_CONTENT_CHARS and tb_set_bytes_control prototype.
tools/testbench/README.md Updates documentation and example scripts for sof-ctl simulation.

blob_bin[n] = atoi(token);
n++;
}

Copy link

Copilot AI May 12, 2025

Choose a reason for hiding this comment

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

Ensure that at least two comma-separated values have been parsed before accessing blob_bin at an offset of 2 to avoid potential out-of-bounds issues. Consider adding a check on the value of 'n' before calling tb_set_bytes_control.

Suggested change
/* Ensure at least two values have been parsed before accessing blob_bin[2]. */
if (n < 2) {
fprintf(stderr, "error: insufficient data in blob file. At least two values are required.\n");
ret = -EINVAL;
goto err;
}

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I'll add this.

name_str += strlen(find_set_switch_str) + 1;
end = line + strlen(line);
copy_len = end - name_str;
blob_name = strndup(name_str, copy_len);
Copy link

Copilot AI May 12, 2025

Choose a reason for hiding this comment

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

Consider trimming any leading or trailing whitespace from the extracted blob_name before using it to open a file, which can prevent file open failures if the command line has extra spaces.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Current released blob files in sof-ctl path do not have whitespace. Maybe need to add later support for quoted paths and filenames to support blanks and special characters with help of some parser lib to avoid to reinvent it but for now I'd not like to to that.

singalsu added 2 commits May 13, 2025 11:39
With this change sof-ctl commands can be executed during
sof-testbench4 simulation, e.g.

sof-ctl -c name='Post Mixer Analog Playback IIR Eq bytes' \
-s tools/ctl/ipc4/eq_iir/loudness.txt

No other than switches -c and -s are supported for simulated
sof-ctl. The blob file must be in normal comma separated ASCII
uint32_t numbers format with nothing else in it.

With this change the SOF processing components can be tested
extensively for their controls during simulated audio streaming.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This addition shows how to use the new bytes control set
feature in control script.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
@singalsu singalsu force-pushed the testbench_add_sofctl branch from 576685a to 30ba23e Compare May 13, 2025 08:41
@singalsu singalsu requested a review from Copilot May 13, 2025 08:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for executing sof-ctl commands during sof-testbench4 simulation, allowing simulation of bytes controls via command scripts.

  • Implements tb_set_bytes_control for IPC4 and a stub implementation for IPC3.
  • Introduces a new command parser (tb_parse_sofctl) and updates control parsing in tb_read_controls to support sof-ctl commands.
  • Updates documentation and header definitions to support blob-file based bytes control commands.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tools/testbench/utils_ipc4.c Adds implementation of tb_set_bytes_control using tb_send_bytes_data.
tools/testbench/utils_ipc3.c Adds stub tb_set_bytes_control returning 0.
tools/testbench/utils.c Adds tb_parse_sofctl for sof-ctl command parsing and updates tb_read_controls.
tools/testbench/include/testbench/utils.h Adds macro for blob content size and function declaration for tb_set_bytes_control.
tools/testbench/README.md Updates documentation to include examples for bytes control simulation.

goto err;
}

blob_bin[n] = atoi(token);
Copy link

Copilot AI May 13, 2025

Choose a reason for hiding this comment

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

Consider using strtol instead of atoi for converting blob file tokens to uint32_t values, to enable robust error checking in case of conversion failures.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

@singalsu I assume code is already validating blob_bin[n] 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.

I don't think this necessary, strtol() could be used to error possible integers over int32_t range. It also supports other numbers than 10-base decimal. There's no such mistakes in computer generated blobs and I don't see security issues from illegal blobs in testbench runtime with user's rights.

@kv2019i kv2019i merged commit 3fa79c4 into thesofproject:main May 15, 2025
40 of 48 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.

4 participants