Add qemu CI #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on: | |
| push: | |
| branches: [ master ] | |
| pull_request: | |
| merge_group: | |
| name: QEMU tests | |
| jobs: | |
| qemu-tests: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| toolchain: [ stable, nightly, 1.68.0 ] | |
| target: | |
| - riscv32i-unknown-none-elf | |
| - riscv32im-unknown-none-elf | |
| - riscv32imc-unknown-none-elf | |
| - riscv32imac-unknown-none-elf | |
| - riscv32imafc-unknown-none-elf | |
| - riscv64imac-unknown-none-elf | |
| - riscv64gc-unknown-none-elf | |
| example: | |
| - empty | |
| - multi_core | |
| features: | |
| - "" | |
| - s-mode | |
| - single-hart | |
| - v-trap | |
| - s-mode,single-hart,v-trap | |
| include: | |
| # Nightly is only for reference and allowed to fail | |
| - toolchain: nightly | |
| experimental: true | |
| exclude: | |
| - toolchain: 1.68.0 | |
| target: riscv32im-unknown-none-elf | |
| - toolchain: 1.68.0 | |
| target: riscv32imafc-unknown-none-elf | |
| runs-on: ubuntu-latest | |
| continue-on-error: ${{ matrix.experimental || false }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Cache cargo | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-${{ matrix.toolchain }}- | |
| - uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: ${{ matrix.toolchain }} | |
| targets: ${{ matrix.target }} | |
| - name: Install QEMU | |
| run: | | |
| set -euo pipefail | |
| for i in 1 2 3; do | |
| sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-system-misc && break || sleep 5 | |
| done | |
| qemu-system-riscv64 --version || true | |
| qemu-system-riscv32 --version || true | |
| - name: Build example for QEMU | |
| run: | | |
| set -euo pipefail | |
| FEATURES_ARG="" | |
| if [ -n "${{ matrix.features }}" ]; then | |
| FEATURES_ARG="--features=${{ matrix.features }}" | |
| fi | |
| RUSTFLAGS="-C link-arg=-Triscv-rt/examples/device.x" cargo build --locked --package riscv-rt --target ${{ matrix.target }} --example ${{ matrix.example }} --release ${FEATURES_ARG} | |
| - name: Run example on QEMU (riscv32) | |
| if: startsWith(matrix.target, 'riscv32') | |
| run: | | |
| set -euo pipefail | |
| FEATURES_LABEL="" | |
| if [ -n "${{ matrix.features }}" ]; then | |
| FEATURES_LABEL=" (${{ matrix.features }})" | |
| else | |
| FEATURES_LABEL=" (no features)" | |
| fi | |
| timeout 30 qemu-system-riscv32 -machine sifive_u -nographic -serial mon:stdio -kernel target/${{ matrix.target }}/release/examples/${{ matrix.example }} || { | |
| exitcode=$? | |
| if [ $exitcode -eq 124 ]; then | |
| echo "ERROR: QEMU timeout${FEATURES_LABEL}" | |
| exit 1 | |
| fi | |
| exit $exitcode | |
| } | |
| - name: Run example on QEMU (riscv64) | |
| if: startsWith(matrix.target, 'riscv64') | |
| run: | | |
| set -euo pipefail | |
| FEATURES_LABEL="" | |
| if [ -n "${{ matrix.features }}" ]; then | |
| FEATURES_LABEL=" (${{ matrix.features }})" | |
| else | |
| FEATURES_LABEL=" (no features)" | |
| fi | |
| timeout 30 qemu-system-riscv64 -machine sifive_u -nographic -serial mon:stdio -kernel target/${{ matrix.target }}/release/examples/${{ matrix.example }} || { | |
| exitcode=$? | |
| if [ $exitcode -eq 124 ]; then | |
| echo "ERROR: QEMU timeout${FEATURES_LABEL}" | |
| exit 1 | |
| fi | |
| exit $exitcode | |
| } |