Skip to content

Conversation

@gbarkadiusz
Copy link
Contributor

@gbarkadiusz gbarkadiusz commented Mar 10, 2025

Added option SOF_ALSA_TOOL to specify whether to use the TinyASLA or ALSA testing tool. For now, it is only for capturing and playback.
The default tool is ALSA.

This PR introduces also a generic wrapper tinyalsa-wrapper.sh to define SOF_ALSA_TOOL in environments where setting environment variables directly is not possible. This is useful for frameworks or systems with limited configuration capabilities.

@gbarkadiusz gbarkadiusz requested a review from a team as a code owner March 10, 2025 13:46
@gbarkadiusz gbarkadiusz force-pushed the topic/add_tinyalsa_support branch 2 times, most recently from f96d4e2 to 9029069 Compare March 10, 2025 14:32
Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

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

This is not scalable at all. It's adding support in only 2 tests and there's already a lot of copy/paste/diverge.

The non-duplicated way is to make aplay_opts into a smarter function that implements all the logic in only one place.

@gbarkadiusz gbarkadiusz force-pushed the topic/add_tinyalsa_support branch from 9029069 to 85a2007 Compare March 18, 2025 08:01
@gbarkadiusz gbarkadiusz requested a review from lgirdwood as a code owner March 18, 2025 08:01
@gbarkadiusz gbarkadiusz force-pushed the topic/add_tinyalsa_support branch 5 times, most recently from 8c7f825 to 1f8a70b Compare March 18, 2025 08:31
@marc-hb
Copy link
Collaborator

marc-hb commented Mar 18, 2025

Avoid "spamming" the PR with force-pushes as this brings down limited hardware resources.

@golowanow
Copy link
Member

Avoid "spamming" the PR with force-pushes as this brings down limited hardware resources.

also, shellcheck can be run locally, before push to PR.

@marc-hb
Copy link
Collaborator

marc-hb commented Mar 18, 2025

Don't forget the -x option, as in: shellcheck -x somefile.sh, otherwise you get a lot of false positives. I wonder why -x is not ON by default.

If you forget which option it is, just look in either the CI logs or in git grep shellcheck -- .github/ and run the same. True not just with shellcheck. That's one big advantage of GitHub actions over Jenkins and similar: no "CI secret".

(there can also be drawbacks having everything in the same git repo, I digress)

@gbarkadiusz gbarkadiusz force-pushed the topic/add_tinyalsa_support branch from 1f8a70b to c36f283 Compare March 19, 2025 12:23
@gbarkadiusz
Copy link
Contributor Author

@marc-hb @golowanow I've changed the approach according to your suggestions. Now, only the lib.sh has been changed. To force the usage of tinyalsa as the testing tool, the testcase should be run with SOF_TINY_ALSA=true before the testcase.
e.g. SOF_TINY_ALSA=true ./test-case/check-playback.sh
Moreover, I've added the declaration of ALSA-related variables to lib.sh to avoid reference before assignment, as @redzynix mentioned.

@gbarkadiusz gbarkadiusz force-pushed the topic/add_tinyalsa_support branch 3 times, most recently from 093579d to 19705a9 Compare March 21, 2025 11:34
Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

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

Just a few minor issues left, otherwise looks good to me. Thanks for your persistence!

case-lib/lib.sh Outdated
pcm=$(func_pipeline_parse_value "$idx" pcm)
# shellcheck disable=SC2034
type=$(func_pipeline_parse_value "$idx" type)
# shellcheck disable=SC2034
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't get this warning, are you sure?

If you are sure:

  • add it only once right before the function and it will apply to whole function. No need to duplicate.
  • Explain very briefly why it's disabled briefly before it. No one knows what SC2034 is by heart.

Copy link
Contributor Author

@gbarkadiusz gbarkadiusz Mar 24, 2025

Choose a reason for hiding this comment

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

SC2034 (warning): variable appears unused. Verify use (or export if used externally).

@gbarkadiusz gbarkadiusz force-pushed the topic/add_tinyalsa_support branch 2 times, most recently from 3a4e037 to 72aa384 Compare March 27, 2025 11:48
@gbarkadiusz gbarkadiusz force-pushed the topic/add_tinyalsa_support branch 6 times, most recently from 6cee092 to e122226 Compare May 12, 2025 13:59
@marc-hb
Copy link
Collaborator

marc-hb commented May 12, 2025

@marc-hb, this way, as a wrapper script, it allows for both alsa and tinyalsa test case flavors to coexist in our current CI environment's configuration.

I still don't get it sorry. Anywhere you write:

check-tinyalsa.sh sometest.sh test args

You can write instead:

SOF_ALSA_TOOL=tinyalsa sometest.sh test args

... and the effect is the same - but with fewer indirections and complexity.

