torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RouteTreeNodeUnitTest.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 RouteNode class.
18 
19 #include <boost/test/unit_test.hpp>
21 
22 namespace torc {
23 namespace router {
24 
25 BOOST_AUTO_TEST_SUITE(router)
26 
27 /// \brief Unit test for the RouteNode class.
28 BOOST_AUTO_TEST_CASE(RouteTreeNodeT) {
29  typedef architecture::Tilewire Tilewire;
30  typedef architecture::Arc Arc;
31  // create accessory wires and tiles
36  Arc arc2(tilewire2, tilewire3);
37  boost::int32_t cost1 = 4;
38  boost::int32_t cost2 = 5;
39 
40  // features tested:
41  // sizeof(RouteNode)
42  BOOST_CHECK_EQUAL(sizeof(RouteTreeNode), sizeof(RouteNode)
43  + sizeof(RouteTreeNode*) + sizeof(std::vector<RouteTreeNode*>*));
44  BOOST_CHECK_EQUAL(sizeof(RouteNode), 32u);
45  BOOST_CHECK_EQUAL(sizeof(RouteTreeNode), 48u);
46  BOOST_CHECK_EQUAL(sizeof(RouteTreeNode*), 8u);
47  BOOST_CHECK_EQUAL(sizeof(std::vector<RouteTreeNode*>*), 8u);
48  BOOST_CHECK_EQUAL(sizeof(boost::int32_t), 4u);
49 
50  // functions tested:
51  // RouteTreeNode();
52  // RouteTreeNode(Tilewire inSource, Tilewire inSink, boost::int32_t inCost,
53  // RouteTreeNode* inParent)
54  RouteTreeNode* routenode1 = new RouteTreeNode(tilewire1, tilewire2, cost1, 0);
55  RouteTreeNode* routenode2 = new RouteTreeNode(arc2, cost1, routenode1);
56  RouteTreeNode* routenode3 = new RouteTreeNode(tilewire3, tilewire4, cost2, routenode2);
57  RouteTreeNode* routenode4 = new RouteTreeNode(tilewire4, tilewire1, cost2, routenode2);
58  RouteTreeNode* routenode5 = new RouteTreeNode();
59  BOOST_CHECK_EQUAL(routenode1 != 0, true);
60  BOOST_CHECK_EQUAL(routenode2 != 0, true);
61  BOOST_CHECK_EQUAL(routenode3 != 0, true);
62  BOOST_CHECK_EQUAL(routenode4 != 0, true);
63  BOOST_CHECK_EQUAL(routenode5 != 0, true);
64 
65  // functions tested:
66  // boost::int32_t getDepth() const;
67  // addChildren(const std::vector<RouteTreeNode*>& newChildren);
68  // boost::uint16_t getNumChildren();
69  // RouteTreeNode* getChild(unsigned int index);
70  // makeParent(const Tilewire& inSource, const Tilewire& inSink;
71  // void normalizeDepth;
72  // void adjustDepth(int adjustment);
73  std::vector<RouteTreeNode*> vec1;
74  vec1.push_back(routenode2);
75  std::vector<RouteTreeNode*> vec2;
76  vec2.push_back(routenode3);
77  vec2.push_back(routenode4);
78  routenode1->addChildren(vec1);
79  routenode2->addChildren(vec2);
80  BOOST_CHECK_EQUAL(routenode1->getDepth() == 0, true);
81  BOOST_CHECK_EQUAL(routenode2->getDepth() == 1, true);
82  BOOST_CHECK_EQUAL(routenode3->getDepth() == 2, true);
83  BOOST_CHECK_EQUAL(routenode4->getDepth() == 2, true);
84  BOOST_CHECK_EQUAL(routenode5->getDepth() == -1, true);
85  BOOST_CHECK_EQUAL(routenode1->getNumChildren() == 1, true);
86  BOOST_CHECK_EQUAL(routenode2->getNumChildren() == 2, true);
87  BOOST_CHECK_EQUAL(routenode3->getNumChildren() == 0, true);
88  BOOST_CHECK_EQUAL(routenode4->getNumChildren() == 0, true);
89  BOOST_CHECK_EQUAL(routenode1->getChild(0) == routenode2, true);
90  BOOST_CHECK_EQUAL(routenode2->getChild(0) == routenode3, true);
91  BOOST_CHECK_EQUAL(routenode2->getChild(1) == routenode4, true);
92 
93  routenode1->makeParent(tilewire4, tilewire3);
94  BOOST_CHECK_EQUAL(tilewire1 == routenode1->getSourceTilewire(), true);
95  BOOST_CHECK_EQUAL(tilewire2 == routenode1->getSinkTilewire(), true);
96  RouteTreeNode* parentnode = (RouteTreeNode*)routenode1->getParent();
97  BOOST_CHECK_EQUAL(tilewire4 == parentnode->getSourceTilewire(), true);
98  BOOST_CHECK_EQUAL(tilewire3 == parentnode->getSinkTilewire(), true);
99  BOOST_CHECK_EQUAL(parentnode->getDepth() == -1, true);
100  routenode4->normalizeDepth();
101  BOOST_CHECK_EQUAL(parentnode->getDepth() == 0, true);
102  BOOST_CHECK_EQUAL(routenode1->getDepth() == 1, true);
103  BOOST_CHECK_EQUAL(routenode2->getDepth() == 2, true);
104  BOOST_CHECK_EQUAL(routenode3->getDepth() == 3, true);
105  BOOST_CHECK_EQUAL(routenode4->getDepth() == 3, true);
106  BOOST_CHECK_EQUAL(routenode5->getDepth() == -1, true);
107 }
108 
109 BOOST_AUTO_TEST_SUITE_END()
110 
111 } // namespace router
112 } // namespace torc
Encapsulation of a tile index in an unsigned 32-bit integer.
Encapsulation of an arc between two tilewires.
Definition: Arc.hpp:28
void addChildren(const std::vector< RouteTreeNode * > &newChildren)
Add children to the node.
RouteNode * getParent() const
Get the node's parent.
Definition: RouteNode.hpp:98
const boost::int32_t getDepth() const
Get the node depth.
Definition: RouteNode.hpp:94
Encapsulation of a wire index in an unsigned 16-bit integer.
const Tilewire & getSinkTilewire() const
Get the sink Tilewire.
Definition: RouteNode.hpp:84
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
const Tilewire & getSourceTilewire() const
Get the source Tilewire.
Definition: RouteNode.hpp:82
boost::uint16_t getNumChildren()
Get the number of children.
An object that holds more complete path information for routing and tracing.
An object that holds an arc and path information for routing.
Definition: RouteNode.hpp:40
void makeParent(const Tilewire &inSource, const Tilewire &inSink)
Allocate a new node and make it the parent of this node.
RouteTreeNode * getChild(unsigned int index)
Get a child by index, returns 0 for invalid index.
BOOST_AUTO_TEST_CASE(NetRouterHeuristicT)
Unit test for the Heuristic.
void normalizeDepth()
Normalize depth of nodes.
Header for the RouteTreeNode class.