-
Notifications
You must be signed in to change notification settings - Fork 59
[SKIP SOF-TEST] test-case: Add ALSA conformance tests #1281
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
[SKIP SOF-TEST] test-case: Add ALSA conformance tests #1281
Conversation
2768492 to
3585cb9
Compare
|
SOFCI TEST |
lyakh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! Just a couple of cosmetic remarks / questions
3585cb9 to
cfa3b3d
Compare
|
@lyakh, thank you, your comments are addressed, please check. |
cfa3b3d to
e189697
Compare
test-case/check-alsa-conformance.sh
Outdated
| skip_test "Neither playback, nor capture ALSA PCM is specified." | ||
| else | ||
| PLAYBACK_OPTIONS=$([ -n "${pcm_p}" ] && echo "-P ${pcm_p}" || echo "") | ||
| CAPTURE_OPTIONS=$([ -n "${pcm_c}" ] && echo "-C ${pcm_c}" || echo "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is OK but it's not good "role-modelling" because a && b || c is NOT equivalent to if a; then b; else c; fi
See difference explained in #312
EDIT: also, echo "" does nothing so why use it?
test-case/check-alsa-conformance.sh
Outdated
| local run_cmd="${ALSA_CONFORMANCE_TEST} ${PLAYBACK_OPTIONS} ${CAPTURE_OPTIONS} --dev_info_only" | ||
| dlogc "${run_cmd}" | ||
| local rc | ||
| bash -c "${run_cmd}" ; rc=$? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks convoluted, why not just:
${run_cmd} || die ...Is this done to expand OPTIONS? Then run_cmd should really be a bash array.
Long and complex strings are an absolute quoting and debugging nightmare in bash and must always be replaced by arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marc-hb, thank you for your comments, I think all are addressed, except this one.
I'd keep it this way (calling from another bash) for these reasons:
- in case we later need to call the test command with timeout.
- to compose OPTIONS with multiple values (-T, -r, -F)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I don't see why
timeout ... "${run_cmd[@]}"would not work - "composing" sounds even more risky = needing arrays even more
- Whatever the reasons are, they definitely deserve a comment in the source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I've managed to change it to arrays. Nice exercise.
test-case/check-alsa-conformance.sh
Outdated
| pcm_p=${OPT_VAL['p']} | ||
| pcm_c=${OPT_VAL['c']} | ||
| rates=$([ -z "${OPT_VAL['r']}" ] && echo '' || echo "--allow-rates ${OPT_VAL['r']}") | ||
| formats=$([ -z "${OPT_VAL['F']}" ] && echo '' || echo "--allow-formats ${OPT_VAL['F']}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The echo '' is not needed.
rates=$([ -z "${OPT_VAL['r']}" ] || echo "--allow-rates ${OPT_VAL['r']}")Also, this repetition is calling for some new prefix_if_not_empty() and prefix_if_1() functions. I know they would be useful outside this new script.
formats=$(prefix_if_not_empty --allow-formats "${OPT_VAL['F']}")e189697 to
91bdb4c
Compare
cf89c0c to
9fecb79
Compare
9fecb79 to
34b33eb
Compare
|
13/Jul/2025 PCMs selection for the test run is extended - now it is possible to
|
test-case/check-alsa-conformance.sh
Outdated
| do | ||
| mapfile -t p_dev_expanded < <(get_card_devices 'playback' "${p_dev}") | ||
| # shellcheck disable=SC2206 | ||
| PLAYBACK_DEVICES+=( ${p_dev_expanded[@]} ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have an example of why this is not:
| PLAYBACK_DEVICES+=( ${p_dev_expanded[@]} ) | |
| PLAYBACK_DEVICES+=( "${p_dev_expanded[@]}" ) |
(that's a LOT of disable=SC2206...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, here it is not needed
34b33eb to
11602d5
Compare
marc-hb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I keep finding minor problems but that's because the code keep changing :-)
| elif [ "${mode}" == 'capture' ]; then | ||
| alsa_list=('arecord' '-l') | ||
| else | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a failure? A dlogi maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will be logged at the caller side as empty devices whereas any dlogi will mess the expected list of devices
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry I read too fast and missed the output was on stdout. A comment at the top of the function would not hurt ;-)
You could still:
- log to stderr
- return 1
- both
None of these would disrupt the caller - and it would give it more information. That it can choose to use or ignore.
| run_cmd+=("--json-file" "${AUDIOTEST_OUT}_${mode}.json") | ||
| dlogc "${run_cmd[@]}" | ||
| local rc=0 | ||
| "${run_prefix[@]}" && "${run_cmd[@]}" || rc=$? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is correct but it's really tricky; not for the faint of heart.
Too many people think A && B || CC is the same as if A; then B; else C; fi and that they can save typing 15 characters that way. But it's not the same! (#312)
# Generally NOT what you want!
true && false || echo 'else_is_also_run!!'
HOWEVER, I think this example is correct but it is in any case way too subtle and bad role-modelling IMHO.
There are (at least) two better ways:
| "${run_prefix[@]}" && "${run_cmd[@]}" || rc=$? | |
| "${run_prefix[@]}" # export can hardly fail | |
| "${run_cmd[@]}" || rc=$? |
Maybe simpler and better IMHO: you don't need run_prefix at all if the current process does not need to be affected:
| "${run_prefix[@]}" && "${run_cmd[@]}" || rc=$? | |
| "PATH=${ALSA_CONFORMANCE_PATH}:${PATH}" "${run_cmd[@]}" || rc=? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried it with different combinations. And the prefix part is to make clear/shorter separation of what is the preparational part (eg. other env. variables).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the name matters, then you can likely just do something like this:
run_prefix="PATH=${ALSA_CONFORMANCE_PATH}:${PATH}"
"${run_prefix}" "${run_cmd[@]}" || rc=$?
or
run_prefix=(PATH="${ALSA_CONFORMANCE_PATH}:${PATH}" FOO=bar)
"${run_prefix[@]}" "${run_cmd[@]}" || rc=$?
yeah, I need to use this test already, so it evolves while in review .. |
test-case/check-alsa-conformance.sh
Outdated
| local gawk_script='match($0, /^card [0-9]+: ('"${arg_pcm}"') .+ device ([0-9]+): /, arr) { print "hw:" arr[1] "," arr[2] }' | ||
| mapfile -t res_devs < <( "${alsa_list[@]}" | gawk "${gawk_script}" ) | ||
| fi | ||
| echo "${res_devs[@]}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For anything non trivial I would always prefer printf
https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo
Not ideal but typical for brand new tests and other big changes. Actually, I had my own requests in mind and not this but it's probably both :-)
To be clear: this is IMHO good enough to merge. As a brand new test, it cannot regress anything :-) On other hand, "fix later" == "fix never" more often than not.... |
11602d5 to
c08c26c
Compare
c08c26c to
6543ac6
Compare
Add ALSA conformance tests from ChromeOS Audio Test package. The new test case `check-alsa-conformance.sh` executes `alsa_conformnance_test` and compose its results into a JSON file. Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
6543ac6 to
3565cbc
Compare
|
15/Jul/2025 with some comments addressed, and 3 new optional parameters ( |
|
merged as no objections and to enable this new test case on CI |
Add ALSA conformance tests from ChromeOS Audio Test package.
The new test case
check-alsa-conformance.shexecutesalsa_conformnance_testand compose its results into a JSON file.