mirror of https://github.com/Nonannet/copapy.git
tests updated with groups and old tests removed
This commit is contained in:
parent
e5f6897ca9
commit
a7c9975c31
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
@ -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()
|
||||
|
|
@ -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,7 +123,8 @@ def test_compile():
|
|||
|
||||
if not check_for_qemu():
|
||||
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--')
|
||||
|
|
|
|||
|
|
@ -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']
|
||||
|
||||
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('--')
|
||||
|
|
|
|||
Loading…
Reference in New Issue