torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NetUnitTest.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 Net class.
18 
19 #include <boost/test/unit_test.hpp>
21 #include "torc/physical/Net.hpp"
22 
23 namespace torc {
24 namespace physical {
25 
26 BOOST_AUTO_TEST_SUITE(physical)
27 
28 /// \brief Unit test for the Net class.
29 BOOST_AUTO_TEST_CASE(NetUnitTest) {
30  // accessory instance and pins
31  std::string name = "name";
32  // create accessory instance, pins, and pips
33  InstanceSharedPtr instancePtr = Factory::newInstancePtr("name", "type", "tile", "site");
34  InstancePinSharedPtr pin1Ptr = Factory::newInstancePinPtr(instancePtr, "pin1");
35  InstancePinSharedPtr pin2Ptr = Factory::newInstancePinPtr(instancePtr, "pin2");
36  InstancePinSharedPtr pin3Ptr = Factory::newInstancePinPtr(instancePtr, "pin3");
37  InstancePinSharedPtr pin4Ptr = Factory::newInstancePinPtr(instancePtr, "pin4");
38  Pip pip1 = Factory::newPip("tile", "source1", "sink1", ePipUnidirectionalBuffered);
39  Pip pip2 = Factory::newPip("tile", "source2", "sink2", ePipUnidirectionalBuffered);
40  Pip pip3 = Factory::newPip("tile", "source3", "sink3", ePipUnidirectionalBuffered);
41 
42  // functions tested:
43  // Net(const string& inName, ENetType inNetType);
44  ENetType normal = eNetTypeNormal;
45  ENetType power = eNetTypePower;
46  ENetType ground = eNetTypeGround;
47  NetSharedPtr net1Ptr = Factory::newNetPtr(name);
48  NetSharedPtr net2Ptr = Factory::newNetPtr(name, power);
49  BOOST_REQUIRE(net1Ptr != 0);
50  BOOST_REQUIRE(net2Ptr != 0);
51 
52  // functions tested:
53  // ENetType getNetType(void) const;
54  // void setNetType(ENetType inNetType);
55  BOOST_CHECK(net1Ptr->getNetType() == normal);
56  BOOST_CHECK(net2Ptr->getNetType() == power);
57  net2Ptr->setNetType(ground);
58  BOOST_CHECK(net2Ptr->getNetType() == ground);
59 
60  // functions tested:
61  // void addSource(const InstancePin& inInstancePin);
62  // void addSink(const InstancePin& inInstancePin);
63  // bool containsSource(const InstancePin& inInstancePin) const;
64  // bool containsSink(const InstancePin& inInstancePin) const;
65  // bool hasAnySources(void) const;
66  // bool hasOneSource(void) const;
67  // bool hasMultipleSources(void) const;
68  // size_t getSourceCount(void) const;
69  // bool hasAnySinks(void) const;
70  // bool hasOneSink(void) const;
71  // bool hasMultipleSinks(void) const;
72  // size_t getSinkCount(void) const;
73  net1Ptr->addSource(pin1Ptr);
74  net1Ptr->addSink(pin2Ptr);
75  net1Ptr->addSink(pin3Ptr);
76  net1Ptr->addSink(pin4Ptr);
77  BOOST_CHECK_EQUAL(net1Ptr->containsSource(pin1Ptr), true);
78  BOOST_CHECK_EQUAL(net1Ptr->containsSink(pin1Ptr), false);
79  BOOST_CHECK_EQUAL(net1Ptr->containsSink(pin2Ptr), true);
80  BOOST_CHECK_EQUAL(net1Ptr->containsSink(pin3Ptr), true);
81  BOOST_CHECK_EQUAL(net1Ptr->containsSink(pin4Ptr), true);
82  BOOST_CHECK_EQUAL(net1Ptr->hasAnySources(), true);
83  BOOST_CHECK_EQUAL(net1Ptr->hasOneSource(), true);
84  BOOST_CHECK_EQUAL(net1Ptr->hasMultipleSources(), false);
85  BOOST_CHECK(net1Ptr->getSourceCount() == 1);
86  BOOST_CHECK_EQUAL(net1Ptr->hasAnySinks(), true);
87  BOOST_CHECK_EQUAL(net1Ptr->hasOneSink(), false);
88  BOOST_CHECK_EQUAL(net1Ptr->hasMultipleSinks(), true);
89  BOOST_CHECK(net1Ptr->getSinkCount() == 3);
90 
91  // functions tested:
92  // bool removeSource(const InstancePin& inInstancePin);
93  // bool removeSink(const InstancePin& inInstancePin);
94  // InstancePinConstIterator sourcesBegin(void) const;
95  // InstancePinConstIterator sourcesEnd(void) const;
96  // InstancePinConstIterator sinksBegin(void) const;
97  // InstancePinConstIterator sinksEnd(void) const;
98  Net::InstancePinSharedPtrConstIterator op = net1Ptr->sourcesBegin();
99  Net::InstancePinSharedPtrConstIterator oe = net1Ptr->sourcesEnd();
100  BOOST_CHECK(*op++ == pin1Ptr);
101  BOOST_CHECK(op == oe);
102  BOOST_CHECK_EQUAL(net1Ptr->removeSource(pin1Ptr), true);
103  BOOST_CHECK_EQUAL(net1Ptr->removeSource(pin2Ptr), false);
104  BOOST_CHECK(net1Ptr->getSourceCount() == 0);
105  Net::InstancePinSharedPtrConstIterator ip = net1Ptr->sinksBegin();
106  Net::InstancePinSharedPtrConstIterator ie = net1Ptr->sinksEnd();
107  BOOST_CHECK(*ip++ == pin2Ptr);
108  BOOST_CHECK(*ip++ == pin3Ptr);
109  BOOST_CHECK(*ip++ == pin4Ptr);
110  BOOST_CHECK(ip == ie);
111  BOOST_CHECK_EQUAL(net1Ptr->removeSink(pin1Ptr), false);
112  BOOST_CHECK_EQUAL(net1Ptr->removeSink(pin2Ptr), true);
113  BOOST_CHECK_EQUAL(net1Ptr->removeSink(pin3Ptr), true);
114  BOOST_CHECK_EQUAL(net1Ptr->removeSink(pin4Ptr), true);
115  BOOST_CHECK(net1Ptr->getSinkCount() == 0);
116 
117  // functions tested:
118  // void addPip(const Pip& inPip);
119  // bool containsPip(const Pip& inPip) const;
120  // bool hasAnyPips(void) const;
121  // size_t getPipCount(void) const;
122  // bool isRouted(void) const;
123  // bool isUnrouted(void) const;
124  net1Ptr->addPip(pip1);
125  net1Ptr->addPip(pip2);
126  net1Ptr->addPip(pip3);
127  BOOST_CHECK_EQUAL(net1Ptr->containsPip(pip1), true);
128  BOOST_CHECK_EQUAL(net1Ptr->containsPip(pip2), true);
129  BOOST_CHECK_EQUAL(net1Ptr->containsPip(pip3), true);
130  BOOST_CHECK_EQUAL(net1Ptr->hasAnyPips(), true);
131  BOOST_CHECK_EQUAL(net1Ptr->isRouted(), true);
132  BOOST_CHECK_EQUAL(net1Ptr->isUnrouted(), false);
133  BOOST_CHECK(net1Ptr->getPipCount() == 3);
134 
135  // functions tested:
136  // bool removePip(const Pip& inPip);
137  // void unroute(void);
138  // PipConstIterator pipsBegin(void) const;
139  // PipConstIterator pipsEnd(void) const;
140  // size_t getPipCount(void) const;
141  // bool isRouted(void) const;
142  // bool isUnrouted(void) const;
143  Net::PipConstIterator pp = net1Ptr->pipsBegin();
144  Net::PipConstIterator pe = net1Ptr->pipsEnd();
145  BOOST_CHECK(*pp++ == pip1);
146  BOOST_CHECK(*pp++ == pip2);
147  BOOST_CHECK(*pp++ == pip3);
148  BOOST_CHECK(pp == pe);
149  BOOST_CHECK_EQUAL(net1Ptr->removePip(pip1), true);
150  BOOST_CHECK_EQUAL(net1Ptr->removePip(pip1), false);
151  BOOST_CHECK_EQUAL(net1Ptr->isRouted(), true);
152  BOOST_CHECK_EQUAL(net1Ptr->isUnrouted(), false);
153  BOOST_CHECK(net1Ptr->getPipCount() == 2);
154  net1Ptr->unroute();
155  BOOST_CHECK_EQUAL(net1Ptr->isRouted(), false);
156  BOOST_CHECK_EQUAL(net1Ptr->isUnrouted(), true);
157  BOOST_CHECK(net1Ptr->getPipCount() == 0);
158 }
159 
160 BOOST_AUTO_TEST_SUITE_END()
161 
162 } // namespace physical
163 } // namespace torc
ENetType
Enumeration of net power types.
PipVector::const_iterator PipConstIterator
Constant iterator to Pip objects.
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.
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.
InstancePinSharedPtrVector::const_iterator InstancePinSharedPtrConstIterator
Constant iterator to InstancePin shared pointer objects.
Physical design programmable interconnect point.
Definition: Pip.hpp:34
Header for the Net class.
static InstancePinSharedPtr newInstancePinPtr(InstanceSharedPtr inInstancePtr, const string &inPinName)
Construct and return a new InstancePin shared pointer.
Header for the Factory class.