diff options
author | Tom Rondeau | 2010-11-13 14:29:11 -0500 |
---|---|---|
committer | Tom Rondeau | 2010-11-13 14:29:11 -0500 |
commit | 77d778896b72379676d2b00e591f9bbb5f6fcc44 (patch) | |
tree | 2f88f7c85aaf7e19adb089edea993637d879c9f0 /gnuradio-core/src/lib | |
parent | 3fb01df05227913c2cc8cde6cb651dc1c9a81ff9 (diff) | |
download | gnuradio-77d778896b72379676d2b00e591f9bbb5f6fcc44.tar.gz gnuradio-77d778896b72379676d2b00e591f9bbb5f6fcc44.tar.bz2 gnuradio-77d778896b72379676d2b00e591f9bbb5f6fcc44.zip |
More test methods. Better testing of the all-to-all policy and more tests for the 1-to-1.
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r-- | gnuradio-core/src/lib/general/gr_annotator_1toall.cc | 99 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_annotator_1toall.h | 79 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_annotator_1toall.i | 37 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_block_tags.cc | 139 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/qa_block_tags.h | 4 |
5 files changed, 134 insertions, 224 deletions
diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.cc b/gnuradio-core/src/lib/general/gr_annotator_1toall.cc deleted file mode 100644 index 47002e3c9..000000000 --- a/gnuradio-core/src/lib/general/gr_annotator_1toall.cc +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- 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 <gr_annotator_1toall.h> -#include <gr_io_signature.h> -#include <string.h> -#include <iostream> -#include <iomanip> - -gr_annotator_1toall_sptr -gr_make_annotator_1toall (size_t sizeof_stream_item, float rel_rate) -{ - return gnuradio::get_initial_sptr (new gr_annotator_1toall (sizeof_stream_item, rel_rate)); -} - -gr_annotator_1toall::gr_annotator_1toall (size_t sizeof_stream_item, float rel_rate) - : gr_block ("annotator_1toall", - gr_make_io_signature (1, 1, sizeof_stream_item), - gr_make_io_signature (1, -1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item), d_rel_rate(rel_rate) -{ - set_tag_propagation_policy(TPP_ALL_TO_ALL); - - d_tag_counter = 0; - set_relative_rate(d_rel_rate); -} - -gr_annotator_1toall::~gr_annotator_1toall () -{ -} - -int -gr_annotator_1toall::general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const float *in = (const float *) input_items[0]; - float *out = (float *) output_items[0]; - - std::stringstream str; - str << name() << unique_id(); - - uint64_t abs_N = nitems_read(0); - std::vector<pmt::pmt_t> all_tags = get_tags_in_range(0, abs_N, abs_N + noutput_items); - - std::vector<pmt::pmt_t>::iterator itr; - for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - d_stored_tags.push_back(*itr); - } - - // Source ID and key for any tag that might get applied from this block - pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); - pmt::pmt_t key = pmt::pmt_string_to_symbol("seq"); - - // Work does nothing to the data stream; just copy all inputs to outputs - // Adds a new tag when the number of items read is a multiple of N - uint64_t N = 10000; - int noutputs = output_items.size(); - for(int j = 0; j < noutput_items; j++) { - abs_N++; - - for(int i = 0; i < noutputs; i++) { - if(abs_N % N == 0) { - pmt::pmt_t value = pmt::pmt_from_uint64(d_tag_counter++); - add_item_tag(i, abs_N, key, value, srcid); - } - - out = (float*)output_items[i]; - out[j] = in[j]; - } - } - - consume_each(noutput_items); - return noutput_items; -} diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.h b/gnuradio-core/src/lib/general/gr_annotator_1toall.h deleted file mode 100644 index e118fd7a0..000000000 --- a/gnuradio-core/src/lib/general/gr_annotator_1toall.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- 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_GR_ANNOTATOR_1TOALL_H -#define INCLUDED_GR_ANNOTATOR_1TOALL_H - -#include <gr_block.h> - -class gr_annotator_1toall; -typedef boost::shared_ptr<gr_annotator_1toall> gr_annotator_1toall_sptr; - -// public constructor -gr_annotator_1toall_sptr -gr_make_annotator_1toall (size_t sizeof_stream_item, float rel_rate=1.0); - -/*! - * \brief All-to-all stream annotator testing block. FOR TESTING PURPOSES ONLY. - * - * This block creates tags to be sent downstream every 10,000 items it sees. The - * tags contain the name and ID of the instantiated block, use "seq" as a key, - * and have a counter that increments by 1 for every tag produced that is used - * as the tag's value. The tags are propagated using the all-to-all policy. - * - * It also stores a copy of all tags it sees flow past it. These tags can be - * recalled externally with the data() member. - * - * This block is only meant for testing and showing how to use the tags. - */ -class gr_annotator_1toall : public gr_block -{ - public: - ~gr_annotator_1toall (); - int general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - void set_rel_rate(float rrate) { d_rel_rate = rrate; set_relative_rate(d_rel_rate); } - float rel_rate() { return d_rel_rate; } - - - std::vector<pmt::pmt_t> data() const - { - return d_stored_tags; - } - -protected: - gr_annotator_1toall (size_t sizeof_stream_item, float rel_rate); - - private: - size_t d_itemsize; - float d_rel_rate; - uint64_t d_tag_counter; - std::vector<pmt::pmt_t> d_stored_tags; - - friend gr_annotator_1toall_sptr - gr_make_annotator_1toall (size_t sizeof_stream_item, float rel_rate); -}; - -#endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_1toall.i b/gnuradio-core/src/lib/general/gr_annotator_1toall.i deleted file mode 100644 index a6bd01017..000000000 --- a/gnuradio-core/src/lib/general/gr_annotator_1toall.i +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- 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. - */ - -GR_SWIG_BLOCK_MAGIC(gr,annotator_1toall); - -gr_annotator_1toall_sptr gr_make_annotator_1toall (size_t sizeof_stream_item, float rel_rate); - -class gr_annotator_1toall : public gr_block -{ -public: - void set_rel_rate(float rrate); - float rel_rate(); - std::vector<pmt::pmt_t> data() const; - -private: - gr_annotator_1toall (size_t sizeof_stream_item, float rel_rate); -}; - diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index ee16ec108..2560b7860 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -29,7 +29,7 @@ #include <gr_null_source.h> #include <gr_null_sink.h> #include <gr_head.h> -#include <gr_annotator_1toall.h> +#include <gr_annotator_alltoall.h> #include <gr_annotator_1to1.h> #include <gruel/pmt.h> @@ -75,11 +75,11 @@ qa_block_tags::t1 () 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_1toall_sptr ann0 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann3 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann4 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); @@ -144,7 +144,6 @@ qa_block_tags::t1 () } } - void qa_block_tags::t2 () { @@ -154,9 +153,103 @@ qa_block_tags::t2 () 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(sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(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(); + + // 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(10000), mp(str1.str()), mp("seq"), mp(0)); + expected_tags2[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); + expected_tags2[2] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags2[3] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags2[4] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags2[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags2[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(6)); + expected_tags2[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags2[8] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags2[9] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(9)); + expected_tags2[10] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags2[11] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + + pmt_t expected_tags4[12]; + expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); + expected_tags4[2] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(5)); + expected_tags4[4] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(8)); + expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags4[8] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[9] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(11)); + expected_tags4[10] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags4[11] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + + std::vector<pmt::pmt_t> tags0 = ann0->data(); + std::vector<pmt::pmt_t> tags1 = ann1->data(); + std::vector<pmt::pmt_t> tags2 = ann2->data(); + std::vector<pmt::pmt_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); + + // 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; + //pmt_equal(tags2[i], expected_tags2[i]) + 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; + //pmt_equal(tags4[i], expected_tags4[i]) + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); + } +} + + +void +qa_block_tags::t3 () +{ + printf("\nqa_block_tags::t3\n"); + + 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(sizeof(int))); - gr_annotator_1toall_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); gr_annotator_1to1_sptr ann3 (gr_make_annotator_1to1(sizeof(int))); gr_annotator_1to1_sptr ann4 (gr_make_annotator_1to1(sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); @@ -224,3 +317,31 @@ qa_block_tags::t2 () } } + +void +qa_block_tags::t4 () +{ + printf("\nqa_block_tags::t4\n"); + + 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(sizeof(int))); + gr_annotator_1to1_sptr ann1 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1to1_sptr ann2 (gr_make_annotator_1to1(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); + + tb->run(); +} + diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h index 44bef9fac..2bf134d96 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.h +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -33,12 +33,16 @@ class qa_block_tags : public CppUnit::TestCase { CPPUNIT_TEST (t0); CPPUNIT_TEST (t1); CPPUNIT_TEST (t2); + CPPUNIT_TEST (t3); + CPPUNIT_TEST (t4); CPPUNIT_TEST_SUITE_END (); private: void t0 (); void t1 (); void t2 (); + void t3 (); + void t4 (); }; |