diff options
Diffstat (limited to 'gr-blocks/python')
-rw-r--r-- | gr-blocks/python/qa_file_metadata.py | 1 | ||||
-rwxr-xr-x | gr-blocks/python/qa_pack_k_bits.py | 68 | ||||
-rw-r--r-- | gr-blocks/python/qa_peak_detector2.py | 58 | ||||
-rwxr-xr-x | gr-blocks/python/qa_regenerate.py | 90 | ||||
-rwxr-xr-x | gr-blocks/python/qa_stream_mux.py | 2 | ||||
-rwxr-xr-x | gr-blocks/python/qa_stretch.py | 67 | ||||
-rw-r--r-- | gr-blocks/python/qa_threshold.py | 54 | ||||
-rwxr-xr-x | gr-blocks/python/qa_throttle.py | 39 | ||||
-rw-r--r-- | gr-blocks/python/qa_transcendental.py | 90 | ||||
-rwxr-xr-x | gr-blocks/python/qa_unpack_k_bits.py | 57 |
10 files changed, 526 insertions, 0 deletions
diff --git a/gr-blocks/python/qa_file_metadata.py b/gr-blocks/python/qa_file_metadata.py index 69974d6dad..c2319a800e 100644 --- a/gr-blocks/python/qa_file_metadata.py +++ b/gr-blocks/python/qa_file_metadata.py @@ -35,6 +35,7 @@ def sig_source_c(samp_rate, freq, amp, N): class test_file_metadata(gr_unittest.TestCase): def setUp(self): + os.environ['GR_CONF_CONTROLPORT_ON'] = 'False' self.tb = gr.top_block() def tearDown(self): 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_peak_detector2.py b/gr-blocks/python/qa_peak_detector2.py new file mode 100644 index 0000000000..4b864e4d70 --- /dev/null +++ b/gr-blocks/python/qa_peak_detector2.py @@ -0,0 +1,58 @@ +#!/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 + +class test_peak_detector2(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_regen1(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_detector2_fb() + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + print dst_data + + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_peak_detector2, "test_peak_detector2.xml") diff --git a/gr-blocks/python/qa_regenerate.py b/gr-blocks/python/qa_regenerate.py new file mode 100755 index 0000000000..a57eeba2bb --- /dev/null +++ b/gr-blocks/python/qa_regenerate.py @@ -0,0 +1,90 @@ +#!/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 + +class test_regenerate(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_regen1(self): + tb = self.tb + + data = [0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + + expected_result = (0, 0, 0, + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + + src = gr.vector_source_b(data, False) + regen = blocks.regenerate_bb(5, 2) + 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_regen2(self): + tb = self.tb + + data = 200*[0,] + data[9] = 1 + data[99] = 1 + + expected_result = 200*[0,] + expected_result[9] = 1 + expected_result[19] = 1 + expected_result[29] = 1 + expected_result[39] = 1 + + expected_result[99] = 1 + expected_result[109] = 1 + expected_result[119] = 1 + expected_result[129] = 1 + + src = gr.vector_source_b(data, False) + regen = blocks.regenerate_bb(10, 3) + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run () + + dst_data = dst.data() + + self.assertEqual(tuple(expected_result), dst_data) + + +if __name__ == '__main__': + gr_unittest.run(test_regenerate, "test_regenerate.xml") diff --git a/gr-blocks/python/qa_stream_mux.py b/gr-blocks/python/qa_stream_mux.py index f21a9bbbc9..657bd3d63f 100755 --- a/gr-blocks/python/qa_stream_mux.py +++ b/gr-blocks/python/qa_stream_mux.py @@ -22,10 +22,12 @@ from gnuradio import gr, gr_unittest import blocks_swig +import os class test_stream_mux (gr_unittest.TestCase): def setUp (self): + os.environ['GR_CONF_CONTROLPORT_ON'] = 'False' self.tb = gr.top_block () def tearDown (self): diff --git a/gr-blocks/python/qa_stretch.py b/gr-blocks/python/qa_stretch.py new file mode 100755 index 0000000000..078b404dbf --- /dev/null +++ b/gr-blocks/python/qa_stretch.py @@ -0,0 +1,67 @@ +#!/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_stretch(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_stretch_01(self): + tb = self.tb + + data = 10*[1,] + data0 = map(lambda x: x/20.0, data) + data1 = map(lambda x: x/10.0, data) + + expected_result0 = 10*[0.05,] + expected_result1 = 10*[0.1,] + + src0 = gr.vector_source_f(data0, False) + src1 = gr.vector_source_f(data1, False) + inter = blocks.streams_to_vector(gr.sizeof_float, 2) + op = blocks.stretch_ff(0.1, 2) + deinter = blocks.vector_to_streams(gr.sizeof_float, 2) + dst0 = gr.vector_sink_f() + dst1 = gr.vector_sink_f() + + tb.connect(src0, (inter,0)) + tb.connect(src1, (inter,1)) + tb.connect(inter, op) + tb.connect(op, deinter) + tb.connect((deinter,0), dst0) + tb.connect((deinter,1), dst1) + tb.run() + + dst0_data = dst0.data() + dst1_data = dst1.data() + + self.assertFloatTuplesAlmostEqual(expected_result0, dst0_data, 4) + self.assertFloatTuplesAlmostEqual(expected_result1, dst1_data, 4) + +if __name__ == '__main__': + gr_unittest.run(test_stretch, "test_stretch.xml") diff --git a/gr-blocks/python/qa_threshold.py b/gr-blocks/python/qa_threshold.py new file mode 100644 index 0000000000..f91af739ad --- /dev/null +++ b/gr-blocks/python/qa_threshold.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. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_threshold(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, 0, 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2] + + expected_result = (0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1) + + src = gr.vector_source_f(data, False) + op = blocks.threshold_ff(1, 1) + dst = gr.vector_sink_f() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_threshold, "test_threshold.xml") diff --git a/gr-blocks/python/qa_throttle.py b/gr-blocks/python/qa_throttle.py new file mode 100755 index 0000000000..5d462f2c9f --- /dev/null +++ b/gr-blocks/python/qa_throttle.py @@ -0,0 +1,39 @@ +#!/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_throttle(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_01(self): + # Test that we can make the block + op = blocks.throttle(gr.sizeof_gr_complex, 1) + +if __name__ == '__main__': + gr_unittest.run(test_throttle, "test_throttle.xml") diff --git a/gr-blocks/python/qa_transcendental.py b/gr-blocks/python/qa_transcendental.py new file mode 100644 index 0000000000..8174f79630 --- /dev/null +++ b/gr-blocks/python/qa_transcendental.py @@ -0,0 +1,90 @@ +#!/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 + +class test_transcendental(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 = 100*[0,] + expected_result = 100*[1,] + + src = gr.vector_source_f(data, False) + op = blocks.transcendental("cos", "float") + dst = gr.vector_sink_f() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5) + + def test_02(self): + tb = self.tb + + data = 100*[3,] + expected_result = 100*[math.log10(3),] + + src = gr.vector_source_f(data, False) + op = blocks.transcendental("log10", "float") + dst = gr.vector_sink_f() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5) + + def test_03(self): + tb = self.tb + + data = 100*[3,] + expected_result = 100*[math.tanh(3),] + + src = gr.vector_source_f(data, False) + op = blocks.transcendental("tanh", "float") + dst = gr.vector_sink_f() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5) + +if __name__ == '__main__': + gr_unittest.run(test_transcendental, "test_transcendental.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") + |