torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CircuitUnitTest.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 Circuit 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 typedef boost::shared_ptr<class RenamableInstance> RenamableInstanceSharedPtr;
29 class RenamableInstance : public Instance {
30 public:
31  void setName(const string& inName) { mName = inName; }
32  static RenamableInstanceSharedPtr& recast(InstanceSharedPtr& inInstancePtr) {
33  return reinterpret_cast<RenamableInstanceSharedPtr&>(inInstancePtr);
34  }
35 };
36 
37 /// \brief Unit test for the Circuit class.
38 BOOST_AUTO_TEST_CASE(CircuitUnitTest) {
39  // functions tested:
40  // Circuit(const string& inName);
41  // size_t getInstanceCount(void) const;
42  // size_t getNetCount(void) const;
43  // InstanceSharedPtrIterator instancesBegin(void);
44  // InstanceSharedPtrIterator instancesEnd(void);
45  // InstanceSharedPtrIterator netsBegin(void);
46  // InstanceSharedPtrIterator netsEnd(void);
47  // create a module, since we cannot create a circuit directly
48  ModuleSharedPtr circuitPtr = Factory::newModulePtr("module", "anchor");
49  // verify that the circuit exists, and that it is empty
50  BOOST_REQUIRE(circuitPtr.get() != 0);
51  BOOST_CHECK(circuitPtr->getInstanceCount() == 0);
52  BOOST_CHECK(circuitPtr->getNetCount() == 0);
53  BOOST_CHECK(circuitPtr->instancesBegin() == circuitPtr->instancesEnd());
54  BOOST_CHECK(circuitPtr->netsBegin() == circuitPtr->netsEnd());
55 
56  // create a few instances and nets, and add them to the circuit
57  InstanceSharedPtr instance1aPtr = Factory::newInstancePtr("instance", "SLICEL", "CLBLL_X16Y59",
58  "SLICE_X27Y59");
59  InstanceSharedPtr instance1bPtr = Factory::newInstancePtr("instance", "dummy", "dummy",
60  "dummy"); // deliberate reuse of instance name
61  NetSharedPtr net1Ptr = Factory::newNetPtr("net1");
62  net1Ptr->addPip(Factory::newPip("CLBLL_X16Y59", "L_DQ", "SITE_LOGIC_OUTS3",
64  NetSharedPtr net2aPtr = Factory::newNetPtr("net2");
65  NetSharedPtr net2bPtr = Factory::newNetPtr("net2"); // deliberate reuse of net name
66  NetSharedPtr net3Ptr = Factory::newNetPtr("net3");
67  //RenamableInstance::recast(instance1aPtr)->setName("goodbye");
68 
69  // functions tested:
70  // bool addInstance(InstanceSharedPtr& inInstancePtr);
71  // bool addNet(NetSharedPtr& inNetPtr);
72  // InstanceSharedPtrIterator findInstance(const string& inName);
73  // NetSharedPtrIterator findNet(const string& inName);
74  // size_t getInstanceCount(void) const;
75  // size_t getNetCount(void) const;
76  BOOST_CHECK_EQUAL(circuitPtr->addInstance(instance1aPtr), true);
77  BOOST_CHECK_EQUAL(circuitPtr->addInstance(instance1bPtr), false); // name already exists
78  BOOST_CHECK_EQUAL(circuitPtr->addNet(net1Ptr), true);
79  BOOST_CHECK_EQUAL(circuitPtr->addNet(net2aPtr), true);
80  BOOST_CHECK_EQUAL(circuitPtr->addNet(net2bPtr), false); // name already exists
81  BOOST_CHECK_EQUAL(circuitPtr->addNet(net3Ptr), true);
82  BOOST_CHECK(circuitPtr->getInstanceCount() == 1);
83  BOOST_CHECK(circuitPtr->getNetCount() == 3);
84 
85  // functions tested:
86  // void unplace(void);
87  // void unroute(void);
88  // unplace and unroute the circuit
89  BOOST_CHECK(instance1aPtr->getTile().length() != 0);
90  BOOST_CHECK(instance1aPtr->getSite().length() != 0);
91  BOOST_CHECK(net1Ptr->getPipCount() != 0);
92  circuitPtr->unplace();
93  circuitPtr->unroute();
94  BOOST_CHECK(instance1aPtr->getTile().length() == 0);
95  BOOST_CHECK(instance1aPtr->getSite().length() == 0);
96  BOOST_CHECK(net1Ptr->getPipCount() == 0);
97 
98  // functions tested:
99  // bool removeInstance(InstanceSharedPtr& inInstancePtr);
100  // bool removeNet(NetSharedPtr& inNetPtr);
101  // size_t getInstanceCount(void) const;
102  // size_t getNetCount(void) const;
103  // find and remove instances and nets
104  BOOST_CHECK(circuitPtr->removeInstance(*circuitPtr->findInstance("instance")));
105  BOOST_CHECK(circuitPtr->removeNet(*circuitPtr->findNet("net1")));
106  BOOST_CHECK(circuitPtr->removeNet(*circuitPtr->findNet("net2")));
107  BOOST_CHECK(circuitPtr->removeNet(*circuitPtr->findNet("net3")));
108  BOOST_CHECK(circuitPtr->getInstanceCount() == 0);
109  BOOST_CHECK(circuitPtr->getNetCount() == 0);
110 }
111 
112 BOOST_AUTO_TEST_SUITE_END()
113 
114 } // namespace physical
115 } // namespace torc
static NetSharedPtr newNetPtr(const string &inName, ENetType inNetType=eNetTypeNormal)
Create and return a new Net share pointer.
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
Physical design instance.
static torc::physical::Pip newPip(const string &inTileName, const string &inSourceWireName, const string &inSinkWireName, EPipDirection inPipDirection, RoutethroughSharedPtr inRoutethroughPtr=RoutethroughSharedPtr())
Construct a pip and return it.
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.
boost::shared_ptr< class RenamableInstance > RenamableInstanceSharedPtr
static ModuleSharedPtr newModulePtr(const string &inName, const string &inAnchor)
Create and return a new Module shared pointer.
Header for the Circuit class.
static RenamableInstanceSharedPtr & recast(InstanceSharedPtr &inInstancePtr)
Header for the Factory class.
void setName(const string &inName)