torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InstanceUnitTest.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 Instance class.
18 
19 #include <boost/test/unit_test.hpp>
22 
23 namespace torc {
24 namespace physical {
25 
26 BOOST_AUTO_TEST_SUITE(physical)
27 
28 /// \brief Unit test for the Instance class.
29 BOOST_AUTO_TEST_CASE(InstanceUnitTest) {
30  // create accessory instances and module
31  std::string name = "name";
32  std::string type = "type";
33  std::string tile = "tile";
34  std::string site = "site";
35  ModuleSharedPtr modulePtr = Factory::newModulePtr("name", "anchor");
36  InstanceSharedPtr instance2Ptr = Factory::newInstancePtr(name, "type", "tile", "site");
37  InstanceReferenceSharedPtr instanceReferencePtr = Factory::newInstanceReferencePtr("name",
38  modulePtr, instance2Ptr);
39 
40  // functions tested:
41  // Instance(const string& inName, const string& inType, const string& inTile,
42  // const string& inSite, EInstanceBonding inBonding,
43  // InstanceReferenceSharedPtr& inInstanceReferencePtr);
44  // create an instance
46  InstanceSharedPtr instance1Ptr = Factory::newInstancePtr(name, "", "", "");
47  BOOST_REQUIRE(instance1Ptr != 0);
48 
49  // functions tested:
50  // void setType(const string& inType);
51  // void setTile(const string& inTile);
52  // void setSite(const string& inSite);
53  // void setBonding(EInstanceBonding inBonding);
54  // void setInstanceReferencePtr(InstanceReferenceSharedPtr inInstanceReferenceSharedPtr);
55  // const string& getType(void) const;
56  // const string& getTile(void) const;
57  // const string& getSite(void) const;
58  // EInstanceBonding getBonding(void) const;
59  // InstanceReferenceSharedPtr getInstanceReferencePtr(void) const;
60  BOOST_CHECK(instance1Ptr->getType().empty());
61  BOOST_CHECK(instance1Ptr->getTile().empty());
62  BOOST_CHECK(instance1Ptr->getSite().empty());
63  BOOST_CHECK(instance1Ptr->getBonding() == eInstanceBondingUnknown);
64  instance1Ptr->setType(type);
65  instance1Ptr->setTile(tile);
66  instance1Ptr->setSite(site);
67  instance1Ptr->setBonding(bonding);
68  instance1Ptr->setInstanceReferencePtr(instanceReferencePtr);
69  BOOST_CHECK(instance1Ptr->getType() == type);
70  BOOST_CHECK(instance1Ptr->getTile() == tile);
71  BOOST_CHECK(instance1Ptr->getSite() == site);
72  BOOST_CHECK(instance1Ptr->getBonding() == bonding);
73  BOOST_CHECK(instance1Ptr->getInstanceReferencePtr() == instanceReferencePtr);
74 
75  // functions tested:
76  // bool operator ==(const Instance& rhs) const;
77  BOOST_CHECK(*instance1Ptr == *instance2Ptr); // comparison based on instance names only
78 
79  // functions tested:
80  // void unplace(void);
81  instance1Ptr->unplace();
82  BOOST_CHECK(instance1Ptr->getTile().empty());
83  BOOST_CHECK(instance1Ptr->getSite().empty());
84 
85  // functions tested:
86  // void addPin(const InstancePinWeakPtr& inInstancePinPtr);
87  // void removePin(const InstancePinWeakPtr& inInstancePinPtr);
88  // const InstancePinSharedPtrConstIterator findPin(const PinName& inPinName);
89  PinName pinName1("name1");
90  PinName pinName2("name2");
91  InstancePinSharedPtr instancePin1Ptr = Factory::newInstancePinPtr(instance1Ptr, pinName1);
92  InstancePinSharedPtr instancePin2Ptr = Factory::newInstancePinPtr(instance1Ptr, pinName1);
93  InstancePinSharedPtr instancePin3Ptr = Factory::newInstancePinPtr(instance1Ptr, pinName2);
94  NetSharedPtr netPtr = Factory::newNetPtr("name");
95  netPtr->addSource(instancePin1Ptr);
96  netPtr->addSource(instancePin2Ptr);
97  netPtr->addSink(instancePin3Ptr);
98  BOOST_CHECK_EQUAL(instance1Ptr->getPinCount(), 3u);
99  BOOST_CHECK_EQUAL(instance1Ptr->getPinCount(pinName1), 2u);
100  BOOST_CHECK_EQUAL(instance1Ptr->getPinCount(pinName2), 1u);
101  Instance::InstancePinSharedPtrConstIterator ipp = instance1Ptr->findPin(pinName1);
102  Instance::InstancePinSharedPtrConstIterator ipe = instance1Ptr->pinsEnd();
103  BOOST_REQUIRE(ipp != ipe);
104  BOOST_CHECK(ipp->second == instancePin1Ptr);
105  BOOST_CHECK_EQUAL(ipp->second->getPinName(), pinName1);
106  BOOST_CHECK_EQUAL(ipp->second->getPinName(), ipp->first);
107  BOOST_CHECK(ipp->second->getParentWeakPtr().lock() == netPtr);
109  Instance::InstancePinSharedPtrConstIterator> range = instance1Ptr->findPinRange(pinName1);
110  BOOST_REQUIRE(range.first != range.second);
111  BOOST_CHECK_EQUAL(range.first->second->getPinName(), pinName1); range.first++;
112  BOOST_CHECK_EQUAL(range.first->second->getPinName(), pinName1); range.first++;
113  BOOST_CHECK(range.first == range.second);
114  netPtr->removeSource(instancePin2Ptr);
115  netPtr->removeSink(instancePin3Ptr);
116  BOOST_CHECK_EQUAL(instance1Ptr->getPinCount(), 1u);
117  BOOST_CHECK_EQUAL(instance1Ptr->getPinCount(pinName1), 1u);
118  BOOST_CHECK_EQUAL(instance1Ptr->getPinCount(pinName2), 0u);
119  ipp = instance1Ptr->findPin(pinName1);
120  ipe = instance1Ptr->pinsEnd();
121  BOOST_REQUIRE(ipp != ipe);
122  BOOST_CHECK(ipp->second == instancePin1Ptr);
123  BOOST_CHECK_EQUAL(ipp->second->getPinName(), pinName1);
124  BOOST_CHECK_EQUAL(ipp->second->getPinName(), ipp->first);
125  BOOST_CHECK(ipp->second->getParentWeakPtr().lock() == netPtr);
126 }
127 
128 BOOST_AUTO_TEST_SUITE_END()
129 
130 } // namespace physical
131 } // namespace torc
EInstanceBonding
Enumeration of pad bonding types.
Encapsulation of a site pin name.
Header for the Instance class.
static NetSharedPtr newNetPtr(const string &inName, ENetType inNetType=eNetTypeNormal)
Create and return a new Net share pointer.
boost::shared_ptr< class InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.
std::string string
BOOST_AUTO_TEST_CASE(XdlUnpackUnitTest)
Unit test for the XdlUnpack class.
boost::shared_ptr< Module > ModuleSharedPtr
Shared pointer encapsulation of a Module.
Definition: Module.hpp:114
InstancePinMap::const_iterator InstancePinSharedPtrConstIterator
Constant iterator to InstancePin shared pointers.
boost::shared_ptr< Net > NetSharedPtr
Shared pointer encapsulation of a Net.
static InstanceSharedPtr newInstancePtr(const string &inName, const string &inType, const string &inTile, const string &inSite, EInstanceBonding inBonding=eInstanceBondingUnknown, InstanceReferenceSharedPtr inInstanceReferencePtr=InstanceReferenceSharedPtr())
Construct and return a new Instance shared pointer.
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
static InstancePinSharedPtr newInstancePinPtr(InstanceSharedPtr inInstancePtr, const string &inPinName)
Construct and return a new InstancePin shared pointer.
static ModuleSharedPtr newModulePtr(const string &inName, const string &inAnchor)
Create and return a new Module shared pointer.
Header for the Factory class.
boost::shared_ptr< InstanceReference > InstanceReferenceSharedPtr
Shared pointer encapsulation of an InstanceReference.
static InstanceReferenceSharedPtr newInstanceReferencePtr(const string &inInstantiationName, ModuleSharedPtr inModulePtr, InstanceSharedPtr inInstancePtr)
Create and return a new InstanceReference shared pointer.