OpenASIP  2.0
HDBTester.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2010 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file HDBTester.cc
26  *
27  * Implementation of HDBTester
28  *
29  * @author Otto Esko 2010 (otto.esko-no.spam-tut.fi)
30  * @note rating: red
31  */
32 #include <iostream>
33 #include <string>
34 #include <vector>
35 #include <set>
36 #include "HDBTester.hh"
37 #include "ImplementationTester.hh"
38 #include "HDBRegistry.hh"
39 using std::string;
40 using std::vector;
41 using std::set;
42 
43 HDBTester::HDBTester(): infoStream_(NULL), errorStream_(NULL), sim_(SIM_GHDL),
44  verbose_(false), leaveDirty_(false) {
45 }
46 
48  std::ostream& infoStream,
49  std::ostream& errorStream,
50  VhdlSim simulator, bool verbose, bool leaveDirty):
51  infoStream_(&infoStream), errorStream_(&errorStream), sim_(simulator),
52  verbose_(verbose), leaveDirty_(leaveDirty) {
53 }
54 
56  // clear hdb cache
58  delete registry;
59 }
60 
61 bool
62 HDBTester::testAllEntries(std::string hdbFile) {
63 
64  ImplementationTester* implTester = initializeTester(hdbFile);
65  if (implTester == NULL) {
66  return false;
67  }
68 
69  bool noFailures = true;
70  set<int> fus = implTester->fuEntryIDs();
71  for (set<int>::iterator iter = fus.begin(); iter != fus.end(); iter++) {
72  if (!testFU(*iter, implTester)) {
73  noFailures = false;
74  std::cerr << "FU Entry " << *iter << " from " << hdbFile
75  << " failed." << std::endl;
76  }
77  }
78 
79  set<int> rfs = implTester->rfEntryIDs();
80  for (set<int>::iterator iter = rfs.begin(); iter != rfs.end(); iter++) {
81  if (!testRF(*iter, implTester)) {
82  noFailures = false;
83  std::cerr << "RF Entry " << *iter << " from " << hdbFile
84  << " failed." << std::endl;
85  }
86  }
87  delete implTester;
88  return noFailures;
89 }
90 
91 bool
92 HDBTester::testOneRF(std::string hdbFile, int entryId) {
93 
94  ImplementationTester* implTester = initializeTester(hdbFile);
95  if (implTester == NULL) {
96  return false;
97  }
98  bool success = testRF(entryId, implTester);
99  delete implTester;
100 
101  if (!success) {
102  std::cerr << "RF Entry " << entryId << " from " << hdbFile
103  << " failed." << std::endl;
104  }
105 
106  return success;
107 }
108 
109 bool
110 HDBTester::testOneFU(std::string hdbFile, int entryId) {
111 
112  ImplementationTester* implTester = initializeTester(hdbFile);
113  if (implTester == NULL) {
114  return false;
115  }
116  bool success = testFU(entryId, implTester);
117  delete implTester;
118 
119  if (!success) {
120  std::cerr << "FU Entry " << entryId << " from " << hdbFile
121  << " failed." << std::endl;
122  }
123 
124  return success;
125 }
126 
128 HDBTester::initializeTester(std::string hdbFile) {
129 
130  ImplementationTester* tester = NULL;
131  try {
132  tester =
134  } catch (Exception& e) {
135  if (errorStream_ != NULL) {
136  *errorStream_ << "Failed to create implementation tester: "
137  << e.errorMessage() << std::endl;
138  }
139  return NULL;
140  }
141  return tester;
142 }
143 
144 bool
146 
147  string reason = "";
148  if (!tester->canTestFU(id, reason)) {
149  if (infoStream_ != NULL) {
150  *infoStream_ << "Cannot test FU id " << id << " because: "
151  << reason << std::endl;
152  }
153  // this is not failure
154  return true;
155  }
156  vector<string> errors;
157  bool success = false;
158  try {
159  success = tester->validateFU(id, errors);
160  } catch (Exception& e) {
161  if (errorStream_ != NULL) {
162  *errorStream_
163  << "Runtime error: " << e.errorMessage() << std::endl;
164  }
165  return false;
166  }
167  if (!errors.empty()) {
168  if (errorStream_ != NULL) {
169  for (unsigned int i = 0; i < errors.size(); i++) {
170  *errorStream_ << errors.at(i);
171  }
172  }
173  success = false;
174  }
175  return success;
176 }
177 
178 bool
180 
181  string reason = "";
182  if (!tester->canTestRF(id, reason)) {
183  if (infoStream_ != NULL) {
184  *infoStream_ << "Cannot test RF id " << id << " because: "
185  << reason << std::endl;
186  }
187  // this is not failure
188  return true;
189  }
190  vector<string> errors;
191  bool success = false;
192  try {
193  success = tester->validateRF(id, errors);
194  } catch (Exception& e) {
195  if (errorStream_ != NULL) {
196  *errorStream_
197  << "Runtime error: " << e.errorMessage() << std::endl;
198  }
199  return false;
200  }
201  if (!errors.empty()) {
202  if (errorStream_ != NULL) {
203  for (unsigned int i = 0; i < errors.size(); i++) {
204  *errorStream_ << errors.at(i);
205  }
206  }
207  success = false;
208  }
209  return success;
210 }
HDBTester::sim_
VhdlSim sim_
Definition: HDBTester.hh:66
ImplementationTester::canTestRF
bool canTestRF(const int entryID, std::string &reason)
Definition: ImplementationTester.cc:219
ImplementationTester
Definition: ImplementationTester.hh:52
ImplementationTester::canTestFU
bool canTestFU(const int entryID, std::string &reason)
Definition: ImplementationTester.cc:175
HDBTester.hh
HDBTester::errorStream_
std::ostream * errorStream_
Definition: HDBTester.hh:65
HDB::HDBRegistry
Definition: HDBRegistry.hh:46
SIM_GHDL
@ SIM_GHDL
Definition: ImplementationTester.hh:48
HDBTester::infoStream_
std::ostream * infoStream_
Definition: HDBTester.hh:64
HDBTester::~HDBTester
virtual ~HDBTester()
Definition: HDBTester.cc:55
Exception
Definition: Exception.hh:54
VhdlSim
VhdlSim
Definition: ImplementationTester.hh:47
HDBTester::testOneRF
bool testOneRF(std::string hdbFile, int entryId)
Definition: HDBTester.cc:92
HDBTester::testFU
bool testFU(int id, ImplementationTester *tester)
Definition: HDBTester.cc:145
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
HDBTester::verbose_
bool verbose_
Definition: HDBTester.hh:67
HDBTester::leaveDirty_
bool leaveDirty_
Definition: HDBTester.hh:68
HDBTester::testAllEntries
bool testAllEntries(std::string hdbFile)
Definition: HDBTester.cc:62
HDBTester::testOneFU
bool testOneFU(std::string hdbFile, int entryId)
Definition: HDBTester.cc:110
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
ImplementationTester::rfEntryIDs
std::set< int > rfEntryIDs() const
Definition: ImplementationTester.cc:382
ImplementationTester::fuEntryIDs
std::set< int > fuEntryIDs() const
Definition: ImplementationTester.cc:369
HDBTester::HDBTester
HDBTester()
Definition: HDBTester.cc:43
HDBRegistry.hh
HDBTester::initializeTester
ImplementationTester * initializeTester(std::string hdbFile)
Definition: HDBTester.cc:128
HDBTester::testRF
bool testRF(int id, ImplementationTester *tester)
Definition: HDBTester.cc:179
ImplementationTester::validateFU
bool validateFU(const int entryID, std::vector< std::string > &errors)
Definition: ImplementationTester.cc:263
ImplementationTester.hh
HDB::HDBRegistry::instance
static HDBRegistry & instance()
Definition: HDBRegistry.cc:62
ImplementationTester::validateRF
bool validateRF(const int entryID, std::vector< std::string > &errors)
Definition: ImplementationTester.cc:321