#!/bin/bash echo "============================================" echo "Running Scorch Test Suite" echo "============================================" # Clear JIT-compiled kernel cache to prevent stale .so files rm -rf ~/.cache/torch_extensions/ 2>/dev/null || true rm -rf /tmp/torch_extensions_* 2>/dev/null || true # Clear build artifacts and inline-compiled extension so rebuild picks up new csrc/. # scorch's setup.py uses package_dir={"":"src"}, so build_ext --inplace writes the # top-level scorch_ops extension to /testbed/src/scorch_ops*.so (NOT /testbed/). # We must delete both candidate paths or a silent build failure will fall through # to a stale snapshot-baked .so and the test run will silently use the wrong build. rm -rf /testbed/build/ /testbed/scorch.egg-info/ 2>/dev/null || true rm -f /testbed/scorch_ops*.so /testbed/src/scorch_ops*.so 2>/dev/null || true # Rebuild scorch_ops C++ extension to match current source. Fail loudly if the # build fails so a stale .so doesn't silently masquerade as the patched build. cd /testbed if ! python setup.py build_ext --inplace --force 2>&1 | tee build_output.log | tail -3; then echo "============================================" echo "BUILD FAILED - scorch_ops C++ extension did not compile" echo "============================================" tail -30 build_output.log exit 1 fi python -m pytest tests/ -v --tb=short --no-header 2>&1 | tee test_output.log if [ -f test_output.log ]; then echo "" echo "============================================" echo "TEST SUMMARY" echo "============================================" SUMMARY_LINE=$(grep -E "={5,}.*in [0-9]+\.[0-9]+s.*={5,}" test_output.log | tail -1) if [ -n "$SUMMARY_LINE" ]; then PASSED=$(echo "$SUMMARY_LINE" | grep -oE '[0-9]+ passed' | grep -oE '[0-9]+' || echo "0") FAILED=$(echo "$SUMMARY_LINE" | grep -oE '[0-9]+ failed' | grep -oE '[0-9]+' || echo "0") SKIPPED=$(echo "$SUMMARY_LINE" | grep -oE '[0-9]+ skipped' | grep -oE '[0-9]+' || echo "0") ERRORS=$(echo "$SUMMARY_LINE" | grep -oE '[0-9]+ error' | grep -oE '[0-9]+' || echo "0") PASSED=${PASSED:-0} FAILED=${FAILED:-0} SKIPPED=${SKIPPED:-0} ERRORS=${ERRORS:-0} TOTAL=$((PASSED + FAILED + SKIPPED + ERRORS)) echo "Total: $TOTAL | Passed: $PASSED | Failed: $FAILED | Skipped: $SKIPPED | Errors: $ERRORS" if [ "$FAILED" -eq "0" ] && [ "$ERRORS" -eq "0" ]; then echo "ALL TESTS PASSED!" exit 0 else echo "SOME TESTS FAILED!" grep -E "(FAILED|ERROR)" test_output.log | head -10 exit 1 fi else echo "Could not parse pytest output" tail -10 test_output.log exit 1 fi fi