Skip to content

Conversation

@libinyang
Copy link
Contributor

This patches add the test cases for user space.
It includes:

  1. verify-ucm-config (already merged)
  2. check-user-packages: test installing user space packages, restart pulseaudio
  3. check-userspace-pa-status: check the pulseaudio can be run successfully
  4. check-userspace-cardinfo: check pulseaudio can parse the ucm correctly and exports the correct card
  5. check-userspace-paplay: go through all the active sinks and play on it if port is available (almost finished, not included in this patchset)
  6. check-userspace-parecord: go through all the active sources and record on it if port is available (almost finished, not included in this patchset)

@libinyang libinyang requested a review from a team as a code owner September 7, 2020 06:31
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.

To save a lot of review time, please run shellcheck -x locally before submitting and start all scripts with set -e (see #312)

Copy link
Contributor

@xiulipan xiulipan left a comment

Choose a reason for hiding this comment

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

Please remove the install code part and update other checks.

@libinyang
Copy link
Contributor Author

libinyang commented Sep 9, 2020

I do not think this function should not be a test case. This should be some ENV check for our CI instead of a shared test case. Please use dpkg or apt for check only. Install should be in other part.

This is an installation script, it does not belong to the test-case directory. Can you submit this in a different Pull Request?

@xiulipan @marc-hb Thanks for raise this discussion. When I developed the check-userspace-packages test case at first, I did put it in sof-sh repo. From logic view, this should be put in sof-sh repo. However, I met some issues when I was trying to install the packages in sof-sh.

  1. install pulseaudio, libasounds serial packages need a lot of dependency. This means we need more check whether they are installed successfully or not. From this point view, it's like a test case to check the dependency issue than just installation.
  2. My final solution of this test case is a little complex logic, such as: Install libasound2 in Monday and test, install pulseaudio in Tuesday and test, install UCM in Wednesday and test. With this we can easily tell the failure is because of libasound2 update, pulseaudio update or UCM updated. It seems this logic is too complex for sof-sh.
  3. I also want to test 'pulseaudio --kill' 'pulseaudio --start (or as Marc suggested use systemctl)' after install the new pulseaudio package. Of course, this should be not a big problem, we can split it a very simple test case which dedicates to test 'start' and 'stop'.

@xiulipan
Copy link
Contributor

xiulipan commented Sep 9, 2020

@libinyang Please split set up test device and test scripts.

  1. Setup scripts should be CI stuff, please add those into our CI scripts.
    For the test case dependency, we have env-check.sh to check and give advice. Also if the case is optional, we should add check before the test run.
  2. Please do not install anything silently. We can add anything into our CI deploy scripts.
  3. This should be OK. If the pulseaudio can be controlled now. Otherwise we will have conflict with other test cases.

Please try to set up a sync up meeting for this at any time you prefer

@marc-hb
Copy link
Collaborator

marc-hb commented Sep 9, 2020

  1. Packages dependencies issues should be tested when new packages are built. Based on discussions in Add document to clarify BKM of user space packages: alsa-lib, alsa-ucm-conf, PulseAudio, GNOME etc linux#2211 It doesn't look like you want to move the debian code to build user space packages to sof-test, correct?
  1. My final solution of this test case is a little complex logic, such as: Install libasound2 in Monday and test, install pulseaudio in Tuesday and test, install UCM in Wednesday and test.
  1. Again based on Add document to clarify BKM of user space packages: alsa-lib, alsa-ucm-conf, PulseAudio, GNOME etc linux#2211, we don't want to upgrade CI to newer user space package versions every week, do we? If correct then each CI upgrade will be manual, ideally performed in a PR. These PRs can be staggered as needed.

  2. We should test pulseaudio continuously, not just when upgrading it and independently from it. pulseaudio could break because of a kernel or firmware change.

@libinyang
Copy link
Contributor Author

libinyang commented Sep 9, 2020

It seems 2 vs 1 to prefer to put it into the sof-sh. OK. I will move it into sof-sh.

This should be OK. If the pulseaudio can be controlled now. Otherwise we will have conflict with other test cases.

No, pulseaudio will conflict with other driver test cases. So I setup 2 CI DUT dedicated for user space test.

Packages dependencies issues should be tested when new packages are built. Based on discussions in thesofproject/linux#2211 It doesn't look like you want to move the debian code to build user space packages to sof-test, correct?

Build machine is different from the DUT. So we won't test the dependencies when building the packages on DUT. I use the debian code to build the alsa lib based on your suggestion.

Again based on thesofproject/linux#2211, we don't want to upgrade CI to newer user space package versions every week, do we? If correct then each CI upgrade will be manual, ideally performed in a PR. These PRs can be staggered as needed.

Based on Mengdong's requirement, this is used to test the upstreamed code. We will use this to make sure the latest alsa lib, pulseaudio and UCM won't break our Intel platform.
In thesofproject/linux#2211, we provide the stable packages, which are for products release. Only with many tests (including automation test and manual test), these packages can be the stable packages.

We should test pulseaudio continuously, not just when upgrading it and independently from it. pulseaudio could break because of a kernel or firmware change.

Yes, this is why we add the user space test case. Actually, the kernel change may cause UCM error, which will cause user space totally not work. I met such issue before. The user space test cases are not finished. I will submit another 2 test cases today of paplay and parecord.

@marc-hb
Copy link
Collaborator

marc-hb commented Sep 9, 2020

OK. I will move it into sof-sh. [...] I use the debian code to build the alsa lib based on your suggestion.

Is this closed source location where the code to build the packages is right now? In thesofproject/linux#2211 I shared a (pretty small), open-source prototype that anyone can use to rebuild alsa-lib packages.

No, pulseaudio will conflict with other driver test cases

I spent some more time trying the systemctl commands suggested in other pulseaudio isssues and it looks like it shouldn't be too hard to control pulseaudio like this. I believe no one surprisingly tried to use systemctl yet so maybe it's just the matter of using the right tools.

Build machine is different from the DUT. So we won't test the dependencies when building the packages on DUT.

Both systems should be Ubuntu 20.04 configured similarly so I don't understand which dependencies could be different, can you share an example? SOF developers shouldn't have to use more than one system. They can but they shouldn't have too. thesofproject/linux#2402 (comment)

Based on Mengdong's requirement,... We will use this to make sure the latest alsa lib, pulseaudio and UCM won't break our Intel platform. In thesofproject/linux#2211, we provide the stable packages, which are for products release

Please write down and submit for review these test cycle and release requirements before submitting the corresponding code. I understand we don't want to wait for official ALSA releases but don't think we want to test every single ALSA commit either, do we?

@marc-hb marc-hb requested a review from plbossart September 9, 2020 06:37
@libinyang
Copy link
Contributor Author

libinyang commented Sep 9, 2020

Is this closed source location where the code to build the packages is right now? In thesofproject/linux#2211 I shared a (pretty small), open-source prototype that anyone can use to rebuild alsa-lib packages.

It is closed source location, in sof-sh repo. Not sure to attach the code address here is OK?

No, pulseaudio will conflict with other driver test cases

I spent some more time trying the systemctl commands suggested in other pulseaudio isssues and it looks like it shouldn't be too hard to control pulseaudio like this. I believe no one surprisingly tried to use systemctl yet so maybe it's just the matter of using the right tools.

I didn't mean the conflict of using systemclt. I was answering Xiuli, that pulseaudio will conflict with aplay test cases.

Build machine is different from the DUT. So we won't test the dependencies when building the packages on DUT.

Both systems should be Ubuntu 20.04 configured similarly so I don't understand which dependencies could be different, can you share an example? SOF developers shouldn't have to use more than one system. They can but they shouldn't have too. thesofproject/linux#2402 (comment)

I don't have example here. But no example doesn't mean there will never be dependency issues, right? With the pulseaudio updated, it may require the related application's upgrade. If you try to install the latest pulseaudio on ubuntu 18.04, I believe you will meet such issue. However, we don't need to take too much effort on it now, this should not be our priority task. And if we really meet such issue, I think we can manually update the system.

Based on Mengdong's requirement,... We will use this to make sure the latest alsa lib, pulseaudio and UCM won't break our Intel platform. In thesofproject/linux#2211, we provide the stable packages, which are for products release

Please write down and submit for review these test cycle and release requirements before submitting the corresponding code. I understand we don't want to wait for official ALSA releases but don't think we want to test every single ALSA commit either, do we?

My plan is to test the user space package once every week. Do you think this test frequency is OK? Xiuli talked to me before that we can change to test every single commit.

@libinyang
Copy link
Contributor Author

libinyang commented Sep 9, 2020

update:

  1. refine the patches based on Xiuli and Marc suggestion
  2. remove the check of packages installation as Xiuli and Marc are strongly against it.
  3. add the test case paplay and parecord

@marc-hb
Copy link
Collaborator

marc-hb commented Sep 9, 2020

I was answering Xiuli, that pulseaudio will conflict with aplay test cases.

Hopefully not when disabled with systemctl --user. Then we can have a unique DUT configuration for everything - which is what developers need anyway. See previous discussions in https://github.com/thesofproject/sof-test/issues?q=+label%3Apulseaudio+

I don't have example here. But no example doesn't mean there will never be dependency issues, right? With the pulseaudio updated, it may require the related application's upgrade

So a separate build system is solving a problem we don't know we have and that we haven't tried to solve yet...

My plan is to test the user space package once every week. Do you think this test frequency is OK?

That seems reasonable to me but it should be discussed with more people. To keep that particular discussion focused it shouldn't be diluted in this PR or in 2211. Instead it should be submitted as focused, documentation PR. You could also start a new topic at https://github.com/orgs/thesofproject/teams/sof-developers

@libinyang
Copy link
Contributor Author

a separate patch to deploy the user space packages patch has been submitted in sof-sh repo as Marc and Xiuli's feedback.

@libinyang
Copy link
Contributor Author

Hopefully not when disabled with systemctl --user. Then we can have a unique DUT configuration for everything - which is what developers need anyway. See previous discussions in https://github.com/thesofproject/sof-test/issues?q=+label%3Apulseaudio+

I checked the sof-sh. Currently we will remove pulseaudio. So it will not impact on our other DUTs in CI.

Copy link
Member

@plbossart plbossart left a comment

Choose a reason for hiding this comment

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

let's be careful about licenses please?

@libinyang
Copy link
Contributor Author

patch updated:

  1. Move pactl stat check into lib.sh as a helper function
  2. Not use jq. Add parameters in pactlinfo.py and make pactlinfo.py return specified information

Copy link
Contributor

@xiulipan xiulipan left a comment

Choose a reason for hiding this comment

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

Could we merge the playback and capture test later? I think we only need some parameter to split playback and catpure.

@libinyang
Copy link
Contributor Author

Could we merge the playback and capture test later? I think we only need some parameter to split playback and catpure.

Sure. We can talk about it in detail.

case-lib/lib.sh Outdated
return 1
fi

return 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

If something goes wrong&>/dev/null will hide it. This is test code, never, ever redirect stderr and hide errors. Redirecting stdout to a log file is useful when it's big. This is not big.

The fewer negations and the more readable. Negations with ! are especially annoying because they cannot be copied to the interactive shell.

pactl stat || {
dloge ...
return 1
}

return 0 is useless most of the time. It is useless here, remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the test cases, why do we care the interactive shell?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my new patch, I will use :
pactl stat &>dev/null || {
dloge ...
return 1
}

I still use "&>dev/null" because error message pactl stat doesn't show explicit information that pactl stat fails. It doesn't help for developer to identity which fails quickly. Instead, I will use dloge to export the useful information for sof-test developer.


# check pulseaudio runs properly or not
if ! func_lib_check_pa; then
die "Please check whether pulseaudio runs correctly or not"
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above, no need for a negation.

## Expect result:
## There is at least one available card for test
##

Copy link
Collaborator

Choose a reason for hiding this comment

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

Use set -e in every new test (old tests are being converted too)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

grep will fail if set -e.

Copy link
Contributor

Choose a reason for hiding this comment

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

try grep ABC || true

Copy link
Collaborator

Choose a reason for hiding this comment

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

See detailed set -e guidelines in #312

OLDIFS=$IFS
dlogc "pactl list cards short"
cardlist=$(pactl list cards short)
((available_card=0))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This bashism not compatible with set -e. Change to the POSIX standard

: $((available_card=0))

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04

dlogi "found card: $(echo "$card" | awk '{print $2}')"
usbcard=$(echo "$card" |grep "[Uu][Ss][Bb]")
if [ -z "$usbcard" ]; then
((available_card++))
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above

rate=${OPT_VALUE_lst['R']}
channel=${OPT_VALUE_lst['C']}

if [[ ! -e $file ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoid negations

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if [[ ! -e $file ]]; then
[[ -e $file ]] || (dlogw "$file does not exist, use /dev/zero as dummy playback source" && file=/dev/zero )

sinkkeys=$(pactlinfo.py --showsinks)
for round in $(seq 1 $round_cnt); do
for i in $sinkkeys; do
if ! sinkcard=$(pactlinfo.py --getsinkcardname "$i"); then
Copy link
Collaborator

Choose a reason for hiding this comment

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

negation

## 1. run pactl to get the cards info
## 2. check the card name
## Expect result:
## There is at least one available card for test
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 see what this test achieves. Other tests also check that pulseaudio is functional and they should also fail if zero card is found so I think this test can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there are several cards and we only care sof cards. Other user space test cases won't check it and return correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Other user space test cases won't check it and return correctly.

This is wrong, all tests that need an sof card to test should either FAIL or SKIP (exit 2) when there is no SOF card. A test should never return PASS after testing nothing.

Copy link
Contributor

@xiulipan xiulipan left a comment

Choose a reason for hiding this comment

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

Please apply some suggestion from marc and run spellcheck for advice.
PS: we may take tare about scripts from other repo
If it is just some string handler and conversion, maybe write a version by our self is better.

rate=${OPT_VALUE_lst['R']}
channel=${OPT_VALUE_lst['C']}

if [[ ! -e $file ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if [[ ! -e $file ]]; then
[[ -e $file ]] || (dlogw "$file does not exist, use /dev/zero as dummy playback source" && file=/dev/zero )

@libinyang
Copy link
Contributor Author

patch updated:

  1. fix the license issue
  2. switch if ! ... to other code style
  3. refine the code based on other review comments.

set -e is still not used because if it is used, the case will fail to run.

## Expect result:
## There is at least one available card for test
##

Copy link
Contributor

Choose a reason for hiding this comment

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

try grep ABC || true

# pactl list cards short format should be like:
# 0 alsa_card.pci-0000_00_1f.3-platform-sof_sdw module-alsa-card.c
dlogi "found card: $(echo "$card" | awk '{print $2}')"
echo "$card" |grep "[Uu][Ss][Bb]" &>/dev/null || ((available_card++))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
echo "$card" |grep "[Uu][Ss][Bb]" &>/dev/null || ((available_card++))
echo "$card" |grep -i usb &>/dev/null || ((available_card++))

So we will ignore the USB card here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. USB is not our scope

dlogc "pactl list cards short"
cardlist=$(pactl list cards short)
((available_card=0))
IFS=$'\n'
Copy link
Contributor

Choose a reason for hiding this comment

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

rate=${OPT_VALUE_lst['R']}
channel=${OPT_VALUE_lst['C']}

[[ -e $file ]] || { dlogw "$file does not exist, use /dev/zero as dummy playback source" && file=/dev/zero; }
Copy link
Contributor

Choose a reason for hiding this comment

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

capture should use dev/null as dummy file to write into.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch. Thanks. Fixed in the latest update

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://unix.stackexchange.com/questions/275794/iterating-over-multiple-line-string-stored-in-variable
echo "$variable" | while IFS= read -r line ; do echo $line; done

I don't why: if I use this such while xxx, the 'available_card' seems to be changed locally and it will remain to 0 out of the loop. So I still keep the original code.

}

# Let's skip testing on USB card
if echo "$sourcecard" |grep "[Uu][Ss][Bb]" &>/dev/null; then
Copy link
Contributor

Choose a reason for hiding this comment

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

grep -i usb is enough
PS: do we need a ignore list or filter list? Three will also be legacy HDA card and other graphic HDMI card.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a "TODO" for the filter list. Currently we don't meet such platform. How about we implement it when we meet such platforms?

Add the helper function to check whether pulseaudio runs
properly or not.

Signed-off-by: Libin Yang <libin.yang@intel.com>
@libinyang
Copy link
Contributor Author

patch updated to add set -e

Check the pulseaudio card info to make sure the card is ready.

Signed-off-by: Libin Yang <libin.yang@intel.com>
Add the tool pactlinfo.py to parse the pactl list information

Signed-off-by: Libin Yang <libin.yang@intel.com>
This test case will go through all the sinks on the tested cards, and
try to paplay it if the active port is not "not available"

Signed-off-by: Libin Yang <libin.yang@intel.com>
This test case will go through all the sources on the tested cards, and
try to parecord it if the active port is not "not available"

Signed-off-by: Libin Yang <libin.yang@intel.com>
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.

In the test cases, why do we care the interactive shell?

It's often useful to copy/paste to the shell for interactive testing. Anyway that is not the main point: it's just good practice to avoid negations because they require a little bit more reading/review effort. Avoid negations as a good practice also tends to avoid double negations (e.g: if ! nocodec_cmode ) which require even more reading effort for no value. I don't think I would not approve a PR just because of negations (see what I just did?)

I don't why: if I use this such while xxx, the 'available_card' seems to be changed locally and it will remain to 0 out of the loop. So I still keep the original code.

Please try to debug this, "I don't why it does not work" is not acceptable. If you can isolate and reproduce in a small function then share that function and I will debug it.

## Expect result:
## There is at least one available card for test
##

Copy link
Collaborator

Choose a reason for hiding this comment

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

See detailed set -e guidelines in #312

## 1. run pactl to get the cards info
## 2. check the card name
## Expect result:
## There is at least one available card for test
Copy link
Collaborator

Choose a reason for hiding this comment

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

Other user space test cases won't check it and return correctly.

This is wrong, all tests that need an sof card to test should either FAIL or SKIP (exit 2) when there is no SOF card. A test should never return PASS after testing nothing.

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 use "&>dev/null" because error message pactl stat doesn't show explicit information that pactl stat fails. It doesn't help for developer to identity which fails quickly. Instead, I will use dloge to export the useful information for sof-test developer.

  • pactl error messages can be googled. So even when they're really really bad (which I suspect is rare), they are still useful because the reader can very quickly see what command failed: a pactl command.

  • If you think some pactl error message is really bad then feel free to ADD your own message but keep the original pact message too.

  • Last but not least: how can you even know in advance all the possible error messages that this pactl command will produce? Did you read the entire pactl source code? People look at test logs only when something unexpected happened, do you have a complete list of all the unexpected things that can happen?

Never, ever discard stderr, period.

Don't discard stdout either before it has become an actual annoyance. Even in that case it's best to redirect it to a file.

This is test code here, we're not trying to build slick iPhone interfaces. No one looks at test logs unless the tests fail. When tests fail people need and want as much original and googlable information as possible, they absolutely do not want alternative error messages hiding the original messages. No one care about "beautiful" test logs.

@marc-hb
Copy link
Collaborator

marc-hb commented Oct 27, 2020

Can you please start a new PR? This one is overloaded with many comments that don't apply any more.

Please also run pylint on the new Python script. It doesn't have to be completely warning-free but it should have a low enough number.

We don't have a defined policy for formatting python code but I recommend black

@libinyang
Copy link
Contributor Author

try to debug this, "I don't why it does not work" is not

Answer from Google shows: When you pipe into a while loop in Bash, it creates a subshell.
https://stackoverflow.com/questions/4667509/shell-variables-set-inside-while-loop-not-visible-outside-of-it

@libinyang
Copy link
Contributor Author

  • pactl error messages can be googled. So even when they're really really bad (which I suspect is rare), they are still useful because the reader can very quickly see what command failed: a pactl command.
  • If you think some pactl error message is really bad then feel free to ADD your own message but keep the original pact message too.
  • Last but not least: how can you even know in advance all the possible error messages that this pactl command will produce? Did you read the entire pactl source code? People look at test logs only when something unexpected happened, do you have a complete list of all the unexpected things that can happen?

Do we need to understand entire source code when we use the tool? Sorry, I'm surprised to know that. What I think is that we and the user don't need to debug the pactl, pulseaudio tools. So I don't export all the error message to users. When I hide the error message, I don't say the error message is useless. The error message is useful to root cause why pactl stat fails. But we don't want to debug why pactl stat fails, do we? My opinion is to decide whether to show the error message case by case. It's not a good idea to mandate to always show the error messages or never show the error messages.

@libinyang
Copy link
Contributor Author

Can you please start a new PR? This one is overloaded with many comments that don't apply any more.

Sure, I will create a new PR later.

Please also run pylint on the new Python script. It doesn't have to be completely warning-free but it should have a low enough number.

Good suggestion. I will try this tool.

We don't have a defined policy for formatting python code but I recommend black

Sorry, I don't understand black means here. Could you please give a little more hints?

@libinyang
Copy link
Contributor Author

It's often useful to copy/paste to the shell for interactive testing. Anyway that is not the main point: it's just good practice to avoid negations because they require a little bit more reading/review effort. Avoid negations as a good practice also tends to avoid double negations (e.g: if ! nocodec_cmode ) which require even more reading effort for no value. I don't think I would not approve a PR just because of negations (see what I just did?)

Just find if ! mycommand; then ... is a recommend format in https://github.com/koalaman/shellcheck/wiki/SC2181

@libinyang
Copy link
Contributor Author

open a new thread #479 and close this one

@libinyang libinyang closed this Nov 2, 2020
@marc-hb
Copy link
Collaborator

marc-hb commented Nov 5, 2020

Answer from Google shows: When you pipe into a while loop in Bash, it creates a subshell.
https://stackoverflow.com/questions/4667509/shell-variables-set-inside-while-loop-not-visible-outside-of-it

There are a number of ways to solve this: https://mywiki.wooledge.org/BashFAQ/024

See process substitution example in tools/CI/shellcheck-gitrange.bash (commit faadb20)

Sorry, I don't understand black means here. Could you please give a little more hints?

apt-get install black
black something.py # re-formats in place

Just find if ! mycommand; then ... is a recommend format in https://github.com/koalaman/shellcheck/wiki/SC2181

No, that page does not "recommend" this format because that page is about $? which is a different issue. This page uses if ! command because it focuses between the difference between the "bad" and "good" code for the $?
issue and it does not want to distract the page from a much more minor and unrelated codestyle issue.

if ! assert_something; then fail works fine but assert_something || fail is more readable for a number of reasons, most which I already explained a couple times here and there. The main reason is that it reads like plain English ("do or die") and looks more like a C assert. It's also one of the most common shell idioms, try grep -R -F ' || ' /usr/bin/ and see other examples in

https://github.com/koalaman/shellcheck/wiki/SC2164
https://github.com/koalaman/shellcheck/wiki/SC2065
https://github.com/koalaman/shellcheck/wiki/SC2103

https://mywiki.wooledge.org/BashPitfalls#cd_.2Ffoo.3B_bar

Code reviews include both required changed and not required changes, "avoid" negations is not required change, it's general advice to make your submissions easier and faster to review.

set -e is still not used because if it is used, the case will fail to run.

I added detailed guidelines and some tips in #312. If that's not enough for some reason please ask me for help. I think this is very important so I will prioritize it.

@marc-hb
Copy link
Collaborator

marc-hb commented Nov 5, 2020

Do we need to understand entire source code when we use the tool?

Only if you discard stderr. Don't discard stderr if you don't want to have to understand the whole pactl source code.

So I don't export all the error message to users. When I hide the error message, I don't say the error message is useless.

You've seen ONE error message in one situation and you're wrongly assuming pactl has no other error message. The entire purpose of test code is to find as many errors as possible in as many places and situations as possible so considering only "the" one error message you've seen so far makes no sense.

But we don't want to debug why pactl stat fails, do we?

This PR was named "add user space test cases" yet you would do not want to observe and try to understand some unexpected pactl failure?!

It's not a good idea to mandate to always show the error messages or never show the error messages.

Especially for test code yes: it is a "good idea" to never discard stderr except in some extremely rare (and well justified) cases. In fact it's absolutely critical for test code.

The user interface of test code is the exact opposite of the user interface of an iPhone: it has to be 100% transparent so users can totally and immediately see through absolutely everything it does. Users look at test logs ONLY when something unexpected happened and then they want to minimize guessing time as much as possible.

Such complete transparency is even more important when running in CI because it's often difficult to reproduce issues in different environment with no ability to interact directly.

@marc-hb
Copy link
Collaborator

marc-hb commented Nov 5, 2020

The user interface of test code is the exact opposite of the user interface of an iPhone: it has to be 100% transparent so users can totally and immediately see through absolutely everything it does. Users look at test logs ONLY when something unexpected happened and then they want to minimize guessing time as much as possible.

Such complete transparency is even more important when running in CI because it's often difficult to reproduce issues in different environment with no ability to interact directly.

Only one day later here's one example why sof-test should be as close as possible to interactive commands : #495 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants