Skip to content

Commit cdc4150

Browse files
authored
Fix benchmark failure cases (#27)
1 parent 164e3e7 commit cdc4150

2 files changed

Lines changed: 72 additions & 10 deletions

File tree

.github/workflows/tilegym-ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,12 @@ jobs:
288288
(needs.build.result == 'success' || needs.build.result == 'skipped')
289289
runs-on: linux-amd64-gpu-rtxpro6000-latest-1
290290
steps:
291-
- name: Checkout code (sparse - only need formatting script)
291+
- name: Checkout code (sparse - need scripts and benchmarks)
292292
uses: actions/checkout@v4
293293
with:
294294
sparse-checkout: |
295295
.github/scripts/format_benchmark_summary.py
296+
tests/benchmark
296297
sparse-checkout-cone-mode: false
297298

298299
- name: Create test results directory
@@ -314,6 +315,7 @@ jobs:
314315
docker pull ${IMAGE}
315316
docker run --rm \
316317
--gpus all \
318+
-v ${{ github.workspace }}/tests/benchmark:/workspace/tilegym/tests/benchmark \
317319
-v ${{ github.workspace }}/test-results:/test-results \
318320
-w /workspace/tilegym/tests/benchmark \
319321
${IMAGE} \

tests/benchmark/run_all.sh

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,34 @@
55
# SPDX-License-Identifier: MIT
66

77
# Run all Python benchmark files and save results
8-
# Usage: ./run_all.sh [OUTPUT_DIR]
8+
# Usage: ./run_all.sh [OUTPUT_DIR] [--json]
9+
10+
# Enable pipefail to catch errors in piped commands
11+
set -o pipefail
912

1013
cd "$(dirname "$0")"
1114

1215
OUTPUT_DIR="${1:-.}"
16+
FORMAT="txt"
17+
18+
# Parse arguments
19+
for arg in "$@"; do
20+
if [[ "$arg" == "--json" ]]; then
21+
FORMAT="json"
22+
elif [[ -z "$OUTPUT_DIR" ]] || [[ "$OUTPUT_DIR" == "--json" ]]; then
23+
OUTPUT_DIR="."
24+
fi
25+
done
26+
27+
# If --json is first argument, reset OUTPUT_DIR
28+
if [[ "$OUTPUT_DIR" == "--json" ]]; then
29+
OUTPUT_DIR="${2:-.}"
30+
fi
31+
1332
mkdir -p "$OUTPUT_DIR"
1433

1534
echo "Running benchmarks sequentially (parallel execution disabled to ensure accurate results)..."
35+
echo "Output format: $FORMAT"
1636
echo "Results will be saved to: $OUTPUT_DIR"
1737
echo "Current directory: $(pwd)"
1838
echo "Benchmark files found: $(ls bench_*.py 2>/dev/null | wc -l)"
@@ -24,7 +44,27 @@ if [[ ! -w "$OUTPUT_DIR" ]]; then
2444
exit 1
2545
fi
2646

27-
# Run each benchmark and capture output
47+
# Use JSON runner if --json flag is set
48+
if [[ "$FORMAT" == "json" ]]; then
49+
echo "Using JSON output format..."
50+
if python3 run_all_json.py "$OUTPUT_DIR"; then
51+
echo ""
52+
echo "=========================================="
53+
echo "All benchmarks complete!"
54+
echo "Results directory: $OUTPUT_DIR"
55+
echo "Files created:"
56+
ls -lh "$OUTPUT_DIR"/*.json 2>/dev/null || echo " No result files found"
57+
echo "=========================================="
58+
exit 0
59+
else
60+
echo "Benchmark execution failed" >&2
61+
exit 1
62+
fi
63+
fi
64+
65+
# Original text format runner
66+
FAILED_BENCHMARKS=()
67+
2868
for file in bench_*.py; do
2969
if [[ ! -f "$file" ]]; then
3070
echo "Warning: No benchmark files matching bench_*.py found" >&2
@@ -38,23 +78,43 @@ for file in bench_*.py; do
3878
echo "Running $file..."
3979
echo "=========================================="
4080

41-
# Ensure output file is created even if benchmark produces no output
42-
touch "$output_file"
43-
44-
if python "$file" 2>&1 | tee "$output_file"; then
81+
# Run benchmark and capture output
82+
# Note: tee will create the file, errors go to both console and file
83+
if python3 "$file" 2>&1 | tee "$output_file"; then
84+
# Success - ensure file is readable
85+
chmod 644 "$output_file" 2>/dev/null || true
4586
echo "✓ PASSED: $file"
4687
echo " Results saved to: $output_file"
4788
else
89+
# Failure - mark file and ensure readable
90+
# tee already captured the output, just prepend marker
91+
(echo "BENCHMARK FAILED"; echo ""; cat "$output_file") > "$output_file.new" 2>/dev/null && \
92+
mv "$output_file.new" "$output_file" 2>/dev/null || \
93+
echo "BENCHMARK FAILED" > "$output_file"
94+
chmod 644 "$output_file" 2>/dev/null || true
4895
echo "✗ FAILED: $file"
49-
echo "FAILED" > "$output_file"
50-
exit 1 # Exit with error if any benchmark fails
96+
echo " Error details saved to: $output_file"
97+
FAILED_BENCHMARKS+=("$file")
5198
fi
5299
echo ""
53100
done
54101

55102
echo "=========================================="
56-
echo "All benchmarks complete!"
103+
if [ ${#FAILED_BENCHMARKS[@]} -eq 0 ]; then
104+
echo "All benchmarks complete! ✓"
105+
else
106+
echo "Benchmarks complete with failures! ✗"
107+
echo "Failed benchmarks:"
108+
for failed in "${FAILED_BENCHMARKS[@]}"; do
109+
echo " - $failed"
110+
done
111+
fi
57112
echo "Results directory: $OUTPUT_DIR"
58113
echo "Files created:"
59114
ls -lh "$OUTPUT_DIR"/*_results.txt 2>/dev/null || echo " No result files found"
60115
echo "=========================================="
116+
117+
# Exit with error if any benchmarks failed
118+
if [ ${#FAILED_BENCHMARKS[@]} -gt 0 ]; then
119+
exit 1
120+
fi

0 commit comments

Comments
 (0)