From d66cdaff21858bf1345875fe8e7a47700cbcfd20 Mon Sep 17 00:00:00 2001 From: Srikanth Muppandam Date: Thu, 16 Oct 2025 10:19:52 +0530 Subject: [PATCH 1/2] init_env: centralize stdout/stderr capture for all tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add optional global tee capture controlled by RUN_STDOUT_ENABLE/… env vars. - Create timestamped (under or ROOT_DIR/logs). - Export the same file so child run.sh scripts append to one unified log. - Install trap to restore FDs on exit; idempotent guard prevents double-capture. Signed-off-by: Srikanth Muppandam --- Runner/init_env | 61 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/Runner/init_env b/Runner/init_env index 2dc8b4c..b49a59a 100755 --- a/Runner/init_env +++ b/Runner/init_env @@ -43,7 +43,10 @@ export __RUNNER_UTILS_BIN_DIR="$ROOT_DIR/common" # --- Ensure TOOLS is usable in all shells --- case ":$PATH:" in *":$TOOLS:"*) : ;; - *) PATH="$TOOLS:$PATH"; export PATH ;; + *) + PATH="$TOOLS:$PATH" + export PATH + ;; esac # --- Optional: pre-check for required tools (safe no-op for minimal builds) --- @@ -51,3 +54,59 @@ if [ -f "$TOOLS/functestlib.sh" ]; then # shellcheck disable=SC1090,SC1091 . "$TOOLS/functestlib.sh" >/dev/null 2>&1 || true fi + +############################################################################### +# Stdout/stderr capture (per-test folder) +# +# Controls (set BEFORE sourcing this file): +# RUN_STDOUT_ENABLE = 1 | 0 (default: 1) +# RUN_STDOUT_TAG = (default: basename of $PWD) +# RUN_STDOUT_FILE = (default: $PWD/_stdout_.log) +# +# Behavior: +# - Writes the capture file into the CURRENT DIRECTORY (usually the test dir). +# - No global logs/stdout directory is created/used. +############################################################################### +_runner_stdout_cleanup() { + st=$? + # restore original fds (if they were saved) + exec 1>&3 2>&4 + if [ -n "${__TEE_PID:-}" ]; then + kill "$__TEE_PID" 2>/dev/null + fi + if [ -n "${PIPE:-}" ]; then + rm -f "$PIPE" 2>/dev/null + fi + exit "$st" +} + +if [ "${RUN_STDOUT_ENABLE:-1}" -eq 1 ] && [ -z "${__RUN_STDOUT_ACTIVE:-}" ]; then + _tag="${RUN_STDOUT_TAG:-$(basename "$(pwd)")}" + _ts="$(date +%Y%m%d-%H%M%S)" + RUN_STDOUT_FILE="${RUN_STDOUT_FILE:-$(pwd)/${_tag}_stdout_${_ts}.log}" + export RUN_STDOUT_FILE + + # Save original stdout/stderr + exec 3>&1 4>&2 + + if command -v tee >/dev/null 2>&1; then + PIPE="$(mktemp -u "/tmp/stdout_pipe.XXXXXX")" + if mkfifo "$PIPE" 2>/dev/null; then + ( tee -a "$RUN_STDOUT_FILE" >&3 ) < "$PIPE" & + __TEE_PID=$! + exec > "$PIPE" 2>&1 + __RUN_STDOUT_ACTIVE=1 + trap _runner_stdout_cleanup EXIT INT TERM + else + # Fallback: file-only capture + exec >> "$RUN_STDOUT_FILE" 2>&1 + __RUN_STDOUT_ACTIVE=1 + trap _runner_stdout_cleanup EXIT INT TERM + fi + else + # Fallback: file-only capture + exec >> "$RUN_STDOUT_FILE" 2>&1 + __RUN_STDOUT_ACTIVE=1 + trap _runner_stdout_cleanup EXIT INT TERM + fi +fi From 163182b2f819e5a71f833709f020d4ea1b6bc250 Mon Sep 17 00:00:00 2001 From: Srikanth Muppandam Date: Thu, 16 Oct 2025 10:20:15 +0530 Subject: [PATCH 2/2] run-test.sh: inherit unified stdout capture from init_env - Source ./init_env first so global tee is activated once per session. - Remove any per-script capture logic; rely on exported RUN_STDOUT_FILE. - Ensure child ./run.sh inherits the environment unchanged (no semantic changes). - Minor cleanup to avoid duplicate env setup; logging remains via functestlib. Signed-off-by: Srikanth Muppandam --- Runner/run-test.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Runner/run-test.sh b/Runner/run-test.sh index 4ff2964..f675fd3 100755 --- a/Runner/run-test.sh +++ b/Runner/run-test.sh @@ -9,6 +9,10 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" # Set TOOLS path to utils under the script directory TOOLS="$SCRIPT_DIR/utils" +# Disable wrapper-level capture; each test will capture in its own folder +export RUN_STDOUT_ENABLE=0 +unset RUN_STDOUT_TAG RUN_STDOUT_FILE + # Safely source init_env from the same directory as this script if [ -f "$SCRIPT_DIR/init_env" ]; then # shellcheck source=/dev/null @@ -46,7 +50,11 @@ execute_test_case() { run_script="$test_path/run.sh" if [ -f "$run_script" ]; then log "Executing test case: $test_name" - (cd "$test_path" && sh "./run.sh" "$@") + ( + cd "$test_path" || exit 2 + # Enable per-test capture in the test folder with a clear tag + RUN_STDOUT_ENABLE=1 RUN_STDOUT_TAG="$test_name" sh "./run.sh" "$@" + ) res_file="$test_path/$test_name.res" if [ -f "$res_file" ]; then if grep -q "SKIP" "$res_file"; then @@ -131,7 +139,8 @@ Usage: Notes: - Extra args are forwarded only when a single is specified. - 'all' runs every test and does not accept additional args. - - Use -h or --help to display this message. + - Each test captures stdout/stderr next to its .res file as: + _stdout_.log EOF }