/ .github / workflows / main.yml
main.yml
  1  name: CI
  2  
  3  on:
  4    push:
  5      branches:
  6        - master
  7        - 'feature/**'
  8    pull_request:
  9      branches:
 10        - master
 11        - 'feature/**'
 12    workflow_dispatch:
 13  
 14  jobs:
 15    build-core:
 16      name: Synthesize full core
 17      runs-on: ubuntu-latest
 18      timeout-minutes: 5
 19      steps:
 20        - name: Checkout
 21          uses: actions/checkout@v4
 22  
 23        - name: Set up Python
 24          uses: actions/setup-python@v5
 25          with:
 26              python-version: '3.13'
 27  
 28        - name: Install Coreblocks dependencies
 29          run: |
 30            python3 -m venv venv
 31            . venv/bin/activate
 32            python3 -m pip install --upgrade pip
 33            python3 -m pip install .
 34  
 35        - name: Generate Verilog
 36          run: |
 37            . venv/bin/activate
 38            PYTHONHASHSEED=0 TRANSACTRON_VERBOSE=1 ./scripts/gen_verilog.py --verbose --config full
 39  
 40        - uses: actions/upload-artifact@v4
 41          with:
 42            name: "verilog-full-core"
 43            path: |
 44              core.v
 45              core.v.json
 46  
 47  
 48    build-riscof-tests:
 49      name: Build regression tests (riscv-arch-test)
 50      runs-on: ubuntu-latest
 51      container: ghcr.io/kuznia-rdzeni/riscv-toolchain:2024.12.07
 52      timeout-minutes: 10
 53      env:
 54        PYENV_ROOT: "/root/.pyenv"
 55        LC_ALL: "C.UTF8"
 56        LANG: "C.UTF8"
 57      defaults:
 58        run:
 59          working-directory: test/external/riscof/
 60  
 61      steps:
 62        - name: Checkout
 63          uses: actions/checkout@v4
 64  
 65        - name: Get submodules HEAD hash
 66          working-directory: .
 67          run: |
 68            # ownership workaround
 69            git config --global --add safe.directory /__w/coreblocks/coreblocks
 70            # paths in command are relative!
 71            git submodule > .gitmodules-hash
 72  
 73        - name: Cache compiled and reference riscv-arch-test
 74          id: cache-riscv-arch-test
 75          uses: actions/cache@v4
 76          env:
 77            cache-name: cache-riscv-arch-test
 78          with:
 79            path: |
 80              test/external/riscof/riscv-arch-test/**/*.elf
 81              test/external/riscof/riscof_work/**/*.signature
 82              test/external/riscof/**/*Makefile*
 83  
 84            key: ${{ env.cache-name }}-${{ runner.os }}-${{ hashFiles(
 85                '**/test/external/riscof/coreblocks/**',
 86                '**/test/external/riscof/spike_simple/**',
 87                '**/test/external/riscof/config.ini',
 88                '**/.gitmodules-hash',
 89                '**/docker/riscv-toolchain.Dockerfile',
 90                '**/.github/workflows/main.yml'
 91              ) }}
 92            lookup-only: true
 93  
 94        - if: ${{ steps.cache-riscv-arch-test.outputs.cache-hit != 'true' }}
 95          name: Checkout with submodules
 96          uses: actions/checkout@v4
 97          with:
 98            submodules: recursive
 99  
