diff options
Diffstat (limited to 'gnuradio-core')
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc | 37 | ||||
-rwxr-xr-x | gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py | 45 |
2 files changed, 68 insertions, 14 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index fa52b7429..877e240c2 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -423,27 +423,40 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const sfg->connect(*s, *d); } } - } // Construct unique list of blocks used either in edges, inputs, // outputs, or by themselves. I still hate STL. - gr_basic_block_vector_t blocks, tmp = d_fg->calc_used_blocks(); + gr_basic_block_vector_t blocks; // unique list of used blocks + gr_basic_block_vector_t tmp = d_fg->calc_used_blocks(); + // First add the list of singleton blocks std::vector<gr_basic_block_sptr>::const_iterator b; // Because flatten_aux is const - for (b = d_blocks.begin(); b != d_blocks.end(); b++) + for (b = d_blocks.begin(); b != d_blocks.end(); b++) tmp.push_back(*b); - std::vector<gr_endpoint_vector_t>::const_iterator ep; // Because flatten_aux is const - std::vector<gr_endpoint>::const_iterator e; // Because flatten_aux is const - - for (ep = d_inputs.begin(); ep != d_inputs.end(); ep++) - for (e = (*ep).begin(); e != (*ep).end(); e++) - tmp.push_back((*e).block()); - - for (e = d_outputs.begin(); e != d_outputs.end(); e++) - tmp.push_back((*e).block()); + // Now add the list of connected input blocks + std::stringstream msg; + for (unsigned int i = 0; i < d_inputs.size(); i++) { + if (d_inputs[i].size() == 0) { + msg << "In hierarchical block " << d_owner->name() << ", input " << i + << " is not connected internally"; + throw std::runtime_error(msg.str()); + } + + for (unsigned int j = 0; j < d_inputs[i].size(); j++) + tmp.push_back(d_inputs[i][j].block()); + } + for (unsigned int i = 0; i < d_outputs.size(); i++) { + gr_basic_block_sptr blk = d_outputs[i].block(); + if (!blk) { + msg << "In hierarchical block " << d_owner->name() << ", output " << i + << " is not connected internally"; + throw std::runtime_error(msg.str()); + } + tmp.push_back(blk); + } sort(tmp.begin(), tmp.end()); std::insert_iterator<gr_basic_block_vector_t> inserter(blocks, blocks.begin()); diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py b/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py index 8fa3d4af9..cc336a4d1 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py @@ -230,14 +230,55 @@ class test_hier_block2(gr_unittest.TestCase): tb.run() self.assertEquals(expected_data, dst.data()) - def test_027_disconnected_internal(self): + def test_027a_internally_unconnected_input(self): tb = gr.top_block() hb = gr.hier_block2("block", gr.io_signature(1, 1, 1), gr.io_signature(1, 1, 1)) + hsrc = gr.vector_source_b([1,]) + hb.connect(hsrc, hb) # wire output internally src = gr.vector_source_b([1, ]) dst = gr.vector_sink_b() - tb.connect(src, hb, dst) # hb is not connected internally + tb.connect(src, hb, dst) # hb's input is not connected internally + self.assertRaises(RuntimeError, + lambda: tb.run()) + + def test_027b_internally_unconnected_output(self): + tb = gr.top_block() + + hb = gr.hier_block2("block", + gr.io_signature(1, 1, 1), + gr.io_signature(1, 1, 1)) + hdst = gr.vector_sink_b() + hb.connect(hb, hdst) # wire input internally + src = gr.vector_source_b([1, ]) + dst = gr.vector_sink_b() + tb.connect(src, hb, dst) # hb's output is not connected internally + self.assertRaises(RuntimeError, + lambda: tb.run()) + + def test_027c_fully_unconnected_output(self): + tb = gr.top_block() + hb = gr.hier_block2("block", + gr.io_signature(1, 1, 1), + gr.io_signature(1, 1, 1)) + hsrc = gr.vector_sink_b() + hb.connect(hb, hsrc) # wire input internally + src = gr.vector_source_b([1, ]) + dst = gr.vector_sink_b() + tb.connect(src, hb) # hb's output is not connected internally or externally + self.assertRaises(RuntimeError, + lambda: tb.run()) + + def test_027d_fully_unconnected_input(self): + tb = gr.top_block() + hb = gr.hier_block2("block", + gr.io_signature(1, 1, 1), + gr.io_signature(1, 1, 1)) + hdst = gr.vector_source_b([1,]) + hb.connect(hdst, hb) # wire output internally + dst = gr.vector_sink_b() + tb.connect(hb, dst) # hb's input is not connected internally or externally self.assertRaises(RuntimeError, lambda: tb.run()) |