From: Kienan Stewart Date: Wed, 8 Jan 2025 14:22:02 +0000 (-0500) Subject: Tests: Support redirection to identical stderr/stdout in`_run_lttng_cmd` X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d3d763c4b4fe5f201cf5c9108f14ce0421f170e8;p=lttng-tools.git Tests: Support redirection to identical stderr/stdout in`_run_lttng_cmd` Observed issue ============== `tests/regression/kernel/test_userspace_probe` fails with the following error: ``` Bail out! The current `_run_lttng_cmd` implementation does not support redirecting stdout and stderr to the same file. ``` Cause ===== The commit aae350f3c2ac878227bae41281e7abca65e33c0f ("Tests: Add path check to prevent incorrect redirection") introduces a safety check to bail out if the same stderr and stdout file are used in `_run_lttng_cmd`. This avoids some foot-gun scenarios where output is expected in a file from both, but the implementation didn't actually support it. E.g., ``` $ (echo stderr >&1 ; echo stdout) > /tmp/a 2>/tmp/a $ cat /tmp/a stdout $ (echo stderr >&1 ; echo stdout) > /tmp/a 2>&1 $ cat /tmp/a stderr stdout ``` There has been a number of changes to both `_run_lttng_cmd` for logging, and it's common for both `stdout_dest` and `stderr_dest` to be set (usually to `/dev/null`). In particular, this check ends up being triggered in `tests/regression/kernel/test_userspace_probe`: ``` 1..175 # Userspace probe - Testing userspace probe on ELF symbol ok 1 - 0 LTTng modules loaded, expected count = 0 # export LTTNG_SESSION_CONFIG_XSD_PATH=/root/workspace/lttng-tools_master_root_slesbuild/babeltrace_version/stable-2.0/build/std/conf/agents/liburcu_version/stable-0.14/node/sles15sp4-amd64-rootnode/platform/sles15sp4-amd64/src/lttng-tools/tests/../src/common/ # env /root/workspace/lttng-tools_master_root_slesbuild/babeltrace_version/stable-2.0/build/std/conf/agents/liburcu_version/stable-0.14/node/sles15sp4-amd64-rootnode/platform/sles15sp4-amd64/src/lttng-tools/tests/../src/bin/lttng-sessiond/lttng-sessiond --consumerd64-path=/root/workspace/lttng-tools_master_root_slesbuild/babeltrace_version/stable-2.0/build/std/conf/agents/liburcu_version/stable-0.14/node/sles15sp4-amd64-rootnode/platform/sles15sp4-amd64/src/lttng-tools/tests/../src/bin/lttng-consumerd/lttng-consumerd 1 ok 2 - Start session daemon # Userspace probe enable on non-existant file # Killing (signal SIGTERM) lttng-sessiond and lt-lttng-sessiond pids: 18167 18182 Bail out! The current `_run_lttng_cmd` implementation does not support redirecting stdout and stderr to the same file. # Looks like you planned 175 tests but only ran 2. ``` Solution ======== Add support for invoking `_run_lttng_cmd` with the same stderr and stdout destinations. Known drawbacks =============== None. Change-Id: I9133ccfd1f524000dbf02dfc05730feca1c59ab7 Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau --- diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 9daaa03c9..bd0d95d38 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -521,12 +521,6 @@ function _run_lttng_cmd local stderr_dest="$2" shift 2 - if [ "$stdout_dest" = "$stderr_dest" ]; then - # The redirection of stderr would overwrite the redirection of - # stdout. We cannot proceed. - LTTNG_BAIL_OUT "The current \`_run_lttng_cmd\` implementation does not support redirecting stdout and stderr to the same file." - fi - opts=("${@}") if [[ -n "${LTTNG_TEST_VERBOSE_CLIENT}" ]] ; then opts=('-vvv' "${opts[@]}") @@ -534,7 +528,11 @@ function _run_lttng_cmd diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN ${opts[*]}" if [[ -n "${stdout_dest}" ]] && [[ -n "${stderr_dest}" ]] ; then - $TESTDIR/../src/bin/lttng/$LTTNG_BIN "${opts[@]}" >"${stdout_dest}" 2>"${stderr_dest}" + if [[ "${stdout_dest}" == "${stderr_dest}" ]] ; then + $TESTDIR/../src/bin/lttng/$LTTNG_BIN "${opts[@]}" >"${stdout_dest}" 2>&1 + else + $TESTDIR/../src/bin/lttng/$LTTNG_BIN "${opts[@]}" >"${stdout_dest}" 2>"${stderr_dest}" + fi elif [[ -n "${stdout_dest}" ]] && [[ -z "${stderr_dest}" ]]; then $TESTDIR/../src/bin/lttng/$LTTNG_BIN "${opts[@]}" >"${stdout_dest}" elif [[ -z "${stdout_dest}" ]] && [[ -n "${stderr_dest}" ]] ; then