commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r10992 - in gnuradio/trunk/gnuradio-core/src: lib/runt


From: jcorgan
Subject: [Commit-gnuradio] r10992 - in gnuradio/trunk/gnuradio-core/src: lib/runtime python/gnuradio/gr
Date: Fri, 8 May 2009 12:51:40 -0600 (MDT)

Author: jcorgan
Date: 2009-05-08 12:51:39 -0600 (Fri, 08 May 2009)
New Revision: 10992

Modified:
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
   gnuradio/trunk/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
Log:
Fix abort when user fails to connect hier_block2 outputs both internally and 
internally; throw meaningful exception instead.

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc       
2009-05-07 18:05:26 UTC (rev 10991)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc       
2009-05-08 18:51:39 UTC (rev 10992)
@@ -423,27 +423,40 @@
        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
+  // 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 (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());
-
+  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());

Modified: gnuradio/trunk/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
===================================================================
--- gnuradio/trunk/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py       
2009-05-07 18:05:26 UTC (rev 10991)
+++ gnuradio/trunk/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py       
2009-05-08 18:51:39 UTC (rev 10992)
@@ -230,17 +230,58 @@
         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())
+
     def test_028_singleton_reconfigure(self):
         tb = gr.top_block()
         hb = gr.hier_block2("block", 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]