torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ModuleTransformerUnitTest.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Unit Test for ModuleTransformer class.
18 
19 #include <boost/test/unit_test.hpp>
25 #include "torc/physical/Design.hpp"
26 #include <fstream>
27 
28 namespace torc {
29 namespace physical {
30 
31 BOOST_AUTO_TEST_SUITE(physical)
32 
33 BOOST_AUTO_TEST_SUITE(moduletransformer)
34 
35 static const string sInstanceOneName = "c1";
36 static const string sInstanceTwoName = "c2";
37 static const string sModuleDefinition = "aModule";
38 static const string sModuleInstanceName = "aModuleInstance";
39 static const string sHierarchySeparator = "/";
40 
41 DesignSharedPtr verifyDesignOpenedSuccessfully(const string & inDesignFileName);
45  InstanceSharedPtrVector inInstanceVector, bool inKeepPlacement = false,
46  bool inKeepRouting = false);
48 void postFlatteningVerifications(DesignSharedPtr inDesignPtr, bool inKeepPlacement = false,
49  bool inKeepRouting = false);
50 
51 /// \brief Verify that the design file opened successfully.
52 /// \param inDesignFileName The design file name.
53 DesignSharedPtr verifyDesignOpenedSuccessfully(const string & inDesignFileName) {
54  // Design shared pointer
55  DesignSharedPtr designPtr;
56  // Create the appropriate file paths
57  boost::filesystem::path physicalPath =
58  torc::common::DirectoryTree::getExecutablePath() / "torc" / "physical";
59  // Original xdl
60  boost::filesystem::path originalPath = physicalPath / inDesignFileName;
61  // Import the XDL design
62  std::fstream fileStream(originalPath.string().c_str());
63  // Verify the file is good
64  BOOST_REQUIRE(fileStream.good());
65  // Import the xdl design
66  XdlImporter importer;
67  importer(fileStream, originalPath.string());
68  // Get a pointer to the design
69  designPtr = importer.getDesignPtr();
70  // Verify the design pointer
71  BOOST_REQUIRE(designPtr.get() != 0);
72  return designPtr;
73 }
74 
75 /// \brief Retrieve the instances to modularize from the design and return them in a vector.
76 /// \param inDesignPtr The design shared pointer.
78  // Create instances vector
79  InstanceSharedPtrVector instPtrVector;
80  // Select instance sInstanceOneName to modularize
81  Design::InstanceSharedPtrIterator instIter = inDesignPtr->findInstance(sInstanceOneName);
82  // Verify design has instance sInstanceOneName
83  BOOST_REQUIRE(instIter != inDesignPtr->instancesEnd());
84  // Add instance pointer to instance vector
85  instPtrVector.push_back(*instIter);
86  // Select instance sInstanceTwoName to modularize
87  instIter = inDesignPtr->findInstance(sInstanceTwoName);
88  // Verify design has instance sInstanceTwoName
89  BOOST_REQUIRE(instIter != inDesignPtr->instancesEnd());
90  instPtrVector.push_back(*instIter);
91  // Return instance vector
92  return instPtrVector;
93 }
94 
95 /// \brief Perform pre-modularization tests on a design.
96 /// \param inDesignPtr The design shared pointer.
97 /// \details The pre-modularization tests consist of the following:
98 /// 1 - Verify module definition does not exist in design.
99 /// 2 - Verify module instance does not exist in design.
101  // Search design for sModuleDefinition
102  Design::ModuleSharedPtrIterator modIter = inDesignPtr->findModule(sModuleDefinition);
103  // Verify design does not have module sModuleDefinition
104  BOOST_REQUIRE(modIter == inDesignPtr->modulesEnd());
105  // Search design for sModuleInstanceName
106  Design::InstanceSharedPtrIterator instIter = inDesignPtr->findInstance(sModuleInstanceName);
107  // Verify design does not have sModuleInstanceName
108  BOOST_REQUIRE(instIter == inDesignPtr->instancesEnd());
109 }
110 
111 /// \brief Perform post-modularization tests on a design.
112 /// \param inDesignPtr The design shared pointer.
113 /// \param inInstanceVector The vector of the instances that were modularized
114 /// \param inKeepPlacement The flag to keep placement when modularizing, defaults to false.
115 /// \param inKeepRouting The flag to keep routing when modularizing, defaults to false.
116 /// \details The post-modularization tests consist of the following:
117 /// 1 - Verify module definition exists in design.
118 /// 2 - Verify module instance exists in design.
119 /// 3 - Verify module instance placement.
120 /// 4 - Verify instances migration & placement.
121 /// 5 - Verify intra net migration & routing.
122 /// 6 - Verify inter net routing.
123 /// 7 - Verify module definition port count.
125  InstanceSharedPtrVector inInstanceVector, bool inKeepPlacement, bool inKeepRouting) {
126  // Begin verify module definition and module instance creation
127  // Search design for sModuleDefinition
128  Design::ModuleSharedPtrIterator modIter = inDesignPtr->findModule(sModuleDefinition);
129  // Verify design has module sModuleDefinition
130  BOOST_REQUIRE(modIter != inDesignPtr->modulesEnd());
131  // Search design for sModuleInstanceName
132  Design::InstanceSharedPtrIterator instIter = inDesignPtr->findInstance(sModuleInstanceName);
133  // Verify design has sModuleInstanceName
134  BOOST_REQUIRE(instIter != inDesignPtr->instancesEnd());
135  // Get a pointer to the module definition
136  ModuleSharedPtr modPtr = *modIter;
137  // Get a pointer to the module instance
138  InstanceSharedPtr instPtr = *instIter;
139  // Verify placement
140  if(!inKeepPlacement) {
141  // Verify module instance is not placed
142  BOOST_REQUIRE_EQUAL(instPtr->getTile().compare(""), 0);
143  BOOST_REQUIRE_EQUAL(instPtr->getSite().compare(""), 0);
144  }
145  // End verify module definition and module instance creation
146 
147  // Begin verify instance migration and placement
148  // Get a begin iterator to inInstanceVector
149  Design::InstanceSharedPtrConstIterator inInstanceVectorBegin = inInstanceVector.begin();
150  // Get an end iterator to inInstanceVector
151  Design::InstanceSharedPtrConstIterator inInstanceVectorEnd = inInstanceVector.end();
152  // Iterate over all instances in inInstanceVector
153  while(inInstanceVectorBegin != inInstanceVectorEnd) {
154  // Get a pointer to the current instance
155  InstanceSharedPtr instPtr = *inInstanceVectorBegin;
156  // Search design for instance
157  instIter = inDesignPtr->findInstance(instPtr->getName());
158  // Verify design does not have instance
159  BOOST_REQUIRE(instIter == inDesignPtr->instancesEnd());
160  // Search module definition for instance
161  instIter = modPtr->findInstance(instPtr->getName());
162  // Verify module definition has instance
163  BOOST_REQUIRE(instIter != modPtr->instancesEnd());
164  // Get a pointer to the looked up instance
165  InstanceSharedPtr modInstPtr = *instIter;
166  // Verify placement
167  if(!inKeepPlacement) {
168  // Verify instance is not placed
169  BOOST_REQUIRE_EQUAL(modInstPtr->getTile().compare(""), 0);
170  BOOST_REQUIRE_EQUAL(modInstPtr->getSite().compare(""), 0);
171  }
172  // Move to next instance
173  inInstanceVectorBegin++;
174  }
175  // End verify instance migration and placement
176 
177  // Begin verify intra net migration and routing
178  // Get a begin iterator to module nets
179  Design::NetSharedPtrIterator moduleNetsBegin = modPtr->netsBegin();
180  // Get an end iterator to module nets
181  Design::NetSharedPtrIterator moduleNetsEnd = modPtr->netsEnd();
182  // Iterate over all module nets
183  while(moduleNetsBegin != moduleNetsEnd) {
184  // Get a pointer to the current net
185  NetSharedPtr moduleNetPtr = *moduleNetsBegin;
186  // Verify routing
187  if(!inKeepRouting) {
188  BOOST_REQUIRE(moduleNetPtr->pipsBegin() == moduleNetPtr->pipsEnd());
189  }
190  // Search for net in design
191  Design::NetSharedPtrIterator designNetItr = inDesignPtr->findNet(moduleNetPtr->getName());
192  // Verify net does not exist in design
193  BOOST_REQUIRE(designNetItr == inDesignPtr->netsEnd());
194  // Move to next net
195  moduleNetsBegin++;
196  }
197  // End verify intra net migration and routing
198 
199  // Begin verify module port count and inter net routing
200  // Initialize port count
201  u_int32_t portCount = 0;
202  // Search design for sModuleInstanceName
203  instIter = inDesignPtr->findInstance(sModuleInstanceName);
204  // Get a pointer to the module instance
205  instPtr = *instIter;
206  // Get a begin iterator to design nets
207  Design::NetSharedPtrIterator designNetsBegin = inDesignPtr->netsBegin();
208  // Get an end iterator to design nets
209  Design::NetSharedPtrIterator designNetsEnd = inDesignPtr->netsEnd();
210  // Iterate over all design nets
211  while(designNetsBegin != designNetsEnd) {
212  // Get a pointer to the current net
213  NetSharedPtr designNetPtr = *designNetsBegin;
214  // Get a begin iterator to net sources
215  Net::InstancePinSharedPtrIterator designNetSourcesBegin = designNetPtr->sourcesBegin();
216  // Get an end iterator to net sources
217  Net::InstancePinSharedPtrIterator designNetSourcesEnd = designNetPtr->sourcesEnd();
218  // Iterate over all net source
219  while(designNetSourcesBegin != designNetSourcesEnd) {
220  // Get a pointer to the current net source pin
221  InstancePinSharedPtr instPinPtr = *designNetSourcesBegin;
222  // Get a pointer to the instance hosting the net source pin
223  InstanceSharedPtr pinInstPtr = instPinPtr->getInstancePtr().lock();
224  // Is this the module instance?
225  if(pinInstPtr == instPtr) {
226  // Verify routing
227  if(!inKeepRouting) {
228  BOOST_REQUIRE(designNetPtr->pipsBegin() == designNetPtr->pipsEnd());
229  }
230  portCount++;
231  }
232  // Move to next source
233  designNetSourcesBegin++;
234  }
235  // Get a begin iterator to net sinks
236  Net::InstancePinSharedPtrIterator designNetSinksBegin = designNetPtr->sinksBegin();
237  // Get an end iterator to net sinks
238  Net::InstancePinSharedPtrIterator designNetSinksEnd = designNetPtr->sinksEnd();
239  // Iterate over all net source
240  while(designNetSinksBegin != designNetSinksEnd) {
241  // Get a pointer to the current net source pin
242  InstancePinSharedPtr instPinPtr = *designNetSinksBegin;
243  // Get a pointer to the instance hosting the net source pin
244  InstanceSharedPtr pinInstPtr = instPinPtr->getInstancePtr().lock();
245  // Is this the module instance?
246  if(pinInstPtr == instPtr) {
247  // Verify routing
248  if(!inKeepRouting) {
249  BOOST_REQUIRE(designNetPtr->pipsBegin() == designNetPtr->pipsEnd());
250  }
251  portCount++;
252  }
253  // Move to next sink
254  designNetSinksBegin++;
255  }
256  // Move to next net
257  designNetsBegin++;
258  }
259 
260  // Verify that module definition has portCount ports
261  BOOST_REQUIRE_EQUAL(modPtr->getPortCount(), portCount);
262  // End verify module port count and inter net routing
263 }
264 
265 /// \brief Perform pre-flattening tests on a design.
266 /// \param inDesignPtr The design shared pointer.
267 /// \details The pre-flattening tests consist of the following:
268 /// 1 - Verify module definition exists in design.
269 /// 2 - Verify module instance exists in design.
271  // Search design for sModuleDefinition
272  Design::ModuleSharedPtrIterator modIter = inDesignPtr->findModule(sModuleDefinition);
273  // Verify design has module sModuleDefinition
274  BOOST_REQUIRE(modIter != inDesignPtr->modulesEnd());
275  // Search design for sModuleInstanceName
276  Design::InstanceSharedPtrIterator instIter = inDesignPtr->findInstance(sModuleInstanceName);
277  // Verify design has sModuleInstanceName
278  BOOST_REQUIRE(instIter != inDesignPtr->instancesEnd());
279 }
280 
281 /// \brief Perform post-flattening tests on a design.
282 /// \param inDesignPtr The design shared pointer.
283 /// \param inKeepPlacement The flag to keep placement when flattening, defaults to false.
284 /// \param inKeepRouting The flag to keep routing when flattening, defaults to false.
285 /// \details The post-flattening tests consist of the following:
286 /// 1 - Verify module definition still exists in design.
287 /// 2 - Verify module instance does not exist in design.
288 /// 3 - Verify module instances cloning & placement.
289 /// 4 - Verify module intra nets cloning & routing.
290 /// 5 - Verify inter nets do not reference module instance & inter net routing.
291 void postFlatteningVerifications(DesignSharedPtr inDesignPtr, bool inKeepPlacement,
292  bool inKeepRouting) {
293  // Begin verify module definition existence and removal of module instance
294  // Search design for sModuleDefinition
295  Design::ModuleSharedPtrIterator modIter = inDesignPtr->findModule(sModuleDefinition);
296  // Verify design has module sModuleDefinition
297  BOOST_REQUIRE(modIter != inDesignPtr->modulesEnd());
298  // Search design for sModuleInstanceName
299  Design::InstanceSharedPtrIterator designInstIter
300  = inDesignPtr->findInstance(sModuleInstanceName);
301  // Verify design has sModuleInstanceName
302  BOOST_REQUIRE(designInstIter == inDesignPtr->instancesEnd());
303  // End verify module definition existence and removal of module instance
304 
305  // Begin verify module instances cloning and placement
306  // Get a pointer to the module definition
307  ModuleSharedPtr modPtr = *modIter;
308  // Get a begin iterator to module definition instances
309  Design::InstanceSharedPtrConstIterator modInstancesBegin = modPtr->instancesBegin();
310  // Get an end iterator to module definition instances
311  Design::InstanceSharedPtrConstIterator modInstancesEnd = modPtr->instancesEnd();
312  // Iterate over all module definition instances
313  while(modInstancesBegin != modInstancesEnd) {
314  // Get a pointer to the current instance
315  InstanceSharedPtr modInstPtr = *modInstancesBegin;
316  // Search for corresponding flattened instance in design
317  designInstIter = inDesignPtr->findInstance(sModuleInstanceName +
318  sHierarchySeparator + modInstPtr->getName());
319  // Verify instance is cloned and moved to design
320  BOOST_REQUIRE(designInstIter != inDesignPtr->instancesEnd());
321  // Verify placement
322  if(!inKeepPlacement) {
323  // Get a pointer to the instance clone
324  InstanceSharedPtr instPtr = *designInstIter;
325  // Verify it is not placed
326  BOOST_REQUIRE_EQUAL(instPtr->getTile().compare(""), 0);
327  BOOST_REQUIRE_EQUAL(instPtr->getSite().compare(""), 0);
328  }
329  // Move to next instance
330  modInstancesBegin++;
331  }
332  // End verify module instances cloning and placement
333 
334  // Begin verify intra net cloning and routing
335  // Get a begin iterator to module nets
336  Design::NetSharedPtrIterator moduleNetsBegin = modPtr->netsBegin();
337  // Get an end iterator to module nets
338  Design::NetSharedPtrIterator moduleNetsEnd = modPtr->netsEnd();
339  // Iterate over all module nets
340  while(moduleNetsBegin != moduleNetsEnd) {
341  // Get a pointer to the current net
342  NetSharedPtr moduleNetPtr = *moduleNetsBegin;
343  // Search for corresponding flattened net in design
344  Design::NetSharedPtrIterator designNetIter = inDesignPtr->findNet(sModuleInstanceName +
345  sHierarchySeparator + moduleNetPtr->getName());
346  // Verify net is cloned and moved to design
347  BOOST_REQUIRE(designNetIter != inDesignPtr->netsEnd());
348  // Get a pointer to the cloned design net
349  NetSharedPtr designNetPtr = *designNetIter;
350  // Verify routing
351  if(!inKeepRouting) {
352  BOOST_REQUIRE(designNetPtr->pipsBegin() == designNetPtr->pipsEnd());
353  }
354  // Move to next net
355  moduleNetsBegin++;
356  }
357  // End verify intra net migration and routing
358 
359  // Begin verify inter nets does not reference module instance & routing
360  // Get a begin iterator to design nets
361  Design::NetSharedPtrIterator designNetsBegin = inDesignPtr->netsBegin();
362  // Get an end iterator to design nets
363  Design::NetSharedPtrIterator designNetsEnd = inDesignPtr->netsEnd();
364  // Iterate over all design nets
365  while(designNetsBegin != designNetsEnd) {
366  // Get a pointer to the current net
367  NetSharedPtr designNetPtr = *designNetsBegin;
368  // Get a begin iterator to net sources
369  Net::InstancePinSharedPtrIterator designNetSourcesBegin = designNetPtr->sourcesBegin();
370  // Get an end iterator to net sources
371  Net::InstancePinSharedPtrIterator designNetSourcesEnd = designNetPtr->sourcesEnd();
372  // Iterate over all net source
373  while(designNetSourcesBegin != designNetSourcesEnd) {
374  // Get a pointer to the current net source pin
375  InstancePinSharedPtr instPinPtr = *designNetSourcesBegin;
376  // Get a pointer to the instance hosting the net source pin
377  InstanceSharedPtr pinInstPtr = instPinPtr->getInstancePtr().lock();
378  // Verify net does not point to flattened module instance
379  BOOST_REQUIRE_NE(pinInstPtr->getName().compare(sModuleInstanceName), 0);
380 
381  // Was this an inter net once?
382  if((pinInstPtr->getName()).find(sModuleInstanceName + sHierarchySeparator)
383  != string::npos) {
384  // Verify routing
385  if(!inKeepRouting) {
386  BOOST_REQUIRE(designNetPtr->pipsBegin() == designNetPtr->pipsEnd());
387  }
388  }
389  // Move to next source
390  designNetSourcesBegin++;
391  }
392  // Get a begin iterator to net sinks
393  Net::InstancePinSharedPtrIterator designNetSinksBegin = designNetPtr->sinksBegin();
394  // Get an end iterator to net sinks
395  Net::InstancePinSharedPtrIterator designNetSinksEnd = designNetPtr->sinksEnd();
396  // Iterate over all net source
397  while(designNetSinksBegin != designNetSinksEnd) {
398  // Get a pointer to the current net source pin
399  InstancePinSharedPtr instPinPtr = *designNetSinksBegin;
400  // Get a pointer to the instance hosting the net source pin
401  InstanceSharedPtr pinInstPtr = instPinPtr->getInstancePtr().lock();
402  // Verify net does not point to flattened module instance
403  BOOST_REQUIRE_NE(pinInstPtr->getName().compare(sModuleInstanceName), 0);
404  // Was this an inter net once?
405  if((pinInstPtr->getName()).find(sModuleInstanceName + sHierarchySeparator)
406  != string::npos) {
407  // Verify routing
408  if(!inKeepRouting) {
409  BOOST_REQUIRE(designNetPtr->pipsBegin() == designNetPtr->pipsEnd());
410  }
411  }
412  // Move to next sink
413  designNetSinksBegin++;
414  }
415  // Move to next net
416  designNetsBegin++;
417  }
418  // End verify inter nets does not reference module instance & routing
419 }
420 
421 /// \brief Unit test for modularizing two instances with intra net.
422 BOOST_AUTO_TEST_CASE(ModularizeWithIntraNetUnitTest) {
423  // Verify file opened successfully
424  DesignSharedPtr designPtr
425  = verifyDesignOpenedSuccessfully("ModuleTransformerUnitTest.Scenario.01.Modularize.xdl");
426  // Get instances to modularize
427  InstanceSharedPtrVector instPtrVector = getInstancesToModularize(designPtr);
428  // Pre modularization verifications
430  // Create a ModuleTransformer object
431  ModuleTransformer moduleTransfomer(designPtr);
432  // Modularize instances in instPtrVector
433  moduleTransfomer.modularize(instPtrVector, sModuleDefinition, sModuleInstanceName);
434  // Post modularization verifications
435  postModularizationVerifications(designPtr, instPtrVector);
436 }
437 
438 /// \brief Unit test for modularizing two instances with input inter net.
439 BOOST_AUTO_TEST_CASE(ModularizeWithInputInterNetUnitTest) {
440  // Verify file opened successfully
441  DesignSharedPtr designPtr
442  = verifyDesignOpenedSuccessfully("ModuleTransformerUnitTest.Scenario.02.Modularize.xdl");
443  // Get instances to modularize
444  InstanceSharedPtrVector instPtrVector = getInstancesToModularize(designPtr);
445  // Pre modularization verifications
447  // Create a ModuleTransformer object
448  ModuleTransformer moduleTransfomer(designPtr);
449  // Modularize instances in instPtrVector
450  moduleTransfomer.modularize(instPtrVector, sModuleDefinition, sModuleInstanceName);
451  // Post modularization verifications
452  postModularizationVerifications(designPtr, instPtrVector);
453 }
454 
455 /// \brief Unit test for modularizing two instances with input fanout input net.
456 BOOST_AUTO_TEST_CASE(ModularizeWithInputFanoutInterNetUnitTest) {
457  // Verify file opened successfully
458  DesignSharedPtr designPtr
459  = verifyDesignOpenedSuccessfully("ModuleTransformerUnitTest.Scenario.03.Modularize.xdl");
460  // Get instances to modularize
461  InstanceSharedPtrVector instPtrVector = getInstancesToModularize(designPtr);
462  // Pre modularization verifications
464  // Create a ModuleTransformer object
465  ModuleTransformer moduleTransfomer(designPtr);
466  // Modularize instances in instPtrVector
467  moduleTransfomer.modularize(instPtrVector, sModuleDefinition, sModuleInstanceName);
468  // Post modularization verifications
469  postModularizationVerifications(designPtr, instPtrVector);
470 }
471 
472 /// \brief Unit test for modularizing two instances with output inter net.
473 BOOST_AUTO_TEST_CASE(ModularizeWithOutputInterNetUnitTest) {
474  // Verify file opened successfully
475  DesignSharedPtr designPtr
476  = verifyDesignOpenedSuccessfully("ModuleTransformerUnitTest.Scenario.04.Modularize.xdl");
477  // Get instances to modularize
478  InstanceSharedPtrVector instPtrVector = getInstancesToModularize(designPtr);
479  // Pre modularization verifications
481  // Create a ModuleTransformer object
482  ModuleTransformer moduleTransfomer(designPtr);
483  // Modularize instances in instPtrVector
484  moduleTransfomer.modularize(instPtrVector, sModuleDefinition, sModuleInstanceName);
485  // Post modularization verifications
486  postModularizationVerifications(designPtr, instPtrVector);
487 }
488 
489 /// \brief Unit test for modularizing two instances with output fanout inter net.
490 BOOST_AUTO_TEST_CASE(ModularizeWithOutputFanoutInterNetUnitTest) {
491  // Verify file opened successfully
492  DesignSharedPtr designPtr
493  = verifyDesignOpenedSuccessfully("ModuleTransformerUnitTest.Scenario.05.Modularize.xdl");
494  // Get instances to modularize
495  InstanceSharedPtrVector instPtrVector = getInstancesToModularize(designPtr);
496  // Pre modularization verifications
498  // Create a ModuleTransformer object
499  ModuleTransformer moduleTransfomer(designPtr);
500  // Modularize instances in instPtrVector
501  moduleTransfomer.modularize(instPtrVector, sModuleDefinition, sModuleInstanceName);
502  // Post modularization verifications
503  postModularizationVerifications(designPtr, instPtrVector);
504 }
505 
506 /// \brief Unit test for modularizing two instances with fanout intra and inter net.
507 BOOST_AUTO_TEST_CASE(ModularizeWithIntraAndInterNetUnitTest) {
508  // Verify file opened successfully
509  DesignSharedPtr designPtr
510  = verifyDesignOpenedSuccessfully("ModuleTransformerUnitTest.Scenario.06.Modularize.xdl");
511  // Get instances to modularize
512  InstanceSharedPtrVector instPtrVector = getInstancesToModularize(designPtr);
513  // Pre modularization verifications
515  // Create a ModuleTransformer object
516  ModuleTransformer moduleTransfomer(designPtr);
517  // Modularize instances in instPtrVector
518  moduleTransfomer.modularize(instPtrVector, sModuleDefinition, sModuleInstanceName);
519  // Post modularization verifications
520  postModularizationVerifications(designPtr, instPtrVector);
521 }
522 // End modularization tests
523 
524 // Begin flattening tests
525 /// \brief Unit test for flattening a module with two instances and an intra net.
526 BOOST_AUTO_TEST_CASE(FlattenWithIntraNetUnitTest) {
527  // Verify file opened successfully
528  DesignSharedPtr designPtr
529  = verifyDesignOpenedSuccessfully("ModuleTransformerUnitTest.Scenario.01.Flatten.xdl");
530  // Pre flattening verifications
531  preFlatteningVerifications(designPtr);
532  // Create a ModuleTransformer object
533  ModuleTransformer moduleTransfomer(designPtr);
534  // Flatten sModuleInstanceName
535  moduleTransfomer.flatten(sModuleInstanceName);
536  // Post flattening verifications
537  postFlatteningVerifications(designPtr);
538 }
539 
540 /// \brief Unit test for flattening two instances with input inter net.
541 BOOST_AUTO_TEST_CASE(FlattenWithInputInterNetUnitTest) {
542  // Verify file opened successfully
543  DesignSharedPtr designPtr
544  = verifyDesignOpenedSuccessfully("ModuleTransformerUnitTest.Scenario.02.Flatten.xdl");
545  // Pre flattening verifications
546  preFlatteningVerifications(designPtr);
547  // Create a ModuleTransformer object
548  ModuleTransformer moduleTransfomer(designPtr);
549  // Flatten sModuleInstanceName
550  moduleTransfomer.flatten(sModuleInstanceName);
551  // Post flattening verifications
552  postFlatteningVerifications(designPtr);
553 }
554 
555 /// \brief Unit test for flattening two instances with input fanout input net.
556 BOOST_AUTO_TEST_CASE(FlattenWithInputFanoutInterNetUnitTest) {
557  // Verify file opened successfully
558  DesignSharedPtr designPtr
559  = verifyDesignOpenedSuccessfully("ModuleTransformerUnitTest.Scenario.03.Flatten.xdl");
560  // Pre flattening verifications
561  preFlatteningVerifications(designPtr);
562  // Create a ModuleTransformer object
563  ModuleTransformer moduleTransfomer(designPtr);
564  // Flatten sModuleInstanceName
565  moduleTransfomer.flatten(sModuleInstanceName);
566  // Post flattening verifications
567  postFlatteningVerifications(designPtr);
568 }
569 
570 /// \brief Unit test for flattening two instances with output inter net.
571 BOOST_AUTO_TEST_CASE(FlattenWithOutputInterNetUnitTest) {
572  // Verify file opened successfully
573  DesignSharedPtr designPtr
574  = verifyDesignOpenedSuccessfully("ModuleTransformerUnitTest.Scenario.04.Flatten.xdl");
575  // Pre flattening verifications
576  preFlatteningVerifications(designPtr);
577  // Create a ModuleTransformer object
578  ModuleTransformer moduleTransfomer(designPtr);
579  // Flatten sModuleInstanceName
580  moduleTransfomer.flatten(sModuleInstanceName);
581  // Post flattening verifications
582  postFlatteningVerifications(designPtr);
583 }
584 
585 /// \brief Unit test for flattening two instances with output fanout inter net.
586 BOOST_AUTO_TEST_CASE(FlattenWithOutputFanoutInterNetUnitTest) {
587  // Verify file opened successfully
588  DesignSharedPtr designPtr
589  = verifyDesignOpenedSuccessfully("ModuleTransformerUnitTest.Scenario.05.Flatten.xdl");
590  // Pre flattening verifications
591  preFlatteningVerifications(designPtr);
592  // Create a ModuleTransformer object
593  ModuleTransformer moduleTransfomer(designPtr);
594  // Flatten sModuleInstanceName
595  moduleTransfomer.flatten(sModuleInstanceName);
596  // Post flattening verifications
597  postFlatteningVerifications(designPtr);
598 }
599 
600 /// \brief Unit test for flattening two instances with fanout intra and inter net.
601 BOOST_AUTO_TEST_CASE(FlattenWithIntraAndInterNetUnitTest) {
602  // Verify file opened successfully
603  DesignSharedPtr designPtr
604  = verifyDesignOpenedSuccessfully("ModuleTransformerUnitTest.Scenario.06.Flatten.xdl");
605  // Pre flattening verifications
606  preFlatteningVerifications(designPtr);
607  // Create a ModuleTransformer object
608  ModuleTransformer moduleTransfomer(designPtr);
609  // Flatten sModuleInstanceName
610  moduleTransfomer.flatten(sModuleInstanceName);
611  // Post flattening verifications
612  postFlatteningVerifications(designPtr);
613 }
614 
615 // End flattening tests
616 
617 BOOST_AUTO_TEST_SUITE_END()
618 
619 BOOST_AUTO_TEST_SUITE_END()
620 
621 } // namespace physical
622 } // namespace torc
void postModularizationVerifications(DesignSharedPtr inDesignPtr, InstanceSharedPtrVector inInstanceVector, bool inKeepPlacement=false, bool inKeepRouting=false)
Perform post-modularization tests on a design.
Utility class to modularize/flatten designs.
static const string sModuleDefinition
std::vector< InstanceSharedPtr > InstanceSharedPtrVector
Vector of Instance shared pointers.
ModuleTransformer class to modularize/flatten designs.
DesignSharedPtr getDesignPtr(void)
Returns a shared pointer for the design.
Header for the DirectoryTree class.
InstancePinSharedPtrVector::iterator InstancePinSharedPtrIterator
Non-constant iterator to InstancePin shared pointer objects.
InstanceSharedPtrVector::const_iterator InstanceSharedPtrConstIterator
Constant iterator to Instance shared pointers.
Definition: Circuit.hpp:72
void postFlatteningVerifications(DesignSharedPtr inDesignPtr, bool inKeepPlacement=false, bool inKeepRouting=false)
Perform post-flattening tests on a design.
boost::shared_ptr< class InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.
BOOST_AUTO_TEST_CASE(XdlUnpackUnitTest)
Unit test for the XdlUnpack class.
static const string sModuleInstanceName
boost::shared_ptr< Module > ModuleSharedPtr
Shared pointer encapsulation of a Module.
Definition: Module.hpp:114
Header for the XdlImporter class.
Header for the XdlExport class.
bool flatten(const string &inModuleInstanceName, bool inKeepPlacement=false, bool inKeepRouting=false)
Flatten a module instance in a design.
Header for the Design class.
static const string sInstanceOneName
boost::shared_ptr< Net > NetSharedPtr
Shared pointer encapsulation of a Net.
boost::filesystem::path path
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
NetSharedPtrVector::iterator NetSharedPtrIterator
Non-constant iterator to Net shared pointers.
Definition: Circuit.hpp:78
bool modularize(const InstanceSharedPtrVector &inInstances, const string &inModuleDefinitionName, const string &inModuleInstanceName, bool inKeepPlacement=false, bool inKeepRouting=false)
Group a set of instances into a module.
Importer from XDL format into a physical design.
ModuleSharedPtrVector::iterator ModuleSharedPtrIterator
Non-constant iterator for Module shared pointers.
DesignSharedPtr verifyDesignOpenedSuccessfully(const string &inDesignFileName)
Verify that the design file opened successfully.
void preModularizationVerifications(DesignSharedPtr inDesignPtr)
Perform pre-modularization tests on a design.
Header for the Factory class.
InstanceSharedPtrVector getInstancesToModularize(DesignSharedPtr inDesignPtr)
Retrieve the instances to modularize from the design and return them in a vector. ...
static const boost::filesystem::path & getExecutablePath(void)
Returns the absolute path to the executable directory.
void preFlatteningVerifications(DesignSharedPtr inDesignPtr)
Perform pre-flattening tests on a design.
InstanceSharedPtrVector::iterator InstanceSharedPtrIterator
Non-constant iterator to Instance shared pointers.
Definition: Circuit.hpp:74
static const string sHierarchySeparator
static const string sInstanceTwoName