Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm tests #54

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 58 additions & 23 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,69 @@
version: 2.1

orbs:
win: circleci/windows@5.0

jobs:
deterministic_x86_64:
docker:
- image: cimg/rust:1.75.0
linux_x86_64:
machine:
image: ubuntu-2004:current
resource_class: medium
steps:
- checkout
- run: cargo --version && cargo test --release && tar -czvf output_x86_64.tar.gz output
- store_artifacts:
path: ./output_x86_64.tar.gz

deterministic_aarch64:
docker:
- image: cimg/rust:1.75.0
- checkout
- run:
name: Setup environment
command: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup.sh &&
chmod +x rustup.sh &&
./rustup.sh -y --default-toolchain nightly --profile minimal --target wasm32-unknown-unknown &&
source "$HOME/.cargo/env" &&
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- run:
name: Run linux x86_64 tests
command: cargo --version &&
cargo test --release &&
tar -czvf linux_x86_64.tar.gz output
- run:
name: Run linux wasm tests
command: cargo --version &&
node --version &&
wasm-pack test --node --features "wasm nodejs"
- store_artifacts:
path: ./linux_x86_64.tar.gz

linux_aarch64:
machine:
image: ubuntu-2004:current
resource_class: arm.medium
steps:
- checkout
- run: cargo --version && cargo test --release && tar -czvf output_aarch64.tar.gz output
- store_artifacts:
path: ./output_aarch64.tar.gz
- checkout
- run:
name: Setup environment
command: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup.sh &&
chmod +x rustup.sh &&
./rustup.sh -y --default-toolchain nightly --profile minimal --target wasm32-unknown-unknown &&
source "$HOME/.cargo/env" &&
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- run:
name: Run linux aarch64 tests
command: cargo --version &&
cargo test --release &&
tar -czvf linux_aarch64.tar.gz output
- run:
name: Run linux wasm tests
command: cargo --version &&
node --version &&
wasm-pack test --node --features "wasm nodejs"
- store_artifacts:
path: ./linux_aarch64.tar.gz

workflows:
deterministic:
jobs:
- deterministic_x86_64:
filters:
branches:
only: [ "master", "test" ]
- deterministic_aarch64:
filters:
branches:
only: [ "master", "test" ]
- linux_x86_64:
filters:
branches:
only: [ "master", "test", "test-full", "test-linux-x64" ]
- linux_aarch64:
filters:
branches:
only: [ "master", "test", "test-full", "test-linux-arm64" ]
2 changes: 0 additions & 2 deletions src/blending_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,12 @@ where

