Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion Runner/init_env
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,70 @@ 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) ---
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 = <string> (default: basename of $PWD)
# RUN_STDOUT_FILE = <path> (default: $PWD/<tag>_stdout_<ts>.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
13 changes: 11 additions & 2 deletions Runner/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -131,7 +139,8 @@ Usage:
Notes:
- Extra args are forwarded only when a single <testcase_name> 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:
<testname>_stdout_<timestamp>.log
EOF
}

Expand Down
Loading