Skip to content

Commit

Permalink
test: add couples tests for WasmModuleHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
qartik committed Oct 9, 2024
1 parent 929614c commit e6e14fe
Showing 1 changed file with 47 additions and 22 deletions.
69 changes: 47 additions & 22 deletions pytket/tests/classical_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ def test_wasm_3() -> None:
assert c.depth() == 1


def test_wasm_3_bytes() -> None:
with open("testfile.wasm", "rb") as f:
bytecode = f.read()
c = Circuit(0, 6)

w = wasm.WasmModuleHandler(bytecode)

c.add_wasm("add_one", w, [1], [1], [Bit(0), Bit(1)])

assert c.depth() == 1


def test_wasm_4() -> None:
w = wasm.WasmFileHandler("testfile.wasm")

Expand Down Expand Up @@ -412,6 +424,19 @@ def test_wasm_function_check_6() -> None:
assert c.depth() == 1


def test_wasm_function_check_6_bytes() -> None:
with open("testfile.wasm", "rb") as f:
bytecode = f.read()

w = wasm.WasmModuleHandler(bytecode)
c = Circuit(20, 20)
c0 = c.add_c_register("c0", 32)
c1 = c.add_c_register("c1", 4)

c.add_wasm_to_reg("add_one", w, [c0], [c1])
assert c.depth() == 1


def test_wasm_function_check_7() -> None:
w = wasm.WasmFileHandler("testfile.wasm", int_size=32)
c = Circuit(20, 20)
Expand Down Expand Up @@ -566,7 +591,7 @@ def test_wasmfilehandler_repr() -> None:
function 'no_return' with 1 i32 parameter(s) and 0 i32 return value(s)
function 'no_parameters' with 0 i32 parameter(s) and 1 i32 return value(s)
function 'new_function' with 0 i32 parameter(s) and 1 i32 return value(s)
unsupported function with invalid parameter or result type: 'add_something'
unsupported function with invalid parameter or result type: 'add_something'
"""
)

Expand All @@ -578,13 +603,13 @@ def test_wasmfilehandler_repr_64() -> None:
== """Functions in wasm file with the uid 6a0a29e235cd5c60353254bc2b459e631d381cdd0bded7ae6cb44afb784bd2de:
function 'init' with 0 i64 parameter(s) and 0 i64 return value(s)
function 'add_something' with 1 i64 parameter(s) and 1 i64 return value(s)
unsupported function with invalid parameter or result type: 'add_one'
unsupported function with invalid parameter or result type: 'multi'
unsupported function with invalid parameter or result type: 'add_two'
unsupported function with invalid parameter or result type: 'add_eleven'
unsupported function with invalid parameter or result type: 'no_return'
unsupported function with invalid parameter or result type: 'no_parameters'
unsupported function with invalid parameter or result type: 'new_function'
unsupported function with invalid parameter or result type: 'add_one'
unsupported function with invalid parameter or result type: 'multi'
unsupported function with invalid parameter or result type: 'add_two'
unsupported function with invalid parameter or result type: 'add_eleven'
unsupported function with invalid parameter or result type: 'no_return'
unsupported function with invalid parameter or result type: 'no_parameters'
unsupported function with invalid parameter or result type: 'new_function'
"""
)

Expand All @@ -607,7 +632,7 @@ def test_wasmfilehandler_repr_2() -> None:
function 'mixed_up_2' with 2 i32 parameter(s) and 1 i32 return value(s)
function 'mixed_up_3' with 3 i32 parameter(s) and 1 i32 return value(s)
function 'unse_internal' with 1 i32 parameter(s) and 1 i32 return value(s)
unsupported function with invalid parameter or result type: 'add_something'
unsupported function with invalid parameter or result type: 'add_something'
"""
)

Expand All @@ -619,18 +644,18 @@ def test_wasmfilehandler_repr_64_2() -> None:
== """Functions in wasm file with the uid 360e60c3b092ad735982ba49207f9c3250b111e5963fb630c69f85266172080b:
function 'init' with 0 i64 parameter(s) and 0 i64 return value(s)
function 'add_something' with 1 i64 parameter(s) and 1 i64 return value(s)
unsupported function with invalid parameter or result type: 'add_one'
unsupported function with invalid parameter or result type: 'multi'
unsupported function with invalid parameter or result type: 'add_two'
unsupported function with invalid parameter or result type: 'add_something_32'
unsupported function with invalid parameter or result type: 'add_eleven'
unsupported function with invalid parameter or result type: 'no_return'
unsupported function with invalid parameter or result type: 'no_parameters'
unsupported function with invalid parameter or result type: 'new_function'
unsupported function with invalid parameter or result type: 'mixed_up'
unsupported function with invalid parameter or result type: 'mixed_up_2'
unsupported function with invalid parameter or result type: 'mixed_up_3'
unsupported function with invalid parameter or result type: 'unse_internal'
unsupported function with invalid parameter or result type: 'add_one'
unsupported function with invalid parameter or result type: 'multi'
unsupported function with invalid parameter or result type: 'add_two'
unsupported function with invalid parameter or result type: 'add_something_32'
unsupported function with invalid parameter or result type: 'add_eleven'
unsupported function with invalid parameter or result type: 'no_return'
unsupported function with invalid parameter or result type: 'no_parameters'
unsupported function with invalid parameter or result type: 'new_function'
unsupported function with invalid parameter or result type: 'mixed_up'
unsupported function with invalid parameter or result type: 'mixed_up_2'
unsupported function with invalid parameter or result type: 'mixed_up_3'
unsupported function with invalid parameter or result type: 'unse_internal'
"""
)

Expand Down Expand Up @@ -658,7 +683,7 @@ def test_wasmfilehandler_multivalue_clang() -> None:
== """Functions in wasm file with the uid 6f821422038eec251d2f4e6bf2b9a5717b18b5c96a8a8e01fb49f080d9610f6e:
function '__wasm_call_ctors' with 0 i32 parameter(s) and 0 i32 return value(s)
function 'init' with 0 i32 parameter(s) and 0 i32 return value(s)
unsupported function with invalid parameter or result type: 'divmod'
unsupported function with invalid parameter or result type: 'divmod'
"""
)

Expand Down

0 comments on commit e6e14fe

Please sign in to comment.