test/common: Free stderr fd from tracing
Consider this: foo() { echo bar >&2 ; } set -x foobar=$(foo 2>&1) [[ $foobar == "bar" ]] The above test will fail since $foobar will also include tracing strings as stderr is where set -x redirects the output. Since in some cases this may troublesome, replace stderr with a dedicated fd allocated dynamically. Signed-off-by: Michal Berger <michalx.berger@intel.com> Change-Id: Ia6609e4463b371c07fab42d2bd291c9e43742df5 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8158 Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
70f7ea3e30
commit
c2feee4fef
@ -1,5 +1,16 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
function xtrace_fd() {
|
||||||
|
if [[ -n $BASH_XTRACEFD && -e /proc/self/fd/$BASH_XTRACEFD ]]; then
|
||||||
|
# Close it first to make sure it's sane
|
||||||
|
exec {BASH_XTRACEFD}>&-
|
||||||
|
fi
|
||||||
|
exec {BASH_XTRACEFD}>&2
|
||||||
|
|
||||||
|
set -x
|
||||||
|
echo "Tracing to $BASH_XTRACEFD FD"
|
||||||
|
}
|
||||||
|
|
||||||
function xtrace_disable() {
|
function xtrace_disable() {
|
||||||
if [ "$XTRACE_DISABLED" != "yes" ]; then
|
if [ "$XTRACE_DISABLED" != "yes" ]; then
|
||||||
PREV_BASH_OPTS="$-"
|
PREV_BASH_OPTS="$-"
|
||||||
@ -1388,7 +1399,7 @@ if $SPDK_AUTOTEST_X; then
|
|||||||
# explicitly enable xtraces, overriding any tracking information.
|
# explicitly enable xtraces, overriding any tracking information.
|
||||||
unset XTRACE_DISABLED
|
unset XTRACE_DISABLED
|
||||||
unset XTRACE_NESTING_LEVEL
|
unset XTRACE_NESTING_LEVEL
|
||||||
set -x
|
xtrace_fd
|
||||||
xtrace_enable
|
xtrace_enable
|
||||||
else
|
else
|
||||||
xtrace_restore
|
xtrace_restore
|
||||||
|
Loading…
Reference in New Issue
Block a user