copapy/tests/test_crash_win.py

56 lines
1.3 KiB
Python
Raw Normal View History

2025-10-09 20:50:57 +00:00
from copapy import Write, CPVariable
2025-10-05 21:09:43 +00:00
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, c2):
i1 = c1 * 3.3 + 5
i2 = c2 * 5 + c1
r1 = i1 + i2 * 55 / 4
r2 = 4 * i2 + 5
2025-10-07 21:20:43 +00:00
return i1, i2, r1, r2
2025-10-05 21:09:43 +00:00
def test_compile():
2025-10-09 20:50:57 +00:00
c1 = CPVariable(4)
c2 = CPVariable(2)
2025-10-07 21:20:43 +00:00
2025-10-05 21:09:43 +00:00
ret = function(c1, c2)
dw, variable_list = copapy.compile_to_instruction_list([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)
copapy.add_read_command(dw, variable_list, net)
2025-10-12 21:21:34 +00:00
dw.write_com(binwrite.Command.END_COM)
2025-10-05 21:09:43 +00:00
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
2025-10-07 21:20:43 +00:00
2025-10-05 21:09:43 +00:00
if __name__ == "__main__":
#test_example()
test_compile()