summaryrefslogtreecommitdiff
path: root/gr-blocks/python
diff options
context:
space:
mode:
authorJohnathan Corgan <johnathan@corganlabs.com>2016-08-01 14:44:07 -0700
committerJohnathan Corgan <johnathan@corganlabs.com>2016-08-01 14:44:07 -0700
commitedbcd297b252c3ee9fc5544cbe12115f45c727a7 (patch)
tree1a03284df8b93a85d89cdb81a4631f66a2379cdb /gr-blocks/python
parent85012bb73b8ad452262d5bd6e4af08fcb137144a (diff)
parent457186838d12607bcf9f5e61eaf937ff5fa090e0 (diff)
Merge branch 'master' into next
Diffstat (limited to 'gr-blocks/python')
-rw-r--r--gr-blocks/python/blocks/qa_tcp_server_sink.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/gr-blocks/python/blocks/qa_tcp_server_sink.py b/gr-blocks/python/blocks/qa_tcp_server_sink.py
new file mode 100644
index 0000000000..f7d3a0af92
--- /dev/null
+++ b/gr-blocks/python/blocks/qa_tcp_server_sink.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+#
+# Copyright 2014 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+from gnuradio import gr, gr_unittest, blocks
+import os
+import socket
+from time import sleep
+
+from threading import Timer
+from multiprocessing import Process
+
+class test_tcp_sink(gr_unittest.TestCase):
+
+ def setUp(self):
+ os.environ['GR_CONF_CONTROLPORT_ON'] = 'False'
+ self.tb_snd = gr.top_block()
+ self.tb_rcv = gr.top_block()
+
+ def tearDown(self):
+ self.tb_rcv = None
+ self.tb_snd = None
+
+ def _tcp_client(self):
+ dst = blocks.vector_sink_s()
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ for t in (0, 0.2):
+# wait until server listens
+ sleep(t)
+ try:
+ sock.connect((self.addr, self.port))
+ except socket.error as e:
+ if e.errno != 111:
+ raise
+ continue
+ break
+ fd = os.dup(sock.fileno())
+ self.tb_rcv.connect(blocks.file_descriptor_source(self.itemsize, fd), dst)
+ self.tb_rcv.run()
+ self.assertEqual(self.data, dst.data())
+
+ def test_001(self):
+ self.addr = '127.0.0.1'
+ self.port = 65510
+ self.itemsize = gr.sizeof_short
+ n_data = 16
+ self.data = tuple([x for x in range(n_data)])
+
+# tcp_server_sink blocks until client does not connect, start client process first
+ p = Process(target=self._tcp_client)
+ p.start()
+
+ src = blocks.vector_source_s(self.data, False)
+ tcp_snd = blocks.tcp_server_sink(self.itemsize, self.addr, self.port, False)
+ self.tb_snd.connect(src, tcp_snd)
+
+ self.tb_snd.run()
+ del tcp_snd
+ self.tb_snd = None
+ p.join()
+
+ def stop_rcv(self):
+ self.timeout = True
+ self.tb_rcv.stop()
+ #print "tb_rcv stopped by Timer"
+
+if __name__ == '__main__':
+ gr_unittest.run(test_tcp_sink, "test_tcp_server_sink.xml")
+