diff options
38 files changed, 2394 insertions, 96 deletions
diff --git a/include/gnuradio/block.hpp b/include/gnuradio/block.hpp index 418657f..42f5f8d 100644 --- a/include/gnuradio/block.hpp +++ b/include/gnuradio/block.hpp @@ -75,18 +75,6 @@ struct GR_RUNTIME_API Block : Element * Basic routines from basic block ******************************************************************/ - long unique_id(void) const; - - std::string name(void) const; - - size_t input_size(const size_t which_input) const; - - size_t output_size(const size_t which_output) const; - - void set_input_size(const size_t size, const size_t which_input); - - void set_output_size(const size_t size, const size_t which_output); - size_t history(const size_t which_input = 0) const; void set_history(const size_t history, const size_t which_input = 0); diff --git a/include/gnuradio/element.hpp b/include/gnuradio/element.hpp index dc153fe..849323a 100644 --- a/include/gnuradio/element.hpp +++ b/include/gnuradio/element.hpp @@ -19,6 +19,7 @@ #include <gnuradio/runtime_api.h> #include <gruel/pmt.h> +#include <gr_io_signature.h> namespace gnuradio { @@ -29,6 +30,8 @@ struct GR_RUNTIME_API Element : boost::shared_ptr<ElementImpl> //! Create an empty element Element(void); + Element(const std::string &name); + /*! * Create an element from a shared pointer to an element. * Good for that factory function/shared ptr paradigm. @@ -38,6 +41,18 @@ struct GR_RUNTIME_API Element : boost::shared_ptr<ElementImpl> boost::shared_ptr<ElementImpl>(*reinterpret_cast<const Element*>(elem.get())) { } + long unique_id(void) const; + + std::string name(void) const; + + void set_output_signature(gr_io_signature_sptr); + + void set_input_signature(gr_io_signature_sptr); + + gr_io_signature_sptr input_signature(void) const; + + gr_io_signature_sptr output_signature(void) const; + }; } //namespace gnuradio diff --git a/include/gnuradio/gr_block.h b/include/gnuradio/gr_block.h index 7418e3d..92f613a 100644 --- a/include/gnuradio/gr_block.h +++ b/include/gnuradio/gr_block.h @@ -19,7 +19,6 @@ #include <gnuradio/runtime_api.h> #include <gnuradio/block.hpp> -#include <gr_io_signature.h> #include <gr_sptr_magic.h> #include <gr_types.h> #include <gr_tags.h> @@ -38,14 +37,6 @@ struct GR_RUNTIME_API gr_block : gnuradio::Block template <typename T> void set_msg_handler(T msg_handler){/*LOL*/} - void set_output_signature(gr_io_signature_sptr); - - void set_input_signature(gr_io_signature_sptr); - - gr_io_signature_sptr input_signature(void) const; - - gr_io_signature_sptr output_signature(void) const; - //! implements work -> calls general work int work( const InputItems &input_items, @@ -74,4 +65,6 @@ struct GR_RUNTIME_API gr_block : gnuradio::Block ) = 0; }; +typedef boost::shared_ptr<gr_block> gr_block_sptr; + #endif /*INCLUDED_GNURADIO_GR_BLOCK_H*/ diff --git a/include/gnuradio/gr_hier_block2.h b/include/gnuradio/gr_hier_block2.h index dd8fdae..7bf1ae9 100644 --- a/include/gnuradio/gr_hier_block2.h +++ b/include/gnuradio/gr_hier_block2.h @@ -39,4 +39,12 @@ struct GR_RUNTIME_API gr_hier_block2 : gnuradio::HierBlock }; +typedef boost::shared_ptr<gr_hier_block2> gr_hier_block2_sptr; + +GR_RUNTIME_API gr_hier_block2_sptr gr_make_hier_block2( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature +); + #endif /*INCLUDED_GNURADIO_GR_HIER_BLOCK2_H*/ diff --git a/include/gnuradio/gr_top_block.h b/include/gnuradio/gr_top_block.h index 199d7b5..8630606 100644 --- a/include/gnuradio/gr_top_block.h +++ b/include/gnuradio/gr_top_block.h @@ -18,15 +18,30 @@ #define INCLUDED_GNURADIO_GR_TOP_BLOCK_H #include <gnuradio/runtime_api.h> +#include <gnuradio/top_block.hpp> #include <gr_hier_block2.h> -struct GR_RUNTIME_API gr_top_block : gr_hier_block2 +struct GR_RUNTIME_API gr_top_block : gnuradio::TopBlock { gr_top_block(void); gr_top_block(const std::string &name); + void lock(void) + { + //NOP + } + + void unlock(void) + { + this->update(); + } + }; +typedef boost::shared_ptr<gr_top_block> gr_top_block_sptr; + +GR_RUNTIME_API gr_top_block_sptr gr_make_top_block(const std::string &name); + #endif /*INCLUDED_GNURADIO_GR_TOP_BLOCK_H*/ diff --git a/include/gnuradio/gr_unittests.h b/include/gnuradio/gr_unittests.h new file mode 100644 index 0000000..9fbf228 --- /dev/null +++ b/include/gnuradio/gr_unittests.h @@ -0,0 +1,43 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010,2011 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_core_api.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <string> + +#include <boost/filesystem/operations.hpp> +#include <boost/filesystem/path.hpp> + +static std::string get_unittest_path(const std::string &filename){ + boost::filesystem::path path = boost::filesystem::current_path() / ".unittests"; + if (!boost::filesystem::is_directory(path)) boost::filesystem::create_directory(path); + return (path / filename).string(); +} diff --git a/include/gnuradio/hier_block.hpp b/include/gnuradio/hier_block.hpp index 1518af5..55f996e 100644 --- a/include/gnuradio/hier_block.hpp +++ b/include/gnuradio/hier_block.hpp @@ -19,7 +19,6 @@ #include <gnuradio/runtime_api.h> #include <gnuradio/element.hpp> -#include <gruel/pmt.h> namespace gnuradio { diff --git a/include/gnuradio/top_block.hpp b/include/gnuradio/top_block.hpp index c131c7d..eb5f6b5 100644 --- a/include/gnuradio/top_block.hpp +++ b/include/gnuradio/top_block.hpp @@ -19,7 +19,6 @@ #include <gnuradio/runtime_api.h> #include <gnuradio/hier_block.hpp> -#include <gruel/pmt.h> namespace gnuradio { @@ -27,6 +26,21 @@ namespace gnuradio struct GR_RUNTIME_API TopBlock : HierBlock { TopBlock(void); + + TopBlock(const std::string &name); + + void update(void); + + void run(void) + { + this->start(); + this->stop(); + this->wait(); + } + + void start(void); + void stop(void); + void wait(void); }; } //namespace gnuradio diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 115b01d..3b0dc4a 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -3,6 +3,7 @@ ######################################################################## include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../tests) ######################################################################## # Append gnuradio-core library sources @@ -16,9 +17,28 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/block.cpp ${CMAKE_CURRENT_SOURCE_DIR}/block_handlers.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hier_block.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/top_block.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gr_block.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_block.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block.cpp +) + +######################################################################## +# Append gnuradio-core test sources +######################################################################## +list(APPEND test_gnuradio_core_sources + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/qa_gr_block.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/qa_gr_hier_block2.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/qa_gr_hier_block2_derived.cc + #${CMAKE_CURRENT_SOURCE_DIR}/../tests/qa_gr_buffer.cc + #${CMAKE_CURRENT_SOURCE_DIR}/../tests/qa_gr_flowgraph.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/qa_gr_top_block.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/qa_gr_io_signature.cc + #${CMAKE_CURRENT_SOURCE_DIR}/../tests/qa_gr_vmcircbuf.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/qa_block_tags.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/qa_runtime.cc + #${CMAKE_CURRENT_SOURCE_DIR}/../tests/qa_set_msg_handler.cc ) ######################################################################## diff --git a/lib/block.cpp b/lib/block.cpp index 2d5b4af..1bd1217 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -16,23 +16,18 @@ #include "element_impl.hpp" #include <gnuradio/block.hpp> -#include <boost/detail/atomic_count.hpp> #include <boost/bind.hpp> using namespace gnuradio; -static boost::detail::atomic_count unique_id_pool(0); - Block::Block(void) { //NOP } -Block::Block(const std::string &name) +Block::Block(const std::string &name): + Element(name) { - this->reset(new ElementImpl()); - (*this)->name = name; - (*this)->unique_id = ++unique_id_pool; this->set_history(0); this->set_output_multiple(1); this->set_fixed_rate(true); @@ -47,17 +42,6 @@ Block::Block(const std::string &name) } - -long Block::unique_id(void) const -{ - return (*this)->unique_id; -} - -std::string Block::name(void) const -{ - return (*this)->name; -} - template <typename V, typename T> void vector_set(V &v, const T &t, const size_t index) { @@ -78,28 +62,6 @@ typename V::value_type vector_get(const V &v, const size_t index) return v[index]; } -size_t Block::input_size(const size_t which_input) const -{ - return vector_get((*this)->input_items_sizes, which_input); -} - -size_t Block::output_size(const size_t which_output) const -{ - return vector_get((*this)->output_items_sizes, which_output); -} - -void Block::set_input_size(const size_t size, const size_t which_input) -{ - vector_set((*this)->input_items_sizes, size, which_input); - (*this)->input_signature = gr_make_io_signaturev(-1, -1, (*this)->input_items_sizes); -} - -void Block::set_output_size(const size_t size, const size_t which_output) -{ - vector_set((*this)->output_items_sizes, size, which_output); - (*this)->output_signature = gr_make_io_signaturev(-1, -1, (*this)->output_items_sizes); -} - size_t Block::history(const size_t which_input) const { return vector_get((*this)->input_history_items, which_input); diff --git a/lib/element.cpp b/lib/element.cpp index 3c97675..d73d68b 100644 --- a/lib/element.cpp +++ b/lib/element.cpp @@ -14,7 +14,11 @@ // You should have received a copy of the GNU Lesser General Public License // along with io_sig program. If not, see <http://www.gnu.org/licenses/>. +#include "element_impl.hpp" #include <gnuradio/element.hpp> +#include <boost/detail/atomic_count.hpp> + +static boost::detail::atomic_count unique_id_pool(0); using namespace gnuradio; @@ -22,3 +26,41 @@ Element::Element(void) { //NOP } + +Element::Element(const std::string &name) +{ + this->reset(new ElementImpl()); + (*this)->name = name; + (*this)->unique_id = ++unique_id_pool; +} + +long Element::unique_id(void) const +{ + return (*this)->unique_id; +} + +std::string Element::name(void) const +{ + return (*this)->name; +} + + +void Element::set_output_signature(gr_io_signature_sptr sig) +{ + (*this)->output_signature= sig; +} + +void Element::set_input_signature(gr_io_signature_sptr sig) +{ + (*this)->input_signature = sig; +} + +gr_io_signature_sptr Element::input_signature(void) const +{ + return (*this)->input_signature; +} + +gr_io_signature_sptr Element::output_signature(void) const +{ + return (*this)->output_signature; +} diff --git a/lib/gr_block.cpp b/lib/gr_block.cpp index b5e00a0..2c51f75 100644 --- a/lib/gr_block.cpp +++ b/lib/gr_block.cpp @@ -34,32 +34,6 @@ gr_block::gr_block( this->set_output_signature(output_signature); } -void gr_block::set_output_signature(gr_io_signature_sptr sig) -{ - for (size_t i = 0; i < sig->sizeof_stream_items().size(); i++) - { - this->set_output_size(sig->sizeof_stream_items()[i], i); - } -} - -void gr_block::set_input_signature(gr_io_signature_sptr sig) -{ - for (size_t i = 0; i < sig->sizeof_stream_items().size(); i++) - { - this->set_input_size(sig->sizeof_stream_items()[i], i); - } -} - -gr_io_signature_sptr gr_block::input_signature(void) const -{ - return (*this)->input_signature; -} - -gr_io_signature_sptr gr_block::output_signature(void) const -{ - return (*this)->output_signature; -} - int gr_block::work( const InputItems &input_items, const OutputItems &output_items diff --git a/lib/gr_hier_block2.cpp b/lib/gr_hier_block2.cpp index 3756b9f..7b61d0f 100644 --- a/lib/gr_hier_block2.cpp +++ b/lib/gr_hier_block2.cpp @@ -23,10 +23,19 @@ gr_hier_block2::gr_hier_block2(void) gr_hier_block2::gr_hier_block2( const std::string &name, - gr_io_signature_sptr, - gr_io_signature_sptr + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature ): gnuradio::HierBlock(name) { - //NOP + this->set_input_signature(input_signature); + this->set_output_signature(output_signature); +} + +gr_hier_block2_sptr gr_make_hier_block2( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature +){ + return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, output_signature)); } diff --git a/lib/gr_top_block.cpp b/lib/gr_top_block.cpp new file mode 100644 index 0000000..238a643 --- /dev/null +++ b/lib/gr_top_block.cpp @@ -0,0 +1,34 @@ +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with io_sig program. If not, see <http://www.gnu.org/licenses/>. + +#include <gr_top_block.h> + +gr_top_block::gr_top_block(void): + gnuradio::TopBlock() +{ + //NOP +} + +gr_top_block::gr_top_block(const std::string &name): + gnuradio::TopBlock(name) +{ + //NOP +} + +gr_top_block_sptr gr_make_top_block(const std::string &name) +{ + return gr_top_block_sptr(new gr_top_block(name)); +} diff --git a/lib/hier_block.cpp b/lib/hier_block.cpp index e915a23..c067ab6 100644 --- a/lib/hier_block.cpp +++ b/lib/hier_block.cpp @@ -24,10 +24,9 @@ HierBlock::HierBlock(void) //NOP } -HierBlock::HierBlock(const std::string &name) +HierBlock::HierBlock(const std::string &name): + Element(name) { - this->reset(new ElementImpl()); - (*this)->name = name; tsbe::TopologyConfig config; (*this)->topology = tsbe::Topology(config); } diff --git a/lib/top_block.cpp b/lib/top_block.cpp new file mode 100644 index 0000000..268064e --- /dev/null +++ b/lib/top_block.cpp @@ -0,0 +1,50 @@ +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with io_sig program. If not, see <http://www.gnu.org/licenses/>. + +#include <gnuradio/top_block.hpp> + +using namespace gnuradio; + +TopBlock::TopBlock(void) +{ + //NOP +} + +TopBlock::TopBlock(const std::string &name): + HierBlock(name) +{ + //TODO +} + +void TopBlock::update(void) +{ + +} + +void TopBlock::start(void) +{ + +} + +void TopBlock::stop(void) +{ + +} + +void TopBlock::wait(void) +{ + +} diff --git a/tests/qa_block_tags.cc b/tests/qa_block_tags.cc new file mode 100644 index 0000000..4fa0a03 --- /dev/null +++ b/tests/qa_block_tags.cc @@ -0,0 +1,450 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <qa_block_tags.h> +#include <gr_block.h> +#include <gr_top_block.h> +#include <gr_null_source.h> +#include <gr_null_sink.h> +#include <gr_head.h> +#include <gr_annotator_alltoall.h> +#include <gr_annotator_1to1.h> +#include <gr_keep_one_in_n.h> +#include <gr_firdes.h> +#include <gruel/pmt.h> + + +// ---------------------------------------------------------------- + +using namespace pmt; + +// set to 1 to turn on debug output +// The debug output fully checks that the tags seen are what are expected. While +// this behavior currently works with our implementation, there is no guarentee +// that the tags will be coming in this specific order, so it's dangerous to +// rely on this as a test of the tag system working. We would really want to +// tags we know we should see and then test that they all occur once, but in no +// particular order. +#define QA_TAGS_DEBUG 0 + +void +qa_block_tags::t0 () +{ + unsigned int N = 1000; + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(int))); + gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_block_sptr snk (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, snk, 0); + + //CPPUNIT_ASSERT_THROW(src->nitems_read(0), std::runtime_error); + //CPPUNIT_ASSERT_THROW(src->nitems_written(0), std::runtime_error); + CPPUNIT_ASSERT_EQUAL(src->nitems_read(0), (uint64_t)0); + CPPUNIT_ASSERT_EQUAL(src->nitems_written(0), (uint64_t)0); + + tb->run(); + + CPPUNIT_ASSERT_THROW(src->nitems_read(0), std::invalid_argument); + CPPUNIT_ASSERT(src->nitems_written(0) >= N); + CPPUNIT_ASSERT_EQUAL(snk->nitems_read(0), (uint64_t)1000); + CPPUNIT_ASSERT_THROW(snk->nitems_written(0), std::invalid_argument); +} + + +void +qa_block_tags::t1 () +{ + int N = 40000; + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(int))); + gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann2, 0); + tb->connect(ann1, 0, ann3, 0); + tb->connect(ann2, 0, ann4, 0); + + tb->connect(ann3, 0, snk0, 0); + tb->connect(ann4, 0, snk1, 0); + + tb->run(); + + std::vector<gr_tag_t> tags0 = ann0->data(); + std::vector<gr_tag_t> tags3 = ann3->data(); + std::vector<gr_tag_t> tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); + +#if QA_TAGS_DEBUG + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1, str2; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + str2 << ann2->name() << ann2->unique_id(); + + pmt_t expected_tags3[8]; + expected_tags3[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags3[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags3[2] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags3[3] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags3[4] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags3[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags3[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags3[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); + + pmt_t expected_tags4[8]; + expected_tags4[0] = mp(pmt_from_uint64(0), mp(str2.str()), mp("seq"), mp(0)); + expected_tags4[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[2] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[4] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); + + std::cout << std::endl << "qa_block_tags::t1" << std::endl; + + // For annotator 3, we know it gets tags from ann0 and ann1, test this + for(size_t i = 0; i < tags3.size(); i++) { + std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); + } + + // For annotator 4, we know it gets tags from ann0 and ann2, test this + std::cout << std::endl; + for(size_t i = 0; i < tags4.size(); i++) { + std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); + } +#endif +} + +void +qa_block_tags::t2 () +{ + int N = 40000; + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(int))); + gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk2 (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann1, 1); + tb->connect(ann1, 0, ann2, 0); + tb->connect(ann1, 1, ann3, 0); + tb->connect(ann1, 2, ann4, 0); + + tb->connect(ann2, 0, snk0, 0); + tb->connect(ann3, 0, snk1, 0); + tb->connect(ann4, 0, snk2, 0); + + tb->run(); + + std::vector<gr_tag_t> tags0 = ann0->data(); + std::vector<gr_tag_t> tags1 = ann1->data(); + std::vector<gr_tag_t> tags2 = ann2->data(); + std::vector<gr_tag_t> tags3 = ann4->data(); + std::vector<gr_tag_t> tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)8); + + // Make sure the rest all have 12 tags + CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)12); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)12); + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)12); + + +#if QA_TAGS_DEBUG + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + + pmt_t expected_tags2[12]; + expected_tags2[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags2[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags2[2] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(1)); + expected_tags2[3] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags2[4] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags2[5] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags2[6] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(6)); + expected_tags2[7] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags2[8] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags2[9] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(9)); + expected_tags2[10] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags2[11] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); + + pmt_t expected_tags4[12]; + expected_tags4[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(2)); + expected_tags4[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags4[2] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(5)); + expected_tags4[4] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[6] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(8)); + expected_tags4[7] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags4[8] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[9] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(11)); + expected_tags4[10] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags4[11] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); + + std::cout << std::endl << "qa_block_tags::t2" << std::endl; + + // For annotator[2-4], we know it gets tags from ann0 and ann1 + // but the tags from the different outputs of ann1 are different for each. + // Just testing ann2 and ann4; if they are correct it would be + // inconceivable for ann3 to have it wrong. + for(size_t i = 0; i < tags2.size(); i++) { + std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); + } + + std::cout << std::endl; + for(size_t i = 0; i < tags4.size(); i++) { + std::cout << "tags2[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); + } +#endif +} + + +void +qa_block_tags::t3 () +{ + int N = 40000; + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(int))); + gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_1to1_sptr ann3 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_annotator_1to1_sptr ann4 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + tb->connect(head, 0, ann0, 1); + + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann2, 0); + tb->connect(ann1, 0, ann3, 0); + tb->connect(ann2, 0, ann4, 0); + + tb->connect(ann3, 0, snk0, 0); + tb->connect(ann4, 0, snk1, 0); + + tb->run(); + + + std::vector<gr_tag_t> tags0 = ann0->data(); + std::vector<gr_tag_t> tags3 = ann3->data(); + std::vector<gr_tag_t> tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); + +#if QA_TAGS_DEBUG + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1, str2; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + str2 << ann2->name() << ann2->unique_id(); + + pmt_t expected_tags3[8]; + expected_tags3[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags3[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags3[2] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags3[3] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags3[4] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags3[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags3[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags3[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); + + pmt_t expected_tags4[8]; + expected_tags4[0] = mp(pmt_from_uint64(0), mp(str2.str()), mp("seq"), mp(0)); + expected_tags4[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[2] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[4] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); + + std::cout << std::endl << "qa_block_tags::t3" << std::endl; + + // For annotator 3, we know it gets tags from ann0 and ann1, test this + for(size_t i = 0; i < tags3.size(); i++) { + std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); + } + + // For annotator 4, we know it gets tags from ann0 and ann2, test this + std::cout << std::endl; + for(size_t i = 0; i < tags4.size(); i++) { + std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); + } +#endif +} + + +void +qa_block_tags::t4 () +{ + int N = 40000; + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(int))); + gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_annotator_1to1_sptr ann1 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_annotator_1to1_sptr ann2 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); + + // using 1-to-1 tag propagation without having equal number of + // ins and outs. Make sure this works; will just exit run early. + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann2, 0); + tb->connect(ann1, 0, snk0, 0); + tb->connect(ann2, 0, snk1, 0); + + std::cerr << std::endl + << "NOTE: This is supposed to produce an error from gr_block_executor" + << std::endl; + tb->run(); +} + + +void +qa_block_tags::t5 () +{ + int N = 40000; + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(float))); + gr_block_sptr head (gr_make_head(sizeof(float), N)); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(float))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(float))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(1000, sizeof(float))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(float))); + + // Rate change blocks + gr_keep_one_in_n_sptr dec10 (gr_make_keep_one_in_n(sizeof(float), 10)); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann1, 0, dec10, 0); + tb->connect(dec10, 0, ann2, 0); + tb->connect(ann2, 0, snk0, 0); + + tb->run(); + + std::vector<gr_tag_t> tags0 = ann0->data(); + std::vector<gr_tag_t> tags1 = ann1->data(); + std::vector<gr_tag_t> tags2 = ann2->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)4); + CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); + + +#if QA_TAGS_DEBUG + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1, str2; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + str2 << ann2->name() << ann2->unique_id(); + + pmt_t expected_tags1[5]; + expected_tags1[0] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags1[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags1[2] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags1[3] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(3)); + + pmt_t expected_tags2[10]; + expected_tags2[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags2[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags2[2] = mp(pmt_from_uint64(1000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags2[3] = mp(pmt_from_uint64(1000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags2[4] = mp(pmt_from_uint64(2000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags2[5] = mp(pmt_from_uint64(2000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags2[6] = mp(pmt_from_uint64(3000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags2[7] = mp(pmt_from_uint64(3000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags2[8] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(4)); + expected_tags2[9] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(4)); + + std::cout << std::endl << "qa_block_tags::t5" << std::endl; + + // annotator 1 gets tags from annotator 0 + std::cout << "tags1.size(): " << tags1.size() << std::endl; + for(size_t i = 0; i < tags1.size(); i++) { + std::cout << "tags1[" << i << "] = " << tags1[i] << "\t\t" << expected_tags1[i] << std::endl; + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags1[i]), pmt_write_string(expected_tags1[i])); + } + + // annotator 2 gets tags from annotators 0 and 1 + std::cout << std::endl; + std::cout << "tags2.size(): " << tags2.size() << std::endl; + for(size_t i = 0; i < tags2.size(); i++) { + std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); + } +#endif +} + diff --git a/tests/qa_block_tags.h b/tests/qa_block_tags.h new file mode 100644 index 0000000..6b7e597 --- /dev/null +++ b/tests/qa_block_tags.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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. + */ + +#ifndef INCLUDED_QA_BLOCK_TAGS_H +#define INCLUDED_QA_BLOCK_TAGS_H + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> +#include <stdexcept> + +class qa_block_tags : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE (qa_block_tags); + CPPUNIT_TEST (t0); + CPPUNIT_TEST (t1); + CPPUNIT_TEST (t2); + CPPUNIT_TEST (t3); + CPPUNIT_TEST (t4); + CPPUNIT_TEST (t5); + CPPUNIT_TEST_SUITE_END (); + + private: + void t0 (); + void t1 (); + void t2 (); + void t3 (); + void t4 (); + void t5 (); + +}; + + +#endif /* INCLUDED_QA_BLOCK_TAGS_H */ diff --git a/tests/qa_gr_block.cc b/tests/qa_gr_block.cc new file mode 100644 index 0000000..aeab5b7 --- /dev/null +++ b/tests/qa_gr_block.cc @@ -0,0 +1,88 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <qa_gr_block.h> +#include <gr_block.h> +#include <gr_io_signature.h> +#include <gr_null_sink.h> +#include <gr_null_source.h> + + +// ---------------------------------------------------------------- + + +void +qa_gr_block::t0 () +{ + // test creation of sources + gr_block_sptr src1 (gr_make_null_source (sizeof (int))); + CPPUNIT_ASSERT_EQUAL (std::string ("null_source"), src1->name ()); + CPPUNIT_ASSERT_EQUAL (0, src1->input_signature()->max_streams ()); + CPPUNIT_ASSERT_EQUAL (1, src1->output_signature()->min_streams ()); + CPPUNIT_ASSERT_EQUAL (1, src1->output_signature()->max_streams ()); + CPPUNIT_ASSERT_EQUAL ((int) sizeof(int), + src1->output_signature()->sizeof_stream_item (0)); + + gr_block_sptr src2 (gr_make_null_source (sizeof (short))); + CPPUNIT_ASSERT_EQUAL (std::string ("null_source"), src2->name ()); + CPPUNIT_ASSERT_EQUAL (0, src2->input_signature()->max_streams ()); + CPPUNIT_ASSERT_EQUAL (1, src2->output_signature()->min_streams ()); + CPPUNIT_ASSERT_EQUAL (1, src2->output_signature()->max_streams ()); + CPPUNIT_ASSERT_EQUAL ((int) sizeof (short), + src2->output_signature()->sizeof_stream_item (0)); +} + + +void +qa_gr_block::t1 () +{ + // test creation of sinks + gr_block_sptr dst1 (gr_make_null_sink (sizeof (int))); + CPPUNIT_ASSERT_EQUAL (std::string ("null_sink"), dst1->name ()); + CPPUNIT_ASSERT_EQUAL (1, dst1->input_signature()->min_streams ()); + CPPUNIT_ASSERT_EQUAL (1, dst1->input_signature()->max_streams ()); + CPPUNIT_ASSERT_EQUAL ((int) sizeof (int), + dst1->input_signature()->sizeof_stream_item (0)); + + CPPUNIT_ASSERT_EQUAL (0, dst1->output_signature()->max_streams ()); + + gr_block_sptr dst2 (gr_make_null_sink (sizeof (short))); + CPPUNIT_ASSERT_EQUAL (std::string ("null_sink"), dst2->name ()); + CPPUNIT_ASSERT_EQUAL (1, dst2->input_signature()->min_streams ()); + CPPUNIT_ASSERT_EQUAL (1, dst2->input_signature()->max_streams ()); + CPPUNIT_ASSERT_EQUAL ((int) sizeof (short), + dst2->input_signature()->sizeof_stream_item (0)); + CPPUNIT_ASSERT_EQUAL (0, dst2->output_signature()->max_streams ()); +} + +void +qa_gr_block::t2 () +{ +} + +void +qa_gr_block::t3 () +{ +} diff --git a/tests/qa_gr_block.h b/tests/qa_gr_block.h new file mode 100644 index 0000000..14c7c40 --- /dev/null +++ b/tests/qa_gr_block.h @@ -0,0 +1,48 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifndef INCLUDED_QA_GR_BLOCK_H +#define INCLUDED_QA_GR_BLOCK_H + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> +#include <stdexcept> + +class qa_gr_block : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE (qa_gr_block); + CPPUNIT_TEST (t0); + CPPUNIT_TEST (t1); + CPPUNIT_TEST (t2); + CPPUNIT_TEST (t3); + CPPUNIT_TEST_SUITE_END (); + + private: + void t0 (); + void t1 (); + void t2 (); + void t3 (); + +}; + + +#endif /* INCLUDED_QA_GR_BLOCK_H */ diff --git a/tests/qa_gr_buffer.cc b/tests/qa_gr_buffer.cc new file mode 100644 index 0000000..c74baf3 --- /dev/null +++ b/tests/qa_gr_buffer.cc @@ -0,0 +1,307 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <qa_gr_buffer.h> +#include <gr_buffer.h> +#include <cppunit/TestAssert.h> +#include <stdlib.h> +#include <gr_random.h> + +static void +leak_check (void f ()) +{ + long buffer_count = gr_buffer_ncurrently_allocated (); + long buffer_reader_count = gr_buffer_reader_ncurrently_allocated (); + + f (); + + CPPUNIT_ASSERT_EQUAL (buffer_reader_count, gr_buffer_reader_ncurrently_allocated ()); + CPPUNIT_ASSERT_EQUAL (buffer_count, gr_buffer_ncurrently_allocated ()); +} + + +// ---------------------------------------------------------------------------- +// test single writer, no readers... +// + +static void +t0_body () +{ + int nitems = 4000 / sizeof (int); + int counter = 0; + + gr_buffer_sptr buf(gr_make_buffer(nitems, sizeof (int), gr_block_sptr())); + + int last_sa; + int sa; + + sa = buf->space_available (); + CPPUNIT_ASSERT (sa > 0); + last_sa = sa; + + for (int i = 0; i < 5; i++){ + sa = buf->space_available (); + CPPUNIT_ASSERT_EQUAL (last_sa, sa); + last_sa = sa; + + int *p = (int *) buf->write_pointer (); + CPPUNIT_ASSERT (p != 0); + + for (int j = 0; j < sa; j++) + *p++ = counter++; + + buf->update_write_pointer (sa); + } +} + +// ---------------------------------------------------------------------------- +// test single writer, single reader +// + +static void +t1_body () + { + int nitems = 4000 / sizeof (int); + int write_counter = 0; + int read_counter = 0; + + gr_buffer_sptr buf(gr_make_buffer(nitems, sizeof (int), gr_block_sptr())); + gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 0, gr_block_sptr())); + + + int sa; + + // write 1/3 of buffer + + sa = buf->space_available (); + CPPUNIT_ASSERT (sa > 0); + + int *p = (int *) buf->write_pointer (); + CPPUNIT_ASSERT (p != 0); + + for (int j = 0; j < sa/3; j++){ + *p++ = write_counter++; + } + buf->update_write_pointer (sa/3); + + + // write the next 1/3 (1/2 of what's left) + + sa = buf->space_available (); + CPPUNIT_ASSERT (sa > 0); + + p = (int *) buf->write_pointer (); + CPPUNIT_ASSERT (p != 0); + + for (int j = 0; j < sa/2; j++){ + *p++ = write_counter++; + } + buf->update_write_pointer (sa/2); + + + // check that we can read it OK + + int ia = r1->items_available (); + CPPUNIT_ASSERT_EQUAL (write_counter, ia); + + int *rp = (int *) r1->read_pointer (); + CPPUNIT_ASSERT (rp != 0); + + for (int i = 0; i < ia/2; i++){ + CPPUNIT_ASSERT_EQUAL (read_counter, *rp); + read_counter++; + rp++; + } + r1->update_read_pointer (ia/2); + + // read the rest + + ia = r1->items_available (); + rp = (int *) r1->read_pointer (); + CPPUNIT_ASSERT (rp != 0); + + for (int i = 0; i < ia; i++){ + CPPUNIT_ASSERT_EQUAL (read_counter, *rp); + read_counter++; + rp++; + } + r1->update_read_pointer (ia); +} + +// ---------------------------------------------------------------------------- +// single writer, single reader: check wrap-around +// + +static void +t2_body () +{ + // 64K is the largest granularity we've seen so far (MS windows file mapping). + // This allows a bit of "white box testing" + + int nitems = (64 * (1L << 10)) / sizeof (int); // 64K worth of ints + + gr_buffer_sptr buf(gr_make_buffer (nitems, sizeof (int), gr_block_sptr())); + gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 0, gr_block_sptr())); + + int read_counter = 0; + int write_counter = 0; + int n; + int *wp = 0; + int *rp = 0; + + // Write 3/4 of buffer + + n = (int) (buf->space_available () * 0.75); + wp = (int *) buf->write_pointer (); + + for (int i = 0; i < n; i++) + *wp++ = write_counter++; + buf->update_write_pointer (n); + + // Now read it all + + int m = r1->items_available (); + CPPUNIT_ASSERT_EQUAL (n, m); + rp = (int *) r1->read_pointer (); + + for (int i = 0; i < m; i++){ + CPPUNIT_ASSERT_EQUAL (read_counter, *rp); + read_counter++; + rp++; + } + r1->update_read_pointer (m); + + // Now write as much as we can. + // This will wrap around the buffer + + n = buf->space_available (); + CPPUNIT_ASSERT_EQUAL (nitems - 1, n); // white box test + wp = (int *) buf->write_pointer (); + + for (int i = 0; i < n; i++) + *wp++ = write_counter++; + buf->update_write_pointer (n); + + // now read it all + + m = r1->items_available (); + CPPUNIT_ASSERT_EQUAL (n, m); + rp = (int *) r1->read_pointer (); + + for (int i = 0; i < m; i++){ + CPPUNIT_ASSERT_EQUAL (read_counter, *rp); + read_counter++; + rp++; + } + r1->update_read_pointer (m); + +} + +// ---------------------------------------------------------------------------- +// single writer, N readers, randomized order and lengths +// ---------------------------------------------------------------------------- + +static void +t3_body () +{ + int nitems = (64 * (1L << 10)) / sizeof (int); + + static const int N = 5; + gr_buffer_sptr buf(gr_make_buffer(nitems, sizeof (int), gr_block_sptr())); + gr_buffer_reader_sptr reader[N]; + int read_counter[N]; + int write_counter = 0; + gr_random random; + + for (int i = 0; i < N; i++){ + read_counter[i] = 0; + reader[i] = gr_buffer_add_reader (buf, 0, gr_block_sptr()); + } + + for (int lc = 0; lc < 1000; lc++){ + + // write some + + int n = (int) (buf->space_available () * random.ran1 ()); + int *wp = (int *) buf->write_pointer (); + + for (int i = 0; i < n; i++) + *wp++ = write_counter++; + + buf->update_write_pointer (n); + + // pick a random reader and read some + + int r = (int) (N * random.ran1 ()); + CPPUNIT_ASSERT (0 <= r && r < N); + + int m = reader[r]->items_available (); + int *rp = (int *) reader[r]->read_pointer (); + + for (int i = 0; i < m; i++){ + CPPUNIT_ASSERT_EQUAL (read_counter[r], *rp); + read_counter[r]++; + rp++; + } + reader[r]->update_read_pointer (m); + } +} + + +// ---------------------------------------------------------------------------- + +void +qa_gr_buffer::t0 () +{ + leak_check (t0_body); +} + +void +qa_gr_buffer::t1 () +{ + leak_check (t1_body); +} + +void +qa_gr_buffer::t2 () +{ + leak_check (t2_body); +} + +void +qa_gr_buffer::t3 () +{ + leak_check (t3_body); +} + +void +qa_gr_buffer::t4 () +{ +} + +void +qa_gr_buffer::t5 () +{ +} diff --git a/tests/qa_gr_buffer.h b/tests/qa_gr_buffer.h new file mode 100644 index 0000000..2937c24 --- /dev/null +++ b/tests/qa_gr_buffer.h @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifndef INCLUDED_QA_GR_BUFFER_H +#define INCLUDED_QA_GR_BUFFER_H + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> + +class qa_gr_buffer : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE (qa_gr_buffer); + CPPUNIT_TEST (t0); + CPPUNIT_TEST (t1); + CPPUNIT_TEST (t2); + CPPUNIT_TEST (t3); + CPPUNIT_TEST (t4); + CPPUNIT_TEST (t5); + CPPUNIT_TEST_SUITE_END (); + + + private: + + void t0 (); + void t1 (); + void t2 (); + void t3 (); + void t4 (); + void t5 (); +}; + + + +#endif /* INCLUDED_QA_GR_BUFFER_H */ diff --git a/tests/qa_gr_flowgraph.cc b/tests/qa_gr_flowgraph.cc new file mode 100644 index 0000000..cce83cb --- /dev/null +++ b/tests/qa_gr_flowgraph.cc @@ -0,0 +1,245 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qa_gr_flowgraph.h> +#include <gr_flowgraph.h> +#include <gr_nop.h> +#include <gr_null_source.h> +#include <gr_null_sink.h> + +void qa_gr_flowgraph::t0() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + CPPUNIT_ASSERT(fg); +} + +void qa_gr_flowgraph::t1_connect() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); +} + +void qa_gr_flowgraph::t2_connect_invalid_src_port_neg() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + CPPUNIT_ASSERT_THROW(fg->connect(nop1, -1, nop2, 0), std::invalid_argument); +} + +void qa_gr_flowgraph::t3_connect_src_port_exceeds() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + CPPUNIT_ASSERT_THROW(fg->connect(src, 1, dst, 0), std::invalid_argument); +} + +void qa_gr_flowgraph::t4_connect_invalid_dst_port_neg() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + CPPUNIT_ASSERT_THROW(fg->connect(nop1, 0, nop2, -1), std::invalid_argument); +} + +void qa_gr_flowgraph::t5_connect_dst_port_exceeds() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + CPPUNIT_ASSERT_THROW(fg->connect(src, 0, dst, 1), std::invalid_argument); +} + +void qa_gr_flowgraph::t6_connect_dst_in_use() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr src1 = gr_make_null_source(sizeof(int)); + gr_block_sptr src2 = gr_make_null_source(sizeof(int)); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + fg->connect(src1, 0, dst, 0); + CPPUNIT_ASSERT_THROW(fg->connect(src2, 0, dst, 0), std::invalid_argument); +} + +void qa_gr_flowgraph::t7_connect_one_src_two_dst() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr dst1 = gr_make_null_sink(sizeof(int)); + gr_block_sptr dst2 = gr_make_null_sink(sizeof(int)); + + fg->connect(src, 0, dst1, 0); + fg->connect(src, 0, dst2, 0); +} + +void qa_gr_flowgraph::t8_connect_type_mismatch() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(char)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + CPPUNIT_ASSERT_THROW(fg->connect(nop1, 0, nop2, 0), std::invalid_argument); +} + +void qa_gr_flowgraph::t9_disconnect() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + fg->disconnect(nop1, 0, nop2, 0); +} + +void qa_gr_flowgraph::t10_disconnect_unconnected_block() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + gr_block_sptr nop3 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + CPPUNIT_ASSERT_THROW(fg->disconnect(nop1, 0, nop3, 0), std::invalid_argument); +} + +void qa_gr_flowgraph::t11_disconnect_unconnected_port() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + CPPUNIT_ASSERT_THROW(fg->disconnect(nop1, 0, nop2, 1), std::invalid_argument); +} + +void qa_gr_flowgraph::t12_validate() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + fg->validate(); +} + +void qa_gr_flowgraph::t13_validate_missing_input_assignment() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + fg->connect(nop1, 0, nop2, 2); + CPPUNIT_ASSERT_THROW(fg->validate(), std::runtime_error); +} + +void qa_gr_flowgraph::t14_validate_missing_output_assignment() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + fg->connect(nop1, 2, nop2, 1); + CPPUNIT_ASSERT_THROW(fg->validate(), std::runtime_error); +} + +void qa_gr_flowgraph::t15_clear() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + + CPPUNIT_ASSERT(fg->edges().size() == 1); + CPPUNIT_ASSERT(fg->calc_used_blocks().size() == 2); + + fg->clear(); + + CPPUNIT_ASSERT(fg->edges().size() == 0); + CPPUNIT_ASSERT(fg->calc_used_blocks().size() == 0); +} + +void qa_gr_flowgraph::t16_partition() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop11 = gr_make_nop(sizeof(int)); + gr_block_sptr nop12 = gr_make_nop(sizeof(int)); + gr_block_sptr nop13 = gr_make_nop(sizeof(int)); + gr_block_sptr nop14 = gr_make_nop(sizeof(int)); + + gr_block_sptr nop21 = gr_make_nop(sizeof(int)); + gr_block_sptr nop22 = gr_make_nop(sizeof(int)); + gr_block_sptr nop23 = gr_make_nop(sizeof(int)); + + gr_block_sptr nop31 = gr_make_nop(sizeof(int)); + gr_block_sptr nop32 = gr_make_nop(sizeof(int)); + + // Build disjoint graph #1 + fg->connect(nop11, 0, nop12, 0); + fg->connect(nop12, 0, nop13, 0); + fg->connect(nop13, 0, nop14, 0); + + // Build disjoint graph #2 + fg->connect(nop21, 0, nop22, 0); + fg->connect(nop22, 0, nop23, 0); + + // Build disjoint graph #3 + fg->connect(nop31, 0, nop32, 0); + + std::vector<gr_basic_block_vector_t> graphs = fg->partition(); + + CPPUNIT_ASSERT(graphs.size() == 3); + CPPUNIT_ASSERT(graphs[0].size() == 4); + CPPUNIT_ASSERT(graphs[1].size() == 3); + CPPUNIT_ASSERT(graphs[2].size() == 2); +} diff --git a/tests/qa_gr_flowgraph.h b/tests/qa_gr_flowgraph.h new file mode 100644 index 0000000..2c2686f --- /dev/null +++ b/tests/qa_gr_flowgraph.h @@ -0,0 +1,75 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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. + */ + +#ifndef INCLUDED_QA_GR_FLOWGRAPH_H +#define INCLUDED_QA_GR_FLOWGRAPH_H + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> +#include <stdexcept> + +class qa_gr_flowgraph : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(qa_gr_flowgraph); + + CPPUNIT_TEST(t0); + CPPUNIT_TEST(t1_connect); + CPPUNIT_TEST(t2_connect_invalid_src_port_neg); + CPPUNIT_TEST(t3_connect_src_port_exceeds); + CPPUNIT_TEST(t4_connect_invalid_dst_port_neg); + CPPUNIT_TEST(t5_connect_dst_port_exceeds); + CPPUNIT_TEST(t6_connect_dst_in_use); + CPPUNIT_TEST(t7_connect_one_src_two_dst); + CPPUNIT_TEST(t8_connect_type_mismatch); + CPPUNIT_TEST(t9_disconnect); + CPPUNIT_TEST(t10_disconnect_unconnected_block); + CPPUNIT_TEST(t11_disconnect_unconnected_port); + CPPUNIT_TEST(t12_validate); + CPPUNIT_TEST(t13_validate_missing_input_assignment); + CPPUNIT_TEST(t14_validate_missing_output_assignment); + CPPUNIT_TEST(t15_clear); + CPPUNIT_TEST(t16_partition); + + CPPUNIT_TEST_SUITE_END(); + +private: + + void t0(); + void t1_connect(); + void t2_connect_invalid_src_port_neg(); + void t3_connect_src_port_exceeds(); + void t4_connect_invalid_dst_port_neg(); + void t5_connect_dst_port_exceeds(); + void t6_connect_dst_in_use(); + void t7_connect_one_src_two_dst(); + void t8_connect_type_mismatch(); + void t9_disconnect(); + void t10_disconnect_unconnected_block(); + void t11_disconnect_unconnected_port(); + void t12_validate(); + void t13_validate_missing_input_assignment(); + void t14_validate_missing_output_assignment(); + void t15_clear(); + void t16_partition(); +}; + +#endif /* INCLUDED_QA_GR_FLOWGRAPH_H */ diff --git a/tests/qa_gr_hier_block2.cc b/tests/qa_gr_hier_block2.cc new file mode 100644 index 0000000..9844d33 --- /dev/null +++ b/tests/qa_gr_hier_block2.cc @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2008,2009 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qa_gr_hier_block2.h> +#include <gr_hier_block2.h> +#include <gr_io_signature.h> +#include <gr_null_source.h> +#include <gr_null_sink.h> + +void qa_gr_hier_block2::test_make() +{ + gr_hier_block2_sptr src1(gr_make_hier_block2("test", + gr_make_io_signature(1, 1, 1 * sizeof(int)), + gr_make_io_signature(1, 1, 1 * sizeof(int)))); + + CPPUNIT_ASSERT(src1); + CPPUNIT_ASSERT_EQUAL(std::string("test"), src1->name()); + + CPPUNIT_ASSERT_EQUAL(1 * (int) sizeof(int), + src1->input_signature()->sizeof_stream_item(0)); + + CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->min_streams()); + CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->max_streams()); + + + CPPUNIT_ASSERT_EQUAL(1 * (int) sizeof(int), + src1->output_signature()->sizeof_stream_item(0)); + + CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->min_streams()); + CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->max_streams()); + +} + + diff --git a/tests/qa_gr_hier_block2.h b/tests/qa_gr_hier_block2.h new file mode 100644 index 0000000..653cd27 --- /dev/null +++ b/tests/qa_gr_hier_block2.h @@ -0,0 +1,42 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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. + */ + +#ifndef INCLUDED_QA_GR_HIER_BLOCK2_H +#define INCLUDED_QA_GR_HIER_BLOCK2_H + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> +#include <stdexcept> + +class qa_gr_hier_block2 : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(qa_gr_hier_block2); + + CPPUNIT_TEST(test_make); + + CPPUNIT_TEST_SUITE_END(); + +private: + void test_make(); +}; + +#endif /* INCLUDED_QA_GR_HIER_BLOCK2_H */ diff --git a/tests/qa_gr_hier_block2_derived.cc b/tests/qa_gr_hier_block2_derived.cc new file mode 100644 index 0000000..060c4e2 --- /dev/null +++ b/tests/qa_gr_hier_block2_derived.cc @@ -0,0 +1,87 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2008 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qa_gr_hier_block2_derived.h> +#include <gr_top_block.h> +#include <gr_io_signature.h> +#include <gr_null_source.h> +#include <gr_null_sink.h> +#include <gr_head.h> +#include <gr_kludge_copy.h> + +// Declare a test C++ hierarchical block + +class gr_derived_block; +typedef boost::shared_ptr<gr_derived_block> gr_derived_block_sptr; +gr_derived_block_sptr gr_make_derived_block(); + +class gr_derived_block : public gr_hier_block2 +{ +private: + friend gr_derived_block_sptr gr_make_derived_block(); + gr_derived_block(); + +public: + ~gr_derived_block(); +}; + + +gr_derived_block_sptr +gr_make_derived_block() +{ + return gnuradio::get_initial_sptr(new gr_derived_block()); +} + +gr_derived_block::gr_derived_block() + : gr_hier_block2("gr_derived_block", + gr_make_io_signature(1, 1, sizeof(int)), // Input signature + gr_make_io_signature(1, 1, sizeof(int))) // Output signature +{ + gr_block_sptr copy(gr_make_kludge_copy(sizeof(int))); + + connect(self(), 0, copy, 0); + connect(copy, 0, self(), 0); +} + +gr_derived_block::~gr_derived_block() +{ +} + +void qa_gr_hier_block2_derived::test_1() +{ + gr_top_block_sptr tb(gr_make_top_block("test")); + + gr_block_sptr src(gr_make_null_source(sizeof(int))); + gr_block_sptr head(gr_make_head(sizeof(int), 1000)); + gr_derived_block_sptr blk(gr_make_derived_block()); + gr_block_sptr dst(gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, blk, 0); + tb->connect(blk, 0, dst, 0); + + tb->run(); +} diff --git a/tests/qa_gr_hier_block2_derived.h b/tests/qa_gr_hier_block2_derived.h new file mode 100644 index 0000000..8e0a188 --- /dev/null +++ b/tests/qa_gr_hier_block2_derived.h @@ -0,0 +1,41 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2008 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. + */ + +#ifndef INCLUDED_QA_GR_HIER_BLOCK2_DERIVED_H +#define INCLUDED_QA_GR_HIER_BLOCK2_DERIVED_H + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> +#include <stdexcept> + +// Declare a QA test case +class qa_gr_hier_block2_derived : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(qa_gr_hier_block2_derived); + CPPUNIT_TEST(test_1); + CPPUNIT_TEST_SUITE_END(); + +private: + void test_1(); +}; + +#endif /* INCLUDED_QA_GR_HIER_BLOCK2_DERIVED_H */ diff --git a/tests/qa_gr_io_signature.cc b/tests/qa_gr_io_signature.cc new file mode 100644 index 0000000..c1737ff --- /dev/null +++ b/tests/qa_gr_io_signature.cc @@ -0,0 +1,64 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <qa_gr_io_signature.h> +#include <gr_io_signature.h> + +void +qa_gr_io_signature::t0 () +{ + gr_make_io_signature (1, 1, sizeof (int)); +} + +void +qa_gr_io_signature::t1 () +{ + gr_make_io_signature (3, 1, sizeof (int)); // throws std::invalid_argument +} + +void +qa_gr_io_signature::t2 () +{ + gr_io_signature_sptr p = + gr_make_io_signature (3, gr_io_signature::IO_INFINITE, sizeof (int)); + + CPPUNIT_ASSERT_EQUAL (p->min_streams (), 3); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item (0), (int) sizeof (int)); +} + +void +qa_gr_io_signature::t3 () +{ + gr_io_signature_sptr p = + gr_make_io_signature3 (0, 5, 1, 2, 3); + + CPPUNIT_ASSERT_EQUAL (p->min_streams (), 0); + CPPUNIT_ASSERT_EQUAL (p->max_streams (), 5); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(0), 1); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(1), 2); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(2), 3); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(3), 3); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(4), 3); +} diff --git a/tests/qa_gr_io_signature.h b/tests/qa_gr_io_signature.h new file mode 100644 index 0000000..9cd6bb5 --- /dev/null +++ b/tests/qa_gr_io_signature.h @@ -0,0 +1,46 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifndef INCLUDED_QA_GR_IO_SIGNATURE_H +#define INCLUDED_QA_GR_IO_SIGNATURE_H + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> +#include <stdexcept> + +class qa_gr_io_signature : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE (qa_gr_io_signature); + CPPUNIT_TEST (t0); + CPPUNIT_TEST_EXCEPTION (t1, std::invalid_argument); + CPPUNIT_TEST (t2); + CPPUNIT_TEST (t3); + CPPUNIT_TEST_SUITE_END (); + + private: + void t0 (); + void t1 (); + void t2 (); + void t3 (); +}; + +#endif /* INCLUDED_QA_GR_IO_SIGNATURE_H */ diff --git a/tests/qa_gr_top_block.cc b/tests/qa_gr_top_block.cc new file mode 100644 index 0000000..cc7b7c7 --- /dev/null +++ b/tests/qa_gr_top_block.cc @@ -0,0 +1,121 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qa_gr_top_block.h> +#include <gr_top_block.h> +#include <gr_head.h> +#include <gr_null_source.h> +#include <gr_null_sink.h> +#include <iostream> + +#define VERBOSE 0 + +void qa_gr_top_block::t0() +{ + if (VERBOSE) std::cout << "qa_gr_top_block::t0()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + CPPUNIT_ASSERT(tb); +} + +void qa_gr_top_block::t1_run() +{ + if (VERBOSE) std::cout << "qa_gr_top_block::t1()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 100000); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->run(); +} + +void qa_gr_top_block::t2_start_stop_wait() +{ + if (VERBOSE) std::cout << "qa_gr_top_block::t2()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 100000); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + + tb->start(); + tb->stop(); + tb->wait(); +} + +void qa_gr_top_block::t3_lock_unlock() +{ + if (VERBOSE) std::cout << "qa_gr_top_block::t3()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + tb->connect(src, 0, dst, 0); + + tb->start(); + + tb->lock(); + tb->unlock(); + + tb->stop(); + tb->wait(); +} + +void qa_gr_top_block::t4_reconfigure() +{ + if (VERBOSE) std::cout << "qa_gr_top_block::t4()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 100000); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + // Start infinite flowgraph + tb->connect(src, 0, dst, 0); + tb->start(); + + // Reconfigure with gr_head in the middle + tb->lock(); + tb->disconnect(src, 0, dst, 0); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->unlock(); + + // Wait for flowgraph to end on its own + tb->wait(); +} diff --git a/tests/qa_gr_top_block.h b/tests/qa_gr_top_block.h new file mode 100644 index 0000000..b223633 --- /dev/null +++ b/tests/qa_gr_top_block.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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. + */ + +#ifndef INCLUDED_QA_GR_TOP_BLOCK_H +#define INCLUDED_QA_GR_TOP_BLOCK_H + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> +#include <stdexcept> + +class qa_gr_top_block : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(qa_gr_top_block); + + CPPUNIT_TEST(t0); + CPPUNIT_TEST(t1_run); + CPPUNIT_TEST(t2_start_stop_wait); + CPPUNIT_TEST(t3_lock_unlock); + CPPUNIT_TEST(t4_reconfigure); // triggers 'join never returns' bug + + CPPUNIT_TEST_SUITE_END(); + +private: + + void t0(); + void t1_run(); + void t2_start_stop_wait(); + void t3_lock_unlock(); + void t4_reconfigure(); +}; + +#endif /* INCLUDED_QA_GR_TOP_BLOCK_H */ diff --git a/tests/qa_gr_vmcircbuf.cc b/tests/qa_gr_vmcircbuf.cc new file mode 100644 index 0000000..e3b36d8 --- /dev/null +++ b/tests/qa_gr_vmcircbuf.cc @@ -0,0 +1,40 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qa_gr_vmcircbuf.h> +#include <cppunit/TestAssert.h> +#include <gr_vmcircbuf.h> +#include <stdio.h> + +void +qa_gr_vmcircbuf::test_all () +{ + int verbose = 1; // summary + + bool ok = gr_vmcircbuf_sysconfig::test_all_factories (verbose); + + CPPUNIT_ASSERT_EQUAL (true, ok); +} diff --git a/tests/qa_gr_vmcircbuf.h b/tests/qa_gr_vmcircbuf.h new file mode 100644 index 0000000..3576660 --- /dev/null +++ b/tests/qa_gr_vmcircbuf.h @@ -0,0 +1,39 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ +#ifndef _QA_GR_VMCIRCBUF_H_ +#define _QA_GR_VMCIRCBUF_H_ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> + +class qa_gr_vmcircbuf : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE (qa_gr_vmcircbuf); + CPPUNIT_TEST (test_all); + CPPUNIT_TEST_SUITE_END (); + + private: + void test_all (); +}; + + +#endif /* _QA_GR_VMCIRCBUF_H_ */ diff --git a/tests/qa_runtime.cc b/tests/qa_runtime.cc new file mode 100644 index 0000000..a15d623 --- /dev/null +++ b/tests/qa_runtime.cc @@ -0,0 +1,61 @@ +/* + * Copyright 2002,2007,2011 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 class gathers together all the test cases for the gr + * directory into a single test suite. As you create new test cases, + * add them here. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <qa_runtime.h> +//#include <qa_gr_vmcircbuf.h> +#include <qa_gr_io_signature.h> +#include <qa_gr_block.h> +//#include <qa_gr_flowgraph.h> +#include <qa_gr_top_block.h> +#include <qa_gr_hier_block2.h> +#include <qa_gr_hier_block2_derived.h> +//#include <qa_gr_buffer.h> +#include <qa_block_tags.h> +//#include <qa_set_msg_handler.h> + +CppUnit::TestSuite * +qa_runtime::suite () +{ + CppUnit::TestSuite *s = new CppUnit::TestSuite ("runtime"); + + //s->addTest (qa_gr_vmcircbuf::suite ()); + s->addTest (qa_gr_io_signature::suite ()); + s->addTest (qa_gr_block::suite ()); + //s->addTest (qa_gr_flowgraph::suite ()); + s->addTest (qa_gr_top_block::suite ()); + s->addTest (qa_gr_hier_block2::suite ()); + s->addTest (qa_gr_hier_block2_derived::suite ()); + //s->addTest (qa_gr_buffer::suite ()); + s->addTest (qa_block_tags::suite ()); + //s->addTest (qa_set_msg_handler::suite ()); + + return s; +} diff --git a/tests/qa_runtime.h b/tests/qa_runtime.h new file mode 100644 index 0000000..da71cbd --- /dev/null +++ b/tests/qa_runtime.h @@ -0,0 +1,38 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 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. + */ + +#ifndef _QA_RUNTIME_H_ +#define _QA_RUNTIME_H_ + +#include <gruel/attributes.h> +#include <cppunit/TestSuite.h> + +//! collect all the tests for the runtime directory + +class __GR_ATTR_EXPORT qa_runtime { + public: + //! return suite of tests for all of runtime directory + static CppUnit::TestSuite *suite (); +}; + + +#endif /* _QA_RUNTIME_H_ */ diff --git a/tests/qa_set_msg_handler.cc b/tests/qa_set_msg_handler.cc new file mode 100644 index 0000000..25ae0b1 --- /dev/null +++ b/tests/qa_set_msg_handler.cc @@ -0,0 +1,85 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2011 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qa_set_msg_handler.h> +#include <gr_top_block.h> +#include <gr_head.h> +#include <gr_null_source.h> +#include <gr_null_sink.h> +#include <gr_nop.h> +#include <gruel/msg_passing.h> +#include <iostream> +#include <boost/thread/thread.hpp> + + +#define VERBOSE 0 + +using namespace pmt; + +/* + * The gr_nop block has been instrumented so that it counts + * the number of messages sent to it. We use this feature + * to confirm that gr_nop's call to set_msg_handler is working + * correctly. + */ + +void qa_set_msg_handler::t0() +{ + static const int NMSGS = 10; + + if (VERBOSE) std::cout << "qa_set_msg_handler::t0()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_nop_sptr nop = gr_make_nop(sizeof(int)); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + tb->connect(src, 0, nop, 0); + tb->connect(nop, 0, dst, 0); + + // Must start graph before sending messages + tb->start(); + + // Send them... + for (int i = 0; i < NMSGS; i++){ + send(nop, mp(mp("example-msg"), mp(i))); + } + + // And send a message to null_source to confirm that the default + // message handling action (which should be a nop) doesn't dump + // core. + send(src, mp(mp("example-msg"), mp(0))); + + // Give the messages a chance to be processed + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + + tb->stop(); + tb->wait(); + + // Confirm that the nop block received the right number of messages. + CPPUNIT_ASSERT_EQUAL(NMSGS, nop->nmsgs_received()); +} diff --git a/tests/qa_set_msg_handler.h b/tests/qa_set_msg_handler.h new file mode 100644 index 0000000..60277a1 --- /dev/null +++ b/tests/qa_set_msg_handler.h @@ -0,0 +1,43 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2011 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. + */ + +#ifndef INCLUDED_QA_SET_MSG_HANDLER_H +#define INCLUDED_QA_SET_MSG_HANDLER_H + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCase.h> +#include <stdexcept> + +class qa_set_msg_handler : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(qa_set_msg_handler); + + CPPUNIT_TEST(t0); + + CPPUNIT_TEST_SUITE_END(); + +private: + + void t0(); +}; + +#endif /* INCLUDED_QA_SET_MSG_HANDLER_H */ |