OpenASIP  2.0
Public Types | Public Member Functions | Private Attributes | Static Private Attributes | List of all members
TestApplication Class Reference

#include <TestApplication.hh>

Collaboration diagram for TestApplication:
Collaboration graph

Public Types

typedef double Runtime
 
typedef int ClockCycles
 

Public Member Functions

 TestApplication (const std::string &testApplicationPath)
 
virtual ~TestApplication ()
 
std::vector< std::string > description () const
 
bool hasApplication () const
 
bool hasSetupSimulation () const
 
bool hasSimulateTTASim () const
 
bool hasCorrectOutput () const
 
bool hasVerifySimulation () const
 
bool hasCleanupSimulation () const
 
bool isValid () const
 
const std::string applicationPath () const
 
void setupSimulation () const
 
std::istream * simulateTTASim () const
 
const std::string correctOutput () const
 
bool verifySimulation () const
 
void cleanupSimulation () const
 
ClockCycles cycleCount () const
 
Runtime maxRuntime () const
 

Private Attributes

const std::string testApplicationPath_
 Path of the test application directory. More...
 
Runtime maxRuntime_
 Maximum runtime of the test appication in nano seconds. More...
 

Static Private Attributes

static const std::string DESCRIPTION_FILE_NAME_ = "description.txt"
 File name of the description text for the application. More...
 
static const std::string APPLICATION_BASE_FILE_NAME_ = "program"
 Name of the sequential program file. Base name of the file that contains the fully linked program. The actual file name will be formed by appending either .bc or .ll, whichever is found first. More...
 
static const std::string SETUP_FILE_NAME_ = "setup.sh"
 Name of the file that contains setup script. More...
 
static const std::string SIMULATE_TTASIM_FILE_NAME_ = "simulate.ttasim"
 Name of the file that runs the simulation. More...
 
static const std::string CORRECT_OUTPUT_FILE_NAME_ = "correct_simulation_output"
 Name of the correct simulation output file. More...
 
static const std::string VERIFY_FILE_NAME_ = "verify.sh"
 Name of the verify script file. More...
 
static const std::string CLEANUP_FILE_NAME_ = "cleanup.sh"
 Name of the clean up file. More...
 
static const std::string MAX_RUNTIME_ = "max_runtime"
 Name of the file that contains maximum runtime. More...
 
static const int MAX_LINE_LENGTH_ = 512
 Maximum line length in a file. More...
 

Detailed Description

Class for handling files in test application directory.

Definition at line 46 of file TestApplication.hh.

Member Typedef Documentation

◆ ClockCycles

Definition at line 49 of file TestApplication.hh.

◆ Runtime

typedef double TestApplication::Runtime

Definition at line 48 of file TestApplication.hh.

Constructor & Destructor Documentation

◆ TestApplication()

TestApplication::TestApplication ( const std::string &  testApplicationPath)

Constructor.

Parameters
testApplicationPathPath of the test application directory.

Definition at line 60 of file TestApplication.cc.

61  : testApplicationPath_(testApplicationPath), maxRuntime_(0) {
62  string maxRuntimeFile = testApplicationPath_
64  + MAX_RUNTIME_;
65  if (FileSystem::fileExists(maxRuntimeFile)) {
66  char line[MAX_LINE_LENGTH_];
67  FILE* file = fopen(maxRuntimeFile.c_str(), "r");
68  if (fgets(line, MAX_LINE_LENGTH_, file) == NULL)
69  abort();
70  try {
72  } catch (const NumberFormatException& exception) {
73  fclose(file);
74  throw IOException(
75  __FILE__, __LINE__, __func__, exception.errorMessage());
76  }
77  fclose(file);
78  }
79 }

References __func__, FileSystem::DIRECTORY_SEPARATOR, Exception::errorMessage(), FileSystem::fileExists(), MAX_LINE_LENGTH_, MAX_RUNTIME_, maxRuntime_, testApplicationPath_, and Conversion::toDouble().

Here is the call graph for this function:

◆ ~TestApplication()

TestApplication::~TestApplication ( )
virtual

Destructor.

Definition at line 84 of file TestApplication.cc.

84  {
85 }

Member Function Documentation

◆ applicationPath()

const std::string TestApplication::applicationPath ( ) const

Returns the application path in the test application directory.

If the file 'sequential_program' does not exists returns an empty string.

Returns
The path of the 'sequential_program' file.

Definition at line 312 of file TestApplication.cc.

312  {
313 
314  if (hasApplication()) {
315  string applicationBCFile =
318  string applicationLLFile =
321 
322  // prioritize the .ll file as it's more portable across
323  // LLVM versions than the bitcode
324  if (FileSystem::fileExists(applicationLLFile)) {
325  return applicationLLFile;
326  }
327  if (FileSystem::fileExists(applicationBCFile)) {
328  return applicationBCFile;
329  }
330 
331  }
332  return "";
333 }

