Skip to content

Commit

Permalink
Script output logging for e2e tests (#306)
Browse files Browse the repository at this point in the history
* Script logging for e2e tests

Signed-off-by: Rado Chmiel <[email protected]>

* Update testing.sh

* Update testing.sh

* Update testing.sh

* Provide fallback location for ARTIFACTS var

---------

Signed-off-by: Rado Chmiel <[email protected]>
  • Loading branch information
radoslawc authored Oct 2, 2024
1 parent 12ba88f commit e1c87b2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions e2e/lib/testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# shellcheck source=e2e/lib/_utils.sh
source "${E2EDIR:-$HOME/test-infra/e2e}/lib/_utils.sh"

LOG_DIR="$HOME/log/e2e"

function _get_test_metadata {
local testfile=$1
local fieldname=$2
Expand All @@ -31,14 +33,25 @@ function run_test {
if [ -f "/sys/class/net/$mgmt_nic/statistics/rx_bytes" ]; then
int_rx_bytes_before=$(cat "/sys/class/net/$mgmt_nic/statistics/rx_bytes")
fi
mkdir -p "$LOG_DIR"
local log_file="$LOG_DIR/$(sed 's/ /_/g' <<< "$testname").log"
info "+++++ starting $testfile $testname"
info "+++++ logging into $log_file"
local rc=0
/bin/bash "$testfile" || rc=$?
# Run the test script logging stdout/stderr to log file
/bin/bash "$testfile" > >(tee -a "$log_file") 2>&1 || rc=$?
local result="PASS"
if [[ $rc != 0 ]]; then
result="FAIL ($rc)"
fi

# Append the result to log file as well
echo "$result" | tee -a "$log_file"
# ARTIFACTS variable should be set by Prow, fallback if it is not
ARTIFACTS="${ARTIFACTS:-$HOME/artifacts}"
mkdir -p "$ARTIFACTS"
# Copy log file to Prow storage
cp "$log_file" "$ARTIFACTS/"

info "+++++ finished $testfile $testname (result: $result)"
local seconds="$(($(date +%s) - int_start))"
printf "TIME $(basename $testfile): %s secs\n" $seconds
Expand Down

0 comments on commit e1c87b2

Please sign in to comment.