From a7c9975c3124869a62a0892e099c94856e23ac86 Mon Sep 17 00:00:00 2001 From: Nicolas Kruse Date: Sun, 9 Nov 2025 22:53:07 +0100 Subject: [PATCH] tests updated with groups and old tests removed --- tests/test_compile.py | 2 ++ tests/test_compile_aarch64.py | 2 ++ tests/test_compile_div.py | 2 ++ tests/test_compile_math.py | 2 ++ tests/test_coparun_module2.py | 39 ------------------------ tests/test_crash_win.py | 57 ----------------------------------- tests/test_ops_aarch64.py | 55 +++++++++++++++++---------------- tests/test_ops_x86.py | 12 ++++++-- 8 files changed, 47 insertions(+), 124 deletions(-) delete mode 100644 tests/test_coparun_module2.py delete mode 100644 tests/test_crash_win.py diff --git a/tests/test_compile.py b/tests/test_compile.py index 7f4fc08..1843b87 100644 --- a/tests/test_compile.py +++ b/tests/test_compile.py @@ -5,6 +5,7 @@ import subprocess import struct from copapy import _binwrite import copapy.backend +import pytest def run_command(command: list[str]) -> str: @@ -39,6 +40,7 @@ def function(c1: NumLike, c2: NumLike) -> tuple[NumLike, ...]: return i1, i2, r1, r2 +@pytest.mark.runner def test_compile(): #c1 = variable(4) diff --git a/tests/test_compile_aarch64.py b/tests/test_compile_aarch64.py index b7a941d..d6e41ee 100644 --- a/tests/test_compile_aarch64.py +++ b/tests/test_compile_aarch64.py @@ -6,6 +6,7 @@ import copapy.backend as backend import copapy as cp import os import warnings +import pytest if os.name == 'nt': # On Windows wsl and qemu-user is required: @@ -40,6 +41,7 @@ def function(c1: NumLike, c2: NumLike) -> tuple[NumLike, ...]: return i1, i2, r1, r2 +@pytest.mark.runner def test_compile(): t1 = cp.vector([10, 11, 12]) + cp.vector(cp.variable(v) for v in range(3)) t2 = t1.sum() diff --git a/tests/test_compile_div.py b/tests/test_compile_div.py index e199917..535f66f 100644 --- a/tests/test_compile_div.py +++ b/tests/test_compile_div.py @@ -3,6 +3,7 @@ from copapy.backend import Write, compile_to_dag import copapy import subprocess from copapy import _binwrite +import pytest def run_command(command: list[str], encoding: str = 'utf8') -> str: @@ -18,6 +19,7 @@ def function(c1: NumLike) -> list[NumLike]: return [r1] +@pytest.mark.runner def test_compile(): c1 = variable(16) diff --git a/tests/test_compile_math.py b/tests/test_compile_math.py index d68a8e6..f27fa94 100644 --- a/tests/test_compile_math.py +++ b/tests/test_compile_math.py @@ -4,6 +4,7 @@ import copapy as cp import subprocess from copapy import _binwrite import copapy.backend +import pytest def run_command(command: list[str]) -> str: @@ -13,6 +14,7 @@ def run_command(command: list[str]) -> str: return result.stdout +@pytest.mark.runner def test_compile(): test_vals = [0.0, 0.0001, 0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.28318530718, 100.0, 1000.0, 100000.0] diff --git a/tests/test_coparun_module2.py b/tests/test_coparun_module2.py deleted file mode 100644 index aa4ef3a..0000000 --- a/tests/test_coparun_module2.py +++ /dev/null @@ -1,39 +0,0 @@ -from coparun_module import coparun -from copapy import variable -from copapy.backend import Write, compile_to_dag, add_read_command -import copapy -from copapy import _binwrite - - -def test_compile(): - - c1 = variable(4) - c2 = variable(2) * 4 - - i1 = c2 * 2 - r1 = i1 + 7 + (c1 + 7 * 9) - r2 = i1 + 9 - out = [Write(r1), Write(r2), Write(c2)] - - il, variables = compile_to_dag(out, copapy.generic_sdb) - - # run program command - il.write_com(_binwrite.Command.RUN_PROG) - - for net in (c1, c2, i1, r1, r2): - add_read_command(il, variables, net) - - # run program command - il.write_com(_binwrite.Command.END_COM) - - #print('* Data to runner:') - #il.print() - - print('+ run coparun') - result = coparun(il.get_data()) - - assert result == 1 - - -if __name__ == "__main__": - test_compile() diff --git a/tests/test_crash_win.py b/tests/test_crash_win.py deleted file mode 100644 index aab0a68..0000000 --- a/tests/test_crash_win.py +++ /dev/null @@ -1,57 +0,0 @@ -from copapy import NumLike, variable -from copapy.backend import Write, Net, compile_to_dag, add_read_command -import copapy -import subprocess -from copapy import _binwrite - - -def run_command(command: list[str], encoding: str = 'utf8') -> str: - process = subprocess.Popen(command, stdout=subprocess.PIPE) - output, error = process.communicate() - - assert error is None, f"Error occurred: {error.decode(encoding)}" - return output.decode(encoding) - - -def function(c1: NumLike, c2: NumLike) -> tuple[NumLike, ...]: - i1 = c1 * 3.3 + 5 - i2 = c2 * 5 + c1 - r1 = i1 + i2 * 55 / 4 - r2 = 4 * i2 + 5 - - return i1, i2, r1, r2 - - -def test_compile(): - - c1 = variable(4) - c2 = variable(2) - - ret = function(c1, c2) - - dw, variable_list = compile_to_dag([Write(net) for net in ret], copapy.generic_sdb) - - # run program command - dw.write_com(_binwrite.Command.RUN_PROG) - - dw.write_com(_binwrite.Command.READ_DATA) - dw.write_int(0) - dw.write_int(36) - - for net, name in zip(ret, ['i1', 'i2', 'r1', 'r2']): - print('+', name) - assert isinstance(net, Net) - add_read_command(dw, variable_list, net) - - dw.write_com(_binwrite.Command.END_COM) - - dw.to_file('bin/test.copapy') - result = run_command(['bin/coparun', 'bin/test.copapy']) - print('* Output from runner:') - print(result) - assert 'Return value: 1' in result - - -if __name__ == "__main__": - #test_example() - test_compile() diff --git a/tests/test_ops_aarch64.py b/tests/test_ops_aarch64.py index 601521e..266d7f5 100644 --- a/tests/test_ops_aarch64.py +++ b/tests/test_ops_aarch64.py @@ -7,6 +7,7 @@ import os import warnings import re import struct +import pytest if os.name == 'nt': # On Windows wsl and qemu-user is required: @@ -80,6 +81,7 @@ def iiftests(c1: NumLike) -> list[NumLike]: iif(c1 < 5, c1 * 3.3, 8.8)] +@pytest.mark.runner def test_compile(): c_i = variable(9) c_f = variable(1.111) @@ -121,35 +123,36 @@ def test_compile(): if not check_for_qemu(): warnings.warn("qemu-aarch64 not found, aarch64 test skipped!", UserWarning) - else: - command = ['bin/coparun-aarch64', 'bin/test-aarch64.copapy'] + ['bin/test-aarch64.copapy.bin'] - result = run_command(qemu_command + command) - print('* Output from runner:\n--') - print(result) - print('--') + return + + command = ['bin/coparun-aarch64', 'bin/test-aarch64.copapy'] + ['bin/test-aarch64.copapy.bin'] + result = run_command(qemu_command + command) + print('* Output from runner:\n--') + print(result) + print('--') - assert 'Return value: 1' in result + assert 'Return value: 1' in result - result_data = parse_results(result) + result_data = parse_results(result) - for test, ref in zip(ret_test, ret_ref): - assert isinstance(test, variable) - address = variables[test][0] - data = result_data[address] - if test.dtype == 'int': - val = int.from_bytes(data, sdb.byteorder, signed=True) - elif test.dtype == 'bool': - val = bool.from_bytes(data, sdb.byteorder) - elif test.dtype == 'float': - en = {'little': '<', 'big': '>'}[sdb.byteorder] - val = struct.unpack(en + 'f', data)[0] - assert isinstance(val, float) - else: - raise Exception(f"Unknown type: {test.dtype}") - print('+', val, ref, test.dtype, f" addr={address}") - #for t in (int, float, bool): - # assert isinstance(val, t) == isinstance(ref, t), f"Result type does not match for {val} and {ref}" - #assert val == pytest.approx(ref, 1e-5), f"Result does not match: {val} and reference: {ref}" # pyright: ignore[reportUnknownMemberType] + for test, ref in zip(ret_test, ret_ref): + assert isinstance(test, variable) + address = variables[test][0] + data = result_data[address] + if test.dtype == 'int': + val = int.from_bytes(data, sdb.byteorder, signed=True) + elif test.dtype == 'bool': + val = bool.from_bytes(data, sdb.byteorder) + elif test.dtype == 'float': + en = {'little': '<', 'big': '>'}[sdb.byteorder] + val = struct.unpack(en + 'f', data)[0] + assert isinstance(val, float) + else: + raise Exception(f"Unknown type: {test.dtype}") + print('+', val, ref, test.dtype, f" addr={address}") + #for t in (int, float, bool): + # assert isinstance(val, t) == isinstance(ref, t), f"Result type does not match for {val} and {ref}" + #assert val == pytest.approx(ref, 1e-5), f"Result does not match: {val} and reference: {ref}" # pyright: ignore[reportUnknownMemberType] if __name__ == "__main__": diff --git a/tests/test_ops_x86.py b/tests/test_ops_x86.py index a108ca5..fb6f0ba 100644 --- a/tests/test_ops_x86.py +++ b/tests/test_ops_x86.py @@ -8,6 +8,7 @@ import re import struct import platform import copapy as cp +import pytest def parse_results(log_text: str) -> dict[int, bytes]: @@ -67,6 +68,7 @@ def iiftests(c1: NumLike) -> list[NumLike]: iif(c1 < 5, c1 * 3.3, 8.8)] +@pytest.mark.runner def test_compile(): t1 = cp.vector([10, 11, 12]) + cp.vector(cp.variable(v) for v in range(3)) t2 = t1.sum() @@ -114,11 +116,17 @@ def test_compile(): dw.to_file('bin/test-x86.copapy') - if platform.machine() != 'AMD64' and platform.machine() != 'x86': + if platform.machine() != 'AMD64' and platform.machine() != 'x86_64': warnings.warn(f"Test skipped, {platform.machine()} not supported for this test.", UserWarning) else: command = ['bin/coparun-x86', 'bin/test-x86.copapy', 'bin/test-x86.copapy.bin'] - result = run_command(command) + + try: + result = run_command(command) + except FileNotFoundError: + warnings.warn(f"Test skipped, executable not found.", UserWarning) + return + print('* Output from runner:\n--') print(result) print('--')