add communications test

This commit is contained in:
Peter McGoron 2023-04-08 15:21:04 +00:00
parent 448b70cc97
commit 52279a9afc
2 changed files with 43 additions and 0 deletions

18
asm/comm.py Normal file
View File

@ -0,0 +1,18 @@
from creole import *
import socket
def connect(ip, port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, port))
return s
def execute(creole_instance, socket):
code = creole_instance()
l = len(code)
assert l <= 0xFFFF
socket.sendall(bytes([l & 0xFF, l >> 8]) + code)
def connect_exec(cr, ip="192.168.1.50", port=6626):
s = connect(ip, port)
execute(cr, s)
return s.recv(1024)

25
asm/test_comm.py Normal file
View File

@ -0,0 +1,25 @@
from comm import *
# These require a connection!
def test_print_char():
p = Program()
p.parse_asm_line(f"SENDVAL 100")
assert connect_exec(p) == b'100'
def test_print_string():
p = Program()
p.parse_lines([
"j .l",
f"db d0 {[ord(x) for x in 'hello world']}",
".l",
"senddat d0"
])
return connect_exec(p).decode()
def test_run_adc():
p = Program()
p.parse_lines([
"read_adc 0 r0",
"sendval r0"
])
return connect_exec(p).decode()