| 1 |
name: Tests |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
pull_request: |
| 6 |
workflow_dispatch: |
| 7 |
|
| 8 |
jobs: |
| 9 |
check-previous-run: |
| 10 |
name: Check for previous successful run |
| 11 |
runs-on: ubuntu-latest |
| 12 |
outputs: |
| 13 |
should_skip: ${{ steps.check.outputs.should_skip }} |
| 14 |
steps: |
| 15 |
- name: Check if commit was already tested |
| 16 |
id: check |
| 17 |
env: |
| 18 |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 19 |
run: | |
| 20 |
echo "Current commit: ${{ github.sha }}" |
| 21 |
echo "Current ref: ${{ github.ref }}" |
| 22 |
|
| 23 |
# Check if there's a previous successful workflow run for this exact commit |
| 24 |
PREVIOUS_RUN=$(gh api \ |
| 25 |
-H "Accept: application/vnd.github+json" \ |
| 26 |
"/repos/${{ github.repository }}/actions/workflows/tests.yml/runs?status=success&per_page=5" \ |
| 27 |
--jq '.workflow_runs[] | select(.head_sha == "${{ github.sha }}") | .id' \ |
| 28 |
| head -n 1) |
| 29 |
|
| 30 |
if [ -n "$PREVIOUS_RUN" ] && [ "$PREVIOUS_RUN" != "${{ github.run_id }}" ]; then |
| 31 |
echo "Found previous successful run: $PREVIOUS_RUN" |
| 32 |
echo "should_skip=true" >> $GITHUB_OUTPUT |
| 33 |
else |
| 34 |
echo "No previous successful run found for this commit" |
| 35 |
echo "should_skip=false" >> $GITHUB_OUTPUT |
| 36 |
fi |
| 37 |
|
| 38 |
test-aarch64: |
| 39 |
name: Test aarch64 |
| 40 |
needs: check-previous-run |
| 41 |
if: needs.check-previous-run.outputs.should_skip != 'true' |
| 42 |
strategy: |
| 43 |
matrix: |
| 44 |
os: [ubuntu-22.04-arm, ubuntu-24.04-arm, macos-14, macos-15, macos-26, macos-latest, windows-11-arm] |
| 45 |
rust-toolchain: |
| 46 |
- "1.89" |
| 47 |
- "stable" |
| 48 |
- "nightly" |
| 49 |
runs-on: ${{ matrix.os }} |
| 50 |
steps: |
| 51 |
- uses: actions/checkout@v4 |
| 52 |
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 |
| 53 |
with: |
| 54 |
toolchain: ${{ matrix.rust-toolchain }} |
| 55 |
components: rustfmt, clippy |
| 56 |
cache-key: ${{ matrix.os }}-${{ matrix.rust-toolchain }}-v2 |
| 57 |
- name: Check |
| 58 |
run: cargo check --all-features |
| 59 |
- name: Architecture check |
| 60 |
run: cargo run --features cli --bin arch-check |
| 61 |
- if: ${{ matrix.rust-toolchain != 'nightly' }} |
| 62 |
name: Format |
| 63 |
run: cargo fmt -- --check |
| 64 |
- if: ${{ matrix.rust-toolchain != 'nightly' }} |
| 65 |
name: Clippy |
| 66 |
run: cargo clippy --all-features -- -D warnings |
| 67 |
- name: Test |
| 68 |
run: cargo test --all-features |
| 69 |
|
| 70 |
test-x86_64: |
| 71 |
name: Test x86_64 |
| 72 |
needs: check-previous-run |
| 73 |
if: needs.check-previous-run.outputs.should_skip != 'true' |
| 74 |
strategy: |
| 75 |
matrix: |
| 76 |
os: [ ubuntu-latest, ubuntu-22.04, ubuntu-24.04, macos-15-intel, windows-2022, windows-2025, windows-latest ] |
| 77 |
rust-toolchain: |
| 78 |
- "1.89" |
| 79 |
- "stable" |
| 80 |
- "nightly" |
| 81 |
runs-on: ${{ matrix.os }} |
| 82 |
steps: |
| 83 |
- uses: actions/checkout@v4 |
| 84 |
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 |
| 85 |
with: |
| 86 |
toolchain: ${{ matrix.rust-toolchain }} |
| 87 |
components: rustfmt, clippy |
| 88 |
cache-key: ${{ matrix.os }}-${{ matrix.rust-toolchain }}-v2 |
| 89 |
- name: Check |
| 90 |
run: cargo check --all-features |
| 91 |
- name: Architecture check |
| 92 |
run: cargo run --features cli --bin arch-check |
| 93 |
- if: ${{ matrix.rust-toolchain != 'nightly' }} |
| 94 |
name: Format |
| 95 |
run: cargo fmt -- --check |
| 96 |
- if: ${{ matrix.rust-toolchain != 'nightly' }} |
| 97 |
name: Clippy |
| 98 |
run: cargo clippy --all-features -- -D warnings |
| 99 |
- name: Test |
| 100 |
run: cargo test --all-features |
| 101 |
|
| 102 |
test-x86-linux: |
| 103 |
name: Test x86 Linux |
| 104 |
needs: check-previous-run |
| 105 |
if: needs.check-previous-run.outputs.should_skip != 'true' |
| 106 |
runs-on: ubuntu-latest |
| 107 |
strategy: |
| 108 |
matrix: |
| 109 |
target: [i586-unknown-linux-gnu, i686-unknown-linux-gnu] |
| 110 |
rust-toolchain: |
| 111 |
- "1.89" |
| 112 |
- "stable" |
| 113 |
- "nightly" |
| 114 |
steps: |
| 115 |
- uses: actions/checkout@v4 |
| 116 |
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 |
| 117 |
with: |
| 118 |
toolchain: ${{ matrix.rust-toolchain }} |
| 119 |
components: rustfmt, clippy |
| 120 |
- name: Set up cross |
| 121 |
run: cargo install cross --locked --version 0.2.5 |
| 122 |
- name: Check |
| 123 |
run: cross check --all-features --target ${{ matrix.target }} |
| 124 |
- name: Architecture check |
| 125 |
run: cross run --features cli --bin arch-check --target ${{ matrix.target }} |
| 126 |
- name: Test |
| 127 |
run: cross test --all-features --target ${{ matrix.target }} |
| 128 |
|
| 129 |
test-x86-windows: |
| 130 |
name: Test x86 Windows |
| 131 |
needs: check-previous-run |
| 132 |
if: needs.check-previous-run.outputs.should_skip != 'true' |
| 133 |
runs-on: windows-2022 |
| 134 |
strategy: |
| 135 |
matrix: |
| 136 |
rust-toolchain: |
| 137 |
- "1.89" |
| 138 |
- "stable" |
| 139 |
- "nightly" |
| 140 |
steps: |
| 141 |
- uses: actions/checkout@v4 |
| 142 |
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 |
| 143 |
with: |
| 144 |
toolchain: ${{ matrix.rust-toolchain }} |
| 145 |
target: i686-pc-windows-msvc |
| 146 |
components: rustfmt, clippy |
| 147 |
cache-key: windows-x86-${{ matrix.rust-toolchain }} |
| 148 |
- name: Check |
| 149 |
run: cargo check --all-features --target i686-pc-windows-msvc |
| 150 |
- name: Architecture check |
| 151 |
run: cargo run --features cli --bin arch-check --target i686-pc-windows-msvc |
| 152 |
- if: ${{ matrix.rust-toolchain != 'nightly' }} |
| 153 |
name: Format |
| 154 |
run: cargo fmt -- --check |
| 155 |
- if: ${{ matrix.rust-toolchain != 'nightly' }} |
| 156 |
name: Clippy |
| 157 |
run: cargo clippy --all-features --target i686-pc-windows-msvc -- -D warnings |
| 158 |
- name: Test |
| 159 |
run: cargo test --all-features --target i686-pc-windows-msvc |
| 160 |
|
| 161 |
test-software: |
| 162 |
name: Test software fallback |
| 163 |
needs: check-previous-run |
| 164 |
if: needs.check-previous-run.outputs.should_skip != 'true' |
| 165 |
runs-on: ubuntu-latest |
| 166 |
strategy: |
| 167 |
matrix: |
| 168 |
target: [powerpc-unknown-linux-gnu, powerpc64-unknown-linux-gnu] |
| 169 |
rust-toolchain: |
| 170 |
- "1.89" |
| 171 |
- "stable" |
| 172 |
- "nightly" |
| 173 |
steps: |
| 174 |
- uses: actions/checkout@v4 |
| 175 |
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 |
| 176 |
with: |
| 177 |
toolchain: ${{ matrix.rust-toolchain }} |
| 178 |
components: rustfmt, clippy |
| 179 |
- name: Set up cross |
| 180 |
run: cargo install cross --locked --version 0.2.5 |
| 181 |
- name: Check |
| 182 |
run: cross check --all-features --target ${{ matrix.target }} |
| 183 |
- name: Architecture check |
| 184 |
run: cross run --features cli --bin arch-check --target ${{ matrix.target }} |
| 185 |
- name: Test |
| 186 |
run: cross test --all-features --target ${{ matrix.target }} |
| 187 |
|
| 188 |
miri-test-x86_64: |
| 189 |
name: Miri Test x86_64 |
| 190 |
needs: [check-previous-run, test-x86_64] |
| 191 |
if: needs.check-previous-run.outputs.should_skip != 'true' |
| 192 |
runs-on: ubuntu-24.04 |
| 193 |
steps: |
| 194 |
- uses: actions/checkout@v4 |
| 195 |
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 |
| 196 |
with: |
| 197 |
toolchain: nightly |
| 198 |
components: miri |
| 199 |
- name: Detect CPU cores |
| 200 |
id: cores |
| 201 |
run: | |
| 202 |
CORES=$(nproc) |
| 203 |
echo "count=$CORES" >> $GITHUB_OUTPUT |
| 204 |
echo "use_nextest=$([[ $CORES -ge 2 ]] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT |
| 205 |
- name: Install nextest |
| 206 |
if: steps.cores.outputs.use_nextest == 'true' |
| 207 |
run: cargo install cargo-nextest --locked |
| 208 |
- name: Setup Miri |
| 209 |
run: cargo miri setup |
| 210 |
- name: Run Miri tests (parallel) |
| 211 |
if: steps.cores.outputs.use_nextest == 'true' |
| 212 |
run: cargo miri nextest run --all-features -j${{ steps.cores.outputs.count }} |
| 213 |
- name: Run Miri tests (serial) |
| 214 |
if: steps.cores.outputs.use_nextest == 'false' |
| 215 |
run: cargo miri test --all-features |
| 216 |
|
| 217 |
test-no-std: |
| 218 |
name: Test no_std |
| 219 |
needs: check-previous-run |
| 220 |
if: needs.check-previous-run.outputs.should_skip != 'true' |
| 221 |
runs-on: ubuntu-latest |
| 222 |
strategy: |
| 223 |
matrix: |
| 224 |
target: |
| 225 |
- thumbv7em-none-eabihf |
| 226 |
- thumbv8m.main-none-eabihf |
| 227 |
- riscv32imac-unknown-none-elf |
| 228 |
rust-toolchain: |
| 229 |
- "1.89" |
| 230 |
- "stable" |
| 231 |
- "nightly" |
| 232 |
steps: |
| 233 |
- uses: actions/checkout@v4 |
| 234 |
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 |
| 235 |
with: |
| 236 |
toolchain: ${{ matrix.rust-toolchain }} |
| 237 |
target: ${{ matrix.target }} |
| 238 |
components: rustfmt, clippy |
| 239 |
cache-key: ${{ matrix.target }}-${{ matrix.rust-toolchain }}-v2 |
| 240 |
- name: Check no_std (no features) |
| 241 |
run: cargo check --target ${{ matrix.target }} --no-default-features --features panic-handler --lib |
| 242 |
- name: Check no_std with alloc |
| 243 |
run: cargo check --target ${{ matrix.target }} --no-default-features --features alloc,panic-handler --lib |
| 244 |
- name: Check no_std with cache |
| 245 |
run: cargo check --target ${{ matrix.target }} --no-default-features --features cache,panic-handler --lib |
| 246 |
- name: Run no_std tests (on host with std test harness) |
| 247 |
run: cargo test --test no_std_tests |
| 248 |
|
| 249 |
test-wasm: |
| 250 |
name: Test WASM |
| 251 |
needs: check-previous-run |
| 252 |
if: needs.check-previous-run.outputs.should_skip != 'true' |
| 253 |
runs-on: ubuntu-latest |
| 254 |
strategy: |
| 255 |
matrix: |
| 256 |
include: |
| 257 |
|
| 258 |
- target: wasm32-unknown-unknown |
| 259 |
rust-toolchain: "1.89" |
| 260 |
- target: wasm32-unknown-unknown |
| 261 |
rust-toolchain: "stable" |
| 262 |
- target: wasm32-unknown-unknown |
| 263 |
rust-toolchain: "nightly" |
| 264 |
|
| 265 |
- target: wasm32-wasip1 |
| 266 |
rust-toolchain: "1.89" |
| 267 |
- target: wasm32-wasip1 |
| 268 |
rust-toolchain: "stable" |
| 269 |
- target: wasm32-wasip1 |
| 270 |
rust-toolchain: "nightly" |
| 271 |
|
| 272 |
- target: wasm32-wasip2 |
| 273 |
rust-toolchain: "nightly" |
| 274 |
|
| 275 |
steps: |
| 276 |
- uses: actions/checkout@v4 |
| 277 |
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 |
| 278 |
with: |
| 279 |
toolchain: ${{ matrix.rust-toolchain }} |
| 280 |
target: ${{ matrix.target }} |
| 281 |
components: rustfmt, clippy |
| 282 |
cache-key: ${{ matrix.target }}-${{ matrix.rust-toolchain }}-v2 |
| 283 |
- name: Check WASM (no features) |
| 284 |
run: cargo check --target ${{ matrix.target }} --no-default-features --features panic-handler --lib |
| 285 |
- name: Check WASM with alloc |
| 286 |
run: cargo check --target ${{ matrix.target }} --no-default-features --features alloc,panic-handler --lib |
| 287 |
- name: Check WASM with cache |
| 288 |
run: cargo check --target ${{ matrix.target }} --no-default-features --features cache,panic-handler --lib |
| 289 |
- name: Build WASM release |
| 290 |
run: cargo build --target ${{ matrix.target }} --no-default-features --features alloc,panic-handler --lib --release |
| 291 |
- name: Run WASM tests (on host with std test harness) |
| 292 |
run: cargo test --test wasm_tests |
| 293 |
- if: ${{ matrix.target == 'wasm32-unknown-unknown' && matrix.rust-toolchain == 'stable' }} |
| 294 |
name: Install wasm-pack |
| 295 |
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh |
| 296 |
- if: ${{ matrix.target == 'wasm32-unknown-unknown' && matrix.rust-toolchain == 'stable' }} |
| 297 |
name: Build WASM package with wasm-pack |
| 298 |
run: wasm-pack build --target web --no-default-features --features alloc,panic-handler |
| 299 |
|
| 300 |
fuzz-test: |
| 301 |
name: Fuzz Testing |
| 302 |
needs: check-previous-run |
| 303 |
if: needs.check-previous-run.outputs.should_skip != 'true' |
| 304 |
runs-on: ${{ matrix.os }} |
| 305 |
strategy: |
| 306 |
fail-fast: false |
| 307 |
matrix: |
| 308 |
os: [ubuntu-24.04, ubuntu-24.04-arm] |
| 309 |
fuzz-target: |
| 310 |
- digest_crc32_autosar |
| 311 |
- digest_crc32_bzip2 |
| 312 |
- digest_crc32_iscsi |
| 313 |
- digest_crc32_iso_hdlc |
| 314 |
- digest_crc64_ecma_182 |
| 315 |
- digest_crc64_nvme |
| 316 |
- checksum_crc32_autosar |
| 317 |
- checksum_crc32_bzip2 |
| 318 |
- checksum_crc32_iscsi |
| 319 |
- checksum_crc32_iso_hdlc |
| 320 |
- checksum_crc64_ecma_182 |
| 321 |
- checksum_crc64_nvme |
| 322 |
steps: |
| 323 |
- uses: actions/checkout@v4 |
| 324 |
- uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 |
| 325 |
with: |
| 326 |
toolchain: nightly |
| 327 |
cache-key: ${{ matrix.os }}-nightly-fuzz |
| 328 |
- name: Install cargo-fuzz |
| 329 |
run: cargo install cargo-fuzz |
| 330 |
- name: Run fuzzer |
| 331 |
run: | |
| 332 |
cargo fuzz run ${{ matrix.fuzz-target }} -- \ |
| 333 |
-max_total_time=60 \ |
| 334 |
-rss_limit_mb=2048 \ |
| 335 |
-timeout=10 \ |
| 336 |
-print_final_stats=1 |
| 337 |
continue-on-error: true |
| 338 |
- name: Upload artifacts on crash |
| 339 |
if: failure() |
| 340 |
uses: actions/upload-artifact@v4 |
| 341 |
with: |
| 342 |
name: fuzz-artifacts-${{ matrix.os }}-${{ matrix.fuzz-target }} |
| 343 |
path: fuzz/artifacts/${{ matrix.fuzz-target }}/ |
| 344 |
|
| 345 |
tests-complete: |
| 346 |
name: All tests complete |
| 347 |
needs: [check-previous-run, test-aarch64, test-x86_64, test-x86-linux, test-x86-windows, test-software, miri-test-x86_64, test-no-std, test-wasm, fuzz-test] |
| 348 |
if: always() |
| 349 |
runs-on: ubuntu-latest |
| 350 |
steps: |
| 351 |
- name: Check test results |
| 352 |
run: | |
| 353 |
echo "Checking test results..." |
| 354 |
echo "Previous run check: ${{ needs.check-previous-run.result }}" |
| 355 |
echo "Should skip: ${{ needs.check-previous-run.outputs.should_skip }}" |
| 356 |
|
| 357 |
if [ "${{ needs.check-previous-run.outputs.should_skip }}" == "true" ]; then |
| 358 |
echo "✓ Tests were skipped because this commit was already tested successfully" |
| 359 |
exit 0 |
| 360 |
fi |
| 361 |
|
| 362 |
# Check if any test job failed |
| 363 |
if [ "${{ needs.test-aarch64.result }}" == "failure" ] || \ |
| 364 |
[ "${{ needs.test-x86_64.result }}" == "failure" ] || \ |
| 365 |
[ "${{ needs.test-x86-linux.result }}" == "failure" ] || \ |
| 366 |
[ "${{ needs.test-x86-windows.result }}" == "failure" ] || \ |
| 367 |
[ "${{ needs.test-software.result }}" == "failure" ] || \ |
| 368 |
[ "${{ needs.miri-test-x86_64.result }}" == "failure" ] || \ |
| 369 |
[ "${{ needs.test-no-std.result }}" == "failure" ] || \ |
| 370 |
[ "${{ needs.test-wasm.result }}" == "failure" ] || \ |
| 371 |
[ "${{ needs.fuzz-test.result }}" == "failure" ]; then |
| 372 |
echo "✗ One or more test jobs failed" |
| 373 |
exit 1 |
| 374 |
fi |
| 375 |
|
| 376 |
echo "✓ All test jobs passed" |