Skip to content

Commit 71302ab

Browse files
authored
tests: Add WASM testing
This commit ensures this crate builds and works on WASM. Signed-off-by: John Nunley <dev@notgull.net>
1 parent 79b9292 commit 71302ab

File tree

6 files changed

+50
-9
lines changed

6 files changed

+50
-9
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ jobs:
3838
- name: Install Rust
3939
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
4040
- run: rustup target add thumbv7m-none-eabi
41-
- name: Install cargo-hack
42-
uses: taiki-e/install-action@cargo-hack
41+
- run: rustup target add wasm32-unknown-unknown
42+
- name: Install cargo-hack and wasm-pack
43+
uses: taiki-e/install-action@v2
44+
with:
45+
tool: cargo-hack,wasm-pack
4346
- run: cargo build --all --all-features --all-targets
4447
- run: cargo hack build --feature-powerset --no-dev-deps
4548
- run: cargo hack build --feature-powerset --no-dev-deps --target thumbv7m-none-eabi --skip std,default
@@ -50,6 +53,11 @@ jobs:
5053
env:
5154
RUSTFLAGS: ${{ env.RUSTFLAGS }} --cfg loom
5255
LOOM_MAX_PREEMPTIONS: 2
56+
- name: Check WASM tests
57+
run: cargo build --target wasm32-unknown-unknown
58+
- run: wasm-pack test --node
59+
- run: wasm-pack test --node --no-default-features
60+
- run: wasm-pack test --node --no-default-features --features portable-atomic
5361

5462
msrv:
5563
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ name = "bench"
3535
harness = false
3636

3737
[dev-dependencies]
38-
criterion = "0.4.0"
38+
criterion = { version = "0.4.0", features = ["cargo_bench_support"], default-features = false }
3939
easy-parallel = "3.1.0"
4040
fastrand = "2.0.0"
4141

42+
[target.'cfg(target_family = "wasm")'.dev-dependencies]
43+
wasm-bindgen-test = "0.3"
44+
4245
[features]
4346
default = ["std"]
4447
std = []

tests/bounded.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#![allow(clippy::bool_assert_comparison)]
22

3-
use std::sync::atomic::{AtomicUsize, Ordering};
4-
53
use concurrent_queue::{ConcurrentQueue, PopError, PushError};
4+
5+
#[cfg(not(target_family = "wasm"))]
66
use easy_parallel::Parallel;
7+
#[cfg(not(target_family = "wasm"))]
8+
use std::sync::atomic::{AtomicUsize, Ordering};
9+
10+
#[cfg(target_family = "wasm")]
11+
use wasm_bindgen_test::wasm_bindgen_test as test;
712

813
#[test]
914
fn smoke() {
@@ -58,6 +63,7 @@ fn len_empty_full() {
5863
assert_eq!(q.is_full(), false);
5964
}
6065

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

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

166+
#[cfg(not(target_family = "wasm"))]
159167
#[test]
160168
fn mpmc() {
161169
const COUNT: usize = if cfg!(miri) { 100 } else { 25_000 };
@@ -187,6 +195,7 @@ fn mpmc() {
187195
}
188196
}
189197

198+
#[cfg(not(target_family = "wasm"))]
190199
#[test]
191200
fn drops() {
192201
const RUNS: usize = if cfg!(miri) { 10 } else { 100 };
@@ -235,6 +244,7 @@ fn drops() {
235244
}
236245
}
237246

247+
#[cfg(not(target_family = "wasm"))]
238248
#[test]
239249
fn linearizable() {
240250
const COUNT: usize = if cfg!(miri) { 500 } else { 25_000 };

tests/loom.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use loom::sync::atomic::{AtomicUsize, Ordering};
55
use loom::sync::{Arc, Condvar, Mutex};
66
use loom::thread;
77

8+
#[cfg(target_family = "wasm")]
9+
use wasm_bindgen_test::wasm_bindgen_test as test;
10+
811
/// A basic MPMC channel based on a ConcurrentQueue and loom primitives.
912
struct Channel<T> {
1013
/// The queue used to contain items.

tests/single.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#![allow(clippy::bool_assert_comparison)]
22

3-
use std::sync::atomic::{AtomicUsize, Ordering};
4-
53
use concurrent_queue::{ConcurrentQueue, PopError, PushError};
4+
5+
#[cfg(not(target_family = "wasm"))]
66
use easy_parallel::Parallel;
7+
#[cfg(not(target_family = "wasm"))]
8+
use std::sync::atomic::{AtomicUsize, Ordering};
9+
10+
#[cfg(target_family = "wasm")]
11+
use wasm_bindgen_test::wasm_bindgen_test as test;
712

813
#[test]
914
fn smoke() {
@@ -60,6 +65,7 @@ fn close() {
6065
assert_eq!(q.pop(), Err(PopError::Closed));
6166
}
6267

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

95+
#[cfg(not(target_family = "wasm"))]
8996
#[test]
9097
fn mpmc() {
9198
const COUNT: usize = if cfg!(miri) { 100 } else { 25_000 };
@@ -117,6 +124,7 @@ fn mpmc() {
117124
}
118125
}
119126

127+
#[cfg(not(target_family = "wasm"))]
120128
#[test]
121129
fn drops() {
122130
const RUNS: usize = if cfg!(miri) { 20 } else { 100 };
@@ -165,6 +173,7 @@ fn drops() {
165173
}
166174
}
167175

176+
#[cfg(not(target_family = "wasm"))]
168177
#[test]
169178
fn linearizable() {
170179
const COUNT: usize = if cfg!(miri) { 500 } else { 25_000 };

tests/unbounded.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#![allow(clippy::bool_assert_comparison)]
22

3-
use std::sync::atomic::{AtomicUsize, Ordering};
4-
53
use concurrent_queue::{ConcurrentQueue, PopError, PushError};
4+
5+
#[cfg(not(target_family = "wasm"))]
66
use easy_parallel::Parallel;
7+
#[cfg(not(target_family = "wasm"))]
8+
use std::sync::atomic::{AtomicUsize, Ordering};
9+
10+
#[cfg(target_family = "wasm")]
11+
use wasm_bindgen_test::wasm_bindgen_test as test;
712

813
#[test]
914
fn smoke() {
@@ -69,6 +74,7 @@ fn close() {
6974
assert_eq!(q.pop(), Err(PopError::Closed));
7075
}
7176

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

104+
#[cfg(not(target_family = "wasm"))]
98105
#[test]
99106
fn mpmc() {
100107
const COUNT: usize = if cfg!(miri) { 100 } else { 25_000 };
@@ -126,6 +133,7 @@ fn mpmc() {
126133
}
127134
}
128135

136+
#[cfg(not(target_family = "wasm"))]
129137
#[test]
130138
fn drops() {
131139
const RUNS: usize = if cfg!(miri) { 20 } else { 100 };

0 commit comments

Comments
 (0)