summaryrefslogtreecommitdiff
path: root/gr-blocks
diff options
context:
space:
mode:
authorJiří Pinkava <j-pi@seznam.cz>2014-12-08 16:46:25 +0100
committerJiří Pinkava <j-pi@seznam.cz>2016-06-29 09:09:19 +0200
commitb238171b32d426dae569042843825b20d75a8010 (patch)
tree06c0184f2dedadd5cc2cc96e62cc9b1cd8c98557 /gr-blocks
parentb49f52f96cdef62d4b7ffa659a3f58363c0c13db (diff)
tcp_server_sink: QA
Diffstat (limited to 'gr-blocks')
-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")
+