(The environment variable can also be used in other ways that the wrapper can't do)

Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

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

I still don't get it sorry.

Thanks @golowanow for the private discussion and explanation. Trying to summarize it here:

sof-test has always been invoked by an internal, higher level, Intel test framework that manages test plans and test runs. This framework has some shortcomings, probably the most important (and somewhat relevant here) being sof-framework/issues/602.

That framework does NOT allow environment variables when defining test plans. The interface only lets the user input a test script and script arguments. So, this wrapper script is a way to disguise and shoehorn an environment variable as a test script, sneaking the real test script as a parameter.

Considering this situation, I cannot think of any better to achieve what this wrapper does. BUT, I think the actual purpose of this script should be much clearer. So interactive users and better test frameworks do NOT start using it when they do not need to.

  • The wrapper should not be called check-tinyalsa.sh which sounds like something good. It should be called something like tinyalsa-wrapper.sh.
  • The comments at the top of the wrapper should clearly state something like "This is a wrapper that allows to define SOF_ALSA_TOOL in frameworks that cannot define environment variables. Do not use this script if you can just define SOF_ALSA_TOOL.
  • The "checking bits" are useful and a very different feature! They should be in a separate "check-tinyalsa.sh` script that performs ONLY the checks and that everyone can use. The former script can call the latter script.

@gbarkadiusz gbarkadiusz force-pushed the topic/add_tinyalsa_support branch from e122226 to b228706 Compare May 13, 2025 09:18
@gbarkadiusz gbarkadiusz requested review from golowanow and marc-hb May 13, 2025 09:44
@gbarkadiusz
Copy link
Contributor Author

  • The "checking bits" are useful and a very different feature! They should be in a separate "check-tinyalsa.sh` script that performs ONLY the checks and that everyone can use. The former script can call the latter script.

I've moved this part to env-check script.

@marc-hb marc-hb dismissed their stale review May 13, 2025 14:09

Done

@gbarkadiusz gbarkadiusz force-pushed the topic/add_tinyalsa_support branch 2 times, most recently from 0da0218 to 83aae71 Compare May 14, 2025 06:15
@gbarkadiusz gbarkadiusz requested a review from redzynix May 14, 2025 06:27
@gbarkadiusz
Copy link
Contributor Author

@marc-hb Please take a look.

Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

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

I keep finding issues sorry. I don't know which it is:

  • I didn't see them before
  • The code has changed
  • I reported them before but my comments got "lost"

Nothing major.

case-lib/lib.sh Outdated
# While using TinyALSA (tinycap -b) we need to convert PCM sample fomrat to bits.
extract_format_number() {
# (e.g., extracting '16' from 'S16_LE')
format=$(printf '%s' "$1" | grep '[0-9]\+' -o)
Copy link
Collaborator

Choose a reason for hiding this comment

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

format is a very common name for a global variable.

This function returns a single value so it could just print it instead and avoid a global?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

dev=$(func_pipeline_parse_value "$idx" dev)
pcm=$(func_pipeline_parse_value "$idx" pcm)
type=$(func_pipeline_parse_value "$idx" type)
snd=$(func_pipeline_parse_value "$idx" snd)
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a lot of global variables with very short names...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

case-lib/lib.sh Outdated
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@"
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
# shellcheck disable=SC2154
if ! sox -n -r "$rate" -c "$channel" noise.wav synth "$duration" white; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indentation? Did you use tabs? I think Github does not like them (I don't either)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, Fixed.

case-lib/lib.sh Outdated
# shellcheck disable=SC2086
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@"
else
printf '%s' "Unknown alsa tool: $SOF_ALSA_TOOL "
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be fatal, using die or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

case-lib/lib.sh Outdated
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
# shellcheck disable=SC2154
if ! sox -n -r "$rate" -c "$channel" noise.wav synth "$duration" white; then
printf '%s' "Error: sox command failed." >&2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
printf '%s' "Error: sox command failed." >&2
printf 'Error: sox command failed.\n' >&2

or

Suggested change
printf '%s' "Error: sox command failed." >&2
dloge 'Error: sox command failed."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

case-lib/lib.sh Outdated

if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
# shellcheck disable=SC2154
extract_format_number "$fmt_elem"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a comment explaining where $fmt_elem comes from? Shellcheck seems to make a good point here....

More global variables :-(

case-lib/lib.sh Outdated
# shellcheck disable=SC2086
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@"
else
printf '%s' "Unknown alsa tool: $SOF_ALSA_TOOL "
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be fatal using die or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

fi
done
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
tinymix -D0 controls | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: later, it would be nice to de-duplicate the sed+grep bit with a function. No need to do it now.

@gbarkadiusz gbarkadiusz force-pushed the topic/add_tinyalsa_support branch from 83aae71 to 646120c Compare May 14, 2025 10:36
Add support for tinyALSA and update env-check and README file.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
Refactor Check-capture and Check-playback tests.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
Add tinyalsa-wrapper used to run any test with tinyAlsa testsets.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
@gbarkadiusz gbarkadiusz force-pushed the topic/add_tinyalsa_support branch from 646120c to 8c585a3 Compare May 14, 2025 10:56
@gbarkadiusz gbarkadiusz requested a review from marc-hb May 14, 2025 11:10
@golowanow golowanow merged commit c7bb56c into thesofproject:main May 14, 2025
3 of 8 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