diff options
Diffstat (limited to 'gr-blocks/python')
-rw-r--r-- | gr-blocks/python/qa_argmax.py | 73 | ||||
-rwxr-xr-x | gr-blocks/python/qa_bin_statistics.py | 227 | ||||
-rw-r--r-- | gr-blocks/python/qa_burst_tagger.py | 60 | ||||
-rwxr-xr-x | gr-blocks/python/qa_max.py | 65 | ||||
-rwxr-xr-x | gr-blocks/python/qa_message.py | 149 | ||||
-rw-r--r-- | gr-blocks/python/qa_moving_average.py | 91 | ||||
-rwxr-xr-x | gr-blocks/python/qa_mute.py | 89 | ||||
-rwxr-xr-x | gr-blocks/python/qa_pack_k_bits.py | 68 | ||||
-rwxr-xr-x | gr-blocks/python/qa_pdu.py | 92 | ||||
-rw-r--r-- | gr-blocks/python/qa_peak_detector.py | 98 | ||||
-rw-r--r-- | gr-blocks/python/qa_peak_detector2.py | 1 | ||||
-rw-r--r-- | gr-blocks/python/qa_probe_signal.py | 65 | ||||
-rw-r--r-- | gr-blocks/python/qa_sample_and_hold.py | 54 | ||||
-rwxr-xr-x | gr-blocks/python/qa_tag_debug.py | 44 | ||||
-rwxr-xr-x | gr-blocks/python/qa_unpack_k_bits.py | 57 |
15 files changed, 1232 insertions, 1 deletions
diff --git a/gr-blocks/python/qa_argmax.py b/gr-blocks/python/qa_argmax.py new file mode 100644 index 0000000000..ec82b71cd4 --- /dev/null +++ b/gr-blocks/python/qa_argmax.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# +# Copyright 2007,2010,2013 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 +import blocks_swig as blocks +import math + +class test_arg_max(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + tb = self.tb + + src1_data = (0,0.2,-0.3,0,12,0) + src2_data = (0,0.0,3.0,0,10,0) + src3_data = (0,0.0,3.0,0,1,0) + + src1 = gr.vector_source_f(src1_data) + s2v1 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data)) + tb.connect(src1, s2v1) + + src2 = gr.vector_source_f(src2_data) + s2v2 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data)) + tb.connect(src2, s2v2) + + src3 = gr.vector_source_f(src3_data) + s2v3 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data)) + tb.connect(src3, s2v3) + + dst1 = gr.vector_sink_s() + dst2 = gr.vector_sink_s() + argmax = blocks.argmax_fs(len(src1_data)) + + tb.connect(s2v1, (argmax, 0)) + tb.connect(s2v2, (argmax, 1)) + tb.connect(s2v3, (argmax, 2)) + + tb.connect((argmax,0), dst1) + tb.connect((argmax,1), dst2) + + tb.run() + index = dst1.data() + source = dst2.data() + self.assertEqual(index, (4,)) + self.assertEqual(source, (0,)) + +if __name__ == '__main__': + gr_unittest.run(test_arg_max, "test_arg_max.xml") + diff --git a/gr-blocks/python/qa_bin_statistics.py b/gr-blocks/python/qa_bin_statistics.py new file mode 100755 index 0000000000..c1b3072530 --- /dev/null +++ b/gr-blocks/python/qa_bin_statistics.py @@ -0,0 +1,227 @@ +#!/usr/bin/env python +# +# Copyright 2006,2007,2010,2013 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 +import blocks_swig as blocks +import random +import struct + +""" +Note: There has been an issue with this block in the past, see Issue +#199. This looks like it might have fixed itself over the years. I am +leaving these tests disabled on our master branch for v3.6 for now, +though, just in case. TWR. +""" + +class counter(gr.feval_dd): + def __init__(self, step_size=1): + gr.feval_dd.__init__(self) + self.step_size = step_size + self.count = 0 + + def eval(self, input): + #print "eval: self.count =", self.count + t = self.count + self.count = self.count + self.step_size + return t + + +class counter3(gr.feval_dd): + def __init__(self, f, step_size): + gr.feval_dd.__init__(self) + self.f = f + self.step_size = step_size + self.count = 0 + + def eval(self, input): + try: + #print "eval: self.count =", self.count + t = self.count + self.count = self.count + self.step_size + self.f(self.count) + except Exception, e: + print "Exception: ", e + return t + +def foobar3(new_t): + #print "foobar3: new_t =", new_t + pass + + +class counter4(gr.feval_dd): + def __init__(self, obj_instance, step_size): + gr.feval_dd.__init__(self) + self.obj_instance = obj_instance + self.step_size = step_size + self.count = 0 + + def eval(self, input): + try: + #print "eval: self.count =", self.count + t = self.count + self.count = self.count + self.step_size + self.obj_instance.foobar4(self.count) + except Exception, e: + print "Exception: ", e + return t + + +class parse_msg(object): + def __init__(self, msg): + self.center_freq = msg.arg1() + self.vlen = int(msg.arg2()) + assert(msg.length() == self.vlen * gr.sizeof_float) + self.data = struct.unpack('%df' % (self.vlen,), msg.to_string()) + +class test_bin_statistics(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block () + + def tearDown(self): + self.tb = None + + def xtest_001(self): + vlen = 4 + tune = counter(1) + tune_delay = 0 + dwell_delay = 1 + msgq = gr.msg_queue() + + src_data = tuple([float(x) for x in + ( 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 16 + )]) + + expected_results = tuple([float(x) for x in + ( 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 16 + )]) + + src = gr.vector_source_f(src_data, False) + s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) + stats = blocks.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) + self.tb.connect(src, s2v, stats) + self.tb.run() + self.assertEqual(4, msgq.count()) + for i in range(4): + m = parse_msg(msgq.delete_head()) + #print "m =", m.center_freq, m.data + self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) + + def xtest_002(self): + vlen = 4 + tune = counter(1) + tune_delay = 1 + dwell_delay = 2 + msgq = gr.msg_queue() + + src_data = tuple([float(x) for x in + ( 1, 2, 3, 4, + 9, 6, 11, 8, + 5, 10, 7, 12, + 13, 14, 15, 16 + )]) + + expected_results = tuple([float(x) for x in + ( 9, 10, 11, 12)]) + + src = gr.vector_source_f(src_data, False) + s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) + stats = blocks.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) + self.tb.connect(src, s2v, stats) + self.tb.run() + self.assertEqual(1, msgq.count()) + for i in range(1): + m = parse_msg(msgq.delete_head()) + #print "m =", m.center_freq, m.data + self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) + + + + def xtest_003(self): + vlen = 4 + tune = counter3(foobar3, 1) + tune_delay = 1 + dwell_delay = 2 + msgq = gr.msg_queue() + + src_data = tuple([float(x) for x in + ( 1, 2, 3, 4, + 9, 6, 11, 8, + 5, 10, 7, 12, + 13, 14, 15, 16 + )]) + + expected_results = tuple([float(x) for x in + ( 9, 10, 11, 12)]) + + src = gr.vector_source_f(src_data, False) + s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) + stats = blocks.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) + self.tb.connect(src, s2v, stats) + self.tb.run() + self.assertEqual(1, msgq.count()) + for i in range(1): + m = parse_msg(msgq.delete_head()) + #print "m =", m.center_freq, m.data + self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) + + def foobar4(self, new_t): + #print "foobar4: new_t =", new_t + pass + + def xtest_004(self): + vlen = 4 + tune = counter4(self, 1) + tune_delay = 1 + dwell_delay = 2 + msgq = gr.msg_queue() + + src_data = tuple([float(x) for x in + ( 1, 2, 3, 4, + 9, 6, 11, 8, + 5, 10, 7, 12, + 13, 14, 15, 16 + )]) + + expected_results = tuple([float(x) for x in + ( 9, 10, 11, 12)]) + + src = gr.vector_source_f(src_data, False) + s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) + stats = blocks.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) + self.tb.connect(src, s2v, stats) + self.tb.run() + self.assertEqual(1, msgq.count()) + for i in range(1): + m = parse_msg(msgq.delete_head()) + #print "m =", m.center_freq, m.data + self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) + + +if __name__ == '__main__': + gr_unittest.run(test_bin_statistics, "test_bin_statistics.xml") diff --git a/gr-blocks/python/qa_burst_tagger.py b/gr-blocks/python/qa_burst_tagger.py new file mode 100644 index 0000000000..5e249cb8b9 --- /dev/null +++ b/gr-blocks/python/qa_burst_tagger.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# +# Copyright 2013 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 +import blocks_swig as blocks +import pmt + +class test_burst_tagger(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + # Just run some data through and make sure it doesn't puke. + src_data = ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + trg_data = (-1, -1, 1, 1, -1, -1, 1, 1, -1, -1) + src = gr.vector_source_i(src_data) + trg = gr.vector_source_s(trg_data) + op = blocks.burst_tagger(gr.sizeof_int) + snk = blocks.tag_debug(gr.sizeof_int, "burst tagger QA") + self.tb.connect(src, (op,0)) + self.tb.connect(trg, (op,1)) + self.tb.connect(op, snk) + self.tb.run() + + x = snk.current_tags() + self.assertEqual(2, x[0].offset) + self.assertEqual(4, x[1].offset) + self.assertEqual(6, x[2].offset) + self.assertEqual(8, x[3].offset) + + self.assertEqual(True, pmt.pmt_to_bool(x[0].value)) + self.assertEqual(False, pmt.pmt_to_bool(x[1].value)) + self.assertEqual(True, pmt.pmt_to_bool(x[2].value)) + self.assertEqual(False, pmt.pmt_to_bool(x[3].value)) + +if __name__ == '__main__': + gr_unittest.run(test_burst_tagger, "test_burst_tagger.xml") diff --git a/gr-blocks/python/qa_max.py b/gr-blocks/python/qa_max.py new file mode 100755 index 0000000000..4af70bd4be --- /dev/null +++ b/gr-blocks/python/qa_max.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# +# Copyright 2007,2010,2013 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 +import blocks_swig as blocks +import math + +class test_max(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + src_data = (0,0.2,-0.3,0,12,0) + expected_result = (float(max(src_data)),) + + src = gr.vector_source_f(src_data) + s2v = blocks.stream_to_vector(gr.sizeof_float, len(src_data)) + op = blocks.max_ff(len(src_data)) + dst = gr.vector_sink_f() + + self.tb.connect(src, s2v, op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(expected_result, result_data) + + def test_002(self): + src_data=(-100,-99,-98,-97,-96,-1) + expected_result = (float(max(src_data)),) + + src = gr.vector_source_f(src_data) + s2v = blocks.stream_to_vector(gr.sizeof_float, len(src_data)) + op = blocks.max_ff(len(src_data)) + dst = gr.vector_sink_f() + + self.tb.connect(src, s2v, op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(expected_result, result_data) + +if __name__ == '__main__': + gr_unittest.run(test_max, "test_max.xml") + diff --git a/gr-blocks/python/qa_message.py b/gr-blocks/python/qa_message.py new file mode 100755 index 0000000000..551fdd6259 --- /dev/null +++ b/gr-blocks/python/qa_message.py @@ -0,0 +1,149 @@ +#!/usr/bin/env python +# +# Copyright 2004,2010,2013 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 +import blocks_swig as blocks +import pmt +import time + +def all_counts(): + return (gr.block_ncurrently_allocated(), + gr.block_detail_ncurrently_allocated(), + gr.buffer_ncurrently_allocated(), + gr.buffer_reader_ncurrently_allocated(), + gr.message_ncurrently_allocated()) + + +class test_message(gr_unittest.TestCase): + + def setUp(self): + self.msgq = gr.msg_queue() + + def tearDown(self): + self.msgq = None + + def leak_check(self, fct): + begin = all_counts() + fct() + # tear down early so we can check for leaks + self.tearDown() + end = all_counts() + self.assertEqual(begin, end) + + def test_100(self): + msg = gr.message(0, 1.5, 2.3) + self.assertEquals(0, msg.type()) + self.assertAlmostEqual(1.5, msg.arg1()) + self.assertAlmostEqual(2.3, msg.arg2()) + self.assertEquals(0, msg.length()) + + def test_101(self): + s = 'This is a test' + msg = gr.message_from_string(s) + self.assertEquals(s, msg.to_string()) + + def test_200(self): + self.leak_check(self.body_200) + + def body_200(self): + self.msgq.insert_tail(gr.message(0)) + self.assertEquals(1, self.msgq.count()) + self.msgq.insert_tail(gr.message(1)) + self.assertEquals(2, self.msgq.count()) + msg0 = self.msgq.delete_head() + self.assertEquals(0, msg0.type()) + msg1 = self.msgq.delete_head() + self.assertEquals(1, msg1.type()) + self.assertEquals(0, self.msgq.count()) + + def test_201(self): + self.leak_check(self.body_201) + + def body_201(self): + self.msgq.insert_tail(gr.message(0)) + self.assertEquals(1, self.msgq.count()) + self.msgq.insert_tail(gr.message(1)) + self.assertEquals(2, self.msgq.count()) + + def test_202(self): + self.leak_check(self.body_202) + + def body_202(self): + # global msg + msg = gr.message(666) + + def test_300(self): + input_data = (0,1,2,3,4,5,6,7,8,9) + src = gr.vector_source_b(input_data) + dst = gr.vector_sink_b() + tb = gr.top_block() + tb.connect(src, dst) + tb.run() + self.assertEquals(input_data, dst.data()) + + def test_301(self): + # Use itemsize, limit constructor + src = blocks.message_source(gr.sizeof_char) + dst = gr.vector_sink_b() + tb = gr.top_block() + tb.connect(src, dst) + src.msgq().insert_tail(gr.message_from_string('01234')) + src.msgq().insert_tail(gr.message_from_string('5')) + src.msgq().insert_tail(gr.message_from_string('')) + src.msgq().insert_tail(gr.message_from_string('6789')) + src.msgq().insert_tail(gr.message(1)) # send EOF + tb.run() + self.assertEquals(tuple(map(ord, '0123456789')), dst.data()) + + def test_302(self): + # Use itemsize, msgq constructor + msgq = gr.msg_queue() + src = blocks.message_source(gr.sizeof_char, msgq) + dst = gr.vector_sink_b() + tb = gr.top_block() + tb.connect(src, dst) + src.msgq().insert_tail(gr.message_from_string('01234')) + src.msgq().insert_tail(gr.message_from_string('5')) + src.msgq().insert_tail(gr.message_from_string('')) + src.msgq().insert_tail(gr.message_from_string('6789')) + src.msgq().insert_tail(gr.message(1)) # send EOF + tb.run() + self.assertEquals(tuple(map(ord, '0123456789')), dst.data()) + + def test_debug_401(self): + msg = pmt.pmt_intern("TESTING") + src = blocks.message_strobe(msg, 500) + snk = blocks.message_debug() + + tb = gr.top_block() + tb.msg_connect(src, "strobe", snk, "store") + tb.start() + time.sleep(1) + tb.stop() + tb.wait() + + rec_msg = snk.get_message(0) + self.assertTrue(pmt.pmt_eqv(rec_msg, msg)) + + +if __name__ == '__main__': + gr_unittest.run(test_message, "test_message.xml") diff --git a/gr-blocks/python/qa_moving_average.py b/gr-blocks/python/qa_moving_average.py new file mode 100644 index 0000000000..169b4746c2 --- /dev/null +++ b/gr-blocks/python/qa_moving_average.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# +# Copyright 2013 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 +import blocks_swig as blocks +import math, random + +def make_random_complex_tuple(L, scale=1): + result = [] + for x in range(L): + result.append(scale*complex(2*random.random()-1, + 2*random.random()-1)) + return tuple(result) + +def make_random_float_tuple(L, scale=1): + result = [] + for x in range(L): + result.append(scale*(2*random.random()-1)) + return tuple(result) + +class test_moving_average(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_01(self): + tb = self.tb + + N = 10000 + seed = 0 + data = make_random_float_tuple(N, 1) + expected_result = N*[0,] + + src = gr.vector_source_f(data, False) + op = blocks.moving_average_ff(100, 0.001) + dst = gr.vector_sink_f() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + # make sure result is close to zero + self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 1) + + def test_02(self): + tb = self.tb + + N = 10000 + seed = 0 + data = make_random_complex_tuple(N, 1) + expected_result = N*[0,] + + src = gr.vector_source_c(data, False) + op = blocks.moving_average_cc(100, 0.001) + dst = gr.vector_sink_c() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + # make sure result is close to zero + self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 1) + +if __name__ == '__main__': + gr_unittest.run(test_moving_average, "test_moving_average.xml") diff --git a/gr-blocks/python/qa_mute.py b/gr-blocks/python/qa_mute.py new file mode 100755 index 0000000000..96c57b2ed1 --- /dev/null +++ b/gr-blocks/python/qa_mute.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005,2007,2010,2013 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 +import blocks_swig as blocks + +class test_mute(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def help_ii(self, src_data, exp_data, op): + for s in zip(range(len(src_data)), src_data): + src = gr.vector_source_i(s[1]) + self.tb.connect(src, (op, s[0])) + dst = gr.vector_sink_i() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_ff(self, src_data, exp_data, op): + for s in zip(range(len(src_data)), src_data): + src = gr.vector_source_f(s[1]) + self.tb.connect(src, (op, s[0])) + dst = gr.vector_sink_f() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_cc(self, src_data, exp_data, op): + for s in zip(range(len(src_data)), src_data): + src = gr.vector_source_c(s[1]) + self.tb.connect(src, (op, s[0])) + dst = gr.vector_sink_c() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def test_unmute_ii(self): + src_data = (1, 2, 3, 4, 5) + expected_result = (1, 2, 3, 4, 5) + op = blocks.mute_ii(False) + self.help_ii((src_data,), expected_result, op) + + def test_mute_ii(self): + src_data = (1, 2, 3, 4, 5) + expected_result = (0, 0, 0, 0, 0) + op = blocks.mute_ii(True) + self.help_ii((src_data,), expected_result, op) + + def test_unmute_cc(self): + src_data = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j) + expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j) + op = blocks.mute_cc(False) + self.help_cc((src_data,), expected_result, op) + + def test_unmute_cc(self): + src_data = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j) + expected_result =(0+0j, 0+0j, 0+0j, 0+0j, 0+0j) + op = blocks.mute_cc(True) + self.help_cc((src_data,), expected_result, op) + +if __name__ == '__main__': + gr_unittest.run(test_mute, "test_mute.xml") diff --git a/gr-blocks/python/qa_pack_k_bits.py b/gr-blocks/python/qa_pack_k_bits.py new file mode 100755 index 0000000000..cd55d2f200 --- /dev/null +++ b/gr-blocks/python/qa_pack_k_bits.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# +# Copyright 2006,2010,2013 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 +import blocks_swig as blocks +import random + +class test_pack(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + src_data = (1,0,1,1,0,1,1,0) + expected_results = (1,0,1,1,0,1,1,0) + src = gr.vector_source_b(src_data,False) + op = blocks.pack_k_bits_bb(1) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_results, dst.data()) + + def test_002(self): + src_data = (1,0,1,1,0,0,0,1) + expected_results = ( 2, 3, 0, 1) + src = gr.vector_source_b(src_data,False) + op = blocks.pack_k_bits_bb(2) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + #self.assertEqual(expected_results, dst.data()) + self.assertEqual(expected_results, dst.data()) + + def test_003(self): + src_data = expected_results = map(lambda x: random.randint(0,3), range(10)); + src = gr.vector_source_b( src_data ); + pack = blocks.pack_k_bits_bb(2); + unpack = blocks.unpack_k_bits_bb(2); + snk = gr.vector_sink_b(); + self.tb.connect(src,unpack,pack,snk); + self.tb.run() + self.assertEqual(list(expected_results), list(snk.data())); + +if __name__ == '__main__': + gr_unittest.run(test_pack, "test_pack.xml") + diff --git a/gr-blocks/python/qa_pdu.py b/gr-blocks/python/qa_pdu.py new file mode 100755 index 0000000000..dc50b7c330 --- /dev/null +++ b/gr-blocks/python/qa_pdu.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python +# +# Copyright 2013 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 +import blocks_swig as blocks +import pmt +import time + +class test_pdu(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_000(self): + # Just run some data through and make sure it doesn't puke. + src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + + src = blocks.pdu_to_tagged_stream(blocks.byte_t) + snk3 = blocks.tagged_stream_to_pdu(blocks.byte_t) + snk2 = gr.vector_sink_b() + snk = gr.tag_debug(1, "test") + snk.set_display(False) + + dbg = gr.message_debug() + + # Test that the right number of ports exist. + pi = snk3.message_ports_in() + po = snk3.message_ports_out() + self.assertEqual(pmt.pmt_length(pi), 0) + self.assertEqual(pmt.pmt_length(po), 1) + + time.sleep(0.1) + self.tb.connect(src, snk) + self.tb.connect(src, snk2) + self.tb.connect(src, snk3) + self.tb.msg_connect(snk3, "pdus", dbg, "store") + self.tb.start() + + # make our reference and message pmts + port = pmt.pmt_intern("pdus") + msg = pmt.pmt_cons( pmt.PMT_NIL, pmt.pmt_make_u8vector(16, 0xFF)) + + # post the message + src.to_basic_block()._post(port, msg) # eww, what's that smell? + + while dbg.num_messages() < 1: + time.sleep(0.5) + self.tb.stop() + self.tb.wait() + + # Get the vector of data from the vector sink + result_data = snk2.data() + + # Get the vector of data from the message sink + # Convert the message PMT as a pair into its vector + result_msg = dbg.get_message(0) + msg_vec = pmt.pmt_cdr(result_msg) + #pmt.pmt_print(msg_vec) + + # Convert the PMT vector into a Python list + msg_data = [] + for i in xrange(16): + msg_data.append(pmt.pmt_u8vector_ref(msg_vec, i)) + + actual_data = 16*[0xFF,] + self.assertEqual(actual_data, list(result_data)) + self.assertEqual(actual_data, msg_data) + +if __name__ == '__main__': + gr_unittest.run(test_pdu, "test_pdu.xml") diff --git a/gr-blocks/python/qa_peak_detector.py b/gr-blocks/python/qa_peak_detector.py new file mode 100644 index 0000000000..c3ff2548c4 --- /dev/null +++ b/gr-blocks/python/qa_peak_detector.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# +# Copyright 2013 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 +import blocks_swig as blocks + +class test_peak_detector(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_01(self): + tb = self.tb + + data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] + + expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + src = gr.vector_source_f(data, False) + regen = blocks.peak_detector_fb() + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + + def test_02(self): + tb = self.tb + + data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] + + expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + src = gr.vector_source_i(data, False) + regen = blocks.peak_detector_ib() + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + + def test_03(self): + tb = self.tb + + data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] + + expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + src = gr.vector_source_s(data, False) + regen = blocks.peak_detector_sb() + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_peak_detector, "test_peak_detector.xml") diff --git a/gr-blocks/python/qa_peak_detector2.py b/gr-blocks/python/qa_peak_detector2.py index 4b864e4d70..b2d8e318dd 100644 --- a/gr-blocks/python/qa_peak_detector2.py +++ b/gr-blocks/python/qa_peak_detector2.py @@ -50,7 +50,6 @@ class test_peak_detector2(gr_unittest.TestCase): tb.run() dst_data = dst.data() - print dst_data self.assertEqual(expected_result, dst_data) diff --git a/gr-blocks/python/qa_probe_signal.py b/gr-blocks/python/qa_probe_signal.py new file mode 100644 index 0000000000..a420df71e5 --- /dev/null +++ b/gr-blocks/python/qa_probe_signal.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# +# Copyright 2012-2013 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. +# + +import time +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_probe_signal(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + value = 12.3 + repeats = 100 + src_data = [value] * repeats + + src = gr.vector_source_f(src_data) + dst = blocks.probe_signal_f() + + self.tb.connect(src, dst) + self.tb.run() + output = dst.level() + self.assertAlmostEqual(value, output, places=6) + + def test_002(self): + vector_length = 10 + repeats = 10 + value = [0.5+i for i in range(0, vector_length)] + src_data = value * repeats + + src = gr.vector_source_f(src_data) + s2v = blocks.stream_to_vector(gr.sizeof_float, vector_length) + dst = blocks.probe_signal_vf(vector_length) + + self.tb.connect(src, s2v, dst) + self.tb.run() + output = dst.level() + self.assertEqual(len(output), vector_length) + self.assertAlmostEqual(value[3], output[3], places=6) + +if __name__ == '__main__': + gr_unittest.run(test_probe_signal, "test_probe_signal.xml") diff --git a/gr-blocks/python/qa_sample_and_hold.py b/gr-blocks/python/qa_sample_and_hold.py new file mode 100644 index 0000000000..59628090d1 --- /dev/null +++ b/gr-blocks/python/qa_sample_and_hold.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# +# Copyright 2013 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. +# + +import time +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_sample_and_hold(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + src_data = 10*[0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1] + ctrl_data = 10*[1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0] + expected_result = 10*(0,0,0,0,4,5,6,7,8,9,9,9,9,9,9,9,9,9) + + src = gr.vector_source_f(src_data) + ctrl = gr.vector_source_b(ctrl_data) + op = blocks.sample_and_hold_ff() + dst = gr.vector_sink_f() + + self.tb.connect(src, (op,0)) + self.tb.connect(ctrl, (op,1)) + self.tb.connect(op, dst) + self.tb.run() + + result = dst.data() + self.assertFloatTuplesAlmostEqual(expected_result, result, places=6) + +if __name__ == '__main__': + gr_unittest.run(test_sample_and_hold, "test_sample_and_hold.xml") diff --git a/gr-blocks/python/qa_tag_debug.py b/gr-blocks/python/qa_tag_debug.py new file mode 100755 index 0000000000..ad85daebcc --- /dev/null +++ b/gr-blocks/python/qa_tag_debug.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# +# Copyright 2012-2013 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 +import blocks_swig as blocks + +class test_tag_debug(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + # Just run some data through and make sure it doesn't puke. + src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + src = gr.vector_source_i(src_data) + op = blocks.tag_debug(gr.sizeof_int, "tag QA") + self.tb.connect(src, op) + self.tb.run() + x = op.current_tags() + +if __name__ == '__main__': + gr_unittest.run(test_tag_debug, "test_tag_debug.xml") diff --git a/gr-blocks/python/qa_unpack_k_bits.py b/gr-blocks/python/qa_unpack_k_bits.py new file mode 100755 index 0000000000..e038d5a03a --- /dev/null +++ b/gr-blocks/python/qa_unpack_k_bits.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# +# Copyright 2006,2010,2013 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 +import blocks_swig as blocks +import random + +class test_unpack(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block () + + def tearDown(self): + self.tb = None + + def test_001(self): + src_data = (1,0,1,1,0,1,1,0) + expected_results = (1,0,1,1,0,1,1,0) + src = gr.vector_source_b(src_data,False) + op = blocks.unpack_k_bits_bb(1) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_results, dst.data()) + + def test_002(self): + src_data = ( 2, 3, 0, 1) + expected_results = (1,0,1,1,0,0,0,1) + src = gr.vector_source_b(src_data,False) + op = blocks.unpack_k_bits_bb(2) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_results, dst.data()) + +if __name__ == '__main__': + gr_unittest.run(test_unpack, "test_unpack.xml") + |