torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PrimitiveStructureUnitTest.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 the PrimitiveStructure class.
18 
19 #include <boost/test/unit_test.hpp>
25 #include "torc/physical/Net.hpp"
26 #include <iostream>
27 #include <fstream>
28 
29 namespace torc {
30 namespace packer {
31 
32 BOOST_AUTO_TEST_SUITE(packer)
33 
34 /// \brief Unit test for the PrimitiveStructure class.
35 BOOST_AUTO_TEST_CASE(PrimitiveStructureUnitTest) {
36 
37  using namespace torc::architecture;
38  // open and initialize a database
39 // DDB ddb("xc7v285t");
40 // DDB ddb("xc6vlx75t");
41  DDB ddb("xc5vlx30");
42 // DDB ddb("xc4vlx15");
43 // DDB ddb("xc2vp4");
44 // DDB ddb("xc2v40");
45 // DDB ddb("xcv50e");
46 // DDB ddb("xcv50");
47  // look up the logic sites in the device
48  const Sites& sites = ddb.getSites();
49  // define a vector of PrimitiveStructure objects
50  typedef std::map<std::string, PrimitiveStructureSharedPtr> PrimitiveStructuresSharedPtrMap;
51  PrimitiveStructuresSharedPtrMap primitiveStructures;
52  // look up the primitive def types
53  typedef const Array<const PrimitiveDef> PrimitiveDefArray;
54  PrimitiveDefArray& primitiveDefs = sites.getSiteTypes();
55  PrimitiveDefArray::const_iterator p = primitiveDefs.begin();
56  PrimitiveDefArray::const_iterator e = primitiveDefs.end();
57  while(p < e) {
58  // create a PrimitiveStructure object for this PrimitiveDef
59  PrimitiveStructureSharedPtr primitiveStructurePtr(new PrimitiveStructure(&*p++));
60  const torc::architecture::PrimitiveDef* primitiveDefPtr
61  = primitiveStructurePtr->getPrimitiveDefPtr();
62  const std::string& primitiveDefName = primitiveDefPtr->getName();
63  // insert the PrimitiveStructure into the map
64  primitiveStructures[primitiveDefName] = primitiveStructurePtr;
65  }
66 
67  // iterate through the PrimitiveStructure entries in the map
68  // (just to make sure we can read out what we put in)
69  PrimitiveStructuresSharedPtrMap::iterator psp = primitiveStructures.begin();
70  PrimitiveStructuresSharedPtrMap::iterator pse = primitiveStructures.end();
71  while(psp != pse) {
72  // look up the PrimitiveDef name and the PrimitiveStructure object
73  std::string primitiveDefName = psp->first;
74  PrimitiveStructureSharedPtr primitiveStructurePtr = psp->second;
75  (void) primitiveStructurePtr;
76  // const torc::architecture::PrimitiveDef* primitiveDefPtr
77  // = primitiveStructurePtr->getPrimitiveDefPtr();
78  // std::cout << "PrimitiveDef: " << primitiveDefName << std::endl;
79  psp++;
80  }
81 
82 }
83 
84 
85 
86 /// \brief Unit test for the PrimitiveStructure class.
87 BOOST_AUTO_TEST_CASE(PrimitiveStructureInstancePinsUnitTest) {
88 
89  using namespace torc::architecture;
90  // create the appropriate file paths
92  / "torc" / "physical" / "DesignUnitTest.reference.xdl";
94  / "regression" / "DesignUnitTest.generated.xdl";
95 
96  // import the XDL design
97  std::fstream fileStream(referencePath.string().c_str());
98  BOOST_REQUIRE(fileStream.good());
99  XdlImporter importer;
100  importer(fileStream, referencePath.string());
101 
102  // look up the design (and do something with it ...)
103  torc::physical::DesignSharedPtr designPtr = importer.getDesignPtr();
104  BOOST_REQUIRE(designPtr.get() != 0);
105 
106  // look up the device database (and do something with it ...)
107  DDB* ddbPtr = importer.releaseDDBPtr();
108 
109  // look up the logic sites in the device
110  const Sites& sites = ddbPtr->getSites();
111  // define a vector of PrimitiveStructure objects
112  typedef std::map<std::string, PrimitiveStructureSharedPtr> PrimitiveStructuresSharedPtrMap;
113  PrimitiveStructuresSharedPtrMap primitiveStructures;
114  // look up the primitive def types
115  typedef const Array<const PrimitiveDef> PrimitiveDefArray;
116  PrimitiveDefArray& primitiveDefs = sites.getSiteTypes();
117  PrimitiveDefArray::const_iterator p = primitiveDefs.begin();
118  PrimitiveDefArray::const_iterator e = primitiveDefs.end();
119  while(p < e) {
120  // create a PrimitiveStructure object for this PrimitiveDef
121  PrimitiveStructureSharedPtr primitiveStructurePtr(new PrimitiveStructure(&*p++));
122  const torc::architecture::PrimitiveDef* primitiveDefPtr
123  = primitiveStructurePtr->getPrimitiveDefPtr();
124  const std::string& primitiveDefName = primitiveDefPtr->getName();
125  // insert the PrimitiveStructure into the map
126  primitiveStructures[primitiveDefName] = primitiveStructurePtr;
127  }
128 
129  // look up a sample instance
131  = designPtr->findInstance("blink");
132  if(instancePtrIterator == designPtr->instancesEnd()) return;
133  torc::physical::InstanceSharedPtr instancePtr = *instancePtrIterator;
134  PrimitiveStructureSharedPtr primitiveStructurePtr = primitiveStructures[instancePtr->getType()];
135  const PrimitiveDef* primitiveDefPtr = primitiveStructurePtr->getPrimitiveDefPtr();
136  if(primitiveDefPtr == 0) return; // this should not happen for valid instances
137  const PrimitivePinArray& primitivePins = primitiveDefPtr->getPins();
138 
144 
145  // iterate over the instance pins
146  InstancePinSharedPtrVector inputPins;
147  InstancePinSharedPtrVector outputPins;
148  Instance::InstancePinSharedPtrConstIterator ipp = instancePtr->pinsBegin();
149  Instance::InstancePinSharedPtrConstIterator ipe = instancePtr->pinsEnd();
150  while(ipp != ipe) {
151  // look up the instance pin
152  InstancePinSharedPtr instancePinPtr = ipp++->second;
153  const std::string& pinName = instancePinPtr->getPinName();
154  NetSharedPtr netPtr = instancePinPtr->getParentWeakPtr().lock();
155  std::cout << " found " << pinName << " connected to net " << netPtr->getName() << ": ";
156  // determine whether the pin is an output
157  PinIndex pinIndex = primitiveDefPtr->findPinIndexByName(pinName);
158  if(static_cast<boost::int32_t>(pinIndex) < 0) continue; // this shouldn't happen
159  const PrimitivePin& primitivePin = primitivePins[pinIndex];
160  if(primitivePin.isInput()) inputPins.push_back(instancePinPtr);
161  if(primitivePin.isOutput()) outputPins.push_back(instancePinPtr);
162  std::cout << (primitivePin.isInput() ? "INPUT" : (primitivePin.isOutput() ? "OUTPUT" : ""))
163  << std::endl;
164  }
165 
166  // iterate over the input pins
167  InstancePinSharedPtrVector::const_iterator ip;
168  InstancePinSharedPtrVector::const_iterator ie;
169  ip = inputPins.begin();
170  ie = inputPins.end();
171  while(ip != ie) {
172  InstancePinSharedPtr instancePinPtr = *ip++;
173  //std::cout << " found INPUT " << instancePinPtr->getPinName() << std::endl;
174  }
175  // iterate over the output pins
176  ip = outputPins.begin();
177  ie = outputPins.end();
178  while(ip != ie) {
179  InstancePinSharedPtr instancePinPtr = *ip++;
180  //std::cout << " found OUTPUT " << instancePinPtr->getPinName() << std::endl;
181  }
182 
183 }
184 
185 
186 BOOST_AUTO_TEST_SUITE_END()
187 
188 } // namespace architecture
189 } // namespace torc
bool isOutput(void) const
Returns true if this pin is a primitive output.
Device database, including complete wiring and logic support.
Definition: DDB.hpp:42
DesignSharedPtr getDesignPtr(void)
Returns a shared pointer for the design.
Header for the DirectoryTree class.
Header for the Instance class.
Encapsulation of primitive site definition, with associated connections, elements, and pins.
std::vector< InstancePinSharedPtr > InstancePinSharedPtrVector
Vector of InstancePin shared pointers.
Header for the PrimitiveStructure class.
bool isInput(void) const
Returns true if this pin is a primitive input.
Encapsulation of a pin index in an unsigned 32-bit integer.
boost::shared_ptr< class InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.
const Sites & getSites(void) const
Returns a constant reference to the family and device site data.
Definition: DDB.hpp:144
std::string string
Architecture aware importer from XDL format into a physical design.
std::vector< InstancePinSharedPtr > InstancePinSharedPtrVector
Vector of InstancePin shared pointers.
Physical design instance.
boost::shared_ptr< Net > NetSharedPtr
Site type and population data for the family and the device.
Definition: Sites.hpp:45
const Array< const Site > & getSites(void) const
Returns the sites for this family.
Definition: Sites.hpp:127
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.
Encapsulation of a primitive pin's name and flags. Primitive pins are logic site inputs or outputs...
BOOST_AUTO_TEST_CASE(PrimitiveStructureUnitTest)
Unit test for the PrimitiveStructure class.
T * begin(void)
Returns the non-constant begin iterator.
Definition: Array.hpp:95
boost::shared_ptr< PrimitiveStructure > PrimitiveStructureSharedPtr
Shared pointer encapsulation of a PrimitiveStructure.
Header for the DDB class.
Encapsulation of the site index, pin name, and pin flags for a package.
Header for the Net class.
Header for the XdlImporter class.
static const boost::filesystem::path & getExecutablePath(void)
Returns the absolute path to the executable directory.
Encapsulation of a static array.
Definition: Array.hpp:39
boost::shared_ptr< InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.
InstanceSharedPtrVector::iterator InstanceSharedPtrIterator
Non-constant iterator to Instance shared pointers.
Definition: Circuit.hpp:74
const string & getName(void) const
Returns the name of the primitive.