Skip to content

Commit 73e17bf

Browse files
committed
add crate that uses assert_instr
1 parent 76a4c53 commit 73e17bf

File tree

6 files changed

+128
-4
lines changed

6 files changed

+128
-4
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ members = [
33
"crates/stdsimd-verify",
44
"crates/stdsimd",
55
]
6+
exclude = [
7+
"crates/wasm-assert-instr-tests"
8+
]
69

710
[profile.release]
811
debug = true

crates/stdsimd-test/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ cc = "1.0"
1111
lazy_static = "1.0"
1212
rustc-demangle = "0.1.8"
1313
wasm-bindgen = "0.2.15"
14+
15+
[features]
16+
default = []
17+
git_wasm_bindgen = []

crates/stdsimd-test/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,20 @@ fn parse_dumpbin(output: &str) -> HashMap<String, Vec<Function>> {
258258
ret
259259
}
260260

261-
#[wasm_bindgen(module = "child_process", version = "*")]
261+
262+
#[cfg_attr(feature = "git_wasm_bindgen",
263+
wasm_bindgen(module = "child_process"))]
264+
#[cfg_attr(not(feature = "git_wasm_bindgen"),
265+
wasm_bindgen(module = "child_process", version = "*"))]
262266
extern "C" {
263267
#[wasm_bindgen(js_name = execSync)]
264268
fn exec_sync(cmd: &str) -> Buffer;
265269
}
266270

267-
#[wasm_bindgen(module = "buffer", version = "*")]
271+
#[cfg_attr(feature = "git_wasm_bindgen",
272+
wasm_bindgen(module = "buffer"))]
273+
#[cfg_attr(not(feature = "git_wasm_bindgen"),
274+
wasm_bindgen(module = "buffer", version = "*"))]
268275
extern "C" {
269276
type Buffer;
270277
#[wasm_bindgen(method, js_name = toString)]
@@ -307,7 +314,7 @@ fn parse_wasm2wat() -> HashMap<String, Vec<Function>> {
307314
if line.starts_with("(elem") {
308315
for (i, name) in line.split_whitespace().skip(3).enumerate() {
309316
let name = name.trim_right_matches(")");
310-
for f in ret.get_mut(name).unwrap() {
317+
for f in ret.get_mut(name).expect("ret.get_mut(name) failed") {
311318
f.addr = Some(i + 1);
312319
}
313320
}
@@ -371,7 +378,8 @@ pub fn assert(fnptr: usize, fnname: &str, expected: &str) {
371378
&& expected.starts_with('"')
372379
&& expected.ends_with('"')
373380
);
374-
expected.get(1..expected.len() - 1).unwrap()
381+
expected.get(1..expected.len() - 1)
382+
.expect("expected must be a '\"' delimited string, e.g., \"nop\"")
375383
};
376384
let mut fnname = fnname.to_string();
377385
let functions = get_functions(fnptr, &mut fnname);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "wasm-assert-instr-tests"
3+
version = "0.1.0"
4+
authors = ["gnzlbg <[email protected]>"]
5+
6+
[dependencies]
7+
coresimd = { path = "../coresimd" }
8+
[dev-dependencies]
9+
stdsimd-test = { path = "../stdsimd-test", features = ["git_wasm_bindgen"] }
10+
11+
[target.wasm32-unknown-unknown.dev-dependencies]
12+
wasm-bindgen-test = { git = 'https://github.com/rustwasm/wasm-bindgen' }
13+
14+
[patch.crates-io]
15+
wasm-bindgen = { git = 'https://github.com/rustwasm/wasm-bindgen' }
16+
wasm-bindgen-test = { git = 'https://github.com/rustwasm/wasm-bindgen' }
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# assert_instr on WASM32
2+
3+
This crate uses `assert_instr` to verify the assembly of wasm functions.
4+
5+
# Set up
6+
7+
This crate needs a couple of tools installed:
8+
9+
1. Install latest version of `wasm-bindgen` CLI tools
10+
11+
```
12+
git clone [email protected]:rustwasm/wasm-bindgen
13+
cd wasm-bindgen
14+
cargo install --path crates/cli
15+
16+
# This makes wasm-bindgen-test-runner the test runner for wasm32-unknown-unknown:
17+
```
18+
19+
2. Install WABT
20+
21+
```
22+
# MacOSX
23+
brew install wabt
24+
25+
# From source:
26+
git clone --recursive https://github.com/WebAssembly/wabt
27+
make -C wabt -j
28+
29+
# Add it to the path
30+
PATH=$PATH:/wabt/bin
31+
```
32+
33+
The `stdsimd-test` proc macro needs to be able to find these in the path. We
34+
could add an environment variable to configure these.
35+
36+
3. Install Node
37+
38+
Using `nvm`, homebrew, or manually. The test runner needs to find a recent
39+
enough node in the `PATH`:
40+
41+
```
42+
# MacOSX
43+
brew install node
44+
45+
# Other
46+
curl https://nodejs.org/dist/v10.8.0/node-v10.8.0-linux-x64.tar.xz | tar xJf -
47+
PATH=$PATH:/node-v10.8.0-linux-x64/bin
48+
```
49+
50+
4. Compile and install linker shim
51+
52+
```
53+
# In stdsimd/
54+
cd ci
55+
rustc lld-shim -o lld-shim
56+
```
57+
58+
# Running the tests
59+
60+
This is how you can run the tests:
61+
62+
```
63+
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER=PATH/TO/lld-shim \
64+
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner \
65+
cargo test --target=wasm32-unknown-unknown --release
66+
```
67+
68+
you can also set the `CARGO_TARGET_WASM32_...` linker and test runner globally
69+
with `export ...`.
70+
71+
To see the build fail, pass it `RUSTFLAGS="-C target-feature=+simd128"`.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! Includes assert_instr tests for wasm that currently pass.
2+
#![feature(stdsimd)]
3+
#![cfg_attr(test, feature(use_extern_macros))]
4+
5+
extern crate coresimd;
6+
#[cfg(test)]
7+
extern crate stdsimd_test;
8+
#[cfg(all(test, target_arch = "wasm32"))]
9+
extern crate wasm_bindgen_test;
10+
11+
use coresimd::arch::wasm32::*;
12+
13+
#[cfg(test)]
14+
use stdsimd_test::assert_instr;
15+
16+
#[cfg(test)]
17+
use wasm_bindgen_test::*;
18+
19+
#[cfg_attr(test, assert_instr(foo))]
20+
pub fn i8x16_add(a: v128, b: v128) -> v128 {
21+
unsafe { i8x16::add(a, b) }
22+
}

0 commit comments

Comments
 (0)