Added RiscV unit tests for python bindings (#15) #174
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Python Bindings Unit Tests" | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| concurrency: | |
| group: build-python-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| python-tests: | |
| name: "Test Python bindings" | |
| strategy: | |
| matrix: | |
| on: [ 'ubuntu-22.04', 'ubuntu-24.04', 'macos-15-intel', 'macos-26' ] | |
| python: [ '3.10', '3.11', '3.12', '3.13', '3.14' ] | |
| runs-on: ${{ matrix.on }} | |
| env: | |
| INSTALL_PREFIX: "/usr/local" | |
| steps: | |
| - name: "Checkout repository" | |
| uses: actions/checkout@v4 | |
| - name: "Set up Python ${{ matrix.python }}" | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python }} | |
| # Install platform build dependencies | |
| - name: "Install system packages (Ubuntu)" | |
| if: startsWith(matrix.on, 'ubuntu-') | |
| run: sudo apt-get update && sudo apt-get install -y ninja-build g++ cmake | |
| - name: "Setup Homebrew (macOS)" | |
| if: startsWith(matrix.on, 'macos-') | |
| uses: Homebrew/actions/setup-homebrew@main | |
| - name: "Install system packages (macOS)" | |
| if: startsWith(matrix.on, 'macos-') | |
| run: brew install ninja gcc cmake | |
| # Install Python build dependencies | |
| - name: "Build and Install Python wheel" | |
| run: | | |
| mkdir -p /tmp/capio_cl_jsons | |
| cp tests/jsons/*.json /tmp/capio_cl_jsons | |
| python -m pip install --upgrade pip | |
| python -m pip install -r build-requirements.txt | |
| python -m build \ | |
| -Ccmake.define.ENABLE_COVERAGE=ON \ | |
| -Ccmake.build-type=Debug \ | |
| -Ccmake.define.CAPIO_CL_BUILD_TESTS=OFF | |
| pip install dist/*.whl | |
| # Run unit tests | |
| - name: "Run Python tests" | |
| run: | | |
| python -m pip install -r test-requirements.txt | |
| pytest -v tests/python/test_* | |
| - name: "Generate coverage report" | |
| if: ${{ startsWith(matrix.on, 'ubuntu-') }} | |
| run: | | |
| pip install --upgrade gcovr | |
| gcovr \ | |
| --exclude-throw-branches \ | |
| --xml coverage.xml \ | |
| . | |
| - name: "Upload coverage report" | |
| if: ${{ startsWith(matrix.on, 'ubuntu-') }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ format('{0}-{1}-tests', matrix.on, matrix.python) }} | |
| path: ./coverage.xml | |
| retention-days: 1 | |
| if-no-files-found: error | |
| riscv-tests: | |
| name: "Build & Test on RISC-V (QEMU)" | |
| strategy: | |
| matrix: | |
| python: [ '3.10', '3.11', '3.12', '3.13', '3.14' ] | |
| runs-on: ubuntu-latest | |
| env: | |
| INSTALL_PREFIX: "/usr/local" | |
| PYTHON_VERSION: "${{ matrix.python }}" | |
| steps: | |
| - name: "Checkout repository" | |
| uses: actions/checkout@v4 | |
| - name: "Build and test inside RISC-V emulated environment (Debian based)" | |
| uses: uraimo/run-on-arch-action@v2 | |
| with: | |
| arch: riscv64 | |
| distro: ubuntu22.04 | |
| githubToken: ${{ github.token }} | |
| install: | | |
| apt-get update | |
| DEBIAN_FRONTEND=noninteractive apt-get install -y \ | |
| python3 python3-pip python3-venv python3-wheel python3-setuptools \ | |
| g++ cmake ninja-build git xxd | |
| run: | | |
| set -eux | |
| echo "🏗️ Building for RISC-V on Ubuntu 22.04" | |
| python3 -m pip install --upgrade pip | |
| python3 -m pip install -r build-requirements.txt | |
| mkdir -p /tmp/capio_cl_jsons | |
| cp tests/jsons/*.json /tmp/capio_cl_jsons | |
| python3 -m build \ | |
| -Ccmake.define.ENABLE_COVERAGE=OFF \ | |
| -Ccmake.build-type=Release \ | |
| -Ccmake.define.CAPIO_CL_BUILD_TESTS=OFF | |
| pip install dist/*.whl | |
| python3 -m pip install -r test-requirements.txt | |
| echo "✅ Running unit tests" | |
| pytest -v tests/python/test_* | tee pytest-riscv.log |