OpenASIP  2.0
TTAUnitTester.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 TTAUnitTester.cc
26  *
27  * Implementation of TTAUnitTester utility program
28  *
29  * @author Otto Esko 2010 (otto.esko-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <cstdlib>
34 #include <string>
35 #include <vector>
36 #include "MachineImplementation.hh"
37 #include "Machine.hh"
38 #include "ADFSerializer.hh"
39 #include "IDFSerializer.hh"
40 #include "IDFValidator.hh"
41 #include "TTAUnitTester.hh"
42 #include "HDBTester.hh"
43 #include "Exception.hh"
46 using std::string;
47 
48 int main(int argc, char* argv[]) {
49 
51  try {
52  options.parse(argv, argc);
53  } catch (ParserStopRequest) {
54  return EXIT_SUCCESS;
55  } catch (const IllegalCommandLine& exception) {
56  std::cerr << exception.errorMessage() << std::endl;
57  return EXIT_FAILURE;
58  }
59 
60  string idfFile = "";
61  if (options.numberOfArguments() == 0) {
62  std::cerr << "IDF file was not given" << std::endl;
64  return EXIT_FAILURE;
65  } else if (options.numberOfArguments() > 1) {
66  std::cerr << "Illegal arguments" << std::endl;
68  return EXIT_FAILURE;
69  } else {
70  idfFile = options.idfFileName();
71  }
72 
73  string adfFile = options.adfFileName();
74 
75  string sim = options.vhdlSim();
76  VhdlSim simulator = SIM_GHDL;
77  if (sim == "modelsim") {
78  simulator = SIM_MODELSIM;
79  } else {
80  simulator = SIM_GHDL;
81  }
82 
83  bool verbose = options.verbose();
84  bool leaveDirty = options.leaveDirty();
85 
86  IDF::MachineImplementation* idf = readIdf(idfFile);
87  if (!idf) {
88  return EXIT_FAILURE;
89  }
90 
91  // validate idf if adf was given
92  if (!adfFile.empty()) {
93  TTAMachine::Machine* mach = readAdf(adfFile);
94  if (!mach) {
95  return EXIT_FAILURE;
96  }
97  if (!validateIdf(*idf, *mach)) {
98  delete(mach);
99  delete(idf);
100  return EXIT_FAILURE;
101  }
102  delete(mach);
103  }
104 
105  if (!testUnits(*idf, simulator, verbose, leaveDirty)) {
106  delete(idf);
107  return EXIT_FAILURE;
108  }
109 
110  delete(idf);
111  return EXIT_SUCCESS;
112 }
113 
114 
116 readAdf(std::string adfName) {
117 
118  ADFSerializer reader;
119  reader.setSourceFile(adfName);
120  TTAMachine::Machine* mach = NULL;
121  try {
122  mach = reader.readMachine();
123  } catch (Exception& e) {
124  std::cerr << "Failed to load ADF file " << adfName << ": "
125  << e.errorMessage() << std::endl;
126  return NULL;
127  }
128  return mach;
129 }
130 
131 
133 readIdf(std::string idfName) {
134 
135  IDF::IDFSerializer reader;
136  reader.setSourceFile(idfName);
138  try {
140  } catch (Exception& e) {
141  std::cerr << "Failed to load IDF file " << idfName << ": "
142  << e.errorMessage() << std::endl;
143  return NULL;
144  }
145  return implementation;
146 }
147 
148 
149 bool
151  const IDF::MachineImplementation& idf,
152  const TTAMachine::Machine& machine) {
153 
154  IDFValidator validator(idf, machine);
155 
156  bool success = validator.validate();
157  if (!success) {
158  for (int i = 0; i < validator.errorCount(); i++) {
159  std::cerr << validator.errorMessage(i) << std::endl;
160  }
161  }
162  return success;
163 }
164 
165 
166 bool
168  const IDF::MachineImplementation &idf,
169  VhdlSim simulator, bool verbose, bool leaveDirty) {
170 
171  HDBTester tester(std::cout, std::cerr, simulator, verbose, leaveDirty);
172 
173  bool allPassed = true;
174  for (int i = 0; i < idf.fuImplementationCount(); i++) {
176  string hdb = unit->hdbFile();
177  int entryId = unit->id();
178  if (!tester.testOneFU(hdb, entryId)) {
179  allPassed = false;
180  }
181  }
182 
183  for (int i = 0; i < idf.rfImplementationCount(); i++) {
185  string hdb = unit->hdbFile();
186  int entryId = unit->id();
187  if (!tester.testOneRF(hdb, entryId)) {
188  allPassed = false;
189  }
190  }
191 
192  return allPassed;
193 }
IDF::UnitImplementationLocation
Definition: UnitImplementationLocation.hh:48
IDFValidator::errorCount
int errorCount() const
Definition: IDFValidator.cc:81
MachInfoCmdLineOptions::printHelp
virtual void printHelp() const
Definition: MachInfoCmdLineOptions.cc:89
ParserStopRequest
Definition: Exception.hh:491
XMLSerializer::setSourceFile
void setSourceFile(const std::string &fileName)
Definition: XMLSerializer.cc:115
TTAUnitTesterCmdLineOptions.hh
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
Exception.hh
CmdLineParser::numberOfArguments
virtual int numberOfArguments() const
implementation
IDF::MachineImplementation * implementation
the implementation definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:61
IDF::IDFSerializer::readMachineImplementation
MachineImplementation * readMachineImplementation()
Definition: IDFSerializer.cc:148
IllegalCommandLine
Definition: Exception.hh:438
testUnits
bool testUnits(const IDF::MachineImplementation &idf, VhdlSim simulator, bool verbose, bool leaveDirty)
Definition: TTAUnitTester.cc:167
IDFValidator::errorMessage
std::string errorMessage(int index) const
Definition: IDFValidator.cc:94
HDBTester.hh
IDFValidator.hh
IDF::MachineImplementation::rfImplementation
RFImplementationLocation & rfImplementation(const std::string &rf) const
Definition: MachineImplementation.cc:377
TTAUnitTesterCmdLineOptions
Definition: TTAUnitTesterCmdLineOptions.hh:39
SIM_GHDL
@ SIM_GHDL
Definition: ImplementationTester.hh:48
ADFSerializer
Definition: ADFSerializer.hh:49
IDFValidator
Definition: IDFValidator.hh:52
validateIdf
bool validateIdf(const IDF::MachineImplementation &idf, const TTAMachine::Machine &machine)
Definition: TTAUnitTester.cc:150
IDF::MachineImplementation::rfImplementationCount
int rfImplementationCount() const
Definition: MachineImplementation.cc:310
IDFValidator::validate
bool validate()
Definition: IDFValidator.cc:66
Machine.hh
Exception
Definition: Exception.hh:54
VhdlSim
VhdlSim
Definition: ImplementationTester.hh:47
readAdf
TTAMachine::Machine * readAdf(std::string adfName)
Definition: TTAUnitTester.cc:116
HDBTester
Definition: HDBTester.hh:39
HDBTester::testOneRF
bool testOneRF(std::string hdbFile, int entryId)
Definition: HDBTester.cc:92
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
CmdLineOptions::parse
void parse(char *argv[], int argc)
Definition: CmdLineOptions.cc:107
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
TTAUnitTester.hh
ADFSerializer.hh
HDBTester::testOneFU
bool testOneFU(std::string hdbFile, int entryId)
Definition: HDBTester.cc:110
IDF::MachineImplementation::fuImplementationCount
int fuImplementationCount() const
Definition: MachineImplementation.cc:299
IDF::UnitImplementationLocation::id
virtual int id() const
Definition: UnitImplementationLocation.cc:127
ADFSerializer::readMachine
TTAMachine::Machine * readMachine()
Definition: ADFSerializer.cc:275
IDF::UnitImplementationLocation::hdbFile
virtual std::string hdbFile() const
Definition: UnitImplementationLocation.cc:99
SIM_MODELSIM
@ SIM_MODELSIM
Definition: ImplementationTester.hh:49
IDF::MachineImplementation::fuImplementation
FUImplementationLocation & fuImplementation(const std::string &fu) const
Definition: MachineImplementation.cc:355
readIdf
IDF::MachineImplementation * readIdf(std::string idfName)
Definition: TTAUnitTester.cc:133
IDF::IDFSerializer
Definition: IDFSerializer.hh:45
IDF::MachineImplementation
Definition: MachineImplementation.hh:54
UnitImplementationLocation.hh
main
int main(int argc, char *argv[])
Definition: TTAUnitTester.cc:48
MachineImplementation.hh
TTAMachine::Machine
Definition: Machine.hh:73
IDFSerializer.hh