From fd03e7500d7aa01f7132af7458122e9f1cd55b1a Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 30 Jan 2023 21:24:12 +0100 Subject: [PATCH] Added testing to rtic-arbiter --- .github/workflows/build.yml | 93 +++++++++++++++++++++++++++++++++++++ rtic-arbiter/src/lib.rs | 25 +++++++++- 2 files changed, 117 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 650fc533da..3ef7d52e18 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,6 +29,21 @@ jobs: working-directory: ./rtic run: cargo fmt --all -- --check + stylearbiter: + name: cargo fmt rtic-arbiter + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Fail on warnings + working-directory: ./rtic-arbiter + run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs + + - name: cargo fmt --check + working-directory: ./rtic-arbiter + run: cargo fmt --all -- --check + stylechannel: name: cargo fmt rtic-channel runs-on: ubuntu-22.04 @@ -112,6 +127,43 @@ jobs: working-directory: ./rtic run: cargo check --target=${{ matrix.target }} + # Compilation check + checkarbiter: + name: check rtic-arbiter + runs-on: ubuntu-22.04 + strategy: + matrix: + target: + - thumbv7m-none-eabi + - thumbv6m-none-eabi + - x86_64-unknown-linux-gnu + toolchain: + - nightly + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Rust ${{ matrix.toolchain }} + working-directory: ./rtic-arbiter + run: | + rustup set profile minimal + rustup override set ${{ matrix.toolchain }} + + - name: Configure Rust target (${{ matrix.target }}) + working-directory: ./rtic-arbiter + run: rustup target add ${{ matrix.target }} + + - name: Fail on warnings + working-directory: ./rtic-arbiter + run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs + + - name: Cache Dependencies + uses: Swatinem/rust-cache@v2 + + - name: cargo check + working-directory: ./rtic-arbiter + run: cargo check --target=${{ matrix.target }} + # Compilation check checkchannel: name: check rtic-channel @@ -246,6 +298,28 @@ jobs: working-directory: ./rtic run: cargo clippy + clippyarbiter: + name: Cargo clippy rtic-arbiter + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Fail on warnings + working-directory: ./rtic-arbiter + run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs + + - name: Add Rust component clippy + working-directory: ./rtic-arbiter + run: rustup component add clippy + + - name: Cache Dependencies + uses: Swatinem/rust-cache@v2 + + - name: cargo clippy + working-directory: ./rtic-arbiter + run: cargo clippy + clippychannel: name: Cargo clippy rtic-channel runs-on: ubuntu-22.04 @@ -465,6 +539,25 @@ jobs: working-directory: ./rtic run: cargo test --test tests + # Run test suite + testsarbiter: + name: tests rtic-arbiter + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Cache Dependencies + uses: Swatinem/rust-cache@v2 + + - name: Fail on warnings + working-directory: ./rtic-arbiter + run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs + + - name: Run cargo test + working-directory: ./rtic-arbiter + run: cargo test --features testing + # Run test suite testschannel: name: tests rtic-channel diff --git a/rtic-arbiter/src/lib.rs b/rtic-arbiter/src/lib.rs index 487c64cecd..519ce2cd34 100644 --- a/rtic-arbiter/src/lib.rs +++ b/rtic-arbiter/src/lib.rs @@ -36,6 +36,9 @@ pub struct Arbiter { taken: AtomicBool, } +unsafe impl Send for Arbiter {} +unsafe impl Sync for Arbiter {} + impl Arbiter { /// Create a new arbiter. pub const fn new(inner: T) -> Self { @@ -171,5 +174,25 @@ extern crate std; #[cfg(test)] mod tests { - // use super::*; + use super::*; + + #[tokio::test] + async fn stress_channel() { + const NUM_RUNS: usize = 100_000; + + static ARB: Arbiter = Arbiter::new(0); + let mut v = std::vec::Vec::new(); + + for _ in 0..NUM_RUNS { + v.push(tokio::spawn(async move { + *ARB.access().await += 1; + })); + } + + for v in v { + v.await.unwrap(); + } + + assert_eq!(*ARB.access().await, NUM_RUNS) + } }