References APPLICATION_BASE_FILE_NAME_, FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), hasApplication(), and testApplicationPath_.

Referenced by DesignSpaceExplorer::evaluate(), and SimpleICOptimizer::explore().

Here is the call graph for this function:

◆ cleanupSimulation()

void TestApplication::cleanupSimulation ( ) const

Cleans up the previous simulation run.

Uses 'cleanup.sh' script if it exists.

Definition at line 208 of file TestApplication.cc.

208  {
209  string cleanupFile =
212  if (FileSystem::fileExists(cleanupFile)) {
213  FileSystem::runShellCommand(cleanupFile);
214  }
215 }

References CLEANUP_FILE_NAME_, FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), FileSystem::runShellCommand(), and testApplicationPath_.

Here is the call graph for this function:

◆ correctOutput()

const std::string TestApplication::correctOutput ( ) const

Returns the correct output from file 'correct_simulation_output' as string.

Returns
Correct output as string.

Definition at line 140 of file TestApplication.cc.

140  {
141 
142  string correctOutputFile =
145  if (!FileSystem::fileExists(correctOutputFile)) {
146  return "";
147  }
148  std::string buf;
149  std::string line;
150  std::ifstream in(correctOutputFile.c_str());
151 
152  if (std::getline(in,line)) {
153  buf += line;
154  }
155  while(std::getline(in,line)) {
156  buf += "\n";
157  buf += line;
158  }
159  return buf;
160 }

References CORRECT_OUTPUT_FILE_NAME_, FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), and testApplicationPath_.

Referenced by DesignSpaceExplorer::evaluate().

Here is the call graph for this function:

◆ cycleCount()

ClockCycles TestApplication::cycleCount ( ) const

◆ description()

std::vector< std::string > TestApplication::description ( ) const

Returns the test application description.

The description is given in the description.txt file of the test application directory.

Returns
The test application description. Returns an empty vector if the desctription.txt file was not found.

Definition at line 97 of file TestApplication.cc.

97  {
98 
99  std::vector<string> description;
100  string descriptionFile =
103  if (FileSystem::fileExists(descriptionFile)) {
104  char line[MAX_LINE_LENGTH_];
105  FILE* file = fopen(descriptionFile.c_str(), "r");
106  while (fgets(line, MAX_LINE_LENGTH_, file)) {
107  description.push_back(line);
108  }
109  fclose(file);
110  }
111  return description;
112 }

References DESCRIPTION_FILE_NAME_, FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), MAX_LINE_LENGTH_, and testApplicationPath_.

Here is the call graph for this function:

◆ hasApplication()

bool TestApplication::hasApplication ( ) const

Returns true if 'sequential_program' file is in the test application directory.

Definition at line 230 of file TestApplication.cc.

230  {
231 
232  string applicationBCFile =
235  string applicationLLFile =
238 
239  return FileSystem::fileExists(applicationBCFile) ||
240  FileSystem::fileExists(applicationLLFile);
241 }

References APPLICATION_BASE_FILE_NAME_, FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), and testApplicationPath_.

Referenced by applicationPath(), and isValid().

Here is the call graph for this function:

◆ hasCleanupSimulation()

bool TestApplication::hasCleanupSimulation ( ) const

Returns true if 'cleanup.sh' file is in the test application directory.

Definition at line 296 of file TestApplication.cc.

296  {
297 
298  string cleanupFile =
301  return FileSystem::fileExists(cleanupFile);
302 }

References CLEANUP_FILE_NAME_, FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), and testApplicationPath_.

Here is the call graph for this function:

◆ hasCorrectOutput()

bool TestApplication::hasCorrectOutput ( ) const

Returns true if 'correct_simulation_output' file is in the test application directory.

Definition at line 272 of file TestApplication.cc.

272  {
273 
274  string correctOutputFile =
277  return FileSystem::fileExists(correctOutputFile);
278 }

References CORRECT_OUTPUT_FILE_NAME_, FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), and testApplicationPath_.

Referenced by DesignSpaceExplorer::evaluate(), and isValid().

Here is the call graph for this function:

◆ hasSetupSimulation()

bool TestApplication::hasSetupSimulation ( ) const

Returns true if 'setup.sh' file is in the test application directory.

Definition at line 247 of file TestApplication.cc.

247  {
248 
249  string setupFile =
252  return FileSystem::fileExists(setupFile);
253 }

References FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), SETUP_FILE_NAME_, and testApplicationPath_.

Here is the call graph for this function:

◆ hasSimulateTTASim()

