tests: Add WASM testing

This commit ensures this crate builds and works on WASM.

Signed-off-by: John Nunley <dev@notgull.net>
This commit is contained in:
John Nunley 2023-12-16 11:20:15 -08:00 committed by GitHub
parent 79b9292d10
commit 71302ab09c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 9 deletions

View File

@ -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
@ -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

View File

@ -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 = []

View File

@ -1,9 +1,14 @@
#![allow(clippy::bool_assert_comparison)]
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};
use concurrent_queue::{ConcurrentQueue, PopError, PushError};
use easy_parallel::Parallel;
#[cfg(target_family = "wasm")]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[test]
fn smoke() {
@ -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 };
@ -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 };
@ -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 };
@ -187,6 +195,7 @@ fn mpmc() {
}
}
#[cfg(not(target_family = "wasm"))]
#[test]
fn drops() {
const RUNS: usize = if cfg!(miri) { 10 } else { 100 };
@ -235,6 +244,7 @@ fn drops() {
}
}
#[cfg(not(target_family = "wasm"))]
#[test]
fn linearizable() {
const COUNT: usize = if cfg!(miri) { 500 } else { 25_000 };

View File

@ -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.

View File

@ -1,9 +1,14 @@
#![allow(clippy::bool_assert_comparison)]
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};
use concurrent_queue::{ConcurrentQueue, PopError, PushError};
use easy_parallel::Parallel;
#[cfg(target_family = "wasm")]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[test]
fn smoke() {
@ -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 };
@ -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 };
@ -117,6 +124,7 @@ fn mpmc() {
}
}
#[cfg(not(target_family = "wasm"))]
#[test]
fn drops() {
const RUNS: usize = if cfg!(miri) { 20 } else { 100 };
@ -165,6 +173,7 @@ fn drops() {
}
}
#[cfg(not(target_family = "wasm"))]
#[test]
fn linearizable() {
const COUNT: usize = if cfg!(miri) { 500 } else { 25_000 };

View File

@ -1,9 +1,14 @@
#![allow(clippy::bool_assert_comparison)]
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};
use concurrent_queue::{ConcurrentQueue, PopError, PushError};
use easy_parallel::Parallel;
#[cfg(target_family = "wasm")]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[test]
fn smoke() {
@ -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 };
@ -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 };
@ -126,6 +133,7 @@ fn mpmc() {
}
}
#[cfg(not(target_family = "wasm"))]
#[test]
fn drops() {
const RUNS: usize = if cfg!(miri) { 20 } else { 100 };