#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
SCRIPT_PATH=$(dirname "$(realpath "$0")")
BUILD_SCRIPT_PATH=$(realpath "$SCRIPT_PATH"/../scripts/build.sh)
if [[ $# -ge 1 ]]; then
CATLASS_ARCH="$1"
else
CATLASS_ARCH=2201
fi
bash "$SCRIPT_PATH/test_compile.sh" "$CATLASS_ARCH"
python3 "$SCRIPT_PATH/test_example.py"
if [[ "$CATLASS_ARCH" == 2201 ]]; then
bash "$BUILD_SCRIPT_PATH" --clean python_extension || exit 1
WHEEL_DIR="$SCRIPT_PATH/../output/python_extension/"
WHEEL_FILE=$(find "$WHEEL_DIR" -type f -name "torch_catlass-*.whl" 2>/dev/null | head -n 1)
if [ -z "$WHEEL_FILE" ]; then
echo "Error: No .whl file found in $WHEEL_DIR"
exit 1
fi
pip install "$WHEEL_FILE"
python3 "$SCRIPT_PATH/test_python_extension.py"
pip uninstall torch_catlass -y
bash "$BUILD_SCRIPT_PATH" --clean torch_library || exit 1
python3 "$SCRIPT_PATH/test_torch_lib.py"
python3 "$SCRIPT_PATH/../tools/tuner/test/test_mstuner.py"
fi
bash "$SCRIPT_PATH/run_optest.sh"
bash "$SCRIPT_PATH/run_cppgen.sh"
bash "$BUILD_SCRIPT_PATH" --clean --tests catlass_unittest || exit 1
$SCRIPT_PATH/../build/tests/unittest/catlass_unittest_"$CATLASS_ARCH"