#[cfg(test)]
mod blending_tests {
use glam::Vec4;
use std::collections::HashMap;
use std::mem;
use wasm_bindgen_test::*;

use super::*;
use crate::base::{ozz_buf, DeterministicState};
use crate::skeleton::Skeleton;

const IDENTITY: SoaTransform = SoaTransform {
translation: SoaVec3::splat_col([0.0; 3]),
Expand Down
3 changes: 1 addition & 2 deletions src/local_to_model_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,13 @@ where

#[cfg(test)]
mod local_to_model_tests {
use glam::{Mat4, Vec3};
use glam::Vec3;
use std::collections::HashMap;
use wasm_bindgen_test::*;

use super::*;
use crate::base::DeterministicState;
use crate::math::{SoaQuat, SoaVec3};
use crate::skeleton::Skeleton;

#[test]
#[wasm_bindgen_test]
Expand Down
1 change: 0 additions & 1 deletion src/sampling_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,6 @@ mod sampling_tests {
use wasm_bindgen_test::*;

use super::*;
use crate::animation::{Float3Key, QuaternionKey};
use crate::base::ozz_buf;

// f16 -> f32
Expand Down
3 changes: 3 additions & 0 deletions tests/additive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use glam::{Mat4, Vec4};
use ozz_animation_rs::math::*;
use ozz_animation_rs::*;
use std::rc::Rc;
use wasm_bindgen_test::*;

mod common;

Expand All @@ -25,6 +26,7 @@ struct TestDataInit {
}

#[test]
#[wasm_bindgen_test]
fn test_additive() {
run_additive(
5..=5,
Expand All @@ -35,6 +37,7 @@ fn test_additive() {

#[cfg(feature = "rkyv")]
#[test]
#[wasm_bindgen_test]
fn test_additive_deterministic() {
run_additive(
-1..=11,
Expand Down
3 changes: 3 additions & 0 deletions tests/blend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use glam::Mat4;
use ozz_animation_rs::math::*;
use ozz_animation_rs::*;
use std::rc::Rc;
use wasm_bindgen_test::*;

mod common;

Expand All @@ -20,6 +21,7 @@ struct TestData {
}

#[test]
#[wasm_bindgen_test]
fn test_blend() {
run_blend(2..=2, |_, data| {
common::compare_with_cpp("blend", "blend", &data.l2m_out, 1e-6).unwrap();
Expand All @@ -28,6 +30,7 @@ fn test_blend() {

#[cfg(feature = "rkyv")]
#[test]
#[wasm_bindgen_test]
fn test_blend_deterministic() {
run_blend(-1..=11, |ratio, data| {
common::compare_with_rkyv("blend", &format!("blend{:+.2}", ratio), data).unwrap();
Expand Down
56 changes: 56 additions & 0 deletions tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#![allow(unused_imports)]
#![allow(dead_code)]

use glam::Mat4;
#[cfg(all(feature = "wasm", feature = "nodejs"))]
use ozz_animation_rs::nodejs;
use ozz_animation_rs::{Animation, Archive, Skeleton};
use std::env::consts::{ARCH, OS};
use std::error::Error;
use std::fs::{self, File};
use std::io::prelude::*;
use std::{env, mem, slice};

#[cfg(not(feature = "wasm"))]
pub fn compare_with_cpp(folder: &str, name: &str, data: &[Mat4], diff: f32) -> Result<(), Box<dyn Error>> {
fs::create_dir_all(format!("./expected/{}", folder)).unwrap();
fs::create_dir_all(format!("./output/{}", folder)).unwrap();
Expand Down Expand Up @@ -32,7 +39,31 @@ pub fn compare_with_cpp(folder: &str, name: &str, data: &[Mat4], diff: f32) -> R
return Ok(());
}

#[cfg(all(feature = "wasm", feature = "nodejs"))]
pub fn compare_with_cpp(folder: &str, name: &str, data: &[Mat4], diff: f32) -> Result<(), Box<dyn Error>> {
let path = format!("./expected/{0}/{1}_cpp.bin", folder, name);
let buf = nodejs::read_file(&path).map_err(|e| String::from(e.to_string()))?;

let data_size = data.len() * mem::size_of::<Mat4>();
if buf.len() != data_size {
return Err(format!("compare_with_cpp() size:{}", data_size).into());
}

let mut expected: Vec<Mat4> = vec![Mat4::default(); data.len()];
let expected_buf = unsafe { slice::from_raw_parts_mut(expected.as_mut_ptr() as *mut _, data_size) };
expected_buf.copy_from_slice(&buf);
for i in 0..expected.len() {
if !Mat4::abs_diff_eq(&data[i], expected[i], diff) {
println!("actual: {:?}", data[i]);
println!("expected: {:?}", expected[i]);
return Err(format!("compare_with_cpp() idx:{}", i).into());
}
}
return Ok(());
}

#[cfg(feature = "rkyv")]
#[cfg(not(feature = "wasm"))]
pub fn compare_with_rkyv<T>(folder: &str, name: &str, data: &T) -> Result<(), Box<dyn Error>>
where
T: PartialEq + rkyv::Serialize<rkyv::ser::serializers::AllocSerializer<30720>>,
Expand Down Expand Up @@ -80,6 +111,31 @@ where
return Ok(());
}

#[cfg(feature = "rkyv")]
#[cfg(all(feature = "wasm", feature = "nodejs"))]
pub fn compare_with_rkyv<T>(folder: &str, name: &str, data: &T) -> Result<(), Box<dyn Error>>
where
T: PartialEq + rkyv::Serialize<rkyv::ser::serializers::AllocSerializer<30720>>,
T::Archived: rkyv::Deserialize<T, rkyv::Infallible>,
{
use miniz_oxide::inflate::decompress_to_vec;
use rkyv::{AlignedVec, Deserialize};

let path = format!("./expected/{0}/{1}.rkyv", folder, name);
let rbuf = nodejs::read_file(&path).map_err(|e| String::from(e.to_string()))?;
let unaligned_buf = decompress_to_vec(&rbuf).map_err(|e| e.to_string())?;
let mut expected_buf = AlignedVec::new();
expected_buf.extend_from_slice(&unaligned_buf);

let archived = unsafe { rkyv::archived_root::<T>(&expected_buf) };
let mut deserializer = rkyv::Infallible::default();
let expected = archived.deserialize(&mut deserializer)?;
if data != &expected {
return Err(format!("compare_with_rkyv({})", path).into());
}
return Ok(());
}

#[cfg(not(feature = "rkyv"))]
pub fn compare_with_rkyv<T>(_folder: &str, _name: &str, _data: &T) -> Result<(), Box<dyn Error>> {
return Ok(());
Expand Down
3 changes: 3 additions & 0 deletions tests/look_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use glam::{Mat4, Quat, Vec3A};
use ozz_animation_rs::math::*;
use ozz_animation_rs::*;
use std::rc::Rc;
use wasm_bindgen_test::*;

mod common;

Expand All @@ -23,6 +24,7 @@ const TARGET_OFFSET: Vec3A = Vec3A::new(0.2, 1.5, -0.3);
const EYES_OFFSET: Vec3A = Vec3A::new(0.07, 0.1, 0.0);

#[test]
#[wasm_bindgen_test]
fn test_look_at() {
run_look_at(1..=1, |_, data| {
common::compare_with_cpp("look_at", "look_at", &data.models2, 1.5e-4).unwrap();
Expand All @@ -31,6 +33,7 @@ fn test_look_at() {

#[cfg(feature = "rkyv")]
#[test]
#[wasm_bindgen_test]
fn test_look_at_deterministic() {
run_look_at(0..=10, |idx, data| {
common::compare_with_rkyv("look_at", &format!("look_at_{:02}", idx), data).unwrap();
Expand Down
3 changes: 3 additions & 0 deletions tests/partial_blend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use glam::{Mat4, Vec4};
use ozz_animation_rs::math::*;
use ozz_animation_rs::*;
use std::rc::Rc;
use wasm_bindgen_test::*;

mod common;

Expand All @@ -18,6 +19,7 @@ struct TestData {
}

#[test]
#[wasm_bindgen_test]
fn test_partial_blend() {
run_partial_blend(5..=5, |_, data| {
common::compare_with_cpp("partial_blend", "partial_blend", &data.l2m_out, 1e-5).unwrap();
Expand All @@ -26,6 +28,7 @@ fn test_partial_blend() {

#[cfg(feature = "rkyv")]
#[test]
#[wasm_bindgen_test]
fn test_partial_blend_deterministic() {
run_partial_blend(-1..=11, |ratio, data| {
common::compare_with_rkyv("partial_blend", &format!("partial_blend{:+.2}", ratio), data).unwrap();
Expand Down
3 changes: 3 additions & 0 deletions tests/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use glam::Mat4;
use ozz_animation_rs::math::*;
use ozz_animation_rs::*;
use std::rc::Rc;
use wasm_bindgen_test::*;

mod common;

Expand All @@ -15,6 +16,7 @@ struct TestData {
}

#[test]
#[wasm_bindgen_test]
fn test_playback() {
run_playback(5..=5, |_, data| {
common::compare_with_cpp("playback", "playback", &data.l2m_out, 1e-5).unwrap()
Expand All @@ -23,6 +25,7 @@ fn test_playback() {

#[cfg(feature = "rkyv")]
#[test]
#[wasm_bindgen_test]
fn test_playback_deterministic() {
run_playback(-1..=11, |ratio, data| {
common::compare_with_rkyv("playback", &format!("playback{:+.2}", ratio), data).unwrap()
Expand Down
3 changes: 3 additions & 0 deletions tests/two_bone_ik.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use glam::{Mat4, Quat, Vec3A};
use ozz_animation_rs::math::*;
use ozz_animation_rs::*;
use std::rc::Rc;
use wasm_bindgen_test::*;

mod common;

Expand All @@ -20,6 +21,7 @@ const TARGET_EXTENT: f32 = 0.5;
const TARGET_OFFSET: Vec3A = Vec3A::new(0.0, 0.2, 0.1);

#[test]
#[wasm_bindgen_test]
fn test_two_bone_ik() {
run_two_bone_ik(1..=1, |_, data| {
common::compare_with_cpp("two_bone_ik", "two_bone_ik", &data.models2, 1e-6).unwrap();
Expand All @@ -28,6 +30,7 @@ fn test_two_bone_ik() {

#[cfg(feature = "rkyv")]
#[test]
#[wasm_bindgen_test]
fn test_two_bone_ik_deterministic() {
run_two_bone_ik(0..=10, |idx, data| {
common::compare_with_rkyv("two_bone_ik", &format!("two_bone_ik_{:02}", idx), data).unwrap();
Expand Down
Loading