Skip to content

Commit

Permalink
feat(occara): add tests for wasm32 (#67)
Browse files Browse the repository at this point in the history
This add testing of occara on wasm32.
The `test_make_bottle_wasm` test still fails for now, since constructing
C++ exceptions is still broken.

After this is fixed in a future PR, we should run this on CI.
  • Loading branch information
maximmaxim345 authored Nov 17, 2024
2 parents e65f698 + e5c6def commit 1f3913d
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 4 deletions.
42 changes: 40 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ console_error_panic_hook = "0.1"
console_log = "1.0"
log = "0.4"
wasm-bindgen = "0.2"
wasm-bindgen-test = "0.3"

[workspace.package]
version = "0.1.0"
Expand Down
2 changes: 2 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ script_runner = "@shell"
script = '''
WASM32_UNKNOWN_UNKNOWN_STDLIB_DIR="$(pwd)/target/wasm-libcxx/wasm32-unknown-unknown-libcxx" # shell2batch:
. $WASM32_UNKNOWN_UNKNOWN_STDLIB_DIR/env.sh # shell2batch: call target\wasm-libcxx\wasm32-unknown-unknown-libcxx\env.bat
cd crates/occara
rustup run nightly wasm-pack test --node
'''
install_crate = "wasm-pack"

Expand Down
6 changes: 5 additions & 1 deletion crates/occara/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ walkdir.workspace = true
autocxx-build.workspace = true
miette.workspace = true

[dev-dependencies]
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
criterion.workspace = true

[dev-dependencies]
wasm-bindgen-test.workspace = true
wasm-libc.workspace = true

[[bench]]
name = "occara"
harness = false
21 changes: 21 additions & 0 deletions crates/occara/tests/make_bottle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use occara::internal::{make_bottle_cpp, make_bottle_rust};
use std::sync::Arc;
use std::thread;
use wasm_bindgen_test::*;

#[test]
#[ignore] // Don't run this test by default, since its quite slow
Expand All @@ -27,3 +28,23 @@ fn test_make_bottle() {
assert!(error_rust_cpp.join().unwrap() < EPSILON);
assert!(error_cpp_rust.join().unwrap() < EPSILON);
}

#[wasm_bindgen_test]
#[allow(dead_code)]
fn test_make_bottle_wasm() {
// TODO(wasm32): This test fails, since exceptions are broken
wasm_libc::init();
const WIDTH: f64 = 50.0;
const HEIGHT: f64 = 70.0;
const THICKNESS: f64 = 30.0;
const EPSILON: f64 = 1e-6;

let bottle_rust = make_bottle_rust(WIDTH, HEIGHT, THICKNESS);
let bottle_cpp = make_bottle_cpp(WIDTH, HEIGHT, THICKNESS);

let error_rust_cpp = bottle_rust.subtract(&bottle_cpp).mass();
let error_cpp_rust = bottle_cpp.subtract(&bottle_rust).mass();

assert!(error_rust_cpp < EPSILON);
assert!(error_cpp_rust < EPSILON);
}
4 changes: 3 additions & 1 deletion crates/occara/tests/meshing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use occara::{
geom::{Direction, Point},
shape::Shape,
};
use wasm_bindgen_test::*;

#[test]
#[wasm_bindgen_test(unsupported = test)]
fn test_mesh_cylinder() {
wasm_libc::init();
let plane = Point::new(0.0, 0.0, 0.0).plane_axis_with(&Direction::z());
let mesh = Shape::cylinder(&plane, 1.0, 1.0).mesh();
let vertices = mesh.vertices();
Expand Down

0 comments on commit 1f3913d

Please sign in to comment.