bool TestApplication::hasSimulateTTASim ( ) const

Returns true if 'simulate.ttasim' file is in the test application directory.

Definition at line 259 of file TestApplication.cc.

259  {
260 
261  string simulateFile =
264  return FileSystem::fileExists(simulateFile);
265 }

References FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), SIMULATE_TTASIM_FILE_NAME_, and testApplicationPath_.

Referenced by DesignSpaceExplorer::simulate(), and simulateTTASim().

Here is the call graph for this function:

◆ hasVerifySimulation()

bool TestApplication::hasVerifySimulation ( ) const

Returns true if 'verify.sh' file is in the test application directory.

Definition at line 284 of file TestApplication.cc.

284  {
285 
286  string verifyFile =
289  return FileSystem::fileExists(verifyFile);
290 }

References FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), testApplicationPath_, and VERIFY_FILE_NAME_.

Referenced by isValid().

Here is the call graph for this function:

◆ isValid()

bool TestApplication::isValid ( ) const
inline

Definition at line 62 of file TestApplication.hh.

62  {
63  return hasApplication() &&
65  }

References hasApplication(), hasCorrectOutput(), and hasVerifySimulation().

Referenced by main().

Here is the call graph for this function:

◆ maxRuntime()

TestApplication::Runtime TestApplication::maxRuntime ( ) const

Returns the maximum runtime that is set in file "max_runtime".

Definition at line 221 of file TestApplication.cc.

221  {
222  return maxRuntime_;
223 }

References maxRuntime_.

Referenced by FrequencySweepExplorer::fastEnough(), and MinimizeMachine::minimizeMachine().

◆ setupSimulation()

void TestApplication::setupSimulation ( ) const

Set up the simulation run.

Uses 'setup.sh' to set up the simulation run.

Definition at line 168 of file TestApplication.cc.

168  {
169 
170  string setupFile =
173  if (FileSystem::fileExists(setupFile)) {
174  FileSystem::runShellCommand(setupFile);
175  }
176 }

References FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), FileSystem::runShellCommand(), SETUP_FILE_NAME_, and testApplicationPath_.

Referenced by DesignSpaceExplorer::simulate().

Here is the call graph for this function:

◆ simulateTTASim()

std::istream * TestApplication::simulateTTASim ( ) const

Returns a istream to 'simulate.ttasim' file.

Client takes responsibility of destroying the stream.

Returns
istream to 'simulate.ttasim' file.

Definition at line 186 of file TestApplication.cc.

186  {
187 
188  std::ifstream* ifStream = new std::ifstream;
189  if (!hasSimulateTTASim()) {
190  return ifStream;
191  }
192  delete ifStream;
193  ifStream = NULL;
194 
195  string simulateFile =
198  return new std::ifstream(simulateFile.c_str());
199 }

References FileSystem::DIRECTORY_SEPARATOR, hasSimulateTTASim(), SIMULATE_TTASIM_FILE_NAME_, and testApplicationPath_.

Referenced by DesignSpaceExplorer::simulate().

Here is the call graph for this function:

◆ verifySimulation()

bool TestApplication::verifySimulation ( ) const

Verifies the previous simulation run.

Uses 'verify.sh' to verify the previous simulation run.

Returns
True if the simulation result was verified as correct.

Definition at line 122 of file TestApplication.cc.

122  {
123 
124  string verifyFile =
127 
128  if (FileSystem::fileExists(verifyFile)) {
129  return FileSystem::runShellCommand(verifyFile);
130  }
131  return false;
132 }

References FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), FileSystem::runShellCommand(), testApplicationPath_, and VERIFY_FILE_NAME_.

Here is the call graph for this function:

Member Data Documentation

◆ APPLICATION_BASE_FILE_NAME_

const string TestApplication::APPLICATION_BASE_FILE_NAME_ = "program"
staticprivate

Name of the sequential program file. Base name of the file that contains the fully linked program. The actual file name will be formed by appending either .bc or .ll, whichever is found first.

Definition at line 88 of file TestApplication.hh.

Referenced by applicationPath(), and hasApplication().

◆ CLEANUP_FILE_NAME_

const string TestApplication::CLEANUP_FILE_NAME_ = "cleanup.sh"
staticprivate

Name of the clean up file.

Definition at line 98 of file TestApplication.hh.

Referenced by cleanupSimulation(), and hasCleanupSimulation().

◆ CORRECT_OUTPUT_FILE_NAME_

const string TestApplication::CORRECT_OUTPUT_FILE_NAME_ = "correct_simulation_output"
staticprivate

Name of the correct simulation output file.

Definition at line 94 of file TestApplication.hh.

Referenced by correctOutput(), and hasCorrectOutput().

