tests: regression: separate bash traces from errors

The BASH_XTRACEFD variable can be used to redirect "set -x" traces
to a dedicated file. We can use it to split the execution trace
(what has actually happened) from the failure messages.

On a failing test this does provide improved clarity when debugging
interactively with "spread -debug". On non-interactive runs the now
shorter error list is also implicitly printed.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
This commit is contained in:
Zygmunt Krynicki 2025-01-10 11:52:16 +01:00
parent cd8b75abc0
commit 2c2e0478f8

View file

@ -104,12 +104,13 @@ environment:
artifacts: artifacts:
- bash.log - bash.log
- bash.err - bash.err
- bash.trace
execute: | execute: |
# Run the shell script that is named after the spread variant we are running # Run the shell script that is named after the spread variant we are running
# now. The makefile runs them all sequentially via the "alltests" goal. Here # now. The makefile runs them all sequentially via the "alltests" goal. Here
# we can parallelize it through spread and also have a way to run precisely # we can parallelize it through spread and also have a way to run precisely
# the test we want, especially for debugging. # the test we want, especially for debugging.
if ! bash -x "$SPREAD_VARIANT".sh >bash.log 2>bash.err; then if ! BASH_XTRACEFD=42 bash -x "$SPREAD_VARIANT".sh >bash.log 2>bash.err 42>bash.trace; then
for xfail in ${XFAIL:-}; do for xfail in ${XFAIL:-}; do
if [ "$SPREAD_SYSTEM" = "$xfail" ]; then if [ "$SPREAD_SYSTEM" = "$xfail" ]; then
echo "Ignoring expected failure of $SPREAD_TASK on $SPREAD_SYSTEM" echo "Ignoring expected failure of $SPREAD_TASK on $SPREAD_SYSTEM"
@ -118,13 +119,17 @@ execute: |
done done
echo "Test $SPREAD_VARIANT has unexpectedly failed" echo "Test $SPREAD_VARIANT has unexpectedly failed"
echo "Test execution logs are in the files bash.{log.err} and are collected as artifacts" echo "Test execution logs are in the files bash.{log,err,trace} and are collected as artifacts"
echo "Bash errors are listed below:"
cat bash.err
exit 1 exit 1
else else
for xfail in ${XFAIL:-}; do for xfail in ${XFAIL:-}; do
if [ "$SPREAD_SYSTEM" = "$xfail" ]; then if [ "$SPREAD_SYSTEM" = "$xfail" ]; then
echo "Test $SPREAD_VARIANT has unexpectedly passed" echo "Test $SPREAD_VARIANT has unexpectedly passed"
echo "Test execution logs are in the files bash.{log.err} and are collected as artifacts" echo "Test execution logs are in the files bash.{log,err,trace} and are collected as artifacts"
echo "Bash errors are listed below:"
cat bash.err
exit 1 exit 1
fi fi
done done