]> git.gag.com Git - debian/gnuradio/commitdiff
Fix abort when user fails to connect hier_block2 outputs both internally and internal...
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 8 May 2009 18:51:39 +0000 (18:51 +0000)
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 8 May 2009 18:51:39 +0000 (18:51 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10992 221aa14e-8319-0410-a670-987f0aec2ac5

gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py

index fa52b7429cee4103bff9f3ede074690dd8a6ed24..877e240c291b5b2eeae3365752dfcf697158d3d7 100644 (file)
@@ -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());
index 8fa3d4af91512f4ce66789452c1e61dad2c014c8..cc336a4d1b495ab271324b3ea2ab35232b48cde7 100755 (executable)
@@ -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())