-
Notifications
You must be signed in to change notification settings - Fork 349
Tools: Testbench: Add sof-ctl simulation to control scripts #9996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||||||||||||||
| #include <sof/lib/notifier.h> | ||||||||||||||||||
|
|
||||||||||||||||||
| #include <ctype.h> | ||||||||||||||||||
| #include <errno.h> | ||||||||||||||||||
| #include <stdint.h> | ||||||||||||||||||
| #include <stdio.h> | ||||||||||||||||||
| #include <stdlib.h> | ||||||||||||||||||
|
|
@@ -388,10 +389,141 @@ static int tb_parse_amixer(struct testbench_prm *tp, char *line) | |||||||||||||||||
| return ret; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| static int tb_parse_sofctl(struct testbench_prm *tp, char *line) | ||||||||||||||||||
| { | ||||||||||||||||||
| struct tb_ctl *ctl; | ||||||||||||||||||
| uint32_t *blob_bin = NULL; | ||||||||||||||||||
| char *blob_name = NULL; | ||||||||||||||||||
| char *blob_str = NULL; | ||||||||||||||||||
| char *control_name = NULL; | ||||||||||||||||||
| char *end; | ||||||||||||||||||
| char *find_ctl_name_str = "-c name=\""; | ||||||||||||||||||
| char *find_end_str = "\" "; | ||||||||||||||||||
| char *find_set_switch_str = "-s"; | ||||||||||||||||||
| char *name_str; | ||||||||||||||||||
| char *rest; | ||||||||||||||||||
| char *token; | ||||||||||||||||||
| int copy_len; | ||||||||||||||||||
| int find_len = strlen(find_ctl_name_str); | ||||||||||||||||||
| int n = 0; | ||||||||||||||||||
| int ret = 0; | ||||||||||||||||||
| FILE *fh; | ||||||||||||||||||
|
|
||||||||||||||||||
| name_str = strstr(line, find_ctl_name_str); | ||||||||||||||||||
| if (!name_str) { | ||||||||||||||||||
| fprintf(stderr, "error: no control name in script line: %s\n", line); | ||||||||||||||||||
| return -EINVAL; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| end = strstr(&name_str[find_len], find_end_str); | ||||||||||||||||||
| if (!end) { | ||||||||||||||||||
| fprintf(stderr, "error: no control name end quote in script line: %s\n", line); | ||||||||||||||||||
| return -EINVAL; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| copy_len = end - name_str - find_len; | ||||||||||||||||||
| control_name = strndup(name_str + find_len, copy_len); | ||||||||||||||||||
| if (!control_name) { | ||||||||||||||||||
| fprintf(stderr, "error: failed to duplicate control name.\n"); | ||||||||||||||||||
| return -errno; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| name_str = strstr(line, find_set_switch_str); | ||||||||||||||||||
| if (!name_str) { | ||||||||||||||||||
| fprintf(stderr, "error: no sof-ctl control set switch in command: %s.\n", | ||||||||||||||||||
| line); | ||||||||||||||||||
| ret = -EINVAL; | ||||||||||||||||||
| goto err; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| name_str += strlen(find_set_switch_str) + 1; | ||||||||||||||||||
| end = line + strlen(line); | ||||||||||||||||||
| copy_len = end - name_str; | ||||||||||||||||||
| blob_name = strndup(name_str, copy_len); | ||||||||||||||||||
|
||||||||||||||||||
| if (!blob_name) { | ||||||||||||||||||
| fprintf(stderr, "error: failed to duplicate blob name.\n"); | ||||||||||||||||||
| ret = -errno; | ||||||||||||||||||
| goto err; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| ctl = tb_find_control_by_name(tp, control_name); | ||||||||||||||||||
| if (!ctl) { | ||||||||||||||||||
| fprintf(stderr, "error: control %s not found in topology.\n", control_name); | ||||||||||||||||||
| ret = -EINVAL; | ||||||||||||||||||
| goto err; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (ctl->type != SND_SOC_TPLG_TYPE_BYTES) { | ||||||||||||||||||
| fprintf(stderr, "error: control %s type %d is not supported.\n", | ||||||||||||||||||
| control_name, ctl->type); | ||||||||||||||||||
| ret = -EINVAL; | ||||||||||||||||||
| goto err; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| blob_str = malloc(TB_MAX_BLOB_CONTENT_CHARS); | ||||||||||||||||||
| if (!blob_str) { | ||||||||||||||||||
| fprintf(stderr, "error: failed to allocate memory for blob file content.\n"); | ||||||||||||||||||
| ret = -ENOMEM; | ||||||||||||||||||
| goto err; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| blob_bin = malloc(TB_MAX_BYTES_DATA_SIZE); | ||||||||||||||||||
| if (!blob_bin) { | ||||||||||||||||||
| fprintf(stderr, "error: failed to allocate memory for blob data.\n"); | ||||||||||||||||||
| ret = -ENOMEM; | ||||||||||||||||||
| goto err; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| printf("Info: Setting control name '%s' to blob '%s'\n", control_name, blob_name); | ||||||||||||||||||
| fh = fopen(blob_name, "r"); | ||||||||||||||||||
| if (!fh) { | ||||||||||||||||||
| fprintf(stderr, "error: could not open file.\n"); | ||||||||||||||||||
| ret = -errno; | ||||||||||||||||||
| goto err; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| end = fgets(blob_str, TB_MAX_BLOB_CONTENT_CHARS, fh); | ||||||||||||||||||
| fclose(fh); | ||||||||||||||||||
| if (!end) { | ||||||||||||||||||
| fprintf(stderr, "error: failed to read data from blob file.\n"); | ||||||||||||||||||
| ret = -ENODATA; | ||||||||||||||||||
| goto err; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| rest = blob_str; | ||||||||||||||||||
| while ((token = strtok_r(rest, ",", &rest))) { | ||||||||||||||||||
| if (n == TB_MAX_BYTES_DATA_SIZE) { | ||||||||||||||||||
| fprintf(stderr, "error: data read exceeds max control data size.\n"); | ||||||||||||||||||
| ret = -EINVAL; | ||||||||||||||||||
| goto err; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| blob_bin[n] = atoi(token); | ||||||||||||||||||
|
||||||||||||||||||
| n++; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
||||||||||||||||||
| /* 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; | |
| } |
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.