Skip to content
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

Testbench: Add different in and out channels count and improve shell helper scripts for components #5152

Merged
merged 3 commits into from
Jan 24, 2022

Conversation

singalsu
Copy link
Collaborator

@singalsu singalsu commented Jan 5, 2022

No description provided.

@singalsu singalsu requested a review from marc-hb January 5, 2022 17:14
@singalsu
Copy link
Collaborator Author

singalsu commented Jan 5, 2022

@marc-hb What do you think of the component run scripts? I will do later a shellcheck fix round for details but does the overall approach look sane to you.

I did this work to help make more advanced automatic tests for beamformer and sound direction tracking. The test script (not yet this patch) captures debug trace output from testbench and parses and checks some internal state variables that way during the test run.

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.

Too much code and layers of indirections. Many of the top-level scripts are just configuration files in disguise. The double level of getopt is especially hurting.

My recommendation: add a new ./comp_run.sh --test_config option and get rid of most top level scripts. Keep it simple: have ./comp_run.sh merely source the config file which defines a bunch of test parameters as shell variables.

@marc-hb
Copy link
Collaborator

marc-hb commented Jan 10, 2022

@marc-hb proposed that this PR would be min changes only to support the additional testbench command line parameters. So this script would not change at all.

IMHO it's more effective to submit small, less controversial PRs very quick and easy to review - while still having a clear long term direction in mind. This also provides much more test coverage, easier bisects, etc. I think it's called "Continuous Integration" ;-)

@singalsu singalsu force-pushed the testbench_scripts_improve branch 2 times, most recently from 2e22604 to 5e01616 Compare January 11, 2022 13:50
@singalsu singalsu requested review from lyakh and marc-hb January 11, 2022 13:54
@singalsu singalsu marked this pull request as ready for review January 11, 2022 13:54
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.

Nothing standing out as fundamentally wrong in the shell script code but requesting changes because of the sheer number of recommendations.

exit 1
;;
esac
done
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please move most of this new code to function(s). Rationales: thesofproject/sof-test#740

Here: parse_args()

Don't move the existing code to functions, I mean not in this PR but at least most of the new code.

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 did that, hope it's like you had in mind.

if [ -z "$FN_TRACE" ]; then
$VALGRIND_CMD $CMD
else
$VALGRIND_CMD $CMD 2> "$FN_TRACE"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you considered valgrind --log-file? It seems messy to mix valgrind with test output and it's also not clear which one uses stderr and when. It can be convenient in interactive use of course but FN_TRACE looks like the opposite of interactive use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not yet done, valgrind outputs into beginning and end, with experience it's easy to spot which is it. But obviously it's not the case for occasional users. The testbench output is quite a mess today, some trace and markup language prints appear mixed. I don't know who needs the markup. It would need a big cleanup with redirect of everything with simulated time stamps.

echo "FS_OUT=48000"
echo "FN_IN=input.raw"
echo "FN_OUT=output.raw"
echo "FN_TRACE=trace.txt"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should FN_TRACE really be part of the test config? That sounds too inflexible, I mean it should be possible and even easy to direct the output of any test config to wherever. Either with a flag or global variable or a mix of both. You can have both like this:

# Default value if not already set (and if you want a non-empty default)
: ${FN_TRACE:=trace.txt}

getopt ...
   # command line takes precedence over env
   FN_TRACE=OPTARG

https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

https://github.com/thesofproject/sof-test/blob/967b7bf485a3586318f4acfa45159cc2055423cb/test-case/run-all-tests.sh#L82

The latter is another, actually relatively similar test script. It's far from perfect but worth taking a look at considering the similarities.

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 I'll make a try. The config above is just an example. For interactive usage the config file could be smaller or omitted. Trace is in testbench is just stderr so normal output redirect works.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, sort of.


shift $((OPTIND -1))

