torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scratch.cpp
Go to the documentation of this file.
1 // TORC - Copyright 2010 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 #if 0
6 #include "torc/physical/xdl/parser.h"
11 #include "torc/physical/Net.hpp"
14 #include "torc/physical/Pip.hpp"
15 #include "torc/physical/Module.hpp"
16 #include "torc/physical/Design.hpp"
17 
18 #include <boost/test/unit_test.hpp>
19 #include "OutputStreamHelpers.hpp"
20 #include <vector>
21 #include <iostream>
22 #include <sstream>
23 #include <algorithm>
24 
25 
26 namespace torc {
27 namespace physical {
28 
29 
30 BOOST_AUTO_TEST_SUITE(physical_database)
31 
32 /// \brief Unit test of scratch work.
33 BOOST_AUTO_TEST_CASE(scratch) {
34  // create a design and verify it
35  const char* designName = "design";
36  Design design(designName);
37  BOOST_CHECK_EQUAL(designName, design.getName());
38 
39  // create a module and verify it
40  const char* moduleName = "module";
41  Module module(moduleName);
42  BOOST_CHECK_EQUAL(moduleName, module.getName());
43 
44  // create an instance and verify it
45  const char* instanceName = "instance";
46  Instance instance(instanceName);
47  BOOST_CHECK_EQUAL(instanceName, instance.getName());
48 
49  // create a net and verify it
50  const char* netName = "net";
51  Net net(netName, eNetTypePower);
52  BOOST_CHECK_EQUAL(netName, net.getName());
53  BOOST_CHECK_EQUAL(eNetTypePower, net.getNetType());
54 
55  // change the net type and verity it
56  net.setNetType(eNetTypeNormal);
57  BOOST_CHECK_EQUAL(eNetTypeNormal, net.getNetType());
58 
59  // create some instance pins
60  InstancePin instancePin1(instance, "pin1");
61  InstancePin instancePin2(instance, "pin2");
62 
63  // add the instance pins to a net
64  net.addSource(instancePin1);
65  net.addSink(instancePin2);
66  BOOST_CHECK(net.hasAnySources());
67  BOOST_CHECK(net.hasOneSource());
68  BOOST_CHECK(net.hasMultipleSources() == false);
69  BOOST_CHECK(net.hasAnySinks());
70  BOOST_CHECK(net.hasOneSink());
71  BOOST_CHECK(net.hasMultipleSinks() == false);
72  // verify that the pins show up in the net
73  InstancePinVector::const_iterator sourcesBegin = net.sourcesBegin();
74  InstancePinVector::const_iterator sourcesEnd = net.sourcesEnd();
75  InstancePinVector::const_iterator sinksBegin = net.sinksBegin();
76  InstancePinVector::const_iterator sinksEnd = net.sinksEnd();
77  BOOST_CHECK_EQUAL(*sourcesBegin, instancePin1);
78  BOOST_CHECK_EQUAL(*sinksBegin, instancePin2);
79  BOOST_CHECK(net.containsSource(instancePin1));
80  BOOST_CHECK(net.containsSource(instancePin2) == false);
81  BOOST_CHECK(net.containsSink(instancePin1) == false);
82  BOOST_CHECK(net.containsSink(instancePin2));
83 
84  // remove the instance pins from the net
85  BOOST_CHECK(net.removeSource(instancePin1)); // should be found and removed
86  BOOST_CHECK(net.removeSource(instancePin2) == false); // should not be found
87  BOOST_CHECK(net.removeSink(instancePin1) == false); // should not be found
88  BOOST_CHECK(net.removeSink(instancePin2)); // should be found and removed
89  sourcesBegin = net.sourcesBegin();
90  sourcesEnd = net.sourcesEnd();
91  sinksBegin = net.sinksBegin();
92  sinksEnd = net.sinksEnd();
93  BOOST_CHECK_EQUAL(sourcesBegin, sourcesEnd);
94  BOOST_CHECK_EQUAL(sinksBegin, sinksEnd);
95  BOOST_CHECK(net.hasAnySources() == false);
96  BOOST_CHECK(net.hasOneSource() == false);
97  BOOST_CHECK(net.hasMultipleSources() == false);
98  BOOST_CHECK(net.hasAnySinks() == false);
99  BOOST_CHECK(net.hasOneSink() == false);
100  BOOST_CHECK(net.hasMultipleSinks() == false);
101 
102  // create some pips
103  Pip pip1("tile1", "source1", "sink1", ePipUnidirectionalBuffered);
104  Pip pip2("tile2", "source2", "sink2", ePipUnidirectionalBuffered);
105  // create a routethrough
106  Routethrough routethrough("setting", "name", "value", instance, "source", "sink");
107 
108  // add the pips to the net
109  net.addPip(pip1);
110  net.addPip(pip2, routethrough);
111  BOOST_CHECK(net.containsPip(pip1));
112  BOOST_CHECK(net.containsPip(pip2));
113 
114  BOOST_CHECK(pip1.isRoutethrough() == false);
115  BOOST_CHECK(pip2.isRoutethrough() == false);
116  PipVector::const_iterator pipsBegin = net.pipsBegin();
117  PipVector::const_iterator pipsEnd = net.pipsEnd();
118  BOOST_CHECK((pipsBegin++)->isRoutethrough() == false);
119  BOOST_CHECK((pipsBegin++)->isRoutethrough());
120 
121  // remove the pips from the net
122  BOOST_CHECK(net.removePip(pip1));
123  BOOST_CHECK(net.removePip(pip2));
124  BOOST_CHECK(net.containsPip(pip1) == false);
125  BOOST_CHECK(net.containsPip(pip2) == false);
126  pipsBegin = net.pipsBegin();
127  pipsEnd = net.pipsEnd();
128  BOOST_CHECK_EQUAL(pipsBegin, pipsEnd);
129 
130  // create some config entries
131  Config config1("name1", "value1");
132  Config config2("name2", "value2");
133  Config config3("name3", "value3");
134  Config config4("name4", "value4");
135  // create a config map and add config entries to it
136  ConfigMap configMap;
137  configMap.setConfig("config", config1);
138  configMap.setConfig("config", config2);
139  configMap.setConfig("_config", config3);
140  configMap.setConfig("_config", config4);
141  BOOST_CHECK(configMap.hasConfig("config"));
142  BOOST_CHECK(configMap.hasConfig("_config"));
143  BOOST_CHECK_EQUAL((size_t) 1, configMap.getMultiConfigCount("config"));
144  BOOST_CHECK_EQUAL((size_t) 2, configMap.getMultiConfigCount("_config"));
145  Config config5;
146  configMap.getConfig("config", config5);
147  BOOST_CHECK_EQUAL(config2, config5);
148  ConfigMap::const_iterator p = configMap.begin();
149  ConfigMap::const_iterator e = configMap.end();
150  BOOST_CHECK_EQUAL(config3, p->second); p++;
151  BOOST_CHECK_EQUAL(config4, p->second); p++;
152  BOOST_CHECK_EQUAL(config2, p->second); p++;
153  std::pair<ConfigMap::const_iterator, ConfigMap::const_iterator> range
154  = configMap.getMultiConfigValues("_config");
155  p = range.first;
156  e = range.second;
157  while(p != e) {
158  std::cout << p->first << ":" << p->second.getName() << ":" << p->second.getValue() << std::endl;
159  p++;
160  }
161 
162  // add the net and the instance to the module
163  module.addInstance(instance);
164  module.addNet(net);
165  // add the module to the design
166  design.addModule(module);
167 
168  // ensure that the module exists in the design
169  ModuleVector::const_iterator modulesBegin = design.modulesBegin();
170  ModuleVector::const_iterator modulesEnd = design.modulesEnd();
171  BOOST_CHECK_EQUAL(*modulesBegin, module);
172  // ensure that the instance and net exist in the module
173  InstanceVector::const_iterator instancesBegin = module.instancesBegin();
174  InstanceVector::const_iterator instancesEnd = module.instancesEnd();
175  NetVector::const_iterator netsBegin = module.netsBegin();
176  NetVector::const_iterator netsEnd = module.netsEnd();
177  BOOST_CHECK_EQUAL(*instancesBegin, instance);
178  BOOST_CHECK_EQUAL(*netsBegin, net);
179 }
180 
181 BOOST_AUTO_TEST_SUITE_END()
182 
183 
184 } // namespace physical
185 } // namespace torc
186 
187 /*
188 #include <boost/multi_index_container.hpp>
189 #include <boost/multi_index/sequenced_index.hpp>
190 #include <boost/multi_index/ordered_index.hpp>
191 #include <boost/multi_index/indexed_by.hpp>
192 
193 using namespace boost::multi_index;
194 
195 struct name{};
196 struct order{};
197 typedef boost::multi_index::multi_index_container<
198  std::string,
199  boost::multi_index::indexed_by<
200  ordered_unique< tag<name>, identity<name> >,
201  sequenced< tag<order> >
202  >
203 > ConfigMap;
204 
205 BOOST_AUTO_TEST_SUITE(physical_database)
206 
207 BOOST_AUTO_TEST_CASE(multi_index) {
208  ConfigMap configMap;
209  BOOST_CHECK(configMap.size() == 0);
210 std::cout << "sizeof(boost::multi_index::multi_index_container): " << sizeof(torc::ConfigMap) << std::endl;
211 std::cout << "sizeof(std::map<std::string,std::string>): " << sizeof(std::map<std::string,std::string>) << std::endl;
212 std::cout << "sizeof(std::multimap<std::string,std::string>): " << sizeof(std::multimap<std::string,std::string>) << std::endl;
213 std::cout << "sizeof(std::vector<torc::InstancePin>): " << sizeof(std::vector<torc::InstancePin>) << std::endl;
214 std::cout << "sizeof(std::vector<torc::Pip>): " << sizeof(std::vector<torc::Pip>) << std::endl;
215 std::cout << "sizeof(std::vector<std::string>): " << sizeof(std::vector<std::string>) << std::endl;
216 
217 }
218 
219 BOOST_AUTO_TEST_SUITE_END()
220 */
221 #endif
Header for the Module class.
Header for the ConfigMap class.
Header for the Config class.
Header for the Instance class.
Header for the Routethrough class.
BOOST_AUTO_TEST_CASE(XdlUnpackUnitTest)
Unit test for the XdlUnpack class.
const_iterator const_iterator
Constant iterator to {setting,Config} pairs.
Definition: ConfigMap.hpp:52
Header for the Design class.
Header for the Named class.
Header for the Net class.
Header for the Pip class.
Header for the InstancePin class.