co-simulation framework start
authorDan White <dan@whiteaudio.com>
Thu, 16 May 2013 00:26:45 +0000 (19:26 -0500)
committerDan White <dan@whiteaudio.com>
Thu, 16 May 2013 00:26:45 +0000 (19:26 -0500)
msp4th/cosim.py [new file with mode: 0644]
msp4th/pc4th

diff --git a/msp4th/cosim.py b/msp4th/cosim.py
new file mode 100644 (file)
index 0000000..1a327f6
--- /dev/null
@@ -0,0 +1,96 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import signal
+import time
+
+import pexpect
+
+
+atoi = pexpect.spawn('miniterm.py',
+        ['--rts=0', '/dev/ttyUSB3', '4800'],
+        logfile=open('ns430.log', 'w'),
+        timeout=5)
+
+pc = pexpect.spawn('./pc4th',
+        logfile=open('pc4th.log', 'w'),
+        timeout=5)
+
+time.sleep(0.2)
+atoi.send(r'\14\12')
+time.sleep(0.1)
+atoi.send(r'\14\12')
+time.sleep(0.1)
+
+def cleanup():
+    os.system('killall _pc4th > /dev/null 2>&1')
+    atoi.close(force=True)
+    pc.close(force=True)
+
+
+def print_side(a, b):
+    alines = [x.rstrip() for x in a.split('\n')]
+    blines = [x.rstrip() for x in b.split('\n')]
+
+    alen = len(alines)
+    blen = len(blines)
+
+    alines.extend([''] * max(blen - alen, 0))
+    blines.extend([''] * max(alen - blen, 0))
+
+    for (aline, bline) in zip(alines, blines):
+        if aline == bline:
+            eq = '='
+        else:
+            eq = '!'
+
+        s = '%-80s %s %-80s' % (aline, eq, bline)
+        print s
+
+def prompt(p):
+    p.expect([r'\r\n>', pexpect.EOF])
+
+def send(p, s):
+    p.send(s)
+
+def interact(p):
+    print '*** Interacting with:', ' '.join(p.args)
+    print '*** escape is ^]'
+    p.interact()
+
+
+try:
+    # side-by-side output
+    prompt(atoi)
+    prompt(pc)
+    print_side(' '.join(atoi.args), ' '.join(pc.args))
+    for line in open('tests.4th'):
+        s = line.rstrip()
+        s += '\r'
+
+        for n in (pc, atoi):
+        #for n in (pc, ):
+            send(n, s)
+            if s.startswith('bye'):
+                #things don't match after this
+                break
+            prompt(n)
+
+        if 0:
+            print
+            print 's   :', s.rstrip()
+            print 'pc  :', pc.before
+            print 'atoi:', atoi.before
+
+        print_side(atoi.before, pc.before)
+
+
+except pexpect.TIMEOUT:
+    print '** TIMEOUT **'
+    cleanup()
+
+#interact(pc)
+#interact(atoi)
+
+cleanup()
index 5d1b5a9b89ff598cc7736afd6021493ccb3de3c7..019a4b8945171e8b863446d69a44f84c2e2a96f8 100755 (executable)
@@ -1,7 +1,17 @@
 #!/bin/bash
 
-make _pc4th >/dev/null && (
-    OLD_STTY=$(stty -g)
+OLD_STTY=$(stty -g)
+
+function cleanup {
+    stty "$OLD_STTY"
+    exit $1
+}
+
+trap cleanup SIGHUP SIGINT SIGTERM
+
+make _pc4th >/dev/null
+
+if [ $? -eq 0 ]; then
     stty cbreak
     stty -echo
     stty -icrnl
@@ -11,6 +21,6 @@ make _pc4th >/dev/null && (
     else
         ./_pc4th < $1
     fi
+fi
 
-    stty "$OLD_STTY"
-    )
+cleanup $?