torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TraceNodeUnitTest.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 TraceNode unit test.
18 
19 #include <boost/test/unit_test.hpp>
23 
24 namespace torc {
25 namespace router {
26 
27 BOOST_AUTO_TEST_SUITE(router)
28 
29 /// \brief Unit test for the RouteNode class.
30 BOOST_AUTO_TEST_CASE(TraceNodeT) {
31  typedef architecture::Tilewire Tilewire;
32  typedef architecture::Arc Arc;
33 
34  // create accessory wires and tiles
41 
42  // features tested:
43  // sizeof(TraceNode)
44  BOOST_CHECK_EQUAL(sizeof(TraceNode), sizeof(boost::int32_t)
45  + sizeof(Tilewire) + sizeof(std::vector<TraceNode*>)
46  + sizeof(std::vector<std::pair<Tilewire, TraceNode*> >));
47  BOOST_CHECK_EQUAL(sizeof(std::vector<TraceNode*>), 24u);
48  BOOST_CHECK_EQUAL(sizeof(std::vector<std::pair<Tilewire, TraceNode*> >), 24u);
49  BOOST_CHECK_EQUAL(sizeof(Tilewire), 6u);
50  BOOST_CHECK_EQUAL(sizeof(TraceNode), 58u);
51  BOOST_CHECK_EQUAL(sizeof(TraceNode*), 8u);
52  BOOST_CHECK_EQUAL(sizeof(boost::int32_t), 4u);
53 
54  // functions tested:
55  // TraceNode(Tilewire inTilewire)
56  TraceNode* tracenode1 = new TraceNode(tilewire1);
57  TraceNode* tracenode2 = new TraceNode(tilewire2);
58  TraceNode* tracenode3 = new TraceNode(tilewire3);
59  TraceNode* tracenode4 = new TraceNode(tilewire4);
60  TraceNode* tracenode5 = new TraceNode(tilewire5);
61  TraceNode* tracenode6 = new TraceNode(tilewire6);
62 
63  BOOST_CHECK(TraceNode::sLiveNodes == 6);
64 
65  //functions tested:
66  // getTilewire()
67  // getDepth()
68  // getNumChildren()
69  // getNumParents()
70  // getChild()
71  // getParent()
72  // removeChild()
73  // removeParent()
74  BOOST_CHECK(tracenode1 != 0);
75  BOOST_CHECK(tracenode1->getDepth() == -1);
76  BOOST_CHECK(tracenode1->getNumChildren() == 0);
77  BOOST_CHECK(tracenode1->getNumParents() == 0);
78  BOOST_CHECK(tracenode1->getTilewire() == tilewire1);
79  BOOST_CHECK(tracenode1->getChild(0) == 0);
80  BOOST_CHECK(tracenode1->getParent(0) == 0);
81  BOOST_CHECK(tracenode1->removeChild(0) == 0);
82  BOOST_CHECK(tracenode1->removeParent(0) == 0);
83 
84  // attach a bunch of nodes together
85  tracenode1->addChild(tracenode3);
86  BOOST_CHECK(tracenode1->getNumChildren() == 1);
87  BOOST_CHECK(tracenode1->getChild(0)->getTilewire() == tilewire3);
88  tracenode2->addChild(tracenode4);
89  BOOST_CHECK(tracenode2->getNumChildren() == 1);
90  BOOST_CHECK(tracenode2->getChild(0)->getTilewire() == tilewire4);
91  tracenode3->addParent(tracenode1);
92  BOOST_CHECK(tracenode3->getNumParents() == 1);
93  BOOST_CHECK(tracenode3->getParent(0)->getTilewire() == tilewire1);
94  tracenode3->addChild(tracenode4);
95  BOOST_CHECK(tracenode3->getNumChildren() == 1);
96  BOOST_CHECK(tracenode3->getChild(0)->getTilewire() == tilewire4);
97  tracenode4->addParent(tracenode2);
98  BOOST_CHECK(tracenode4->getNumParents() == 1);
99  tracenode4->addParent(tracenode3);
100  BOOST_CHECK(tracenode4->getNumParents() == 2);
101  std::vector<TraceNode*> testvec;
102  testvec.push_back(tracenode5);
103  testvec.push_back(tracenode6);
104  tracenode4->addChildren(testvec);
105  BOOST_CHECK(tracenode4->getNumChildren() == 2);
106  tracenode5->addParent(tracenode4);
107  BOOST_CHECK(tracenode5->getNumParents() == 1);
108  tracenode6->addParent(tracenode4);
109  BOOST_CHECK(tracenode6->getNumParents() == 1);
110 
111  // remove all node connections
112  BOOST_CHECK(tracenode1->removeChild(0)->getTilewire() == tilewire3);
113  BOOST_CHECK(tracenode1->getNumChildren() == 0);
114  BOOST_CHECK(tracenode2->removeChild(0)->getTilewire() == tilewire4);
115  BOOST_CHECK(tracenode2->getNumChildren() == 0);
116  BOOST_CHECK(tracenode3->removeParent(0) == tracenode1);
117  BOOST_CHECK(tracenode3->getNumParents() == 0);
118  BOOST_CHECK(tracenode3->removeChild(0)->getTilewire() == tilewire4);
119  BOOST_CHECK(tracenode3->getNumChildren() == 0);
120  BOOST_CHECK(tracenode4->removeParent(1) == tracenode3);
121  BOOST_CHECK(tracenode4->getNumParents() == 1);
122  BOOST_CHECK(tracenode4->removeParent(0) == tracenode2);
123  BOOST_CHECK(tracenode4->getNumParents() == 0);
124  BOOST_CHECK(tracenode4->removeChild(0)->getTilewire() == tilewire5);
125  BOOST_CHECK(tracenode4->getNumChildren() == 1);
126  BOOST_CHECK(tracenode4->removeChild(0)->getTilewire() == tilewire6);
127  BOOST_CHECK(tracenode4->getNumChildren() == 0);
128  BOOST_CHECK(tracenode5->removeParent(0) == tracenode4);
129  BOOST_CHECK(tracenode5->getNumParents() == 0);
130  BOOST_CHECK(tracenode6->removeParent(0)->getTilewire() == tilewire4);
131  BOOST_CHECK(tracenode6->getNumParents() == 0);
132 
133  // clean up
134  delete tracenode1;
135  delete tracenode2;
136  delete tracenode3;
137  delete tracenode4;
138  delete tracenode5;
139  delete tracenode6;
140 
141  BOOST_CHECK(TraceNode::sLiveNodes == 0);
142 
143  tracenode1 = new TraceNode(tilewire1);
144  tracenode2 = new TraceNode(tilewire2);
145  tracenode3 = new TraceNode(tilewire3);
146  tracenode4 = new TraceNode(tilewire4);
147  tracenode5 = new TraceNode(tilewire5);
148  tracenode6 = new TraceNode(tilewire6);
149 
150  // attach the nodes together again
151  tracenode1->addChild(tracenode3);
152  tracenode2->addChild(tracenode4);
153  tracenode3->addParent(tracenode1);
154  tracenode3->addChild(tracenode4);
155  tracenode4->addParent(tracenode2);
156  tracenode4->addParent(tracenode3);
157  testvec.clear();
158  testvec.push_back(tracenode5);
159  testvec.push_back(tracenode6);
160  tracenode4->addChildren(testvec);
161  tracenode5->addParent(tracenode4);
162  tracenode6->addParent(tracenode4);
163 
164  BOOST_CHECK(TraceNode::sLiveNodes == 6);
165 
166  // testing the destructor, but no way to verfiy that it is working???
167  delete tracenode1;
168  delete tracenode2;
169  delete tracenode3;
170  delete tracenode4;
171  delete tracenode5;
172  delete tracenode6;
173 
174  BOOST_CHECK(TraceNode::sLiveNodes == 0);
175 }
176 
177 BOOST_AUTO_TEST_SUITE_END()
178 
179 } // namespace router
180 } // namespace torc
Encapsulation of a tile index in an unsigned 32-bit integer.
Encapsulation of an arc between two tilewires.
Definition: Arc.hpp:28
Tilewire getTilewire()
Get the Tilewire associated with this node.
Definition: TraceNode.hpp:130
void addParent(TraceNode *newParent)
Add parent to the node.
Definition: TraceNode.hpp:150
TraceNode * getChild(boost::uint32_t index)
Get a child by index, returns 0 for invalid index.
Definition: TraceNode.hpp:162
TraceNode * getParent(boost::uint32_t index)
Get a parent by index, returns 0 for invalid index.
Definition: TraceNode.hpp:167
Header for the TraceNode class.
Encapsulation of a wire index in an unsigned 16-bit integer.
boost::int32_t getDepth() const
Get the depth of this node from the furthest node with no parent.
Definition: TraceNode.hpp:133
Header for torc::physical output stream helpers.
TraceNode * removeParent(boost::uint32_t index)
Remove a parent by index, returns 0 for invalid index.
Definition: TraceNode.hpp:179
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
static boost::int32_t sLiveNodes
Static allocation and deallocation count.
Definition: TraceNode.hpp:85
boost::uint32_t getNumParents()
Get the number of parents.
Definition: TraceNode.hpp:158
void addChildren(const TraceNodePtrVector &newChildren)
Add children to the node.
Definition: TraceNode.hpp:137
Header for the DDB class.
boost::uint32_t getNumChildren()
Get the number of children.
Definition: TraceNode.hpp:154
BOOST_AUTO_TEST_CASE(NetRouterHeuristicT)
Unit test for the Heuristic.
An object that holds more complete path information for routing and tracing.
Definition: TraceNode.hpp:44
TraceNode * removeChild(boost::uint32_t index)
Remove a child by index, returns 0 for invalid index.
Definition: TraceNode.hpp:172
void addChild(TraceNode *newChild)
brief Add child to the node.
Definition: TraceNode.hpp:145