Skip to content

Commit

Permalink
tests: Add WASM testing
Browse files Browse the repository at this point in the history
This commit ensures this crate builds and works on WASM.

Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull authored Dec 16, 2023
1 parent 79b9292 commit 71302ab
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ jobs:
- name: Install Rust
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- run: rustup target add thumbv7m-none-eabi
- name: Install cargo-hack
uses: taiki-e/install-action@cargo-hack
- run: rustup target add wasm32-unknown-unknown
- name: Install cargo-hack and wasm-pack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack,wasm-pack
- run: cargo build --all --all-features --all-targets
- run: cargo hack build --feature-powerset --no-dev-deps
- run: cargo hack build --feature-powerset --no-dev-deps --target thumbv7m-none-eabi --skip std,default
Expand All @@ -50,6 +53,11 @@ jobs:
env:
RUSTFLAGS: ${{ env.RUSTFLAGS }} --cfg loom
LOOM_MAX_PREEMPTIONS: 2
- name: Check WASM tests
run: cargo build --target wasm32-unknown-unknown
- run: wasm-pack test --node
- run: wasm-pack test --node --no-default-features
- run: wasm-pack test --node --no-default-features --features portable-atomic

msrv:
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ name = "bench"
harness = false

[dev-dependencies]
criterion = "0.4.0"
criterion = { version = "0.4.0", features = ["cargo_bench_support"], default-features = false }
easy-parallel = "3.1.0"
fastrand = "2.0.0"

[target.'cfg(target_family = "wasm")'.dev-dependencies]
wasm-bindgen-test = "0.3"

[features]
default = ["std"]
std = []
14 changes: 12 additions & 2 deletions tests/bounded.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#![allow(clippy::bool_assert_comparison)]

use std::sync::atomic::{AtomicUsize, Ordering};

use concurrent_queue::{ConcurrentQueue, PopError, PushError};

#[cfg(not(target_family = "wasm"))]
use easy_parallel::Parallel;
#[cfg(not(target_family = "wasm"))]
use std::sync::atomic::{AtomicUsize, Ordering};

#[cfg(target_family = "wasm")]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[test]
fn smoke() {
Expand Down Expand Up @@ -58,6 +63,7 @@ fn len_empty_full() {
assert_eq!(q.is_full(), false);
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn len() {
const COUNT: usize = if cfg!(miri) { 50 } else { 25_000 };
Expand Down Expand Up @@ -130,6 +136,7 @@ fn close() {
assert_eq!(q.pop(), Err(PopError::Closed));
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn spsc() {
const COUNT: usize = if cfg!(miri) { 100 } else { 100_000 };
Expand All @@ -156,6 +163,7 @@ fn spsc() {
.run();
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn mpmc() {
const COUNT: usize = if cfg!(miri) { 100 } else { 25_000 };
Expand Down Expand Up @@ -187,6 +195,7 @@ fn mpmc() {
}
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn drops() {
const RUNS: usize = if cfg!(miri) { 10 } else { 100 };
Expand Down Expand Up @@ -235,6 +244,7 @@ fn drops() {
}
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn linearizable() {
const COUNT: usize = if cfg!(miri) { 500 } else { 25_000 };
Expand Down
3 changes: 3 additions & 0 deletions tests/loom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use loom::sync::atomic::{AtomicUsize, Ordering};
use loom::sync::{Arc, Condvar, Mutex};
use loom::thread;

#[cfg(target_family = "wasm")]
use wasm_bindgen_test::wasm_bindgen_test as test;

/// A basic MPMC channel based on a ConcurrentQueue and loom primitives.
struct Channel<T> {
/// The queue used to contain items.
Expand Down
13 changes: 11 additions & 2 deletions tests/single.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#![allow(clippy::bool_assert_comparison)]

use std::sync::atomic::{AtomicUsize, Ordering};

use concurrent_queue::{ConcurrentQueue, PopError, PushError};

#[cfg(not(target_family = "wasm"))]
use easy_parallel::Parallel;
#[cfg(not(target_family = "wasm"))]
use std::sync::atomic::{AtomicUsize, Ordering};

#[cfg(target_family = "wasm")]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[test]
fn smoke() {
Expand Down Expand Up @@ -60,6 +65,7 @@ fn close() {
assert_eq!(q.pop(), Err(PopError::Closed));
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn spsc() {
const COUNT: usize = if cfg!(miri) { 100 } else { 100_000 };
Expand All @@ -86,6 +92,7 @@ fn spsc() {
.run();
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn mpmc() {
const COUNT: usize = if cfg!(miri) { 100 } else { 25_000 };
Expand Down Expand Up @@ -117,6 +124,7 @@ fn mpmc() {
}
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn drops() {
const RUNS: usize = if cfg!(miri) { 20 } else { 100 };
Expand Down Expand Up @@ -165,6 +173,7 @@ fn drops() {
}
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn linearizable() {
const COUNT: usize = if cfg!(miri) { 500 } else { 25_000 };
Expand Down
12 changes: 10 additions & 2 deletions tests/unbounded.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#![allow(clippy::bool_assert_comparison)]

use std::sync::atomic::{AtomicUsize, Ordering};

use concurrent_queue::{ConcurrentQueue, PopError, PushError};

#[cfg(not(target_family = "wasm"))]
use easy_parallel::Parallel;
#[cfg(not(target_family = "wasm"))]
use std::sync::atomic::{AtomicUsize, Ordering};

#[cfg(target_family = "wasm")]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[test]
fn smoke() {
Expand Down Expand Up @@ -69,6 +74,7 @@ fn close() {
assert_eq!(q.pop(), Err(PopError::Closed));
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn spsc() {
const COUNT: usize = if cfg!(miri) { 100 } else { 100_000 };
Expand All @@ -95,6 +101,7 @@ fn spsc() {
.run();
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn mpmc() {
const COUNT: usize = if cfg!(miri) { 100 } else { 25_000 };
Expand Down Expand Up @@ -126,6 +133,7 @@ fn mpmc() {
}
}

#[cfg(not(target_family = "wasm"))]
#[test]
fn drops() {
const RUNS: usize = if cfg!(miri) { 20 } else { 100 };
Expand Down

0 comments on commit 71302ab

Please sign in to comment.