Skip to content

test-case: refine the test script and fix the shellcheck warnings - #316

Merged
aiChaoSONG merged 1 commit into
thesofproject:masterfrom
keqiaozhang:echoref_refine
Aug 13, 2020
Merged

aiChaoSONG merged 1 commit into
thesofproject:masterfrom
keqiaozhang:echoref_refine

Conversation

@keqiaozhang

Copy link
Copy Markdown
Contributor

Refine the check-fw-echo-reference.sh script and fix some shellcheck warnings.

Signed-off-by: Zhang Keqiao keqiao.zhang@linux.intel.com

@keqiaozhang
keqiaozhang requested a review from marc-hb as a code owner August 6, 2020 05:56
lyakh
lyakh previously requested changes Aug 6, 2020
Comment thread test-case/check-fw-echo-reference.sh Outdated
Comment thread test-case/check-fw-echo-reference.sh

@marc-hb marc-hb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please use check-fw-echo-reference.sh in your commit subject to be more specific

Comment thread test-case/check-fw-echo-reference.sh Outdated
sleep 1
dlogc "alsabat -C $cp_dev -c $channel -f $fmt -r $rate -F $frequency"
alsabat -C "$cp_dev" -c "$channel" -f "$fmt" -r "$rate" -F "$frequency"
if ! alsabat -C "$cp_dev" -c "$channel" -f "$fmt" -r "$rate" -F "$frequency"; then

@marc-hb marc-hb Aug 6, 2020 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In general I think this style is better:

alsabat -C ... || {
   find ...
   die "test X failed because..."
}

there are a couple reasons:

  • The fewer negations the better.
  • You cannot copy/paste ! commands to the interactive command line (try it)
  • doIt || die reads more like error handling for doIt and less like doIt is a test

Comment thread test-case/check-fw-echo-reference.sh Outdated
Comment thread test-case/check-fw-echo-reference.sh Outdated
__upload_wav_file
exit 1
if ! timeout 2 bash -c wait $alsabatPID; then
kill -9 $alsabatPID

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If alsabat should have stopped and it didn't then it is a test failure and we should die "test failed because..." here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated.

Comment thread test-case/check-fw-echo-reference.sh Outdated
if [[ "$?" != "0" ]]; then
__upload_wav_file
exit 1
if ! timeout 2 bash -c wait $alsabatPID; then

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is already a /bin/bash script, why is bash -c needed here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried timeout 2 wait $pid directly, but failed with "timeout: failed to run command ‘wait’: No such file or directory"
but looks like with bash -c, it can only fix the error, but it cannot return error code when $pid is timed out.
so I changed the way to check it.

alsabat -P "$pb_dev" --standalone -c "$channel" -f "$fmt" -r "$rate" -n "$frames" -F "$frequency" &
alsabat -P "$pb_dev" --standalone -c "$channel" -f "$fmt" -r "$rate" -n "$frames" -F "$frequency" & alsabatPID=$!
# playback may have low latency, add 0.5 second delay to aviod recording zero at beginning.
sleep 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The comment says 0.5 but the code says 1.
Did you mean "high" latency?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it should be 1 second delay.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated.

Comment thread test-case/check-fw-echo-reference.sh
@@ -84,17 +75,20 @@ do
fi

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this print a warning?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Comment thread test-case/check-fw-echo-reference.sh Outdated
dlogc "alsabat -P $pb_dev --standalone -c $channel -f $fmt -r $rate -n $frames -F $frequency"
alsabat -P "$pb_dev" --standalone -c "$channel" -f "$fmt" -r "$rate" -n "$frames" -F "$frequency" &
# playback may have low latency, add 0.5 second delay to aviod recording zero at beginning.
alsabat -P "$pb_dev" --standalone -c "$channel" -f "$fmt" -r "$rate" -n "$frames" -F "$frequency" &\

Copy link
Copy Markdown
Collaborator

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 backslash. I remember that the syntax for & is the same as for ;, I think it helps.

Comment thread test-case/check-fw-echo-reference.sh Outdated
die "alsabat test failed on pcm: $cp_dev"
}

timeout 5 tail --pid=$alsabatPID -f /dev/null || die "Failed to stop alsabat playback"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry I gave you some wrong advice earlier: timeout wait $pid does not work because wait is a built-in that works only for direct child processes. tail --pid is an interesting idea but it doesn't not collect the exit status/error code of the alsabat command which is the goal here so tail --pid doesn't not solve the problem. This works:

timeout -k 10 5 alsabat -P "$pb_dev" -... -F "$frequency" & timedAlsabatPID=$!
...
...
wait $timedAlsabatPID || die "alsabat failed..."

Unlike my previous advice I tested this logic and it does fail when alsabat fail.

@keqiaozhang keqiaozhang Aug 12, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @marc-hb for your suggestion, I have updated the code and did some fine-tuning for the time.

refine the check-fw-echo-reference.sh script and fix some
shellcheck warnings.

Signed-off-by: Zhang Keqiao <keqiao.zhang@linux.intel.com>

@marc-hb marc-hb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @keqiaozhang !

@aiChaoSONG
aiChaoSONG dismissed lyakh’s stale review August 13, 2020 03:20

review addressed, to merge need to dismiss

@aiChaoSONG aiChaoSONG left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@aiChaoSONG
aiChaoSONG merged commit fd545ae into thesofproject:master Aug 13, 2020
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