torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PhysicalDiffUnitTest.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 PhysicalDiff class.
18 
19 #include <sstream>
20 #include <boost/test/unit_test.hpp>
22 
23 namespace torc {
24 
25 BOOST_AUTO_TEST_SUITE(utils)
26 
27 /// \brief Unit test for the design diff function.
28 BOOST_AUTO_TEST_CASE(PhysicalDiffDesignUnitTest) {
29  std::ostringstream nullstream(std::ostringstream::out);
30  PhysicalDiff pd(nullstream);
31  // functions tested:
32  // bool diffDesign(const DesignSharedPtr& left, const DesignSharedPtr& right);
33 
34  std::string designName = "design";
35  std::string designName2 = "design2"; // not comparing differing names for the moment
36  std::string deviceName = "device";
37  std::string deviceName2 = "device2";
38  std::string devicePackage = "package";
39  std::string devicePackage2 = "package2";
40  std::string deviceSpeedGrade = "speed_grade";
41  std::string deviceSpeedGrade2 = "speed_grade2";
42  std::string xdlVersion = "xdl_version";
43  std::string xdlVersion2 = "xdl_version2";
44 
46  deviceName, devicePackage, deviceSpeedGrade, xdlVersion);
47  BOOST_REQUIRE(designPtrLeft.get() != 0);
49  deviceName, devicePackage, deviceSpeedGrade, xdlVersion);
50  BOOST_REQUIRE(designPtrRight.get() != 0);
51 
52  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
53  designPtrRight->setDevice(deviceName2);
54  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
55  designPtrRight->setDevice(deviceName);
56  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
57 
58  designPtrLeft->setPackage(devicePackage2);
59  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
60  designPtrLeft->setPackage(devicePackage);
61  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
62 
63  designPtrLeft->setSpeedGrade(deviceSpeedGrade2);
64  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
65  designPtrLeft->setSpeedGrade(deviceSpeedGrade);
66  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
67 
68  designPtrRight->setXdlVersion(xdlVersion2);
69  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
70  designPtrRight->setXdlVersion(xdlVersion);
71  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
72 
73  physical::ModuleSharedPtr module1PtrLeft
74  = physical::Factory::newModulePtr("module1", "anchor1");
75  physical::ModuleSharedPtr module2PtrLeft
76  = physical::Factory::newModulePtr("module2", "anchor2");
77  physical::ModuleSharedPtr module1PtrRight
78  = physical::Factory::newModulePtr("module1", "anchor1");
79  physical::ModuleSharedPtr module2PtrRight
80  = physical::Factory::newModulePtr("module2", "anchor2");
81 
82  BOOST_REQUIRE(designPtrLeft->addModule(module1PtrLeft) == true);
83  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
84  BOOST_REQUIRE(designPtrRight->addModule(module1PtrRight) == true);
85  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
86 
87  BOOST_REQUIRE(designPtrRight->addModule(module2PtrRight) == true);
88  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
89  BOOST_REQUIRE(designPtrLeft->addModule(module2PtrLeft) == true);
90  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
91 
92 }
93 
94 /// \brief Unit test for the module diff function.
95 BOOST_AUTO_TEST_CASE(PhysicalDiffModuleUnitTest) {
96  std::ostringstream nullstream(std::ostringstream::out);
97  PhysicalDiff pd(nullstream);
98  // functions tested:
99  // bool diffModule(const ModuleSharedPtr& left, const ModuleSharedPtr& right);
100 
101  std::string anchor = "anchor";
102  std::string anchor2 = "anchor2"; // not comparing differing names for the moment
103  std::string portname = "port";
104  std::string portname2 = "port2";
105  std::string pinname = "pinname";
106  std::string pinname2 = "pinname2";
107 
108  physical::InstanceSharedPtr instancePtrLeft
109  = physical::Factory::newInstancePtr("instname", "type", "tile", "site",
111  physical::InstanceSharedPtr instancePtrRight
112  = physical::Factory::newInstancePtr("instname", "type", "tile", "site",
114 
115  physical::ModuleSharedPtr modulePtrLeft
116  = physical::Factory::newModulePtr("module1", anchor);
117  physical::ModuleSharedPtr modulePtrRight
118  = physical::Factory::newModulePtr("module1", anchor);
119  physical::PortSharedPtr portLeft
120  = physical::Factory::newPortPtr(portname, instancePtrLeft, pinname);
121  physical::PortSharedPtr portLeft2
122  = physical::Factory::newPortPtr(portname, instancePtrLeft, pinname2);
123  physical::PortSharedPtr portRight
124  = physical::Factory::newPortPtr(portname, instancePtrRight, pinname);
125  physical::PortSharedPtr portRight2
126  = physical::Factory::newPortPtr(portname, instancePtrRight, pinname2);
127 
128  BOOST_REQUIRE(pd.diffModule(modulePtrLeft, modulePtrRight) == true);
129  modulePtrRight->setAnchor(anchor2);
130  BOOST_REQUIRE(pd.diffModule(modulePtrLeft, modulePtrRight) == false);
131  modulePtrRight->setAnchor(anchor);
132  BOOST_REQUIRE(pd.diffModule(modulePtrLeft, modulePtrRight) == true);
133 
134  modulePtrLeft->addPort(portLeft);
135  BOOST_REQUIRE(pd.diffModule(modulePtrLeft, modulePtrRight) == false);
136  modulePtrRight->addPort(portRight);
137  BOOST_REQUIRE(pd.diffModule(modulePtrLeft, modulePtrRight) == true);
138 
139  modulePtrRight->removePort(portRight);
140  modulePtrRight->addPort(portRight2);
141  BOOST_REQUIRE(pd.diffModule(modulePtrLeft, modulePtrRight) == false);
142  modulePtrLeft->removePort(portLeft);
143  modulePtrLeft->addPort(portLeft2);
144  BOOST_REQUIRE(pd.diffModule(modulePtrLeft, modulePtrRight) == true);
145 
146 }
147 
148 /// \brief Unit test for the circuit diff function.
149 BOOST_AUTO_TEST_CASE(PhysicalDiffCircuitUnitTest) {
150  std::ostringstream nullstream(std::ostringstream::out);
151  PhysicalDiff pd(nullstream);
152  // functions tested:
153  // bool diffCircuit(const CircuitSharedPtr& left, const CircuitSharedPtr& right);
154 
155  std::string designName = "design";
156  std::string deviceName = "device";
157  std::string devicePackage = "package";
158  std::string deviceSpeedGrade = "speed_grade";
159  std::string xdlVersion = "xdl_version";
160 
162  deviceName, devicePackage, deviceSpeedGrade, xdlVersion);
163  BOOST_REQUIRE(designPtrLeft.get() != 0);
164  physical::DesignSharedPtr designPtrRight = physical::Factory::newDesignPtr(designName,
165  deviceName, devicePackage, deviceSpeedGrade, xdlVersion);
166  BOOST_REQUIRE(designPtrRight.get() != 0);
167 
169  = physical::Factory::newInstancePtr("name1", "type1", "tile1", "site1");
171  = physical::Factory::newInstancePtr("name2", "type2", "tile2", "site2");
172  physical::InstanceSharedPtr inst1Right
173  = physical::Factory::newInstancePtr("name1", "type1", "tile1", "site1");
174  physical::InstanceSharedPtr inst2Right
175  = physical::Factory::newInstancePtr("name2", "type2", "tile2", "site2");
176 
177  physical::NetSharedPtr net1Left
179  physical::NetSharedPtr net2Left
181  physical::NetSharedPtr net1Right
183  physical::NetSharedPtr net2Right
185 
186  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
187 
188  designPtrLeft->addInstance(inst1Left);
189  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
190  designPtrRight->addInstance(inst1Right);
191  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
192  designPtrRight->addInstance(inst2Right);
193  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
194  designPtrLeft->addInstance(inst2Left);
195  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
196 
197  designPtrRight->addNet(net1Right);
198  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
199  designPtrLeft->addNet(net1Left);
200  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
201  designPtrLeft->addNet(net2Left);
202  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
203  designPtrRight->addNet(net2Right);
204  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
205 
206 }
207 
208 /// \brief Unit test for the config_map diff function.
209 BOOST_AUTO_TEST_CASE(PhysicalDiffConfigMapUnitTest) {
210  std::ostringstream nullstream(std::ostringstream::out);
211  PhysicalDiff pd(nullstream);
212  // functions tested:
213  // bool diffConfigMap(const ConfigMapSharedPtr& left, const ConfigMapSharedPtr& right,
214  // const string& parentStr);
215 
216  std::string designName = "design";
217  std::string deviceName = "device";
218  std::string devicePackage = "package";
219  std::string deviceSpeedGrade = "speed_grade";
220  std::string xdlVersion = "xdl_version";
221 
222  std::string setting1 = "setting1";
223  std::string setting2 = "setting2";
224 
226  deviceName, devicePackage, deviceSpeedGrade, xdlVersion);
227  BOOST_REQUIRE(designPtrLeft.get() != 0);
228  physical::DesignSharedPtr designPtrRight = physical::Factory::newDesignPtr(designName,
229  deviceName, devicePackage, deviceSpeedGrade, xdlVersion);
230  BOOST_REQUIRE(designPtrRight.get() != 0);
231 
232  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
233 
234  designPtrLeft->setConfig("setting1", "name1", "value1");
235  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
236  designPtrRight->setConfig("setting1", "name1", "value1");
237  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
238  designPtrRight->setConfig("setting2", "name2", "value2");
239  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
240  designPtrLeft->setConfig("setting2", "name2", "value3");
241  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == false);
242  designPtrLeft->setConfig("setting2", "name2", "value2");
243  BOOST_REQUIRE(pd.diffDesign(designPtrLeft, designPtrRight) == true);
244 
245 }
246 
247 /// \brief Unit test for the instance diff function.
248 BOOST_AUTO_TEST_CASE(PhysicalDiffInstanceUnitTest) {
249  std::ostringstream nullstream(std::ostringstream::out);
250  PhysicalDiff pd(nullstream);
251  // functions tested:
252  // bool diffInstance(const InstanceSharedPtr& left, const InstanceSharedPtr& right);
253 
254  std::string name = "name";
255  std::string type = "type";
256  std::string type2 = "type2";
257  std::string tile = "tile";
258  std::string tile2 = "tile2";
259  std::string site = "site";
260  std::string site2 = "site2";
261 
262  physical::InstanceSharedPtr instancePtrLeft
263  = physical::Factory::newInstancePtr(name, type, tile, site);
264  BOOST_REQUIRE(instancePtrLeft.get() != 0);
265  physical::InstanceSharedPtr instancePtrRight
266  = physical::Factory::newInstancePtr(name, type, tile, site);
267  BOOST_REQUIRE(instancePtrRight.get() != 0);
268 
269  BOOST_REQUIRE(pd.diffInstance(instancePtrLeft, instancePtrRight) == true);
270 
271  instancePtrLeft->setType(type2);
272  BOOST_REQUIRE(pd.diffInstance(instancePtrLeft, instancePtrRight) == false);
273  instancePtrRight->setType(type2);
274  BOOST_REQUIRE(pd.diffInstance(instancePtrLeft, instancePtrRight) == true);
275 
276  instancePtrRight->setTile(tile2);
277  BOOST_REQUIRE(pd.diffInstance(instancePtrLeft, instancePtrRight) == false);
278  instancePtrLeft->setTile(tile2);
279  BOOST_REQUIRE(pd.diffInstance(instancePtrLeft, instancePtrRight) == true);
280 
281  instancePtrLeft->setSite(site2);
282  BOOST_REQUIRE(pd.diffInstance(instancePtrLeft, instancePtrRight) == false);
283  instancePtrRight->setSite(site2);
284  BOOST_REQUIRE(pd.diffInstance(instancePtrLeft, instancePtrRight) == true);
285 
286  instancePtrLeft->setBonding(physical::eInstanceBondingBonded);
287  BOOST_REQUIRE(pd.diffInstance(instancePtrLeft, instancePtrRight) == false);
288  instancePtrRight->setBonding(physical::eInstanceBondingBonded);
289  BOOST_REQUIRE(pd.diffInstance(instancePtrLeft, instancePtrRight) == true);
290 
291 }
292 
293 /// \brief Unit test for the net diff function.
294 BOOST_AUTO_TEST_CASE(PhysicalDiffNetUnitTest) {
295  std::ostringstream nullstream(std::ostringstream::out);
296  PhysicalDiff pd(nullstream);
297  // functions tested:
298  // bool diffNet(const NetSharedPtr& left, const NetSharedPtr& right);
299 
300  physical::InstanceSharedPtr instPtrLeft
301  = physical::Factory::newInstancePtr("inst1", "itype", "tile", "site");
302  physical::InstanceSharedPtr instPtrRight
303  = physical::Factory::newInstancePtr("inst1", "itype", "tile", "site");
304  physical::InstancePinSharedPtr instPin1LeftPtr
305  = physical::Factory::newInstancePinPtr(instPtrLeft, "pin1");
306  physical::InstancePinSharedPtr instPin2LeftPtr
307  = physical::Factory::newInstancePinPtr(instPtrLeft, "pin2");
308  physical::InstancePinSharedPtr instPin1RightPtr
309  = physical::Factory::newInstancePinPtr(instPtrRight, "pin1");
310  physical::InstancePinSharedPtr instPin2RightPtr
311  = physical::Factory::newInstancePinPtr(instPtrRight, "pin2");
313  "tile1", "source1", "sink1", physical::ePipUnidirectionalBuffered);
315  "tile1", "source1", "sink1", physical::ePipUnidirectionalBuffered);
316 
317  std::string name = "name";
319 
320  physical::NetSharedPtr netPtrLeft = physical::Factory::newNetPtr(name, type);
321  physical::NetSharedPtr netPtrRight = physical::Factory::newNetPtr(name, type);
322 
323  BOOST_REQUIRE(pd.diffNet(netPtrLeft, netPtrRight) == true);
324 
325  netPtrRight->setNetType(physical::eNetTypeNormal);
326  BOOST_REQUIRE(pd.diffNet(netPtrLeft, netPtrRight) == false);
327  netPtrLeft->setNetType(physical::eNetTypeNormal);
328  BOOST_REQUIRE(pd.diffNet(netPtrLeft, netPtrRight) == true);
329 
330  netPtrLeft->addSource(instPin1LeftPtr);
331  BOOST_REQUIRE(pd.diffNet(netPtrLeft, netPtrRight) == false);
332  netPtrRight->addSource(instPin1RightPtr);
333  BOOST_REQUIRE(pd.diffNet(netPtrLeft, netPtrRight) == true);
334 
335  netPtrLeft->addSink(instPin2LeftPtr);
336  BOOST_REQUIRE(pd.diffNet(netPtrLeft, netPtrRight) == false);
337  netPtrRight->addSink(instPin2RightPtr);
338  BOOST_REQUIRE(pd.diffNet(netPtrLeft, netPtrRight) == true);
339 
340  netPtrRight->addPip(pip1Right);
341  BOOST_REQUIRE(pd.diffNet(netPtrLeft, netPtrRight) == false);
342  netPtrLeft->addPip(pip1Left);
343  BOOST_REQUIRE(pd.diffNet(netPtrLeft, netPtrRight) == true);
344 }
345 
346 BOOST_AUTO_TEST_SUITE_END()
347 
348 } // namespace torc
ENetType
Enumeration of net power types.
static PortSharedPtr newPortPtr(const string &inName, InstanceSharedPtr inInstancePtr, const string &inPinName)
Create and return a new Port shared pointer.
bool diffDesign(const DesignSharedPtr &left, const DesignSharedPtr &right)
Diff design pointers and then recursively compare modules and inherited members.
bool diffInstance(const InstanceSharedPtr &left, const InstanceSharedPtr &right)
Diff instance pointers and then the underlying config map.
boost::shared_ptr< Port > PortSharedPtr
Shared pointer encapsulation of a Port.
PhysicalDiff class for comparing physical netlists.
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::shared_ptr< Module > ModuleSharedPtr
Shared pointer encapsulation of a Module.
Definition: Module.hpp:114
bool diffNet(const NetSharedPtr &left, const NetSharedPtr &right)
Diff net pointers and then the underlying config map.
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.
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
bool diffModule(const ModuleSharedPtr &left, const ModuleSharedPtr &right)
Diff module pointers and then recursively compare inherited members from circuit. ...
Physical design programmable interconnect point.
Definition: Pip.hpp:34
static InstancePinSharedPtr newInstancePinPtr(InstanceSharedPtr inInstancePtr, const string &inPinName)
Construct and return a new InstancePin shared pointer.
static ModuleSharedPtr newModulePtr(const string &inName, const string &inAnchor)
Create and return a new Module shared pointer.
Diff utility class for comparing physical netlists.
BOOST_AUTO_TEST_CASE(XilinxDatabaseTypesUnitTest)
Unit test for device database type sizes.
static DesignSharedPtr newDesignPtr(const string &inName, const string &inDevice, const string &inPackage, const string &inSpeedGrade, const string &inXdlVersion)
Create and return a new Design shared pointer.