aboutsummaryrefslogtreecommitdiffstats
path: root/asm
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2023-04-08 15:21:04 +0000
committerGravatar Peter McGoron 2023-04-08 15:21:04 +0000
commit52279a9afc6afb3c589216e3f930e3d8d96dd119 (patch)
treee9be1050df499c261d68bfb5c3d2ece7a10a700a /asm
parentchange data to base 10 instead of base 16 (diff)
add communications testupsilon
Diffstat (limited to 'asm')
-rw-r--r--asm/comm.py18
-rw-r--r--asm/test_comm.py25
2 files changed, 43 insertions, 0 deletions
diff --git a/asm/comm.py b/asm/comm.py
new file mode 100644
index 0000000..9a6c188
--- /dev/null
+++ b/asm/comm.py
@@ -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)
diff --git a/asm/test_comm.py b/asm/test_comm.py
new file mode 100644
index 0000000..f71f3d3
--- /dev/null
+++ b/asm/test_comm.py
@@ -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()