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

tests: fix bug: lack of option sof-logger in tests #1251

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arikgreen
Copy link

@arikgreen arikgreen commented Feb 6, 2025

Add option -s (sof-logger) to tests for fix issue
sof-test/case-lib/lib.sh: line 955: [: -eq: unary operator expected

# Disable logging when available...
if [ ${OPT_VAL['s']} -eq 0 ]; then
    return 0
fi

before fix: run
after fix: run

@arikgreen arikgreen requested a review from a team as a code owner February 6, 2025 15:48
@marc-hb
Copy link
Collaborator

marc-hb commented Feb 6, 2025

Duplicating the same -s code in every test is not very "scalable", it wasn't a good design in the first place.

Have you considered using SOF_LOGGING == 'none' instead?

Also, maybe that code could be moved to case-lib/lib.sh.

if [ ${OPT_VAL['s']} -eq 0 ]; then [: -eq: unary operator expected

This is missing quotes BTW, it should be:

if [ "${OPT_VAL['s']}" -eq 0 ]; then

shellcheck should tell us that.

@lgirdwood
Copy link
Member

@arikgreen any update for review comments ?

@arikgreen
Copy link
Author

Duplicating the same -s code in every test is not very "scalable", it wasn't a good design in the first place.

Have you considered using SOF_LOGGING == 'none' instead?

Also, maybe that code could be moved to case-lib/lib.sh.

Yes, you right duplicate same code isn't good technic. Maybe it is a right time to fix it and move the code to the lib.sh.
I prepare the fix.

@arikgreen
Copy link
Author

@arikgreen any update for review comments ?

sorry for late but I was sick for last week.

@arikgreen arikgreen added the DNM Do not merge label Feb 18, 2025
Fix for:
```
/home/ubuntu/sof-test/test-case/../case-lib/lib.sh: line 955:
[: -eq: unary operator expected
```

Signed-off-by: Artur Wilczak <[email protected]>
@arikgreen arikgreen force-pushed the arikgreen/fix-sof-logger-opt-val-issue branch from 3256720 to 2cd5085 Compare February 18, 2025 13:55
@arikgreen
Copy link
Author

@marc-hb I decided implement a better quick fix

@arikgreen arikgreen removed the DNM Do not merge label Feb 18, 2025
@arikgreen arikgreen requested a review from marc-hb February 18, 2025 14:43
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.

LGTM but I think there's a less subtle way.

Also, the PR description is now completely out of date with the commit message (that's because of the unusual "force-push" way SOF uses GitHub zephyrproject-rtos/zephyr#39194 - I digress)

@@ -952,7 +952,7 @@ is_ipc4()
logger_disabled()
{
# Disable logging when available...
if [ ${OPT_VAL['s']} -eq 0 ]; then
if [[ ${OPT_VAL['s']} -eq 0 ]]; then
Copy link
Collaborator

@marc-hb marc-hb Feb 18, 2025

Choose a reason for hiding this comment

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

That difference between [ ] and [[ ]] is too subtle IMHO, I think most people won't know it. You could just do this instead: Wrong suggestion, see below.

Suggested change
if [[ ${OPT_VAL['s']} -eq 0 ]]; then
if [ "${OPT_VAL['s']}" = 0 ]; then

Copy link
Collaborator

@marc-hb marc-hb Feb 18, 2025

Choose a reason for hiding this comment

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

This should be correct but please test it:

Suggested change
if [[ ${OPT_VAL['s']} -eq 0 ]]; then
if [ -n "${OPT_VAL['s']}" ] && [ "${OPT_VAL['s']}" -eq 0 ]; then

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.

Actually, your [[ ]] solution and my = solution are both wrong.

  • All tests that support the -s flag have OPT_VAL['s'] equals to 1 by default. Because the default is to collect logs when you don't pass -s (sorry for the double and triple negations, not all of them sof-test's fault)

  • Tests that do NOT support -s flag and have OPT_VAL['s'] undefined must of course consistently default to collecting logs too.

So, undefined OPT_VAL['s'] must be equivalent to OPT_VAL['s'] = 1: both must collect logs by default. The current code emits an ugly -eq warning but it is functionally correct.

Both the [[ ]] solution and my = solution make undefined equivalent to 0, which stops collecting logs and hides errors in tests that do not support -s. It would unfortunately not be the first time:

How did you test this?

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.

3 participants