|
| 1 | +name: Hardware SPDM Test |
| 2 | + |
| 3 | +# Runs examples/spdm/spdm_test.sh on the self-hosted Pi with a real TPM. |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: [master] |
| 8 | + paths: |
| 9 | + - 'src/spdm/**' |
| 10 | + - 'wolftpm/spdm/**' |
| 11 | + - 'examples/spdm/**' |
| 12 | + - 'src/tpm2_wrap.c' |
| 13 | + - 'src/tpm2_spdm.c' |
| 14 | + - 'src/tpm2.c' |
| 15 | + - 'hal/tpm_io_linux.c' |
| 16 | + - 'configure.ac' |
| 17 | + - '.github/workflows/hw-spdm-test.yml' |
| 18 | + - 'scripts/hw-runner-health-check.sh' |
| 19 | + - 'tests/unit_tests.c' |
| 20 | + pull_request_target: |
| 21 | + branches: [master] |
| 22 | + types: [opened, synchronize, reopened] |
| 23 | + paths: |
| 24 | + - 'src/spdm/**' |
| 25 | + - 'wolftpm/spdm/**' |
| 26 | + - 'examples/spdm/**' |
| 27 | + - 'src/tpm2_wrap.c' |
| 28 | + - 'src/tpm2_spdm.c' |
| 29 | + - 'src/tpm2.c' |
| 30 | + - 'hal/tpm_io_linux.c' |
| 31 | + - 'configure.ac' |
| 32 | + - '.github/workflows/hw-spdm-test.yml' |
| 33 | + - 'scripts/hw-runner-health-check.sh' |
| 34 | + - 'tests/unit_tests.c' |
| 35 | + |
| 36 | +permissions: read-all |
| 37 | + |
| 38 | +# Serialize runs; hardware state is shared. |
| 39 | +concurrency: |
| 40 | + group: hw-spdm-runner |
| 41 | + cancel-in-progress: false |
| 42 | + |
| 43 | +jobs: |
| 44 | + hw-spdm: |
| 45 | + if: > |
| 46 | + github.event_name != 'pull_request_target' || |
| 47 | + contains(fromJSON('["OWNER","MEMBER"]'), |
| 48 | + github.event.pull_request.author_association) |
| 49 | + runs-on: [self-hosted, Linux, ARM64, wolftpm-spdm] |
| 50 | + timeout-minutes: 25 |
| 51 | + |
| 52 | + strategy: |
| 53 | + fail-fast: false |
| 54 | + matrix: |
| 55 | + include: |
| 56 | + - vendor: nuvoton |
| 57 | + expected_vendor: "NPCT75x" |
| 58 | + wolftpm_config: "--enable-spdm --enable-nuvoton --enable-debug" |
| 59 | + spi_cs: "0" |
| 60 | + modes: "nuvoton" |
| 61 | + - vendor: nations |
| 62 | + expected_vendor: "NS350" |
| 63 | + wolftpm_config: "--enable-spdm --enable-nations --enable-debug" |
| 64 | + spi_cs: "1" |
| 65 | + modes: "nations nations-psk" |
| 66 | + |
| 67 | + steps: |
| 68 | + - name: Harden Runner |
| 69 | + uses: step-security/harden-runner@6c3c2f2c1c457b00c10c4848d6f5491db3b629df # v2.18.0 |
| 70 | + with: |
| 71 | + egress-policy: audit |
| 72 | + |
| 73 | + - name: Checkout wolfTPM |
| 74 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 75 | + with: |
| 76 | + ref: ${{ github.event.pull_request.head.sha || github.sha }} |
| 77 | + persist-credentials: false |
| 78 | + |
| 79 | + - name: Hardware health check |
| 80 | + id: health |
| 81 | + continue-on-error: true |
| 82 | + run: bash scripts/hw-runner-health-check.sh "${{ matrix.spi_cs }}" |
| 83 | + |
| 84 | + - name: Warn if health check failed |
| 85 | + if: steps.health.outcome == 'failure' |
| 86 | + run: echo "::warning::Runner hardware check failed on ${{ runner.name }}. Skipping hardware tests." |
| 87 | + |
| 88 | + - name: Clean workspace (preserve wolfssl cache dir) |
| 89 | + if: steps.health.outcome == 'success' |
| 90 | + run: git clean -xdf |
| 91 | + |
| 92 | + - name: Resolve wolfSSL SHA and choose prefix |
| 93 | + id: wolfssl |
| 94 | + if: steps.health.outcome == 'success' |
| 95 | + run: | |
| 96 | + MAX_CACHE_AGE_SECS=86400 |
| 97 | + SHA=$(curl -sf https://api.github.com/repos/wolfssl/wolfssl/commits/master | jq -r .sha) |
| 98 | + echo "sha=$SHA" >> "$GITHUB_OUTPUT" |
| 99 | + HIT=false |
| 100 | + if [ "${{ github.event_name }}" = "push" ]; then |
| 101 | + PREFIX="$HOME/wolfssl-install" |
| 102 | + if [ -f "$PREFIX/.sha" ] && [ "$(cat "$PREFIX/.sha")" = "$SHA" ]; then |
| 103 | + AGE=$(( $(date +%s) - $(stat -c %Y "$PREFIX/.sha") )) |
| 104 | + [ "$AGE" -lt "$MAX_CACHE_AGE_SECS" ] && HIT=true |
| 105 | + fi |
| 106 | + else |
| 107 | + PREFIX="$RUNNER_TEMP/wolfssl-install" |
| 108 | + mkdir -p "$PREFIX" |
| 109 | + fi |
| 110 | + echo "prefix=$PREFIX" >> "$GITHUB_OUTPUT" |
| 111 | + echo "hit=$HIT" >> "$GITHUB_OUTPUT" |
| 112 | +
|
| 113 | + - name: Checkout wolfSSL |
| 114 | + if: steps.health.outcome == 'success' && steps.wolfssl.outputs.hit != 'true' |
| 115 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 116 | + with: |
| 117 | + repository: wolfssl/wolfssl |
| 118 | + path: wolfssl |
| 119 | + ref: ${{ steps.wolfssl.outputs.sha }} |
| 120 | + persist-credentials: false |
| 121 | + |
| 122 | + - name: Build & install wolfSSL (user prefix, no sudo) |
| 123 | + if: steps.health.outcome == 'success' && steps.wolfssl.outputs.hit != 'true' |
| 124 | + working-directory: ./wolfssl |
| 125 | + run: | |
| 126 | + ./autogen.sh |
| 127 | + ./configure --prefix=${{ steps.wolfssl.outputs.prefix }} \ |
| 128 | + --enable-wolftpm --enable-ecc --enable-sha384 \ |
| 129 | + --enable-aesgcm --enable-hkdf --enable-sp |
| 130 | + make -j"$(nproc)" |
| 131 | + make install |
| 132 | + echo '${{ steps.wolfssl.outputs.sha }}' > '${{ steps.wolfssl.outputs.prefix }}/.sha' |
| 133 | +
|
| 134 | + - name: Build wolfTPM (${{ matrix.vendor }}) |
| 135 | + if: steps.health.outcome == 'success' |
| 136 | + run: | |
| 137 | + ./autogen.sh |
| 138 | + ./configure ${{ matrix.wolftpm_config }} \ |
| 139 | + CPPFLAGS='-DTPM2_SPI_DEV_CS="${{ matrix.spi_cs }}"' \ |
| 140 | + CFLAGS="-I${{ steps.wolfssl.outputs.prefix }}/include" \ |
| 141 | + LDFLAGS="-L${{ steps.wolfssl.outputs.prefix }}/lib" |
| 142 | + make -j"$(nproc)" |
| 143 | +
|
| 144 | + - name: Detect ${{ matrix.vendor }} TPM on SPI CS ${{ matrix.spi_cs }} |
| 145 | + id: detect |
| 146 | + if: steps.health.outcome == 'success' |
| 147 | + env: |
| 148 | + LD_LIBRARY_PATH: ${{ steps.wolfssl.outputs.prefix }}/lib |
| 149 | + run: | |
| 150 | + EXPECTED='${{ matrix.expected_vendor }}' |
| 151 | + # caps may hang or error if no chip is at this CS; time-bound it. |
| 152 | + OUT=$(timeout 15 ./examples/wrap/caps 2>&1 || true) |
| 153 | + echo "$OUT" |
| 154 | + if echo "$OUT" | grep -q "Vendor ${EXPECTED}"; then |
| 155 | + echo "present=true" >> "$GITHUB_OUTPUT" |
| 156 | + echo "[detect] ${EXPECTED} TPM found on CS ${{ matrix.spi_cs }}" |
| 157 | + else |
| 158 | + echo "present=false" >> "$GITHUB_OUTPUT" |
| 159 | + fi |
| 160 | +
|
| 161 | + - name: Warn if ${{ matrix.vendor }} TPM not present |
| 162 | + if: steps.health.outcome == 'success' && steps.detect.outputs.present == 'false' |
| 163 | + run: echo "::warning::${{ matrix.expected_vendor }} not detected on SPI CS ${{ matrix.spi_cs }}. Skipping ${{ matrix.vendor }} SPDM tests — wire the chip and re-run, or ignore if this vendor isn't installed on this runner." |
| 164 | + |
| 165 | + - name: Run SPDM hardware tests (${{ matrix.vendor }}) |
| 166 | + if: steps.health.outcome == 'success' && steps.detect.outputs.present == 'true' |
| 167 | + env: |
| 168 | + LD_LIBRARY_PATH: ${{ steps.wolfssl.outputs.prefix }}/lib |
| 169 | + run: | |
| 170 | + set -e |
| 171 | + for mode in ${{ matrix.modes }}; do |
| 172 | + echo "=== spdm_test.sh mode=$mode ===" |
| 173 | + ./examples/spdm/spdm_test.sh ./examples/spdm/spdm_ctrl "$mode" \ |
| 174 | + 2>&1 | tee "spdm-${{ matrix.vendor }}-${mode}.log" |
| 175 | + done |
| 176 | +
|
| 177 | + - name: Post-job cleanup |
| 178 | + if: always() && steps.health.outcome == 'success' && steps.detect.outputs.present == 'true' |
| 179 | + env: |
| 180 | + LD_LIBRARY_PATH: ${{ steps.wolfssl.outputs.prefix }}/lib |
| 181 | + run: | |
| 182 | + pgrep -u "$(id -u)" -a | grep -vE '(Runner\.Listener|Runner\.Worker|actions-runner)' || true |
| 183 | + pkill -u "$(id -u)" -f 'spdm_ctrl|unit\.test|caps$' 2>/dev/null || true |
| 184 | + sleep 1 |
| 185 | + gpioset gpiochip0 4=0 2>/dev/null && sleep 0.1 && gpioset gpiochip0 4=1 2>/dev/null || true |
| 186 | + sleep 2 |
| 187 | + ./examples/spdm/spdm_ctrl --connect --unlock 2>/dev/null || true |
| 188 | + ./examples/management/flush 2>/dev/null || true |
| 189 | + echo "[cleanup] done" |
| 190 | +
|
| 191 | + - name: Upload logs on failure |
| 192 | + if: failure() |
| 193 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 194 | + with: |
| 195 | + name: hw-spdm-logs-${{ matrix.vendor }} |
| 196 | + path: | |
| 197 | + *.log |
| 198 | + config.log |
| 199 | + retention-days: 14 |
0 commit comments