[nexus] only print logs for failed tests in run_nexus_tests.sh (#12502)

This commit updates run_nexus_tests.sh to improve the readability
and utility of test execution:
- Capture test execution output in a log file.
- Only print the captured logs if the test fails.
- Provide a concise one-line status (PASSED/FAILED) for each test.
- Automatically clean up temporary work directories for passing tests.
- Preserve artifacts (PCAP, JSON, logs) for failed tests and print
  the path to the preserved artifacts.
This commit is contained in:
Jonathan Hui
2026-02-19 19:54:26 -06:00
committed by GitHub
parent be867deea6
commit 9a525c46e4
+10 -12
View File
@@ -145,10 +145,6 @@ run_test()
local verify_script="${REPO_ROOT}/tests/nexus/verify_${test_base}.py"
local nexus_bin="${NEXUS_BIN_DIR}/${test_name}"
printf "========================================================================================\n"
printf "Running %s...\n" "$test_full"
printf "========================================================================================\n"
if [[ ! -x $nexus_bin ]]; then
printf "Error: %s not found or not executable in %s. Did you build the tests?\n" "$test_name" "$NEXUS_BIN_DIR" >&2
return 1
@@ -157,6 +153,9 @@ run_test()
# Create a temporary directory for test artifacts
local work_dir
work_dir=$(mktemp -d "${TEMP_DIR}/nexus_test_${test_full}.XXXXXX")
local log_file="${work_dir}/test.log"
printf "Running %-40s... " "$test_full"
# Run the Nexus C++ test and verification in a subshell to isolate the working directory
(
@@ -182,24 +181,23 @@ run_test()
printf "Verification for %s FAILED\n" "$test_full" >&2
exit 1
fi
else
printf "\n"
printf "No verification script found for %s (%s), skipping verification.\n" "$test_full" "$verify_script"
fi
)
) >"$log_file" 2>&1
local exit_code="$?"
if [[ $exit_code -eq 0 ]]; then
printf "\n"
printf "%s PASSED\n" "$test_full"
printf " PASSED\n"
if [[ -d $work_dir && $work_dir == "${TEMP_DIR}/"* ]]; then
rm -rf "$work_dir"
fi
return 0
else
printf "\n"
printf "%s FAILED. Artifacts preserved in: %s\n" "$test_full" "$work_dir" >&2
printf " FAILED\n"
printf "========================================================================================\n"
cat "$log_file"
printf "========================================================================================\n"
printf "Artifacts preserved in: %s\n" "$work_dir"
return 1
fi
}