diff options
author | Eric Blossom | 2011-01-06 21:48:12 -0800 |
---|---|---|
committer | Eric Blossom | 2011-01-06 21:48:12 -0800 |
commit | bb438e7d12c5767123f8abed5810f284a5f18bf8 (patch) | |
tree | 0050d2fc45ac7104805ab7352403cc7f93623274 /gnuradio-core/src | |
parent | 1dc1dbeef3eb15e1316857d4dd7ba32c4304bf69 (diff) | |
download | gnuradio-bb438e7d12c5767123f8abed5810f284a5f18bf8.tar.gz gnuradio-bb438e7d12c5767123f8abed5810f284a5f18bf8.tar.bz2 gnuradio-bb438e7d12c5767123f8abed5810f284a5f18bf8.zip |
Add QA code for gr_basic_block::set_msg_handler.
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r-- | gnuradio-core/src/lib/runtime/Makefile.am | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_runtime.cc | 4 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc | 85 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_set_msg_handler.h | 43 |
4 files changed, 133 insertions, 1 deletions
diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 0fdb58aff..3dd2b42f5 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -81,6 +81,7 @@ libruntime_qa_la_SOURCES = \ qa_gr_io_signature.cc \ qa_gr_vmcircbuf.cc \ qa_block_tags.cc \ + qa_set_msg_handler.cc \ qa_runtime.cc grinclude_HEADERS = \ @@ -140,6 +141,7 @@ noinst_HEADERS = \ qa_gr_top_block.h \ qa_gr_vmcircbuf.h \ qa_block_tags.h \ + qa_set_msg_handler.h \ qa_runtime.h swiginclude_HEADERS = \ diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index 967d4bfa8..c0bee8ea0 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -1,5 +1,5 @@ /* - * Copyright 2002,2007 Free Software Foundation, Inc. + * Copyright 2002,2007,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -39,6 +39,7 @@ #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 () @@ -54,6 +55,7 @@ qa_runtime::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/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc new file mode 100644 index 000000000..d52ca78b9 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/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))); + + // Surrender our CPU for a bit + boost::this_thread::yield(); + + 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/gnuradio-core/src/lib/runtime/qa_set_msg_handler.h b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.h new file mode 100644 index 000000000..e73fffbcd --- /dev/null +++ b/gnuradio-core/src/lib/runtime/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 */ |