OpenASIP 2.2
Loading...
Searching...
No Matches
TestApplication.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 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 TestApplication.cc
26 *
27 * Implementation of TestApplication class.
28 *
29 * @author Jari Mäntyneva 2007 (jari.mantyneva-no.spam-tut.fi)
30 * @author Esa Määttä 2008 (esa.maatta-no.spam-tut.fi)
31 * @note rating: red
32 */
33
34#include <cstdio>
35#include <fstream>
36
37#include "TestApplication.hh"
38#include "FileSystem.hh"
39#include "Conversion.hh"
40
41
42using std::string;
43
44const string TestApplication::DESCRIPTION_FILE_NAME_ = "description.txt";
46const string TestApplication::SETUP_FILE_NAME_ = "setup.sh";
47const string TestApplication::SIMULATE_TTASIM_FILE_NAME_ = "simulate.ttasim";
49 "correct_simulation_output";
50const string TestApplication::VERIFY_FILE_NAME_ = "verify.sh";
51const string TestApplication::CLEANUP_FILE_NAME_ = "cleanup.sh";
53 "functions_of_interest";
54const string TestApplication::MAX_RUNTIME_ = "max_runtime";
56
57/**
58 * Constructor.
59 *
60 * @param testApplicationPath Path of the test application directory.
61 */
62TestApplication::TestApplication(const string& testApplicationPath)
63 : testApplicationPath_(testApplicationPath), maxRuntime_(0) {
64 string maxRuntimeFile = testApplicationPath_
67 if (FileSystem::fileExists(maxRuntimeFile)) {
68 char line[MAX_LINE_LENGTH_];
69 FILE* file = fopen(maxRuntimeFile.c_str(), "r");
70 if (fgets(line, MAX_LINE_LENGTH_, file) == NULL)
71 abort();
72 try {
74 } catch (const NumberFormatException& exception) {
75 fclose(file);
76 throw IOException(
77 __FILE__, __LINE__, __func__, exception.errorMessage());
78 }
79 fclose(file);
80 }
81
83 std::ifstream f(
86 std::string str(
87 (std::istreambuf_iterator<char>(f)),
88 std::istreambuf_iterator<char>());
90 }
91}
92
93/**
94 * Destructor.
95 */
98
99/**
100 * Returns the test application description.
101 *
102 * The description is given in the description.txt file of the test
103 * application directory.
104 *
105 * @return The test application description. Returns an empty vector if the
106 * desctription.txt file was not found.
107 */
108std::vector<std::string>
110
111 std::vector<string> description;
112 string descriptionFile =
115 if (FileSystem::fileExists(descriptionFile)) {
116 char line[MAX_LINE_LENGTH_];
117 FILE* file = fopen(descriptionFile.c_str(), "r");
118 while (fgets(line, MAX_LINE_LENGTH_, file)) {
119 description.push_back(line);
120 }
121 fclose(file);
122 }
123 return description;
124}
125
126/**
127 * Verifies the previous simulation run.
128 *
129 * Uses 'verify.sh' to verify the previous simulation run.
130 *
131 * @return True if the simulation result was verified as correct.
132 */
133bool
135
136 string verifyFile =
139
140 if (FileSystem::fileExists(verifyFile)) {
141 return FileSystem::runShellCommand(verifyFile);
142 }
143 return false;
144}
145
146/**
147 * Returns the correct output from file 'correct_simulation_output' as string.
148 *
149 * @return Correct output as string.
150 */
151const std::string
153
154 string correctOutputFile =
157 if (!FileSystem::fileExists(correctOutputFile)) {
158 return "";
159 }
160 std::string buf;
161 std::string line;
162 std::ifstream in(correctOutputFile.c_str());
163
164 if (std::getline(in,line)) {
165 buf += line;
166 }
167 while(std::getline(in,line)) {
168 buf += "\n";
169 buf += line;
170 }
171 return buf;
172}
173
174/**
175 * Set up the simulation run.
176 *
177 * Uses 'setup.sh' to set up the simulation run.
178 */
179void
181
182 string setupFile =
185 if (FileSystem::fileExists(setupFile)) {
186 FileSystem::runShellCommand(setupFile);
187 }
188}
189
190/**
191 * Returns a istream to 'simulate.ttasim' file.
192 *
193 * Client takes responsibility of destroying the stream.
194 *
195 * @return istream to 'simulate.ttasim' file.
196 */
197std::istream*
199
200 std::ifstream* ifStream = new std::ifstream;
201 if (!hasSimulateTTASim()) {
202 return ifStream;
203 }
204 delete ifStream;
205 ifStream = NULL;
206
207 string simulateFile =
210 return new std::ifstream(simulateFile.c_str());
211}
212
213
214/**
215 * Cleans up the previous simulation run.
216 *
217 * Uses 'cleanup.sh' script if it exists.
218 */
219void
221 string cleanupFile =
224 if (FileSystem::fileExists(cleanupFile)) {
225 FileSystem::runShellCommand(cleanupFile);
226 }
227}
228
229/**
230 * Returns the maximum runtime that is set in file "max_runtime".
231 */
234 return maxRuntime_;
235}
236
237/**
238 * Returns true if 'sequential_program' file is in the test application
239 * directory.
240 */
241bool
243
244 string applicationBCFile =
247 string applicationLLFile =
250
251 return FileSystem::fileExists(applicationBCFile) ||
252 FileSystem::fileExists(applicationLLFile);
253}
254
255/**
256 * Returns true if 'setup.sh' file is in the test application directory.
257 */
258bool
266
267/**
268 * Returns true if 'simulate.ttasim' file is in the test application directory.
269 */
270bool
278
279/**
280 * Returns true if 'correct_simulation_output' file is in the test
281 * application directory.
282 */
283bool
285
286 string correctOutputFile =
289 return FileSystem::fileExists(correctOutputFile);
290}
291
292/**
293 * Returns true if 'verify.sh' file is in the test application directory.
294 */
295bool
303
304/**
305 * Returns true if 'cleanup.sh' file is in the test application directory.
306 */
307bool
315
316/**
317 * @return true if 'functions_of_interest' file is found in the application
318 * directory.
319 */
320bool
326
327/**
328 * Returns the application path in the test application directory.
329 *
330 * If the file 'sequential_program' does not exists returns an empty string.
331 *
332 * @return The path of the 'sequential_program' file.
333 */
334const std::string
336
337 if (hasApplication()) {
338 string applicationBCFile =
341 string applicationLLFile =
344
345 // prioritize the .ll file as it's more portable across
346 // LLVM versions than the bitcode
347 if (FileSystem::fileExists(applicationLLFile)) {
348 return applicationLLFile;
349 }
350 if (FileSystem::fileExists(applicationBCFile)) {
351 return applicationBCFile;
352 }
353
354 }
355 return "";
356}
#define __func__
static double toDouble(const T &source)
std::string errorMessage() const
Definition Exception.cc:123
static bool runShellCommand(const std::string command)
static bool fileIsReadable(const std::string fileName)
static const std::string DIRECTORY_SEPARATOR
static bool fileExists(const std::string fileName)
std::vector< TCEString > split(const std::string &delim) const
Definition TCEString.cc:114
bool hasCorrectOutput() const
const std::string correctOutput() const
static const std::string APPLICATION_BASE_FILE_NAME_
Name of the sequential program file. Base name of the file that contains the fully linked program....
bool hasCleanupSimulation() const
void cleanupSimulation() const
bool hasSimulateTTASim() const
bool hasApplication() const
static const std::string MAX_RUNTIME_
Name of the file that contains maximum runtime.
const std::string testApplicationPath_
Path of the test application directory.
std::vector< TCEString > functionsOfInterest_
The names of the functions of interest (in terms of cycle count).
static const std::string VERIFY_FILE_NAME_
Name of the verify script file.
const std::string applicationPath() const
Runtime maxRuntime() const
static const std::string CLEANUP_FILE_NAME_
Name of the clean up file.
TestApplication(const std::string &testApplicationPath)
static const int MAX_LINE_LENGTH_
Maximum line length in a file.
std::istream * simulateTTASim() const
static const std::string DESCRIPTION_FILE_NAME_
File name of the description text for the application.
static const std::string SETUP_FILE_NAME_
Name of the file that contains setup script.
virtual ~TestApplication()
bool hasVerifySimulation() const
bool hasFunctionsOfInterest() const
static const std::string SIMULATE_TTASIM_FILE_NAME_
Name of the file that runs the simulation.
std::vector< std::string > description() const
void setupSimulation() const
bool verifySimulation() const
static const std::string CORRECT_OUTPUT_FILE_NAME_
Name of the correct simulation output file.
bool hasSetupSimulation() const
Runtime maxRuntime_
Maximum runtime of the test appication in nano seconds.
static const std::string FUNCTIONS_OF_INTEREST_FILE_NAME_
Name of the file that has a comma separated list of functions of interest for the cycle count measure...