summaryrefslogtreecommitdiff
path: root/host/proto/test
diff options
context:
space:
mode:
Diffstat (limited to 'host/proto/test')
-rw-r--r--host/proto/test/asserv.py36
-rw-r--r--host/proto/test/fio.py22
-rw-r--r--host/proto/test/interactive.py29
3 files changed, 87 insertions, 0 deletions
diff --git a/host/proto/test/asserv.py b/host/proto/test/asserv.py
new file mode 100644
index 00000000..e578d9dd
--- /dev/null
+++ b/host/proto/test/asserv.py
@@ -0,0 +1,36 @@
+import sys
+sys.path.append (sys.path[0] + '/..')
+
+import proto
+from fio import IO
+import time, select, os
+
+# Pass program name as argument.
+fout, fin = os.popen2 (sys.argv[1:], 't', 1)
+time.sleep (0.5)
+io = IO (fin, fout)
+
+def log (x):
+ print x
+
+p = proto.Proto (io, time.time, 0.5, log)
+
+done = 0
+
+def reset ():
+ print 'reset'
+
+def counter_stat (left, right, aux0):
+ print 'counter %u, %u, %u' % (left, right, aux0)
+ global done
+ done += 1
+
+p.register ('z', '', reset)
+p.register ('C', 'HHH', counter_stat)
+
+p.send ('C', 'B', 255)
+
+while not p.sync () or done != 3:
+ fds = select.select ((p,), (), (), 0.1)[0]
+ for i in fds:
+ i.read ()
diff --git a/host/proto/test/fio.py b/host/proto/test/fio.py
new file mode 100644
index 00000000..07646199
--- /dev/null
+++ b/host/proto/test/fio.py
@@ -0,0 +1,22 @@
+
+class IO:
+ def __init__ (self, fin = None, fout = None):
+ if fin is None:
+ import sys, tty
+ self.fin = sys.stdin
+ self.fout = sys.stdout
+ tty.setcbreak (sys.stdin.fileno ())
+ else:
+ self.fin = fin
+ self.fout = fout
+
+ def read (self, *args):
+ buf = self.fin.read (*args).replace ('\n', '\r')
+ return buf
+
+ def write (self, *args):
+ return self.fout.write (*[i.replace ('\r', '\n') for i in args])
+
+ def fileno (self):
+ return self.fin.fileno ()
+
diff --git a/host/proto/test/interactive.py b/host/proto/test/interactive.py
new file mode 100644
index 00000000..f68dd121
--- /dev/null
+++ b/host/proto/test/interactive.py
@@ -0,0 +1,29 @@
+import sys
+sys.path.append (sys.path[0] + '/..')
+
+import proto
+from fio import IO
+import time, select
+
+def log (x):
+ print x
+
+p = proto.Proto (IO (), time.time, 2, log)
+
+def a (i, j):
+ print 'a (%d, %d)' % (i, j)
+
+def b (i):
+ print 'b (%d)' % i
+
+p.register ('a', 'BH', a)
+p.register ('b', 'L', b)
+
+p.send ('a', 'BH', 1, 2)
+p.send ('b', 'L', 3)
+
+while True:
+ p.sync ()
+ fds = select.select ((p,), (), (), 0.1)[0]
+ for i in fds:
+ i.read ()