Skip to content

cargo test

cargo test #121

name: cargo test
# Two test paths exercise the integration suite:
#
# - test-prebuilt: bare-metal Linux runner, prebuilt BabbleSim binaries
# pulled from the nrf-sim-bridge GitHub Releases. Fast, runs on every
# push, every PR, and nightly.
#
# - test-source-build: full Zephyr/BabbleSim build from source inside the
# dev container (`cargo xtask docker-build` -> `cargo xtask zephyr-setup
# --build-from-source`). Slow but validates the Dockerfile and the
# Zephyr toolchain end-to-end. Nightly by default; can be run manually.
on:
push:
branches:
- main
- master
pull_request:
schedule:
- cron: '0 2 * * *' # 02:00 UTC nightly
workflow_dispatch:
inputs:
run_cargo_check:
description: Run cargo-check job
type: boolean
required: true
default: true
run_test_prebuilt:
description: Run prebuilt test job
type: boolean
required: true
default: true
run_test_source_build:
description: Run source-build test job
type: boolean
required: true
default: false
permissions:
contents: read
jobs:
cargo-check:
name: cargo check (host)
if: github.event_name != 'workflow_dispatch' || inputs.run_cargo_check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo check --workspace --all-targets
test-prebuilt:
name: cargo test (prebuilt, bare metal)
if: github.event_name != 'workflow_dispatch' || inputs.run_test_prebuilt
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
# `cargo xtask zephyr-setup --prebuilt` only needs to download
# tarballs into external/, so the nrf submodule is not required.
with:
submodules: false
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install BabbleSim runtime deps
# libglib2.0-0 -> bs_2G4_phy_v1 links against glib at runtime
# socat -> spawn_zephyr_rpc_server_with_socat bridges PTY <-> Unix socket
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends libglib2.0-0 socat
- name: cargo xtask zephyr-setup --prebuilt
run: cargo xtask zephyr-setup --prebuilt
- name: cargo test --workspace --lib
run: cargo test --workspace --lib
- name: cargo test --test integration_test
# BabbleSim spawns real processes per test under /tmp/bs_<user>/;
# serialize to avoid sim_id collisions.
run: cargo test --test integration_test -- --test-threads=1
test-source-build:
name: cargo test (source build, devcontainer)
if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.run_test_source_build)
runs-on: ubuntu-latest
steps:
- name: Free up disk space
run: |
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/share/boost "$AGENT_TOOLSDIRECTORY"
docker system prune -af --volumes || true
df -h
- name: Add 8 GB of swap (Zephyr build can OOM otherwise)
run: |
sudo swapoff /swapfile 2>/dev/null || true
sudo rm -f /swapfile
sudo fallocate -l 8G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
free -h
- name: Checkout repository
# Source build needs the nrf submodule for west to resolve manifests.
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Rust toolchain (host, for `cargo xtask docker-build`)
uses: dtolnay/rust-toolchain@stable
- name: cargo xtask docker-build
run: cargo xtask docker-build
- name: Chown workspace to container UID 1000
run: sudo chown -R 1000:1000 "$GITHUB_WORKSPACE"
- name: cargo xtask docker-run zephyr-setup + tests
env:
# This host-side `cargo xtask ...` invocation runs after the workspace
# is chowned for the container user. Keep host artifacts in /tmp so
# host Cargo does not need to write under $GITHUB_WORKSPACE/target.
CARGO_TARGET_DIR: /tmp/cargo-target-host
run: |
cargo xtask docker-run -- bash -lc '
set -euo pipefail
echo "=== cargo xtask zephyr-setup --build-from-source ==="
cargo xtask zephyr-setup --build-from-source
echo "=== cargo test --workspace --lib ==="
cargo test --workspace --lib
echo "=== cargo test --test integration_test ==="
cargo test --test integration_test -- --test-threads=1
'
- name: Restore workspace permissions for runner
if: always()
run: sudo chown -R runner:runner "$GITHUB_WORKSPACE"