summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJosh Blum2012-11-06 01:38:42 -0800
committerJosh Blum2012-11-06 01:38:42 -0800
commit4cec45599e1daf81db5aae72c15e005883f59088 (patch)
tree3a94d62c3c60618a2136c3f3addb2598c57afc98 /tests
parentbf7ac68a7bb91bbef8bd74f59df3ee1908d87ca8 (diff)
downloadsandhi-4cec45599e1daf81db5aae72c15e005883f59088.tar.gz
sandhi-4cec45599e1daf81db5aae72c15e005883f59088.tar.bz2
sandhi-4cec45599e1daf81db5aae72c15e005883f59088.zip
work on python blocks and unit test
Diffstat (limited to 'tests')
-rw-r--r--tests/block_test.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/block_test.py b/tests/block_test.py
index b598b27..a6dccfc 100644
--- a/tests/block_test.py
+++ b/tests/block_test.py
@@ -19,9 +19,72 @@ class NullSink(gras.Block):
def work(self, ins, outs):
self.mark_done()
+class VectorSource(gras.Block):
+ def __init__(self, out_sig, vec):
+ gras.Block.__init__(self,
+ name='VectorSource',
+ in_sig=None,
+ out_sig=[out_sig],
+ )
+ self._vec = vec
+
+ def work(self, ins, outs):
+ print 'vector source work'
+ num = min(len(outs[0]), len(self._vec))
+ if num == 0:
+ self.mark_done()
+ return
+ #print 'outs[0][:num] is '
+ #print len(outs)
+ #print len(outs[0])
+ #print outs[0][0]
+ #print outs[0][:num]
+ outs[0][:num] = self._vec[:num]
+ self.produce(0, num)
+ self._vec = self._vec[num:]
+ #if not self._vec:
+ # self.mark_done()
+ print 'vector source work done'
+
+class VectorSink(gras.Block):
+ def __init__(self, in_sig):
+ gras.Block.__init__(self,
+ name='VectorSink',
+ in_sig=[in_sig],
+ out_sig=None,
+ )
+ self._vec = list()
+
+ def get_vector(self):
+ return self._vec
+
+ def work(self, ins, outs):
+ print 'vector sink work'
+ self._vec.extend(ins[0].copy())
+ self.consume(0, len(ins[0]))
+ print 'vector sink work done'
+
class BlockTest(unittest.TestCase):
+ def test_vector_blocks(self):
+ vec_source = VectorSource(numpy.uint32, [0, 9, 8, 7, 6])
+ vec_sink = VectorSink(numpy.uint32)
+
+ print 'make tb'
+ tb = gras.TopBlock()
+ print 'connect'
+ tb.connect(vec_source, vec_sink)
+ print 'run'
+ tb.run()
+ print 'done run'
+ tb = None
+
+ print vec_sink.get_vector()
+ vec_source = None
+ vec_sink = None
+
def test_make_block(self):
+ return
null_src = NullSource()
null_sink = NullSink()