mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
Added testing to rtic-arbiter
This commit is contained in:
parent
ac891333f1
commit
fd03e7500d
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
|
working-directory: ./rtic
|
||||||
run: cargo fmt --all -- --check
|
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:
|
stylechannel:
|
||||||
name: cargo fmt rtic-channel
|
name: cargo fmt rtic-channel
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
@ -112,6 +127,43 @@ jobs:
|
||||||
working-directory: ./rtic
|
working-directory: ./rtic
|
||||||
run: cargo check --target=${{ matrix.target }}
|
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
|
# Compilation check
|
||||||
checkchannel:
|
checkchannel:
|
||||||
name: check rtic-channel
|
name: check rtic-channel
|
||||||
|
@ -246,6 +298,28 @@ jobs:
|
||||||
working-directory: ./rtic
|
working-directory: ./rtic
|
||||||
run: cargo clippy
|
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:
|
clippychannel:
|
||||||
name: Cargo clippy rtic-channel
|
name: Cargo clippy rtic-channel
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
@ -465,6 +539,25 @@ jobs:
|
||||||
working-directory: ./rtic
|
working-directory: ./rtic
|
||||||
run: cargo test --test tests
|
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
|
# Run test suite
|
||||||
testschannel:
|
testschannel:
|
||||||
name: tests rtic-channel
|
name: tests rtic-channel
|
||||||
|
|
|
@ -36,6 +36,9 @@ pub struct Arbiter<T> {
|
||||||
taken: AtomicBool,
|
taken: AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl<T> Send for Arbiter<T> {}
|
||||||
|
unsafe impl<T> Sync for Arbiter<T> {}
|
||||||
|
|
||||||
impl<T> Arbiter<T> {
|
impl<T> Arbiter<T> {
|
||||||
/// Create a new arbiter.
|
/// Create a new arbiter.
|
||||||
pub const fn new(inner: T) -> Self {
|
pub const fn new(inner: T) -> Self {
|
||||||
|
@ -171,5 +174,25 @@ extern crate std;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
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