mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-12-24 02:49:34 +01:00
Added testing to rtic-arbiter
This commit is contained in:
parent
5c1cefbf4e
commit
f2e0cd342e
2 changed files with 117 additions and 1 deletions
93
.github/workflows/build.yml
vendored
93
.github/workflows/build.yml
vendored
|
@ -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
|
||||
|
|
|
@ -36,6 +36,9 @@ pub struct Arbiter<T> {
|
|||
taken: AtomicBool,
|
||||
}
|
||||
|
||||
unsafe impl<T> Send for Arbiter<T> {}
|
||||
unsafe impl<T> Sync for Arbiter<T> {}
|
||||
|
||||
impl<T> Arbiter<T> {
|
||||
/// 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<usize> = 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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue