|
| 1 | +name: Native AOT tests |
| 2 | + |
| 3 | +# Publishes the test suite with PublishAot and runs the native binary on x64 and arm64. |
| 4 | +# |
| 5 | +# Not a duplicate of the JIT run: ILC resolves Vector256/Vector128.IsHardwareAccelerated at build |
| 6 | +# time against an instruction-set baseline instead of against the live CPU, so the same source can |
| 7 | +# compile to a different kernel. The x86-64-v3 legs guarantee AVX2; the default ones do not. |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches: [ master, main ] |
| 12 | + pull_request: |
| 13 | + branches: [ master, main ] |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +jobs: |
| 17 | + aot: |
| 18 | + name: ${{ matrix.rid }}${{ matrix.instruction-set && format(' ({0})', matrix.instruction-set) || '' }} |
| 19 | + runs-on: ${{ matrix.runner }} |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + include: |
| 27 | + - { runner: ubuntu-24.04, rid: linux-x64, instruction-set: '' } |
| 28 | + - { runner: ubuntu-24.04, rid: linux-x64, instruction-set: x86-64-v3 } |
| 29 | + - { runner: ubuntu-24.04-arm, rid: linux-arm64, instruction-set: '' } |
| 30 | + - { runner: macos-26, rid: osx-arm64, instruction-set: '' } |
| 31 | + - { runner: windows-2025, rid: win-x64, instruction-set: x86-64-v3 } |
| 32 | + |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v7 |
| 35 | + |
| 36 | + - name: Setup .NET |
| 37 | + uses: actions/setup-dotnet@v5 |
| 38 | + with: |
| 39 | + dotnet-version: 10.0.x |
| 40 | + |
| 41 | + # ILC links through clang and needs zlib's headers. |
| 42 | + - name: Install native toolchain (Linux) |
| 43 | + if: runner.os == 'Linux' |
| 44 | + run: sudo apt-get update && sudo apt-get install -y clang zlib1g-dev |
| 45 | + |
| 46 | + # An empty IlcInstructionSet is a no-op, so the default-baseline legs need no special case. |
| 47 | + - name: Publish (Native AOT) |
| 48 | + shell: bash |
| 49 | + run: | |
| 50 | + dotnet publish src/Base58Encoding.Tests/Base58Encoding.Tests.csproj \ |
| 51 | + --configuration Release --runtime ${{ matrix.rid }} --output aot-out \ |
| 52 | + -p:PublishAot=true -p:IlcInstructionSet=${{ matrix.instruction-set }} 2>&1 | tee publish.log |
| 53 | +
|
| 54 | + # Scoped to Base58Encoding so an unrelated xunit or SimpleBase warning cannot fail CI. Warning |
| 55 | + # lines end with the driving project path, which contains the name too, so strip it first. |
| 56 | + - name: Assert no AOT/trim warnings from the library |
| 57 | + shell: bash |
| 58 | + run: | |
| 59 | + ours=$(grep -E 'warning IL[0-9]+' publish.log | sed -E 's/ \[[^][]*\]$//' | grep 'Base58Encoding' || true) |
| 60 | + if [ -n "$ours" ]; then |
| 61 | + echo "::error::Base58Encoding produced trim/AOT warnings:" |
| 62 | + echo "$ours" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | +
|
| 66 | + # No `dotnet` in front: a standalone binary. bash resolves the .exe suffix on Windows. |
| 67 | + - name: Run the suite natively |
| 68 | + shell: bash |
| 69 | + run: | |
| 70 | + chmod +x aot-out/Base58Encoding.Tests* |
| 71 | + ./aot-out/Base58Encoding.Tests | tee native.log |
| 72 | +
|
| 73 | + # The xunit package is swapped on PublishAot, so the native legs discover tests with a source |
| 74 | + # generator while every other run uses reflection. Source-generated discovery is a strict subset: |
| 75 | + # a test it cannot see (generic test methods, interface-based attributes) is silently absent |
| 76 | + # rather than an error, so without this both legs would go green while the native one tested |
| 77 | + # less. Runtime-skipped tests still count toward Total -- VectorInstructionSetTests skips itself |
| 78 | + # here -- so a mismatch means genuinely undiscovered tests. One leg is enough: discovery does not |
| 79 | + # vary by RID or instruction set. The counts are read from the last summary line: a failing |
| 80 | + # VectorInstructionSetTests dumps its child's console output, which carries one too. |
| 81 | + - name: Discovery parity with the JIT package |
| 82 | + if: matrix.rid == 'linux-x64' && matrix.instruction-set == '' |
| 83 | + shell: bash |
| 84 | + run: | |
| 85 | + dotnet run --project src/Base58Encoding.Tests/Base58Encoding.Tests.csproj --configuration Release | tee jit.log |
| 86 | + native=$(grep -oP 'Total: \K[0-9]+' native.log | tail -1) |
| 87 | + jit=$(grep -oP 'Total: \K[0-9]+' jit.log | tail -1) |
| 88 | + echo "native discovered $native, JIT discovered $jit" |
| 89 | + if [ -z "$native" ] || [ -z "$jit" ]; then |
| 90 | + echo "::error::could not parse a test count from one of the runs" |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + if [ "$native" != "$jit" ]; then |
| 94 | + echo "::error::source-generated discovery found $native tests, reflection found $jit" |
| 95 | + exit 1 |
| 96 | + fi |
0 commit comments