1name: Run tests
2
3on:
4 pull_request: {}
5 schedule:
6  - cron: '0 0 * * 0' # every sunday
7
8
9env:
10  ZEPHYR_SDK_VERSION: 0.16.5
11  ZEPHYR_REV: 5cbf7b1b9d13a39f36ad8dabfaeaec21d98cf5ff
12
13jobs:
14  merge-test-1:
15    runs-on: ubuntu-22.04
16    strategy:
17      matrix:
18        platform: ["native_posix", "native_posix/native/64", "mps2/an521/cpu0"]
19        asserts: ["", "-x VERBOSE=ON -x ASSERTS=ON"]
20    name: Merge test 1 - Twister (Ubuntu) (${{ matrix.platform }}${{ matrix.asserts != '' && ' with asserts' || '' }})
21    steps:
22    - name: Checkout the code
23      uses: actions/checkout@v4
24
25    - name: Install zcbor
26      uses: ./.github/actions/install_zcbor
27
28    - name: Prepare and run tests
29      uses: ./.github/actions/prepare_and_run_tests
30      with:
31        twister_arguments: "--timestamps --platform ${{ matrix.platform }} ${{ matrix.asserts }} --exclude-tag release"
32        zephyr_toolchain: ${{ matrix.platform == 'mps2/an521/cpu0' && 'zephyr' || 'host'}}
33        zephyr_toolchain_arch: ${{ matrix.platform == 'mps2/an521/cpu0' && 'arm' || ''}}
34
35  merge-test-1-win:
36    runs-on: windows-latest
37    strategy:
38      matrix:
39        platform: ["mps2/an521/cpu0"]
40        asserts: [""]
41    name: Merge test 1 - Twister (Windows) (${{ matrix.platform }}${{ matrix.asserts != '' && ' with asserts' || '' }} - build only)
42    steps:
43    - name: Checkout the code
44      uses: actions/checkout@v4
45
46    - name: Checkout Zephyr
47      run: |
48        git init zephyr-clone
49        cd zephyr-clone
50        git remote add origin https://github.com/zephyrproject-rtos/zephyr
51        git fetch origin $env:ZEPHYR_REV --depth=1
52        git reset --hard FETCH_HEAD
53
54    - name: Install zcbor and pip dependencies
55      run: |
56        $ErrorActionPreference="Stop"
57        pip install -U -r scripts\requirements.txt -r zephyr-clone\scripts\requirements-base.txt -r zephyr-clone\scripts\requirements-build-test.txt -r zephyr-clone\scripts\requirements-run-test.txt; if($LastExitCode -ne 0) {Write-Error "$LastExitCode"};
58        pip install -e .
59
60    - name: Install ninja and 7zip
61      run: |
62        choco feature enable -n allowGlobalConfirmation
63        choco install ninja 7zip
64
65    - name: Run West
66      run: |
67        $ErrorActionPreference="Stop"
68        west init -l zephyr-clone; if($LastExitCode -ne 0) {Write-Error "$LastExitCode"};
69        west update cmsis
70
71    - name: Install Zephyr SDK (ARM)
72      run: |
73        $client = new-object System.Net.WebClient
74        $client.DownloadFile("https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$env:ZEPHYR_SDK_VERSION/zephyr-sdk-${env:ZEPHYR_SDK_VERSION}_windows-x86_64_minimal.7z", "$pwd\zephyr-sdk-${env:ZEPHYR_SDK_VERSION}_windows-x86_64_minimal.7z")
75        7z x $pwd\zephyr-sdk-${env:ZEPHYR_SDK_VERSION}_windows-x86_64_minimal.7z
76        Rename-Item -Path zephyr-sdk-${env:ZEPHYR_SDK_VERSION} -NewName zephyr-sdk
77        cd zephyr-sdk
78        $client.DownloadFile("https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$env:ZEPHYR_SDK_VERSION/toolchain_windows-x86_64_arm-zephyr-eabi.7z", "$pwd\toolchain_windows-x86_64_arm-zephyr-eabi.7z")
79        7z x $pwd\toolchain_windows-x86_64_arm-zephyr-eabi.7z
80
81    - name: Run Twister
82      shell: cmd
83      run: |
84        set ZEPHYR_BASE=%cd%\zephyr-clone
85        set ZEPHYR_TOOLCHAIN_VARIANT=zephyr
86        set ZEPHYR_SDK_INSTALL_DIR=%cd%\zephyr-sdk
87        python %ZEPHYR_BASE%\scripts\twister -i -v -T tests -W --timestamps --platform ${{ matrix.platform }} ${{ matrix.asserts }} --exclude-tag release --build-only
88
89
90  merge-test-2:
91    runs-on: ubuntu-22.04
92    strategy:
93      matrix:
94        python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
95    name: Merge tests 2 - Python (${{ matrix.python-version }}) functional tests (Ubuntu)
96    steps:
97    - name: Checkout the code
98      uses: actions/checkout@v4
99
100    - name: Setup Python
101      uses: actions/setup-python@v5
102      with:
103        python-version: ${{ matrix.python-version }}
104        allow-prereleases: true
105
106    - name: Install zcbor
107      uses: ./.github/actions/install_zcbor
108      with:
109        zcbor_package: 'setup_install'
110
111    - name: Run python tests
112      working-directory: tests/scripts
113      run: |
114        python3 -m unittest test_zcbor
115
116  merge-test-2-win:
117    runs-on: windows-latest
118    name: Merge tests 2 - Python (${{ matrix.python-version }}) functional tests (Windows)
119    steps:
120    - name: Checkout the code
121      uses: actions/checkout@v4
122
123    - name: Read zcbor version
124      run: |
125        echo "ZCBOR_VERSION=$(cat zcbor/VERSION)" >> $env:GITHUB_ENV
126
127    - name: Install west and dependencies
128      run: |
129        pip install -U pip
130        pip install -U build
131        pip install -U -r scripts/requirements.txt
132
133    - name: Generate and install zcbor package
134      run: |
135        $ErrorActionPreference="Stop"
136        python -m build; if($LastExitCode -ne 0) {Write-Error "$LastExitCode"};
137        pip install dist/zcbor-$env:ZCBOR_VERSION-py3-none-any.whl; if($LastExitCode -ne 0) {Write-Error "$LastExitCode"};
138        pip uninstall -y zcbor
139        pip install -e .
140
141    - name: Run python tests
142      working-directory: tests/scripts
143      run: |
144        python3 -m unittest test_zcbor
145
146  merge-test-3:
147    runs-on: ubuntu-22.04
148    name: Merge tests 3 - Check repo files (Ubuntu)
149    steps:
150    - name: Checkout the code
151      uses: actions/checkout@v4
152
153    - name: Setup Python
154      uses: actions/setup-python@v5
155      with:
156        python-version: '3.12'
157
158    - name: Install zcbor
159      uses: ./.github/actions/install_zcbor
160      with:
161        zcbor_package: 'setup_develop'
162
163    - name: Run tests on repo files
164      working-directory: tests/scripts
165      run: |
166        python3 -m unittest test_repo_files
167
168  release-test-1:
169    runs-on: ubuntu-22.04
170    name: Release tests 1 - Check versions
171    needs:
172    - merge-test-1
173    - merge-test-1-win
174    - merge-test-2
175    - merge-test-2-win
176    - merge-test-3
177    if: "startswith(github.head_ref, 'release/')"
178    steps:
179    - name: Checkout the code
180      uses: actions/checkout@v4
181
182    - name: Install zcbor
183      uses: ./.github/actions/install_zcbor
184
185    - name: Run python release tests
186      working-directory: tests/scripts
187      run: |
188        set -e
189        echo -n ${{ github.head_ref }} > HEAD_REF
190        python3 -m unittest test_versions
191        rm HEAD_REF
192
193  release-test-2:
194    runs-on: ubuntu-22.04
195    name: Release tests 2 - Fuzz
196    needs:
197    - release-test-1
198    steps:
199    - name: Checkout the code
200      uses: actions/checkout@v4
201
202    - name: Read zcbor version
203      run: echo "ZCBOR_VERSION=$(cat zcbor/VERSION)" >> $GITHUB_ENV
204
205    - name: Install zcbor
206      uses: ./.github/actions/install_zcbor
207
208    - name: Install packages
209      run: |
210        sudo apt update
211        sudo apt install -y afl++
212
213    - name: Run everything fuzz tests
214      working-directory: tests/fuzz
215      run: |
216        ./test-afl.sh 2400 64 everything
217
218    - name: Run manifest12 fuzz tests
219      working-directory: tests/fuzz
220      run: |
221        ./test-afl.sh 800 64 manifest12
222
223    - name: Run pet fuzz tests
224      working-directory: tests/fuzz
225      run: |
226        ./test-afl.sh 400 64 pet
227
228    - name: Rename fuzz failures
229      if: ${{ failure() }}
230      working-directory: tests/fuzz/build-afl/output/default/crashes/
231      run: |
232        for i in ./* ; do mv "$i" "${i//:/_}_1"; done
233
234    - name: Upload fuzz failures
235      if: ${{ failure() }}
236      uses: actions/upload-artifact@v4
237      with:
238        name: fuzz-failures
239        path: tests/fuzz/build-afl/output/default/crashes/
240
241    - name: Upload release files
242      uses: actions/upload-artifact@v4
243      with:
244        name: zcbor-release-${{ env.ZCBOR_VERSION }}
245        path: dist/*
246
247  release-test-3:
248    runs-on: ubuntu-22.04
249    strategy:
250      matrix:
251        python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
252        asserts: ["", "-x VERBOSE=ON -x ASSERTS=ON"]
253    name: Release tests 3 (Python ${{ matrix.python-version }}${{ matrix.asserts != '' && ' with asserts' || '' }})
254    needs:
255    - merge-test-1
256    - merge-test-1-win
257    - merge-test-2
258    - merge-test-2-win
259    - merge-test-3
260    if: "github.event_name == 'schedule' || (github.event_name == 'pull_request' && startswith(github.head_ref, 'release/'))"
261    steps:
262    - name: Checkout the code
263      uses: actions/checkout@v4
264
265    - name: Setup Python
266      uses: actions/setup-python@v5
267      with:
268        python-version: ${{ matrix.python-version }}
269        allow-prereleases: true
270
271    - name: Install zcbor
272      uses: ./.github/actions/install_zcbor
273      with:
274        zcbor_package: 'setup_install'
275
276    - name: Prepare and run tests
277      uses: ./.github/actions/prepare_and_run_tests
278      with:
279        twister_arguments: "--timestamps --platform native_posix --platform native_posix/native/64 --platform mps2/an521/cpu0 --platform qemu_malta/qemu_malta/be ${{ matrix.asserts }}"
280        zephyr_toolchain: zephyr
281        zephyr_toolchain_arch: arm,mips
282
283  release-test-4:
284    runs-on: ubuntu-22.04
285    strategy:
286      matrix:
287        python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
288        asserts: ["", "-x VERBOSE=ON -x ASSERTS=ON"]
289    name: Release tests 4 (Python ${{ matrix.python-version }}${{ matrix.asserts != '' && ' with asserts' || '' }})
290    needs:
291    - merge-test-1
292    - merge-test-1-win
293    - merge-test-2
294    - merge-test-2-win
295    - merge-test-3
296    if: "github.event_name == 'schedule' || (github.event_name == 'pull_request' && startswith(github.head_ref, 'release/'))"
297    steps:
298    - name: Checkout the code
299      uses: actions/checkout@v4
300
301    - name: Setup Python
302      uses: actions/setup-python@v5
303      with:
304        python-version: ${{ matrix.python-version }}
305        allow-prereleases: true
306
307    - name: Install zcbor
308      uses: ./.github/actions/install_zcbor
309      with:
310        zcbor_package: 'setup_develop'
311
312    - name: Run python tests on samples
313      working-directory: tests/scripts
314      run: |
315        python3 -m unittest test_repo_files.TestSamples
316