Skip to content

Commit 3345fe9

Browse files
committed
Applied suggestions, turned on assertions, added dim order strides to unit tests
1 parent 7926335 commit 3345fe9

File tree

3 files changed

+221
-61
lines changed

3 files changed

+221
-61
lines changed

extension/wasm/test/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ add_custom_target(
4343
add_executable(executorch_wasm_tests)
4444
target_link_libraries(executorch_wasm_tests PUBLIC executorch_wasm)
4545
target_link_options(
46-
executorch_wasm_tests PUBLIC --embed-file "${MODELS_DIR}@/" --post-js
46+
executorch_wasm_tests
47+
PUBLIC
48+
--embed-file
49+
"${MODELS_DIR}@/"
50+
--post-js
4751
${CMAKE_CURRENT_SOURCE_DIR}/unittests.js
52+
-sASSERTIONS=2
4853
)
4954
set_target_properties(
5055
executorch_wasm_tests PROPERTIES OUTPUT_NAME "executorch_wasm.test"

extension/wasm/test/unittests.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ describe("Tensor", () => {
7979
expect(tensor.scalarType).toEqual(et.ScalarType.Long);
8080
tensor.delete();
8181
});
82+
83+
test("with dim order and strides", () => {
84+
const tensor = et.Tensor.fromArray([2, 2], [1, 2, 3, 4], et.ScalarType.Float, [0, 1], [2, 1]);
85+
expect(tensor.data).toEqual(new Float32Array([1, 2, 3, 4]));
86+
expect(tensor.sizes).toEqual([2, 2]);
87+
tensor.delete();
88+
});
89+
90+
test("incorrect dim order", () => {
91+
expect(() => et.Tensor.fromArray([2, 2], [1, 2, 3, 4], et.ScalarType.Float, [1])).toThrow();
92+
expect(() => et.Tensor.fromArray([2, 2], [1, 2, 3, 4], et.ScalarType.Float, [1, 2])).toThrow();
93+
});
94+
95+
test("incorrect strides", () => {
96+
expect(() => et.Tensor.fromArray([2, 2], [1, 2, 3, 4], et.ScalarType.Float, [1, 1], [2, 1])).toThrow();
97+
});
8298
});
8399

84100
describe("Module", () => {

0 commit comments

Comments
 (0)