.PHONY: all build test test-unit test-cpu test-gpu test-integration bench bench-rust bench-python install clean help
all: test
PYTHON := $(shell if [ -f .venv/bin/python ]; then echo .venv/bin/python; else echo python3; fi)
install:
@echo "Installing test dependencies..."
@if command -v uv >/dev/null 2>&1; then \
uv sync --extra test; \
else \
echo "uv not found, using pip..."; \
$(PYTHON) -m pip install -e ".[test]"; \
fi
build: install
@echo "Building test module..."
$(PYTHON) -m maturin develop
test: test-unit test-integration
bench: bench-rust bench-python
PYTHON_LIBDIR := $(shell $(PYTHON) -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR') or '')")
test-unit:
@echo "Running Rust unit tests..."
DYLD_LIBRARY_PATH="$(PYTHON_LIBDIR)" \
LD_LIBRARY_PATH="$(PYTHON_LIBDIR)" \
PATH="$(PYTHON_LIBDIR):$(PATH)" \
cargo test --lib
test-integration: build
@echo "Running integration tests..."
$(PYTHON) -m pytest tests/test_dlpack_integration.py -v
test-cpu: build
@echo "Running CPU integration tests..."
$(PYTHON) -m pytest tests/test_dlpack_integration.py -v -k "Cpu or not Gpu"
test-gpu: build
@echo "Running GPU integration tests..."
$(PYTHON) -m pytest tests/test_dlpack_integration.py -v -k "Gpu"
test-memory: build
@echo "Running memory safety tests..."
$(PYTHON) -m pytest tests/test_dlpack_integration.py -v -k "MemorySafety"
test-stress: build
@echo "Running stress tests..."
$(PYTHON) -m pytest tests/test_dlpack_integration.py -v -k "Stress"
bench-rust:
@echo "Running Rust benchmarks..."
DYLD_LIBRARY_PATH="$(PYTHON_LIBDIR)" \
LD_LIBRARY_PATH="$(PYTHON_LIBDIR)" \
PATH="$(PYTHON_LIBDIR):$(PATH)" \
cargo bench --bench dlpack
bench-python: build
@echo "Running Python benchmarks..."
$(PYTHON) benchmarks/bench_dlpack.py --size 1000000 --iters 200
clean:
@echo "Cleaning..."
rm -rf target/
rm -rf tests/test_module/target/
rm -rf *.egg-info/
rm -rf .pytest_cache/
rm -rf __pycache__/
rm -rf tests/__pycache__/
find . -name "*.pyc" -delete
find . -name "*.pyo" -delete
find . -name "*.so" -delete
check:
cargo check
cargo clippy
fmt:
cargo fmt
help:
@echo "pyo3-dlpack Test Commands"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " test Run all tests (unit + integration)"
@echo " test-unit Run Rust unit tests only"
@echo " test-integration Run Python integration tests"
@echo " test-cpu Run CPU integration tests only"
@echo " test-gpu Run GPU integration tests only"
@echo " test-memory Run memory safety tests"
@echo " test-stress Run stress tests"
@echo " bench Run all benchmarks"
@echo " bench-rust Run Rust benchmarks (Criterion)"
@echo " bench-python Run Python benchmarks"
@echo " install Install test dependencies (uv sync --extra test)"
@echo " build Build the Python test module"
@echo " clean Clean all build artifacts"
@echo " check Run cargo check and clippy"
@echo " fmt Format Rust code"
@echo " help Show this help"