#!/bin/bash
set -uo pipefail
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
PROJECT_ROOT=$(realpath "${SCRIPT_DIR}/..")
BUILD_SH="$PROJECT_ROOT/scripts/build.sh"
OUTPUT_DIR="$PROJECT_ROOT/output"
run_pyext() {
echo ""
echo "=== [python_extension] build + install + test ==="
bash "$BUILD_SH" --clean python_extension || return 1
wheel=$(find "$OUTPUT_DIR/python_extension" -name 'torch_catlass-*.whl' 2>/dev/null | head -1)
if [ -z "$wheel" ]; then
echo " wheel not found under $OUTPUT_DIR/python_extension"
return 1
fi
pip install "$wheel" || return 1
python3 "$SCRIPT_DIR/test_python_extension.py" || return 1
pip uninstall torch_catlass -y >/dev/null 2>&1 || true
return 0
}
run_torch_lib() {
echo ""
echo "=== [torch_lib] build + test ==="
bash "$BUILD_SH" --clean torch_library || return 1
python3 "$SCRIPT_DIR/test_torch_lib.py" || return 1
return 0
}
FAILED=0
for target in pyext torch_lib; do
if run_${target}; then
echo " [OK] ${target}"
else
echo " [FAIL] ${target}"
FAILED=$((FAILED + 1))
fi
done
echo ""
echo "============================================================"
if [ "${FAILED}" -eq 0 ]; then
echo "All python extension tests passed."
else
echo "SUMMARY: ${FAILED} target(s) failed."
fi
echo "============================================================"
exit "${FAILED}"