|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Runs the Core Profile REST TCK runner with a 30-minute timeout, then parses |
| 3 | +# the failsafe XML reports and writes all failing test identifiers to |
| 4 | +# failing_test_coreprofile_rest_tck.txt in the workspace root. |
| 5 | +# |
| 6 | +# Usage: |
| 7 | +# ./scripts/coreprofile_rest_tck.sh [timeout_seconds] |
| 8 | +# |
| 9 | +# Examples: |
| 10 | +# ./scripts/coreprofile_rest_tck.sh # default 3-hour timeout |
| 11 | +# ./scripts/coreprofile_rest_tck.sh 3600 # 1-hour timeout |
| 12 | +# |
| 13 | +# To re-run a single failing test afterwards: |
| 14 | +# cd test/tck/coreprofile/rest/runner |
| 15 | +# mvn verify -Dit.test="ClassName#methodName" |
| 16 | + |
| 17 | +set -uo pipefail |
| 18 | + |
| 19 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 20 | +RUNNER_DIR="$SCRIPT_DIR/../test/tck/coreprofile/rest/runner" |
| 21 | +REPORTS_DIR="$RUNNER_DIR/target/failsafe-reports" |
| 22 | +OUTPUT_FILE="$SCRIPT_DIR/coreprofile_rest_tck.txt" |
| 23 | +TIMEOUT_SECONDS="${1:-10800}" # default: 3 hours |
| 24 | + |
| 25 | +echo "=========================================" |
| 26 | +echo " Core Profile REST TCK Runner" |
| 27 | +echo " Timeout: ${TIMEOUT_SECONDS}s (3 hours)" |
| 28 | +echo "=========================================" |
| 29 | +echo "" |
| 30 | + |
| 31 | +# Run Maven with a timeout; -fae keeps going after failures so all reports |
| 32 | +# are generated even when individual tests fail. |
| 33 | +echo "Starting: mvn verify -fae" |
| 34 | +echo "" |
| 35 | + |
| 36 | +# Use a background process + timeout guard so we can kill the whole Maven |
| 37 | +# process tree if the deadline is reached. |
| 38 | +mvn verify -fae -f "$RUNNER_DIR/pom.xml" & |
| 39 | +MVN_PID=$! |
| 40 | + |
| 41 | +# Wait up to TIMEOUT_SECONDS for Maven to finish naturally. |
| 42 | +ELAPSED=0 |
| 43 | +INTERVAL=5 |
| 44 | +TIMED_OUT=0 |
| 45 | + |
| 46 | +while kill -0 "$MVN_PID" 2>/dev/null; do |
| 47 | + sleep $INTERVAL |
| 48 | + ELAPSED=$((ELAPSED + INTERVAL)) |
| 49 | + if (( ELAPSED >= TIMEOUT_SECONDS )); then |
| 50 | + echo "" |
| 51 | + echo "WARN: Timeout of ${TIMEOUT_SECONDS}s reached — killing Maven process tree..." |
| 52 | + # Kill the entire process group so forked JVMs are also terminated. |
| 53 | + kill -- -"$MVN_PID" 2>/dev/null || kill "$MVN_PID" 2>/dev/null || true |
| 54 | + TIMED_OUT=1 |
| 55 | + break |
| 56 | + fi |
| 57 | +done |
| 58 | + |
| 59 | +# Reap the background process (ignore its exit code; we care about reports). |
| 60 | +wait "$MVN_PID" 2>/dev/null || true |
| 61 | + |
| 62 | +echo "" |
| 63 | +if (( TIMED_OUT )); then |
| 64 | + echo "NOTE: TCK was stopped after ${TIMEOUT_SECONDS}s. Parsing partial results." |
| 65 | +else |
| 66 | + echo "TCK run finished after ${ELAPSED}s. Parsing results." |
| 67 | +fi |
| 68 | +echo "" |
| 69 | + |
| 70 | +# ---- Parse failsafe XML reports ---------------------------------------- |
| 71 | +if [[ ! -d "$REPORTS_DIR" ]]; then |
| 72 | + echo "ERROR: No failsafe reports found at $REPORTS_DIR" |
| 73 | + exit 1 |
| 74 | +fi |
| 75 | + |
| 76 | +python3 - "$REPORTS_DIR" "$OUTPUT_FILE" <<'PYEOF' |
| 77 | +import sys |
| 78 | +import os |
| 79 | +import xml.etree.ElementTree as ET |
| 80 | +
|
| 81 | +reports_dir = sys.argv[1] |
| 82 | +output_file = sys.argv[2] |
| 83 | +
|
| 84 | +failing = [] |
| 85 | +
|
| 86 | +for fname in sorted(os.listdir(reports_dir)): |
| 87 | + if not (fname.startswith("TEST-") and fname.endswith(".xml")): |
| 88 | + continue |
| 89 | + path = os.path.join(reports_dir, fname) |
| 90 | + try: |
| 91 | + tree = ET.parse(path) |
| 92 | + except ET.ParseError as e: |
| 93 | + print(f" WARN: could not parse {fname}: {e}", file=sys.stderr) |
| 94 | + continue |
| 95 | + root = tree.getroot() |
| 96 | + for tc in root.findall("testcase"): |
| 97 | + if tc.find("failure") is not None or tc.find("error") is not None: |
| 98 | + classname = tc.get("classname", "") |
| 99 | + name = tc.get("name", "") |
| 100 | + failing.append(f"{classname}#{name}") |
| 101 | +
|
| 102 | +with open(output_file, "w") as f: |
| 103 | + for t in failing: |
| 104 | + f.write(t + "\n") |
| 105 | +
|
| 106 | +print(f"Found {len(failing)} failing test(s). Written to {output_file}") |
| 107 | +PYEOF |
0 commit comments