torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RouteNetUnitTest.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 Source for the RouteNet unit test.
18 
19 #include <boost/test/unit_test.hpp>
20 #include "torc/router/RouteNet.hpp"
21 
22 namespace torc {
23 namespace router {
24 
25 BOOST_AUTO_TEST_SUITE(router)
26 
27 /// \brief Unit test for the Net class.
29  typedef architecture::Tilewire Tilewire;
31  typedef architecture::Arc Arc;
33  typedef std::string string;
34 
39  Arc arc1(tilewire1, tilewire2);
40  Arc arc2(tilewire2, tilewire3);
41  string name1 = "Name1";
42  string name2 = "Name2";
43  TilewireVector sources;
44  TilewireVector sinks;
45  sources.push_back(tilewire1);
46  sinks.push_back(tilewire2);
47  sinks.push_back(tilewire3);
48 
49  // features tested:
50  // sizeof(RouteNet);
51  BOOST_CHECK_EQUAL(sizeof(RouteNet), sizeof(string) + sizeof(TilewireVector)
52  + sizeof(TilewireVector) + sizeof(ArcVector) + sizeof(RouteNodePtrVector)
53  + sizeof(boost::unordered_map<boost::uint32_t, boost::any>));
54  //BOOST_CHECK_EQUAL(sizeof(RouteNet), 144u);
55 
56  // functions tested:
57  // RouteNet(string& inName);
58  // RouteNet(string& inName, const TilewireVector& inSources, const TilewireVector& inSinks)
59  RouteNet rn1(name1);
60  RouteNet rn2(name2, sources, sinks);
61 
62  // functions tested:
63  // bool containsSource(Tilewire inTilewire)
64  // bool containsSink(Tilewire inTilewire)
65  // bool containsArc(const Arc& inArc)
66  // void addSource(Tilewire inTilewire)
67  // void addSink(Tilewire inTilewire)
68  // bool removeSource(Tilewire inTilewire)
69  // bool removeSink(Tilewire inTilewire)
70  // void addArc(const Arc& inArc)
71  // bool removeArc(const Arc& inArc)
72  // void unroute(void)
73  // bool hasAnySources(void) const
74  // bool hasOneSource(void) const
75  // bool hasMultipleSources(void) const
76  // size_t getSourceCount(void) const
77  // bool hasAnySinks(void) const
78  // bool hasOneSink(void) const
79  // bool hasMultipleSinks(void) const
80  // size_t getSinkCount(void) const
81  // bool hasAnyArcs(void) const
82  // size_t getArcCount(void) const
83  // const string& const getName()
84  BOOST_CHECK_EQUAL(rn1.getName(), name1);
85  BOOST_CHECK_EQUAL(rn1.containsSource(tilewire4), false);
86  BOOST_CHECK_EQUAL(rn1.containsSink(tilewire4), false);
87  BOOST_CHECK_EQUAL(rn1.containsArc(arc1), false);
88  BOOST_CHECK_EQUAL(rn1.hasAnySources(), false);
89  BOOST_CHECK_EQUAL(rn1.hasOneSource(), false);
90  BOOST_CHECK_EQUAL(rn1.hasAnySinks(), false);
91  BOOST_CHECK_EQUAL(rn1.hasOneSink(), false);
92  BOOST_CHECK_EQUAL(rn1.hasMultipleSources(), false);
93  BOOST_CHECK_EQUAL(rn1.hasMultipleSinks(), false);
94  BOOST_CHECK_EQUAL(rn1.hasAnyArcs(), false);
95  BOOST_CHECK_EQUAL(rn1.removeSource(tilewire2), false);
96  BOOST_CHECK_EQUAL(rn1.removeSink(tilewire2), false);
97  BOOST_CHECK_EQUAL(rn1.removeArc(arc1), false);
98 
99  BOOST_CHECK_EQUAL(rn2.getName(), name2);
100  BOOST_CHECK_EQUAL(rn2.hasAnySources(), true);
101  BOOST_CHECK_EQUAL(rn2.hasOneSource(), true);
102  BOOST_CHECK_EQUAL(rn2.hasAnySinks(), true);
103  BOOST_CHECK_EQUAL(rn2.hasMultipleSinks(), true);
104  BOOST_CHECK_EQUAL(rn2.containsSource(tilewire1), true);
105  BOOST_CHECK_EQUAL(rn2.containsSink(tilewire3), true);
106  BOOST_CHECK_EQUAL(rn2.containsArc(arc1), false);
107  rn2.addArc(arc1);
108  BOOST_CHECK_EQUAL(rn2.containsArc(arc1), true);
109  BOOST_CHECK_EQUAL(rn2.containsSource(tilewire4), false);
110  rn2.addSource(tilewire4);
111  BOOST_CHECK_EQUAL(rn2.containsSource(tilewire4), true);
112  BOOST_CHECK_EQUAL(rn2.removeSource(tilewire4), true);
113  BOOST_CHECK_EQUAL(rn2.containsSource(tilewire4), false);
114  BOOST_CHECK_EQUAL(rn2.containsSink(tilewire2), true);
115  BOOST_CHECK_EQUAL(rn2.removeSink(tilewire2), true);
116  BOOST_CHECK_EQUAL(rn2.containsSink(tilewire2), false);
117  rn2.addSink(tilewire2);
118  BOOST_CHECK_EQUAL(rn2.containsSink(tilewire2), true);
119  BOOST_CHECK_EQUAL(rn2.getArcCount(), 1u);
120 
121 
122 
123 
124 
125 }
126 
127 BOOST_AUTO_TEST_SUITE_END()
128 
129 } // namespace physical
130 } // namespace torc
Encapsulation of a tile index in an unsigned 32-bit integer.
Encapsulation of an arc between two tilewires.
Definition: Arc.hpp:28
std::vector< Tilewire > TilewireVector
Vector of Tilewire objects.
Definition: Tilewire.hpp:101
std::vector< RouteNode * > RouteNodePtrVector
Vector of RouteNode pointers.
Definition: RouteNode.hpp:115
size_t getArcCount(void) const
Returns the number of arcs on the net.
Definition: RouteNet.hpp:167
const string & getName() const
Returns the name of the net.
Definition: RouteNet.hpp:199
bool containsSink(Tilewire inTilewire) const
Determines whether the given Tilewire is a sink of this net.
Definition: RouteNet.hpp:88
bool removeSource(Tilewire inTilewire)
Removes the given Tilewire from the sources of this net.
Definition: RouteNet.hpp:109
Encapsulation of a wire index in an unsigned 16-bit integer.
bool hasMultipleSinks(void) const
Returns true if the next has more than one sink.
Definition: RouteNet.hpp:161
std::vector< Arc > ArcVector
Vector of Arc objects.
Definition: Arc.hpp:78
std::string string
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
bool hasAnySources(void) const
Returns true if the net has any sources.
Definition: RouteNet.hpp:149
bool hasAnyArcs(void) const
Returns true if the net has any arcs.
Definition: RouteNet.hpp:165
bool hasOneSink(void) const
Returns true if the net has exactly one sink.
Definition: RouteNet.hpp:159
bool removeSink(Tilewire inTilewire)
Removes the given instance pin from the sinks of this net.
Definition: RouteNet.hpp:119
bool hasOneSource(void) const
Returns true if the net has exactly one source.
Definition: RouteNet.hpp:151
void addSource(Tilewire inTilewire)
Adds the given Tilewire as a source for this net.
Definition: RouteNet.hpp:98
bool containsArc(const Arc &inArc) const
Determines whether the net contains the given arc.
Definition: RouteNet.hpp:93
void addArc(const Arc &inArc)
Adds the given arc to this net.
Definition: RouteNet.hpp:128
bool hasMultipleSources(void) const
Returns true if the net has more than one source.
Definition: RouteNet.hpp:153
BOOST_AUTO_TEST_CASE(NetRouterHeuristicT)
Unit test for the Heuristic.
void addSink(Tilewire inTilewire)
Adds the given Tilewire as a sink for this net.
Definition: RouteNet.hpp:103
bool removeArc(const Arc &inArc)
Removes the given arc from this net.
Definition: RouteNet.hpp:133
bool hasAnySinks(void) const
Returns true if the net has any sinks.
Definition: RouteNet.hpp:157
bool containsSource(Tilewire inTilewire) const
Determines whether the given Tilewire is a source of this net.
Definition: RouteNet.hpp:83
Header for the Net class.