torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UnrouterUnitTest.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 Regression test for the Unrouter class.
18 
19 #include <boost/test/unit_test.hpp>
22 #include "torc/router/Trace.hpp"
23 #include <map>
24 
25 //#include <boost/filesystem/convenience.hpp>
27 //#include "torc/physical/Factory.hpp"
28 //#include "torc/physical/XdlExporter.hpp"
31 #include <fstream>
32 
33 namespace torc {
34 namespace router {
35 
37  int& argc;
38  char**&argv;
42  std::fstream fileStream;
46  std::map<architecture::Tilewire, int> sinkCounts;
49 
50  TracerTestFixture() : argc(boost::unit_test::framework::master_test_suite().argc),
51  argv(boost::unit_test::framework::master_test_suite().argv),
52  directoryTree(argv[0]),
53  testPath(directoryTree.getExecutablePath() / "torc" / "router"),
54  referencePath(testPath / "TracerUnitTest.xdl"),
56  //importer(fileStream, referencePath.string()),
57  //ddbPtr(importer.releaseDDBPtr()),
58  //tracer(*ddbPtr)
59  {
60  BOOST_REQUIRE(argc >= 1);
61  BOOST_REQUIRE(fileStream.good());
64  BOOST_REQUIRE(designPtr.get() != 0);
66  BOOST_REQUIRE(ddbPtr != 0);
67  //tracer(*ddbPtr);
68 
69  BOOST_CHECK_EQUAL(designPtr->getNetCount(), 1u);
70  BOOST_CHECK_EQUAL(ddbPtr->getArcUsage().getArcUsageCount(), 53u);
71  //BOOST_TEST_MESSAGE("Should the pip count really include the routethrough?");
72  //BOOST_CHECK_EQUAL(ddbPtr->getArcUsage().getArcUsageCount(), 54u);
73 
74  sourceTw = ddbPtr->lookupTilewire("CLBLL_X16Y39", "L_C");
75  sourceTw2 = ddbPtr->lookupTilewire("CLBLL_X16Y39", "L_CMUX");
76 
78  tempTw = ddbPtr->lookupTilewire("CLBLM_X13Y42", "L_D1");
79  sinkCounts.insert(std::pair<architecture::Tilewire, int>(tempTw, 0));
80  tempTw = ddbPtr->lookupTilewire("CLBLM_X18Y36", "L_A1");
81  sinkCounts.insert(std::pair<architecture::Tilewire, int>(tempTw, 0));
82  tempTw = ddbPtr->lookupTilewire("CLBLM_X18Y36", "L_D3");
83  sinkCounts.insert(std::pair<architecture::Tilewire, int>(tempTw, 0));
84  tempTw = ddbPtr->lookupTilewire("CLBLM_X13Y36", "M_B6");
85  sinkCounts.insert(std::pair<architecture::Tilewire, int>(tempTw, 0));
86  tempTw = ddbPtr->lookupTilewire("CLBLM_X13Y36", "M_C5");
87  sinkCounts.insert(std::pair<architecture::Tilewire, int>(tempTw, 0));
88  tempTw = ddbPtr->lookupTilewire("CLBLM_X13Y36", "M_D3");
89  sinkCounts.insert(std::pair<architecture::Tilewire, int>(tempTw, 0));
90  tempTw = ddbPtr->lookupTilewire("CLBLM_X13Y42", "L_D2");
91  sinkCounts.insert(std::pair<architecture::Tilewire, int>(tempTw, 0));
92  tempTw = ddbPtr->lookupTilewire("CLBLL_X16Y42", "L_A1");
93  sinkCounts.insert(std::pair<architecture::Tilewire, int>(tempTw, 0));
94  tempTw = ddbPtr->lookupTilewire("CLBLL_X16Y42", "L_CE");
95  sinkCounts.insert(std::pair<architecture::Tilewire, int>(tempTw, 0));
96  tempTw = ddbPtr->lookupTilewire("CLBLM_X18Y40", "L_BX");
97  sinkCounts.insert(std::pair<architecture::Tilewire, int>(tempTw, 0));
98  tempTw = ddbPtr->lookupTilewire("CLBLM_X18Y40", "L_B4");
99  sinkCounts.insert(std::pair<architecture::Tilewire, int>(tempTw, 0));
100  }
102  delete ddbPtr;
103  }
104 };
105 
106 BOOST_FIXTURE_TEST_SUITE(router, TracerTestFixture)
107 /*
108 /// \brief Unit test for the traceSource function in the Tracer.
109 BOOST_AUTO_TEST_CASE(router_unrouter_tracetosinks) {
110  Tracer tracer(*ddbPtr);
111  RouteTreeNode* rtn;
112  RouteTreeNode* rtn2;
113  rtn = tracer.traceToSinks(sourceTw);
114  rtn2 = tracer.traceToSinks(sourceTw2);
115  rtn->normalizeDepth();
116  rtn2->normalizeDepth();
117  std::vector<RouteTreeNode*> vec;
118  std::vector<RouteTreeNode*> wavefront;
119  //vec.push_back(rtn);
120  //vec.push_back(rtn2);
121  wavefront.push_back(rtn);
122  wavefront.push_back(rtn2);
123  while (wavefront.size() != 0) {
124  RouteTreeNode* node = wavefront.back();
125  wavefront.pop_back();
126  vec.push_back(node);
127  for (unsigned int i = 0; i < node->getNumChildren(); i++) {
128  wavefront.push_back(node->getChild(i));
129  }
130  }
131  std::map<architecture::Tilewire, int>::iterator it;
132  for (unsigned int i = 0 ; i < vec.size(); i++) {
133  it = sinkCounts.find(vec[i]->getSinkTilewire());
134  if (it != sinkCounts.end()) {
135  it->second++;
136  }
137  }
138  BOOST_TEST_MESSAGE(*ddbPtr);
139  for (it = sinkCounts.begin(); it != sinkCounts.end(); it++) {
140  BOOST_TEST_MESSAGE("Checking sink " << it->first);
141  BOOST_CHECK(it->second == 1);
142  }
143 }
144 
145 /// \brief Unit test for the traceBranch function in the Tracer.
146 BOOST_AUTO_TEST_CASE(router_unrouter_tracebranch) {
147  Tracer tracer(*ddbPtr);
148  architecture::Tilewire branchSource = ddbPtr->lookupTilewire("INT_X14Y37", "SL2END0");
149  RouteTreeNode* rtn;
150  rtn = tracer.traceBranch(branchSource);
151  rtn->normalizeDepth();
152  std::vector<RouteTreeNode*> vec;
153  std::vector<RouteTreeNode*> wavefront;
154  vec.push_back(rtn);
155  wavefront.push_back(rtn);
156  while (wavefront.size() != 0) {
157  RouteTreeNode* node = wavefront.back();
158  wavefront.pop_back();
159  vec.push_back(node);
160  for (unsigned int i = 0; i < node->getNumChildren(); i++) {
161  wavefront.push_back(node->getChild(i));
162  }
163  }
164  std::map<architecture::Tilewire, int>::iterator it;
165  for (unsigned int i = 0 ; i < vec.size(); i++) {
166 std::cout << "NODE: " << vec[i]->getArc() << std::endl;
167  it = sinkCounts.find(vec[i]->getSinkTilewire());
168  if (it != sinkCounts.end()) {
169  it->second++;
170  }
171  }
172  BOOST_TEST_MESSAGE(*ddbPtr);
173  for (it = sinkCounts.begin(); it != sinkCounts.end(); it++) {
174  BOOST_TEST_MESSAGE("Checking sink " << it->first);
175  BOOST_CHECK_EQUAL(it->second, 1);
176  //std::cout << it->first << " " << it->second << std::endl;
177  }
178 }
179 
180 /// \brief Unit test for the traceSink function in the Tracer.
181 BOOST_AUTO_TEST_CASE(router_unrouter_tracesink) {
182 }
183 
184 /// \brief Unit test for the traceFull function in the Tracer.
185 BOOST_AUTO_TEST_CASE(router_unrouter_tracefull) {
186  Tracer tracer(*ddbPtr);
187  architecture::Tilewire branchSource = ddbPtr->lookupTilewire("INT_X14Y37", "SL2END0");
188 std::cout << *ddbPtr << "START: " << branchSource << std::endl;
189  RouteTreeNode* rtn;
190  rtn = tracer.traceFull(branchSource);
191  rtn->normalizeDepth();
192  rtn = (RouteTreeNode*)rtn->getTop();
193  std::vector<RouteTreeNode*> vec;
194  std::vector<RouteTreeNode*> wavefront;
195  wavefront.push_back(rtn);
196  while (wavefront.size() != 0) {
197  RouteTreeNode* node = wavefront.back();
198  wavefront.pop_back();
199  vec.push_back(node);
200  for (unsigned int i = 0; i < node->getNumChildren(); i++) {
201  wavefront.push_back(node->getChild(i));
202  }
203  }
204  std::map<architecture::Tilewire, int>::iterator it;
205  for (unsigned int i = 0 ; i < vec.size(); i++) {
206 std::cout << "NODE: " << vec[i]->getArc() << std::endl;
207  it = sinkCounts.find(vec[i]->getSinkTilewire());
208  if (it != sinkCounts.end()) {
209  it->second++;
210  }
211  }
212  BOOST_TEST_MESSAGE(*ddbPtr);
213  for (it = sinkCounts.begin(); it != sinkCounts.end(); it++) {
214  BOOST_TEST_MESSAGE("Checking sink " << it->first);
215  BOOST_CHECK_EQUAL(it->second, 1);
216  //std::cout << it->first << " " << it->second << std::endl;
217  }
218 }
219 */
220 BOOST_AUTO_TEST_SUITE_END()
221 
222 } // namespace router
223 } // namespace torc
Device database, including complete wiring and logic support.
Definition: DDB.hpp:42
architecture::XdlImporter importer
torc::common::DirectoryTree directoryTree
DesignSharedPtr getDesignPtr(void)
Returns a shared pointer for the design.
Header for the DirectoryTree class.
architecture::Tilewire sourceTw2
DDB * releaseDDBPtr(void)
Releases ownership of the device database. The caller is now responsible for deleting it...
std::map< architecture::Tilewire, int > sinkCounts
std::string string
Header for Boost.Test helper functions.
Architecture aware importer from XDL format into a physical design.
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
Encapsulation of filesystem paths that are used by the library.
Header for torc::physical output stream helpers.
Header for the Trace class.
boost::filesystem::path path
boost::filesystem::path referencePath
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
boost::filesystem::path testPath
Header for the DDB class.
Header for the XdlImporter class.
torc::physical::DesignSharedPtr designPtr
architecture::Tilewire sourceTw