|
| 1 | +# SPDX-FileCopyrightText: 2023-2024 Sony Semiconductor Solutions Corporation |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_call: |
| 7 | + inputs: |
| 8 | + builder-tag: |
| 9 | + description: The builder tag to be used |
| 10 | + default: ghcr.io/${{ inputs.package-namespace }}/builder-raspios-bookworm |
| 11 | + required: false |
| 12 | + type: string |
| 13 | + ref: |
| 14 | + type: string |
| 15 | + required: true |
| 16 | + package-namespace: |
| 17 | + description: The package namespace for docker images |
| 18 | + default: ${{ github.repository }} |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + |
| 22 | +jobs: |
| 23 | + test: |
| 24 | + name: Unit tests (${{ matrix.name }}, ${{ matrix.platform }}) |
| 25 | + runs-on: ${{ matrix.runner }} |
| 26 | + container: |
| 27 | + image: ghcr.io/${{ inputs.package-namespace }}/builder-${{ matrix.name }}:${{ inputs.builder-tag }} |
| 28 | + credentials: |
| 29 | + username: ${{ github.actor }} |
| 30 | + password: ${{ github.token }} |
| 31 | + options: ${{ startsWith(matrix.runner, 'buildjet') && '--user 1000:1001' || '--user 1001:127' }} |
| 32 | + timeout-minutes: 30 |
| 33 | + strategy: |
| 34 | + fail-fast: false |
| 35 | + matrix: |
| 36 | + include: |
| 37 | + - name: raspios-bookworm |
| 38 | + runner: ${{ github.event.repository.private && 'buildjet-8vcpu-ubuntu-2204-arm' || 'ubuntu-24.04-arm' }} |
| 39 | + platform: arm64 |
| 40 | + - name: ubuntu-noble |
| 41 | + runner: ${{ github.event.repository.private && 'buildjet-8vcpu-ubuntu-2204-arm' || 'ubuntu-24.04-arm' }} |
| 42 | + platform: arm64 |
| 43 | + - name: ubuntu-noble |
| 44 | + runner: ${{ github.event.repository.private && 'buildjet-4vcpu-ubuntu-2204' || 'ubuntu-24.04' }} |
| 45 | + platform: amd64 |
| 46 | + |
| 47 | + steps: |
| 48 | + - name: Checkout source |
| 49 | + uses: actions/checkout@v4 |
| 50 | + with: |
| 51 | + ref: ${{ inputs.ref }} |
| 52 | + |
| 53 | + - name: Download test modules |
| 54 | + uses: actions/download-artifact@v4 |
| 55 | + with: |
| 56 | + name: test-modules-${{ matrix.name }}-${{ matrix.platform }}-${{ github.run_id }} |
| 57 | + path: test_modules/ |
| 58 | + |
| 59 | + - name: Download Python SDK |
| 60 | + uses: actions/download-artifact@v4 |
| 61 | + with: |
| 62 | + name: python-sdk-${{ matrix.name }}-${{ matrix.platform }}-${{ github.run_id }} |
| 63 | + path: py-sdk |
| 64 | + |
| 65 | + - name: Set permissions |
| 66 | + run: chmod +x test_modules/*.elf |
| 67 | + |
| 68 | + - name: Build dependencies |
| 69 | + run: | |
| 70 | + make -j$((`nproc` * 2)) \ |
| 71 | + KBUILD_DEFCONFIG=configs/unit-test-all-hubs-wasm.config \ |
| 72 | + CFLAGS="-g" \ |
| 73 | + TOOL=clang \ |
| 74 | + depend |
| 75 | +
|
| 76 | + - name: Build agent |
| 77 | + run: | |
| 78 | + make -j$((`nproc` * 2))\ |
| 79 | + KBUILD_DEFCONFIG=configs/unit-test-all-hubs-wasm.config\ |
| 80 | + TOOL=clang \ |
| 81 | + SANITIZER=ENABLED \ |
| 82 | + COVERAGE=ccov \ |
| 83 | + CFLAGS="-g -Og -Werror" \ |
| 84 | +
|
| 85 | + - name: Build tests |
| 86 | + run: | |
| 87 | + make -C test -j$((`nproc` * 2))\ |
| 88 | + TOOL=clang \ |
| 89 | + SANITIZER=ENABLED \ |
| 90 | + COVERAGE=ccov \ |
| 91 | + CFLAGS="-g -Og -Werror" \ |
| 92 | + LDFLAGS="-fuse-ld=lld -g" \ |
| 93 | + build |
| 94 | +
|
| 95 | + - name: Install the Python SDK |
| 96 | + run: | |
| 97 | + python3 -m venv .venv |
| 98 | + . .venv/bin/activate |
| 99 | + pip3 install py-sdk/*.whl |
| 100 | +
|
| 101 | + - name: Run tests |
| 102 | + env: |
| 103 | + ASAN_OPTIONS: detect_leaks=1:detect_stack_use_after_return=1 |
| 104 | + UBSAN_OPTIONS: print_stacktrace=1 |
| 105 | + TERM: xterm |
| 106 | + run: . .venv/bin/activate && make -C test -j RUNFLAGS='-c -t 60' |
| 107 | + |
| 108 | + - name: Print failure logs |
| 109 | + if: failure() |
| 110 | + run: | |
| 111 | + awk '/FAIL/ { |
| 112 | + file = FILENAME |
| 113 | + sub(/\.res/, ".log", file) |
| 114 | + printf("::group::%s[%s] log\n", file, $2) |
| 115 | + system("cat " file) |
| 116 | + printf("::endgroup::\n") |
| 117 | + }' test/logs/*/src/*/*.res |
| 118 | +
|
| 119 | + - name: Generate coverage |
| 120 | + run: | |
| 121 | + make \ |
| 122 | + TOOL=clang \ |
| 123 | + COVERAGE=ccov \ |
| 124 | + coverage-ci |
| 125 | +
|
| 126 | + - name: Report HTTP upload performance |
| 127 | + run: | |
| 128 | + ./scripts/print-http-stats.sh >> $GITHUB_STEP_SUMMARY |
| 129 | +
|
| 130 | + # Upload test logs upon failure. |
| 131 | + - name: Upload logs |
| 132 | + uses: actions/upload-artifact@v4 |
| 133 | + if: always() |
| 134 | + with: |
| 135 | + name: test-log-${{ matrix.name }}-${{ matrix.platform }}-${{ github.run_id }}-${{ github.run_attempt }} |
| 136 | + path: test/logs/**/*.log |
| 137 | + retention-days: ${{ job.status == 'success' && '7' || '14' }} |
| 138 | + |
| 139 | + - name: Upload coverage results |
| 140 | + uses: actions/upload-artifact@v4 |
| 141 | + with: |
| 142 | + # Use a specific folder to not overwrite log files |
| 143 | + name: coverage-report-${{ matrix.name }}-${{ matrix.platform }}-${{github.run_id}} |
| 144 | + path: coverage |
| 145 | + retention-days: ${{ job.status == 'success' && '7' || '14' }} |
| 146 | + |
| 147 | + - name: Report code coverage |
| 148 | + if: ${{ matrix.name == 'raspios-bookworm' && matrix.platform == 'arm64' }} |
| 149 | + id: report-action-lcov |
| 150 | + uses: zgosalvez/github-actions-report-lcov@v4.1.2 |
| 151 | + with: |
| 152 | + title-prefix: ${{ matrix.name }}-${{ matrix.platform }} |
| 153 | + coverage-files: coverage/filtered.lcov |
| 154 | + minimum-coverage: 55 |
| 155 | + github-token: ${{ github.token }} |
| 156 | + update-comment: true |
| 157 | + |
| 158 | + - name: Report summary coverage to status |
| 159 | + if: ${{ matrix.name == 'raspios-bookworm' && matrix.platform == 'arm64' }} |
| 160 | + uses: guibranco/github-status-action-v2@v1.1.13 |
| 161 | + with: |
| 162 | + authToken: ${{ github.token }} |
| 163 | + context: "Coverage line level: " |
| 164 | + description: ${{ steps.report-action-lcov.outputs.total-coverage }}% |
| 165 | + state: success |
| 166 | + sha: ${{ github.event.pull_request.head.sha || inputs.ref }} |
0 commit comments