tests updated with groups and old tests removed

This commit is contained in:
Nicolas Kruse 2025-11-09 22:53:07 +01:00
parent e5f6897ca9
commit a7c9975c31
8 changed files with 47 additions and 124 deletions

View File

@ -5,6 +5,7 @@ import subprocess
import struct import struct
from copapy import _binwrite from copapy import _binwrite
import copapy.backend import copapy.backend
import pytest
def run_command(command: list[str]) -> str: def run_command(command: list[str]) -> str:
@ -39,6 +40,7 @@ def function(c1: NumLike, c2: NumLike) -> tuple[NumLike, ...]:
return i1, i2, r1, r2 return i1, i2, r1, r2
@pytest.mark.runner
def test_compile(): def test_compile():
#c1 = variable(4) #c1 = variable(4)

View File

@ -6,6 +6,7 @@ import copapy.backend as backend
import copapy as cp import copapy as cp
import os import os
import warnings import warnings
import pytest
if os.name == 'nt': if os.name == 'nt':
# On Windows wsl and qemu-user is required: # 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 return i1, i2, r1, r2
@pytest.mark.runner
def test_compile(): def test_compile():
t1 = cp.vector([10, 11, 12]) + cp.vector(cp.variable(v) for v in range(3)) t1 = cp.vector([10, 11, 12]) + cp.vector(cp.variable(v) for v in range(3))
t2 = t1.sum() t2 = t1.sum()

View File

@ -3,6 +3,7 @@ from copapy.backend import Write, compile_to_dag
import copapy import copapy
import subprocess import subprocess
from copapy import _binwrite from copapy import _binwrite
import pytest
def run_command(command: list[str], encoding: str = 'utf8') -> str: def run_command(command: list[str], encoding: str = 'utf8') -> str:
@ -18,6 +19,7 @@ def function(c1: NumLike) -> list[NumLike]:
return [r1] return [r1]
@pytest.mark.runner
def test_compile(): def test_compile():
c1 = variable(16) c1 = variable(16)

View File

@ -4,6 +4,7 @@ import copapy as cp
import subprocess import subprocess
from copapy import _binwrite from copapy import _binwrite
import copapy.backend import copapy.backend
import pytest
def run_command(command: list[str]) -> str: def run_command(command: list[str]) -> str:
@ -13,6 +14,7 @@ def run_command(command: list[str]) -> str:
return result.stdout return result.stdout
@pytest.mark.runner
def test_compile(): 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] 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]

View File

@ -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()

View File

@ -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()

View File

@ -7,6 +7,7 @@ import os
import warnings import warnings
import re import re
import struct import struct
import pytest
if os.name == 'nt': if os.name == 'nt':
# On Windows wsl and qemu-user is required: # 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)] iif(c1 < 5, c1 * 3.3, 8.8)]
@pytest.mark.runner
def test_compile(): def test_compile():
c_i = variable(9) c_i = variable(9)
c_f = variable(1.111) c_f = variable(1.111)
@ -121,35 +123,36 @@ def test_compile():
if not check_for_qemu(): if not check_for_qemu():
warnings.warn("qemu-aarch64 not found, aarch64 test skipped!", UserWarning) warnings.warn("qemu-aarch64 not found, aarch64 test skipped!", UserWarning)
else: 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 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('--')
result_data = parse_results(result) assert 'Return value: 1' in result
for test, ref in zip(ret_test, ret_ref): result_data = parse_results(result)
assert isinstance(test, variable)
address = variables[test][0] for test, ref in zip(ret_test, ret_ref):
data = result_data[address] assert isinstance(test, variable)
if test.dtype == 'int': address = variables[test][0]
val = int.from_bytes(data, sdb.byteorder, signed=True) data = result_data[address]
elif test.dtype == 'bool': if test.dtype == 'int':
val = bool.from_bytes(data, sdb.byteorder) val = int.from_bytes(data, sdb.byteorder, signed=True)
elif test.dtype == 'float': elif test.dtype == 'bool':
en = {'little': '<', 'big': '>'}[sdb.byteorder] val = bool.from_bytes(data, sdb.byteorder)
val = struct.unpack(en + 'f', data)[0] elif test.dtype == 'float':
assert isinstance(val, float) en = {'little': '<', 'big': '>'}[sdb.byteorder]
else: val = struct.unpack(en + 'f', data)[0]
raise Exception(f"Unknown type: {test.dtype}") assert isinstance(val, float)
print('+', val, ref, test.dtype, f" addr={address}") else:
#for t in (int, float, bool): raise Exception(f"Unknown type: {test.dtype}")
# assert isinstance(val, t) == isinstance(ref, t), f"Result type does not match for {val} and {ref}" print('+', val, ref, test.dtype, f" addr={address}")
#assert val == pytest.approx(ref, 1e-5), f"Result does not match: {val} and reference: {ref}" # pyright: ignore[reportUnknownMemberType] #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__": if __name__ == "__main__":

View File

@ -8,6 +8,7 @@ import re
import struct import struct
import platform import platform
import copapy as cp import copapy as cp
import pytest
def parse_results(log_text: str) -> dict[int, bytes]: 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)] iif(c1 < 5, c1 * 3.3, 8.8)]
@pytest.mark.runner
def test_compile(): def test_compile():
t1 = cp.vector([10, 11, 12]) + cp.vector(cp.variable(v) for v in range(3)) t1 = cp.vector([10, 11, 12]) + cp.vector(cp.variable(v) for v in range(3))
t2 = t1.sum() t2 = t1.sum()
@ -114,11 +116,17 @@ def test_compile():
dw.to_file('bin/test-x86.copapy') 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) warnings.warn(f"Test skipped, {platform.machine()} not supported for this test.", UserWarning)
else: else:
command = ['bin/coparun-x86', 'bin/test-x86.copapy', 'bin/test-x86.copapy.bin'] 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('* Output from runner:\n--')
print(result) print(result)
print('--') print('--')