diff options
author | Johnathan Corgan | 2012-05-05 13:21:38 -0700 |
---|---|---|
committer | Johnathan Corgan | 2012-06-08 07:44:57 -0700 |
commit | 630cd06cb33d628fa6426866f006580aad30f84b (patch) | |
tree | bb3e819ebcec9a4b6100a43c026d5104481182a7 /gr-blocks/python | |
parent | 9038efc67028ac6bab05bfd60a8de7e6c2ba3fd7 (diff) | |
download | gnuradio-630cd06cb33d628fa6426866f006580aad30f84b.tar.gz gnuradio-630cd06cb33d628fa6426866f006580aad30f84b.tar.bz2 gnuradio-630cd06cb33d628fa6426866f006580aad30f84b.zip |
blocks: adds new top-level component gr-blocks with first block
gr::blocks::add_XX
Diffstat (limited to 'gr-blocks/python')
-rw-r--r-- | gr-blocks/python/CMakeLists.txt | 47 | ||||
-rw-r--r-- | gr-blocks/python/__init__.py | 28 | ||||
-rwxr-xr-x | gr-blocks/python/qa_add_and_friends.py | 195 |
3 files changed, 270 insertions, 0 deletions
diff --git a/gr-blocks/python/CMakeLists.txt b/gr-blocks/python/CMakeLists.txt new file mode 100644 index 000000000..a7f0e741a --- /dev/null +++ b/gr-blocks/python/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright 2012 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. + +######################################################################## +include(GrPython) + +GR_PYTHON_INSTALL( + FILES + __init__.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/blocks + COMPONENT "blocks_python" +) + +######################################################################## +# Handle the unit tests +######################################################################## +if(ENABLE_TESTING) +include(GrTest) +file(GLOB py_qa_test_files "qa_*.py") +foreach(py_qa_test_file ${py_qa_test_files}) + get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) + set(GR_TEST_PYTHON_DIRS + ${CMAKE_BINARY_DIR}/gnuradio-core/src/python + ${CMAKE_BINARY_DIR}/gnuradio-core/src/lib/swig + ${CMAKE_BINARY_DIR}/gr-blocks/python + ${CMAKE_BINARY_DIR}/gr-blocks/swig + ) + set(GR_TEST_TARGET_DEPS gruel gnuradio-core gnuradio-blocks) + GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${py_qa_test_file}) +endforeach(py_qa_test_file) +endif(ENABLE_TESTING) diff --git a/gr-blocks/python/__init__.py b/gr-blocks/python/__init__.py new file mode 100644 index 000000000..c786d3a22 --- /dev/null +++ b/gr-blocks/python/__init__.py @@ -0,0 +1,28 @@ +# +# Copyright 2012 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. +# + +''' +This is the gr-blocks package. This package provides GNU Radio +processing blocks common to many flowgraphs. +''' + +from blocks_swig import * + diff --git a/gr-blocks/python/qa_add_and_friends.py b/gr-blocks/python/qa_add_and_friends.py new file mode 100755 index 000000000..7d008202b --- /dev/null +++ b/gr-blocks/python/qa_add_and_friends.py @@ -0,0 +1,195 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,2010,2012 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 + +class test_add_and_friends(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_ss(self, src_data, exp_data, op): + for s in zip(range(len(src_data)), src_data): + src = gr.vector_source_s(s[1]) + self.tb.connect(src, (op, s[0])) + dst = gr.vector_sink_s() + 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_add_ff(self): + src1_data = (1.0, 2.0, 3.0, 4.0, 5.0) + src2_data = (8.0, -3.0, 4.0, 8.0, 2.0) + expected_result = (9.0, -1.0, 7.0, 12.0, 7.0) + op = blocks_swig.add_ff() + self.help_ff((src1_data, src2_data), expected_result, op) + + def test_add_ss(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (9, -1, 7, 12, 7) + op = blocks_swig.add_ss() + self.help_ss((src1_data, src2_data), expected_result, op) + + def test_add_ii(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (9, -1, 7, 12, 7) + op = blocks_swig.add_ii() + self.help_ii((src1_data, src2_data), expected_result, op) + + def test_add_cc(self): + src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) + src2_data = (8+8j, -3-3j, 4+4j, 8+8j, 2+2j) + expected_result = (9+9j, -1-1j, 7+7j, 12+12j, 7+7j) + op = blocks_swig.add_cc() + self.help_cc((src1_data, src2_data), expected_result, op) + + """ + def test_add_const_ii(self): + src_data = (1, 2, 3, 4, 5) + expected_result = (6, 7, 8, 9, 10) + op = gr.add_const_ii(5) + self.help_ii((src_data,), expected_result, op) + + def test_add_const_cc(self): + src_data = (1, 2, 3, 4, 5) + expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j) + op = gr.add_const_cc(5j) + self.help_cc((src_data,), expected_result, op) + + def test_mult_const_ii(self): + src_data = (-1, 0, 1, 2, 3) + expected_result = (-5, 0, 5, 10, 15) + op = gr.multiply_const_ii(5) + self.help_ii((src_data,), expected_result, op) + + def test_mult_const_ff(self): + src_data = (-1, 0, 1, 2, 3) + expected_result = (-5, 0, 5, 10, 15) + op = gr.multiply_const_cc(5) + self.help_cc((src_data,), expected_result, op) + + def test_mult_const_cc(self): + src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) + expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j) + op = gr.multiply_const_cc(5) + self.help_cc((src_data,), expected_result, op) + + def test_mult_const_cc2(self): + src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) + expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j) + op = gr.multiply_const_cc(5+2j) + self.help_cc((src_data,), expected_result, op) + + def test_mult_ii(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (8, -6, 12, 32, 10) + op = gr.multiply_ii() + self.help_ii((src1_data, src2_data), + expected_result, op) + + def test_mult_ff(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (8, -6, 12, 32, 10) + op = gr.multiply_ff() + self.help_ff((src1_data, src2_data), + expected_result, op) + + def test_mult_cc(self): + src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) + src2_data = (8, -3, 4, 8, 2) + expected_result = (8+8j, -6-6j, 12+12j, 32+32j, 10+10j) + op = gr.multiply_cc() + self.help_cc((src1_data, src2_data), + expected_result, op) + + def test_sub_ii_1(self): + src1_data = (1, 2, 3, 4, 5) + expected_result = (-1, -2, -3, -4, -5) + op = gr.sub_ii() + self.help_ii((src1_data,), + expected_result, op) + + def test_sub_ii_2(self): + src1_data = (1, 2, 3, 4, 5) + src2_data = (8, -3, 4, 8, 2) + expected_result = (-7, 5, -1, -4, 3) + op = gr.sub_ii() + self.help_ii((src1_data, src2_data), + expected_result, op) + + def test_div_ff_1(self): + src1_data = (1, 2, 4, -8) + expected_result = (1, 0.5, 0.25, -.125) + op = gr.divide_ff() + self.help_ff((src1_data,), + expected_result, op) + + def test_div_ff_2(self): + src1_data = ( 5, 9, -15, 1024) + src2_data = (10, 3, -5, 64) + expected_result = (0.5, 3, 3, 16) + op = gr.divide_ff() + self.help_ff((src1_data, src2_data), + expected_result, op) + """ + +if __name__ == '__main__': + gr_unittest.run(test_add_and_friends, "test_add_and_friends.xml") |