summaryrefslogtreecommitdiff
path: root/gr-blocks/python
diff options
context:
space:
mode:
authorJiří Pinkava <j-pi@seznam.cz>2015-04-09 08:55:04 +0200
committerJohnathan Corgan <johnathan@corganlabs.com>2016-06-25 09:47:40 -0700
commita99f8ac8cc9a15ab608081c10a7733fce125e276 (patch)
tree86c4d7b5fb53039a95d0e2f146b20d5b52cf2c6a /gr-blocks/python
parent0e18622160a33c10d5853fc3e3d0ee4ebaa41829 (diff)
runtime: fix state handling in top_block
d_state is intended to track running state of top block. * initial state is IDLE * set state to RUNNING when start() is called * set state to IDLE when stop() is called * set state to IDLE when all work is done (reqires call of wait()) * unlock() resume/start execution only if state is RUNNING
Diffstat (limited to 'gr-blocks/python')
-rwxr-xr-xgr-blocks/python/blocks/qa_hier_block2.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/gr-blocks/python/blocks/qa_hier_block2.py b/gr-blocks/python/blocks/qa_hier_block2.py
index 97206a248d..3e780806bc 100755
--- a/gr-blocks/python/blocks/qa_hier_block2.py
+++ b/gr-blocks/python/blocks/qa_hier_block2.py
@@ -2,6 +2,7 @@
from gnuradio import gr, gr_unittest, blocks
import numpy
+import threading
import time
class add_ff(gr.sync_block):
@@ -427,7 +428,7 @@ class test_hier_block2(gr_unittest.TestCase):
procs = hblock.processor_affinity()
self.assertEquals((0,), procs)
- def test_lock_unlock(self):
+ def test_34a_lock_unlock(self):
hblock = gr.top_block("test_block")
src = blocks.null_source(gr.sizeof_float)
throttle = blocks.throttle(gr.sizeof_float, 32000)
@@ -442,5 +443,28 @@ class test_hier_block2(gr_unittest.TestCase):
hblock.stop()
hblock.wait()
+ def test_34b_lock_unlock(self):
+ hblock = gr.top_block("test_block")
+ src = blocks.null_source(gr.sizeof_float)
+ throttle = blocks.throttle(gr.sizeof_float, 32000)
+ sink = blocks.null_sink(gr.sizeof_float)
+ hblock.connect(src, throttle, sink)
+ hblock.set_processor_affinity([0,])
+ def thread_01(hblock, cls):
+ cls.test_34b_val = 10
+ hblock.lock()
+ cls.test_34b_val = 20
+ hblock.unlock()
+ cls.test_34b_val = 30
+ time.sleep(0.5)
+ cls.test_34b_val = 40
+ hblock.stop()
+ hblock.start()
+ self.test_34b_val = 0
+ t1 = threading.Thread(target=thread_01, args=(hblock, self, ))
+ t1.start()
+ hblock.wait()
+ self.assertEqual(40, self.test_34b_val)
+
if __name__ == "__main__":
gr_unittest.run(test_hier_block2, "test_hier_block2.xml")