if [[ -z $SOURCED_CONFIG ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Initialize your booleans to either the true or false strings. Then you can use them in this very terse and readable:

if $SOURCED_CONFIG; then
 ....

https://github.com/thesofproject/sof/blob/71cd9666a95cc/scripts/build-tools.sh#L104

Caveat: they MUST always be defined to either true or false and inside the script itself (cause don't trust user input). But in this SOURCED_CONFIG case (and probably others) you are already doing that.

You can do the same with not just "true" and "false" but any command or function BTW, including your own functions. Example at https://github.com/thesofproject/sof-test/blob/967b7bf485a3586/test-case/run-all-tests.sh#L126

Most people don't realize this but shell scripting is a "functional" language.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done for SOURCED_CONFIG and VALGRIND.

shift $((OPTIND -1))

if [[ -z $SOURCED_CONFIG ]]; then
if [ $# -ne 8 ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

"do || die" / assert style:

Suggested change
if [ $# -ne 8 ]; then
[ -n "$SOURCED_CONFIG" ] || [ $# -eq 8 ] || {
usage
exit 1
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This maybe works, I haven't tested with Matlab tests, but I don't think it improves readability:

    if ! "$SOURCED_CONFIG"; then
	[ $# -eq 8 ] || {
	    usage "$0"
	    exit 1
	}
	
	COMP=$1
	DIRECTION=$2
	BITS_IN=$3
	BITS_OUT=$4
	FS_IN=$5
	FS_OUT=$6
	FN_IN=$7
	FN_OUT=$8
    fi

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As above now, but I guess it's not what you were suggesting.

valgrind --leak-check=yes --error-exitcode=1 $CMD
rm -f "$FN_OUT"
rm -f "$FN_TRACE"
if [ "$VALGRIND" = "yes" ]; then
Copy link
Collaborator

@marc-hb marc-hb Jan 11, 2022

Choose a reason for hiding this comment

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

You don't need the if VALGRIND test.

If you drop the 2> redirection and switch to --log-file or something, then you don't need the if FN_TRACE either.

You can run this same command with $MAYBE_VALGRIND maybe empty maybe not and it will Just Work:

  $MAYBE_VALGRIND $CMD

Again $MAYBE_REDIRECT does not work, you need the if for conditional redirections.

(I'm not suggesting to actually prefix the variable with MAYBE_)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

LOL -- I might have used maybe :) Good recommendations, thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I might have used maybe :)

Maybe it's better :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done with $VALGRIND_CMD $CMD, no --log-file yet.

@singalsu singalsu force-pushed the testbench_scripts_improve branch from 5e01616 to 963c344 Compare January 18, 2022 15:06
@singalsu
Copy link
Collaborator Author

I've not yet addressed the comments. The previous push added enable of verbose traces for library build for testbench. The extra_opts handling is fixed.

@singalsu singalsu force-pushed the testbench_scripts_improve branch from 963c344 to abe6db9 Compare January 19, 2022 17:03
@singalsu singalsu requested a review from marc-hb January 19, 2022 17:14
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.

Besides some missing quotes (please run shellcheck) the shell script changes look good to me.

I cannot review the matlab and C code unfortunately, not familiar enough with them.

FS_IN=$5
FS_OUT=$6
FN_IN=$7
FN_OUT=$8
Copy link
Collaborator

Choose a reason for hiding this comment

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

shellcheck warnings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, shellcheck thinks I should use $VALGRIND_CMD "$CMD". But in that case valgrind things the whole testbench command is the binary to run. Do you ideas how to do this fix in way that still works?

Copy link
Collaborator

@marc-hb marc-hb Jan 20, 2022

Choose a reason for hiding this comment

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

Yes, shellcheck thinks I should use $VALGRIND_CMD "$CMD".

"$CMD" is the tricky one, I wasn't referring to this one. I was only commenting about the easy ones like: FN_OUT="$8".

There are two ways to deal with the $CMD quoting problem:

  • Add a # shellcheck disable=SC1234 silencer comment that states "thank you shellcheck but I know what I'm doing"
  • Replace $CMD with a bash array "${CMD[@]}" https://mywiki.wooledge.org/BashGuide/Arrays
  • Do nothing and do not achieve shellcheck perfection. The fewer warnings the better but does not have to be zero.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Shellcheck didn't complain about likes of FN_OUT=$8. OK, I'll fix those.

This patch adds to command line switch -n for output channels count.
Existing -c is for in channels, new -n is for out channels count. Out
channels count is same as input if -n is not present. Switch -q is
added to quiet the trace output if it is not needed.

The Matlab language test scripts for components are updated to use
the -t config.sh interface of comp_run.sh. It allows more flexible
control of input and output streams.

Signed-off-by: Seppo Ingalsuo <[email protected]>
The path append of current directory (.) is not correct for
the signal processing package function iirnotch. The issue does
not happen with Octave since it has pei_tseng_notch().

The standard notch function is used in all THD+N tests so this
issue has caused fail of nearly all tests with Matlab.

Signed-off-by: Seppo Ingalsuo <[email protected]>
Some useful algorithms internal traces are output with debug traces.
This patch enables the verbose trace (CONFIG_TRACEV) for library build.

Signed-off-by: Seppo Ingalsuo <[email protected]>
@singalsu singalsu force-pushed the testbench_scripts_improve branch from abe6db9 to cdf4e8c Compare January 21, 2022 09:17
@singalsu singalsu requested a review from marc-hb January 21, 2022 09:19
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.

Reviewed the C parts. @ShriramShastry can you review the matlab. Thanks

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.

Shellcheck didn't complain about likes of FN_OUT=$8. OK, I'll fix those.

Sorry I forgot the first exception in https://mywiki.wooledge.org/Quotes#When_Should_You_Quote.3F
(assignments)

Instead I follow this rule:
https://mywiki.wooledge.org/Quotes#I.27m_Too_Lazy_to_Read.2C_Just_Tell_Me_What_to_Do

When in doubt, double-quote every expansion in your shell commands.

{
cat <<EOFHELP
Usage: $0 <options> <comp direction bits_in bits_out fs_in fs_out input output>
Example 1: $0 volume playback 16 16 48000 48000 input.raw output.raw
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add some -e or other option in this example to make it even clearer that combining flags and positional parameters is OK.

@lgirdwood lgirdwood merged commit 95d8e94 into thesofproject:main Jan 24, 2022
@singalsu singalsu deleted the testbench_scripts_improve branch September 16, 2022 07:56
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