@@ -126,6 +126,7 @@ public void testConnectPortInstsThruHier(boolean netToPin) {
126126 @ Test
127127 public void testConnectPortInstsThruHierNet () {
128128 Design d = Design .readCheckpoint (RapidWrightDCP .getPath ("bnn.dcp" ), true );
129+ EDIFNetlist netlist = d .getNetlist ();
129130 boolean includeSrcs = true ;
130131 boolean includeSnks = false ;
131132
@@ -134,27 +135,38 @@ public void testConnectPortInstsThruHierNet() {
134135 // [net] 'test_net'
135136 String netName = "test_net" ;
136137 d .getTopEDIFCell ().createNet (netName );
137- EDIFHierNet net = d .getNetlist ().getHierNetFromName (netName );
138- EDIFHierPortInst pin = d .getNetlist ().getHierPortInstFromName ("bd_0_i/hls_inst/inst/add_ln180_1_reg_1471_reg[5]/Q" );
138+ EDIFHierNet net = netlist .getHierNetFromName (netName );
139+ EDIFHierPortInst pin = netlist .getHierPortInstFromName ("bd_0_i/hls_inst/inst/add_ln180_1_reg_1471_reg[5]/Q" );
140+ Assertions .assertEquals (2 , pin .getNet ().getPortInsts ().size ());
139141 EDIFTools .connectPortInstsThruHier (net , pin , "test_connect" );
140142 Assertions .assertEquals (1 , net .getNet ().getPortInsts ().size ());
141143 List <EDIFHierPortInst > leafPins = net .getLeafHierPortInsts (includeSrcs , includeSnks );
142144 Assertions .assertEquals (1 , leafPins .size ());
143145 Assertions .assertEquals (pin .toString (), leafPins .get (0 ).toString ());
144-
146+ // Needed to punch a new port ...
147+ Assertions .assertEquals (3 , pin .getNet ().getPortInsts ().size ());
148+ Assertions .assertTrue (pin .getHierarchicalNet ().getPortInsts ().stream ().anyMatch (
149+ // ... upwards from the pin
150+ ehpi -> ehpi .toString ().equals ("bd_0_i/hls_inst/inst/test_connect" )
151+ ));
152+
153+
145154 // Test connecting a source in a low hierarchical cell to an unconnected net in another (separate) low hierarchical cell
146155 // [pin] 'bd_0_i/hls_inst/inst/grp_bin_dense_fu_523/ram_reg_bram_0_i_6__4/O' -->
147156 // [net] 'bd_0_i/hls_inst/inst/wt_mem_V_U/top_wt_mem_V_ram_U/test_net2'
148157 netName = "test_net2" ;
149- EDIFHierCellInst targetInst = d . getNetlist () .getHierCellInstFromName ("bd_0_i/hls_inst/inst/wt_mem_V_U/top_wt_mem_V_ram_U" );
158+ EDIFHierCellInst targetInst = netlist .getHierCellInstFromName ("bd_0_i/hls_inst/inst/wt_mem_V_U/top_wt_mem_V_ram_U" );
150159 targetInst .getCellType ().createNet (netName );
151160 net = targetInst .getNet (netName );
152- pin = d .getNetlist ().getHierPortInstFromName ("bd_0_i/hls_inst/inst/grp_bin_dense_fu_523/ram_reg_bram_0_i_6__4/O" );
161+ pin = netlist .getHierPortInstFromName ("bd_0_i/hls_inst/inst/grp_bin_dense_fu_523/ram_reg_bram_0_i_6__4/O" );
162+ Assertions .assertEquals (2 , pin .getNet ().getPortInsts ().size ());
153163 EDIFTools .connectPortInstsThruHier (net , pin , "test_connect2" );
154164 Assertions .assertEquals (1 , net .getNet ().getPortInsts ().size ());
155165 leafPins = net .getLeafHierPortInsts (includeSrcs , includeSnks );
156166 Assertions .assertEquals (1 , leafPins .size ());
157167 Assertions .assertEquals (pin .toString (), leafPins .get (0 ).toString ());
168+ // Re-used the existing port
169+ Assertions .assertEquals (2 , pin .getNet ().getPortInsts ().size ());
158170
159171 includeSrcs = false ;
160172 includeSnks = true ;
@@ -164,29 +176,62 @@ public void testConnectPortInstsThruHierNet() {
164176 // [pin] 'bd_0_i/hls_inst/inst/add_ln180_1_reg_1471_reg[5]/D'
165177 netName = "test_net3" ;
166178 d .getTopEDIFCell ().createNet (netName );
167- net = d .getNetlist ().getHierNetFromName (netName );
168- pin = d .getNetlist ().getHierPortInstFromName ("bd_0_i/hls_inst/inst/add_ln180_1_reg_1471_reg[5]/D" );
179+ net = netlist .getHierNetFromName (netName );
180+ Assertions .assertEquals (0 , net .getNet ().getPortInsts ().size ());
181+ pin = netlist .getHierPortInstFromName ("bd_0_i/hls_inst/inst/add_ln180_1_reg_1471_reg[5]/D" );
182+ Assertions .assertEquals (2 , pin .getNet ().getPortInsts ().size ());
169183 ECOTools .disconnectNet (d , pin );
184+ Assertions .assertNull (pin .getNet ());
170185 EDIFTools .connectPortInstsThruHier (net , pin , "test_connect3" );
186+ // Needed to punch a new port
171187 Assertions .assertEquals (1 , net .getNet ().getPortInsts ().size ());
188+ Assertions .assertTrue (net .getPortInsts ().stream ().anyMatch (
189+ // ... downwards from the net
190+ ehpi -> ehpi .toString ().equals ("bd_0_i/test_connect3" )
191+ ));
192+
193+
172194 leafPins = net .getLeafHierPortInsts (includeSrcs , includeSnks );
173195 Assertions .assertEquals (1 , leafPins .size ());
174196 Assertions .assertEquals (pin .toString (), leafPins .get (0 ).toString ());
175197
198+ // Needed to punch a new port
199+ Assertions .assertEquals (2 , pin .getNet ().getPortInsts ().size ());
200+ Assertions .assertTrue (pin .getHierarchicalNet ().getPortInsts ().stream ().anyMatch (
201+ // ... upwards from the pin
202+ ehpi -> ehpi .toString ().equals ("bd_0_i/hls_inst/inst/test_connect3" )
203+ ));
204+
176205 // Test connecting a sink in a low hierarchical cell to an unconnected net in
177206 // another (separate) low hierarchical cell
178207 // [net] 'bd_0_i/hls_inst/inst/wt_mem_V_U/top_wt_mem_V_ram_U/test_net4' -->
179208 // [pin] 'bd_0_i/hls_inst/inst/add_ln180_1_reg_1471_reg[4]/D'
180209 netName = "test_net4" ;
181210 targetInst .getCellType ().createNet (netName );
182211 net = targetInst .getNet (netName );
183- pin = d .getNetlist ().getHierPortInstFromName ("bd_0_i/hls_inst/inst/add_ln180_1_reg_1471_reg[4]/D" );
212+ Assertions .assertEquals (0 , net .getNet ().getPortInsts ().size ());
213+ pin = netlist .getHierPortInstFromName ("bd_0_i/hls_inst/inst/add_ln180_1_reg_1471_reg[4]/D" );
214+ Assertions .assertEquals (2 , pin .getNet ().getPortInsts ().size ());
184215 ECOTools .disconnectNet (d , pin );
216+ Assertions .assertNull (pin .getNet ());
185217 EDIFTools .connectPortInstsThruHier (net , pin , "test_connect4" );
218+ // Needed to punch a new port
186219 Assertions .assertEquals (1 , net .getNet ().getPortInsts ().size ());
220+ Assertions .assertTrue (net .getPortInsts ().stream ().anyMatch (
221+ // ... upwards from the net
222+ ehpi -> ehpi .toString ().equals ("bd_0_i/hls_inst/inst/wt_mem_V_U/top_wt_mem_V_ram_U/test_connect4" )
223+ ));
224+
187225 leafPins = net .getLeafHierPortInsts (includeSrcs , includeSnks );
188226 Assertions .assertEquals (1 , leafPins .size ());
189227 Assertions .assertEquals (pin .toString (), leafPins .get (0 ).toString ());
228+
229+ // Needed to punch a new port
230+ Assertions .assertEquals (2 , pin .getNet ().getPortInsts ().size ());
231+ Assertions .assertTrue (pin .getHierarchicalNet ().getPortInsts ().stream ().anyMatch (
232+ // ... downwards from the pin
233+ ehpi -> ehpi .toString ().equals ("bd_0_i/hls_inst/inst/wt_mem_V_U/test_connect4" )
234+ ));
190235 }
191236
192237
0 commit comments