100        - if: ${{ steps.cache-riscv-arch-test.outputs.cache-hit != 'true' }}
101          name: Setup PATH
102          run: echo "/.pyenv/bin" >> $GITHUB_PATH
103  
104        - if: ${{ steps.cache-riscv-arch-test.outputs.cache-hit != 'true' }}
105          name: Setup pyenv python
106          run: |
107            eval "$(pyenv init --path)"
108            pyenv global 3.6.15
109            . /venv3.6/bin/activate
110  
111        - if: ${{ steps.cache-riscv-arch-test.outputs.cache-hit != 'true' }}
112          name: Setup arch test suite
113          run: |
114            . /venv3.6/bin/activate
115            riscof testlist --config=config.ini --suite=riscv-arch-test/riscv-test-suite/ --env=riscv-arch-test/riscv-test-suite/env
116  
117        - if: ${{ steps.cache-riscv-arch-test.outputs.cache-hit != 'true' }}
118          name: Build and run tests on reference and generate Makefiles
119          run: |
120            . /venv3.6/bin/activate
121            riscof run --config=config.ini --suite=riscv-arch-test/riscv-test-suite/ --env=riscv-arch-test/riscv-test-suite/env
122  
123        - if: ${{ steps.cache-riscv-arch-test.outputs.cache-hit != 'true' }}
124          name: Build tests for Coreblocks
125          run: |
126            MAKEFILE_PATH=riscof_work/Makefile.build-DUT-coreblocks ../../../ci/riscof_run_makefile.sh
127  
128        - if: ${{ steps.cache-riscv-arch-test.outputs.cache-hit != 'true' }}
129          name: Upload compiled and reference tests artifact
130          uses: actions/upload-artifact@v4
131          with:
132            name: "riscof-tests"
133            path: |
134              test/external/riscof/riscv-arch-test/**/*.elf
135              test/external/riscof/riscof_work/**/*.signature
136              test/external/riscof/**/*Makefile*
137  
138    run-riscof-tests:
139      name: Run regression tests (riscv-arch-test)
140      runs-on: ubuntu-22.04  # older version for compatibility with Docker image
141      container: ghcr.io/kuznia-rdzeni/verilator:v5.008-2023.11.19_v
142      needs: [ build-riscof-tests, build-core ]
143      timeout-minutes: 30
144      steps:
145        - name: Checkout
146          uses: actions/checkout@v4
147  
148        - name: Get submodules HEAD hash
149          run: |
150            git config --global --add safe.directory /__w/coreblocks/coreblocks
151            git submodule > .gitmodules-hash
152  
153        - name: Set up Python
154          uses: actions/setup-python@v5
155          with:
156              python-version: '3.13'
157  
158        - name: Install Coreblocks dependencies
159          run: |
160            python3 -m venv venv
161            . venv/bin/activate
162            python3 -m pip install --upgrade pip
163            python3 -m pip install ".[dev]"
164  
165        - uses: actions/download-artifact@v4
166          name: Download full verilog core
167          with:
168            name: "verilog-full-core"
169            path: .
170  
171        - uses: actions/cache@v4
172          name: Download tests from cache
173          env:
174            cache-name: cache-riscv-arch-test
175          with:
176            path: |
177              test/external/riscof/riscv-arch-test/**/*.elf
178              test/external/riscof/riscof_work/**/*.signature
179              test/external/riscof/**/*Makefile*
180  
181            key: ${{ env.cache-name }}-${{ runner.os }}-${{ hashFiles(
182                '**/test/external/riscof/coreblocks/**',
183                '**/test/external/riscof/spike_simple/**',
184                '**/test/external/riscof/config.ini',
185                '**/.gitmodules-hash',
186                '**/docker/riscv-toolchain.Dockerfile',
187                '**/.github/workflows/main.yml'
188              ) }}
189            fail-on-cache-miss: true
190  
191        - name: Run tests on Coreblocks
192          run: |
193            . venv/bin/activate
194            MAKEFILE_PATH=test/external/riscof/riscof_work/Makefile.run-DUT-coreblocks NPROC=1 ./ci/riscof_run_makefile.sh
195  
196        - name: Compare signatures (test results)
197          run: MAKEFILE_PATH=test/external/riscof/riscof_work/Makefile.run-DUT-coreblocks ./ci/riscof_compare.sh
198  
199  
200    build-regression-tests:
201      name: Build regression tests (riscv-tests)
202      runs-on: ubuntu-latest
203      container: ghcr.io/kuznia-rdzeni/riscv-toolchain:2024.12.07
204      timeout-minutes: 10
205      steps:
206        - name: Checkout
207          uses: actions/checkout@v4
208  
209        - name: Get submodules HEAD hash
210          run: |
211            git config --global --add safe.directory /__w/coreblocks/coreblocks
212            git submodule > .gitmodules-hash
213  
214        - name: Cache regression-tests
215          id: cache-regression
216          uses: actions/cache@v4
217          env:
218            cache-name: cache-regression-tests
219          with:
220            path: test/external/riscv-tests/test-*
221            key: ${{ env.cache-name }}-${{ runner.os }}-${{ hashFiles(
222                '**/test/external/riscv-tests/environment/custom/**',
223                '**/test/external/riscv-tests/Makefile',
224                '**/.gitmodules-hash',
225                '**/docker/riscv-toolchain.Dockerfile',
226                '**/.github/workflows/main.yml'
227              ) }}
228            lookup-only: true
229  
230        - if: ${{ steps.cache-regression.outputs.cache-hit != 'true' }}
231          name: Checkout with submodules
232          uses: actions/checkout@v4
233          with:
234            submodules: recursive
235  
236        - if: ${{ steps.cache-regression.outputs.cache-hit != 'true' }}
237          run: cd test/external/riscv-tests && make
238  
239        - if: ${{ steps.cache-regression.outputs.cache-hit != 'true' }}
240          name: Upload riscv-tests
241          uses: actions/upload-artifact@v4
242          with:
243            path: test/external/riscv-tests
244  
245    run-regression-tests:
246      name: Run regression tests (riscv-tests)
247      runs-on: ubuntu-22.04  # older version for compatibility with Docker image
248      timeout-minutes: 20
249      container: ghcr.io/kuznia-rdzeni/verilator:v5.008-2023.11.19_v
250      needs: [ build-regression-tests, build-core ]
251      steps:
252        - name: Checkout
253          uses: actions/checkout@v4
254  
255        - name: Get submodules HEAD hash
256          run: |
257            git config --global --add safe.directory /__w/coreblocks/coreblocks
258            git submodule > .gitmodules-hash
259  
260        - name: Set up Python
261          uses: actions/setup-python@v5
262          with:
263            python-version: '3.13'
264  
265        - name: Install dependencies
266          run: |
267            python3 -m venv venv
268            . venv/bin/activate
269            python3 -m pip install --upgrade pip
270            python3 -m pip install ".[dev]"
271  
272        - uses: actions/download-artifact@v4
273          name: Download full verilog core
274          with:
275            name: "verilog-full-core"
276            path: .
277  
278        - uses: actions/cache@v4
279          name: Download tests from cache
280          env:
281            cache-name: cache-regression-tests
282          with:
283            path: test/external/riscv-tests/test-*
284            key: ${{ env.cache-name }}-${{ runner.os }}-${{ hashFiles(
285                '**/test/external/riscv-tests/environment/custom/**',
286                '**/test/external/riscv-tests/Makefile',
287                '**/.gitmodules-hash',
288                '**/docker/riscv-toolchain.Dockerfile',
289                '**/.github/workflows/main.yml'
290              ) }}
291            fail-on-cache-miss: true
292  
293        - name: Run tests
294          run: |
295            . venv/bin/activate
296            scripts/run_tests.py -a regression
297  
298        - name: Check regression with pysim
299          run: |
300            . venv/bin/activate
301            ./scripts/run_tests.py -c 1 -a -b pysim regression
302  
303  
304    unit-test:
305      name: Run unit tests
306      runs-on: ubuntu-latest
307      timeout-minutes: 60
308      steps:
309        - name: Checkout
310          uses: actions/checkout@v4
311  
312        - name: Set up Python
313          uses: actions/setup-python@v5
314          with:
315            python-version: '3.13'
316            cache: 'pip'
317            cache-dependency-path: |
318              pyproject.toml
319  
320        - name: Install dependencies
321          run: |
322            python -m pip install --upgrade pip
323            pip3 install ".[dev]"
324            sudo apt-get install -y binutils-riscv64-unknown-elf
325  
326        - name: Run tests
327          run: ./scripts/run_tests.py -v
328  
329        - name: Check traces and profiles
330          run: ./scripts/run_tests.py -t -p -c 1 TestCore
331  
332        - name: Check listing tests
333          run: ./scripts/run_tests.py -l
334  
335    lint:
336      name: Check code formatting and typing
337      runs-on: ubuntu-latest
338      timeout-minutes: 5
339      steps:
340        - name: Checkout
341          uses: actions/checkout@v4
342  
343        - name: Set up Python
344          uses: actions/setup-python@v5
345          with:
346            python-version: '3.13'
347            cache: 'pip'
348            cache-dependency-path: |
349              pyproject.toml
350  
351        - name: Install dependencies
352          run: |
353            python -m pip install --upgrade pip
354            pip3 install ".[dev]"
355  
356        - name: Check format
357          run: ./scripts/lint.sh check_format
358  
359        - name: Check types
360          run: ./scripts/lint.sh check_types
361  
362        - name: Check line endings
363          run: |
364            git add --renormalize .
365            git diff --cached --exit-code
366  
367        - name: Check pre-commit hooks
368          run: pre-commit run --all-files --show-diff-on-failure