◆ DESCRIPTION_FILE_NAME_

const string TestApplication::DESCRIPTION_FILE_NAME_ = "description.txt"
staticprivate

File name of the description text for the application.

Definition at line 83 of file TestApplication.hh.

Referenced by description().

◆ MAX_LINE_LENGTH_

const int TestApplication::MAX_LINE_LENGTH_ = 512
staticprivate

Maximum line length in a file.

Definition at line 102 of file TestApplication.hh.

Referenced by description(), and TestApplication().

◆ MAX_RUNTIME_

const string TestApplication::MAX_RUNTIME_ = "max_runtime"
staticprivate

Name of the file that contains maximum runtime.

Definition at line 100 of file TestApplication.hh.

Referenced by TestApplication().

◆ maxRuntime_

Runtime TestApplication::maxRuntime_
private

Maximum runtime of the test appication in nano seconds.

Definition at line 80 of file TestApplication.hh.

Referenced by maxRuntime(), and TestApplication().

◆ SETUP_FILE_NAME_

const string TestApplication::SETUP_FILE_NAME_ = "setup.sh"
staticprivate

Name of the file that contains setup script.

Definition at line 90 of file TestApplication.hh.

Referenced by hasSetupSimulation(), and setupSimulation().

◆ SIMULATE_TTASIM_FILE_NAME_

const string TestApplication::SIMULATE_TTASIM_FILE_NAME_ = "simulate.ttasim"
staticprivate

Name of the file that runs the simulation.

Definition at line 92 of file TestApplication.hh.

Referenced by hasSimulateTTASim(), and simulateTTASim().

◆ testApplicationPath_

const std::string TestApplication::testApplicationPath_
private

◆ VERIFY_FILE_NAME_

const string TestApplication::VERIFY_FILE_NAME_ = "verify.sh"
staticprivate

Name of the verify script file.

Definition at line 96 of file TestApplication.hh.

Referenced by hasVerifySimulation(), and verifySimulation().


The documentation for this class was generated from the following files:
NumberFormatException
Definition: Exception.hh:421
TestApplication::maxRuntime_
Runtime maxRuntime_
Maximum runtime of the test appication in nano seconds.
Definition: TestApplication.hh:80
TestApplication::CLEANUP_FILE_NAME_
static const std::string CLEANUP_FILE_NAME_
Name of the clean up file.
Definition: TestApplication.hh:98
TestApplication::DESCRIPTION_FILE_NAME_
static const std::string DESCRIPTION_FILE_NAME_
File name of the description text for the application.
Definition: TestApplication.hh:83
TestApplication::hasSimulateTTASim
bool hasSimulateTTASim() const
Definition: TestApplication.cc:259
Conversion::toDouble
static double toDouble(const T &source)
TestApplication::hasApplication
bool hasApplication() const
Definition: TestApplication.cc:230
TestApplication::hasVerifySimulation
bool hasVerifySimulation() const
Definition: TestApplication.cc:284
__func__
#define __func__
Definition: Application.hh:67
TestApplication::CORRECT_OUTPUT_FILE_NAME_
static const std::string CORRECT_OUTPUT_FILE_NAME_
Name of the correct simulation output file.
Definition: TestApplication.hh:94
TestApplication::MAX_LINE_LENGTH_
static const int MAX_LINE_LENGTH_
Maximum line length in a file.
Definition: TestApplication.hh:102
TestApplication::SETUP_FILE_NAME_
static const std::string SETUP_FILE_NAME_
Name of the file that contains setup script.
Definition: TestApplication.hh:90
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
TestApplication::description
std::vector< std::string > description() const
Definition: TestApplication.cc:97
TestApplication::SIMULATE_TTASIM_FILE_NAME_
static const std::string SIMULATE_TTASIM_FILE_NAME_
Name of the file that runs the simulation.
Definition: TestApplication.hh:92
TestApplication::MAX_RUNTIME_
static const std::string MAX_RUNTIME_
Name of the file that contains maximum runtime.
Definition: TestApplication.hh:100
TestApplication::APPLICATION_BASE_FILE_NAME_
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....
Definition: TestApplication.hh:88
TestApplication::testApplicationPath_
const std::string testApplicationPath_
Path of the test application directory.
Definition: TestApplication.hh:78
FileSystem::fileExists
static bool fileExists(const std::string fileName)
TestApplication::VERIFY_FILE_NAME_
static const std::string VERIFY_FILE_NAME_
Name of the verify script file.
Definition: TestApplication.hh:96
IOException
Definition: Exception.hh:130
FileSystem::runShellCommand
static bool runShellCommand(const std::string command)
TestApplication::hasCorrectOutput
bool hasCorrectOutput() const
Definition: TestApplication.cc:272