Nektar++
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Nektar::TestData Class Reference

The TestData class is responsible for parsing a test XML file and storing the data. More...

#include <TestData.h>

Public Member Functions

 TestData (const fs::path &pFilename, po::variables_map &pVm)
 TestData constructor. More...
 
 TestData (const TestData &pSrc)
 
const std::string & GetDescription () const
 Returns the description of a test. More...
 
const CommandGetCommand (unsigned int pId) const
 
unsigned int GetNumCommands () const
 
std::string GetMetricType (unsigned int pId) const
 Returns the type of metric to be collected for a given metric ID. More...
 
unsigned int GetNumMetrics () const
 Returns the number of metrics to be collected for the test. More...
 
TiXmlElement * GetMetric (unsigned int pId)
 Returns a pointer to the TiXmlElement object representing the metric for a given metric ID. More...
 
unsigned int GetMetricId (unsigned int pId)
 Returns the ID of the metric for a given metric ID. More...
 
DependentFile GetDependentFile (unsigned int pId) const
 
unsigned int GetNumDependentFiles () const
 Returns the number of dependent files required for the test. More...
 
unsigned int GetNumRuns () const
 Returns the number of runs to be performed for the test. More...
 
void SaveFile ()
 

Private Member Functions

void Parse (TiXmlDocument *pDoc)
 Parse the test file and populate member variables for the test. More...
 
Command ParseCommand (TiXmlElement *pElmt) const
 

Private Attributes

po::variables_map m_cmdoptions
 
std::string m_description
 
std::vector< Commandm_commands
 
TiXmlDocument * m_doc
 
std::vector< TiXmlElement * > m_metrics
 
std::vector< DependentFilem_files
 
unsigned int m_runs
 The number of times to run the test. More...
 

Detailed Description

The TestData class is responsible for parsing a test XML file and storing the data.

Definition at line 70 of file TestData.h.

Constructor & Destructor Documentation

◆ TestData() [1/2]

Nektar::TestData::TestData ( const fs::path &  pFilename,
po::variables_map &  pVm 
)

TestData constructor.

The class is constructed with the path to the test XML file and a po::variables_map object containing the command-line options passed to the program.

Parameters
pFilename
pVm

Definition at line 58 of file TestData.cpp.

59 : m_cmdoptions(pVm)
60{
61 // Process test file format.
62 m_doc = new TiXmlDocument(pFilename.string().c_str());
63
64 bool loadOkay = m_doc->LoadFile();
65
66 ASSERTL0(loadOkay,
67 "Failed to load test definition file: " + pFilename.string() +
68 "\n" + string(m_doc->ErrorDesc()));
69
70 Parse(m_doc);
71}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
void Parse(TiXmlDocument *pDoc)
Parse the test file and populate member variables for the test.
Definition: TestData.cpp:198
TiXmlDocument * m_doc
Definition: TestData.h:96
po::variables_map m_cmdoptions
Definition: TestData.h:93

References ASSERTL0, m_doc, and Parse().

◆ TestData() [2/2]

Nektar::TestData::TestData ( const TestData pSrc)

Definition at line 73 of file TestData.cpp.

74{
75 boost::ignore_unused(pSrc);
76}

Member Function Documentation

◆ GetCommand()

const Command & Nektar::TestData::GetCommand ( unsigned int  pId) const

Definition at line 84 of file TestData.cpp.

85{
86 ASSERTL0(pId < m_commands.size(),
87 "Command ID '" + std::to_string(pId) + "' not found");
88 return m_commands[pId];
89}
std::vector< Command > m_commands
Definition: TestData.h:95

References ASSERTL0, and m_commands.

Referenced by main().

◆ GetDependentFile()

DependentFile Nektar::TestData::GetDependentFile ( unsigned int  pId) const

Definition at line 131 of file TestData.cpp.

132{
133 ASSERTL0(pId < m_files.size(), "File index out of range.");
134 return m_files[pId];
135}
std::vector< DependentFile > m_files
Definition: TestData.h:98

References ASSERTL0, and m_files.

Referenced by main().

◆ GetDescription()

const std::string & Nektar::TestData::GetDescription ( ) const

Returns the description of a test.

Definition at line 79 of file TestData.cpp.

80{
81 return m_description;
82}
std::string m_description
Definition: TestData.h:94

References m_description.

◆ GetMetric()

TiXmlElement * Nektar::TestData::GetMetric ( unsigned int  pId)

Returns a pointer to the TiXmlElement object representing the metric for a given metric ID.

Definition at line 116 of file TestData.cpp.

117{
118 ASSERTL0(pId < m_metrics.size(), "Metric index out of range.");
119 return m_metrics[pId];
120}
std::vector< TiXmlElement * > m_metrics
Definition: TestData.h:97

References ASSERTL0, and m_metrics.

Referenced by main().

◆ GetMetricId()

unsigned int Nektar::TestData::GetMetricId ( unsigned int  pId)

Returns the ID of the metric for a given metric ID.

Definition at line 123 of file TestData.cpp.

124{
125 ASSERTL0(pId < m_metrics.size(), "Metric index out of range.");
126 const char *id = m_metrics[pId]->Attribute("id");
127 ASSERTL0(id, "No ID found for metric!");
128 return boost::lexical_cast<unsigned int>(id);
129}

References ASSERTL0, and m_metrics.

Referenced by main().

◆ GetMetricType()

std::string Nektar::TestData::GetMetricType ( unsigned int  pId) const

Returns the type of metric to be collected for a given metric ID.

Definition at line 97 of file TestData.cpp.

98{
99 ASSERTL0(pId < m_metrics.size(), "Metric ID out of range.");
100
101 // read the property name
102 ASSERTL0(m_metrics[pId]->Attribute("type"),
103 "Missing 'type' attribute in metric " +
104 boost::lexical_cast<string>(pId) + ").");
105 return boost::to_upper_copy(string(m_metrics[pId]->Attribute("type")));
106}

References ASSERTL0, and m_metrics.

Referenced by main().

◆ GetNumCommands()

unsigned int Nektar::TestData::GetNumCommands ( ) const

Definition at line 91 of file TestData.cpp.

92{
93 return m_commands.size();
94}

References m_commands.

Referenced by main().

◆ GetNumDependentFiles()

unsigned int Nektar::TestData::GetNumDependentFiles ( ) const

Returns the number of dependent files required for the test.

Definition at line 138 of file TestData.cpp.

139{
140 return m_files.size();
141}

References m_files.

Referenced by main().

◆ GetNumMetrics()

unsigned int Nektar::TestData::GetNumMetrics ( ) const

Returns the number of metrics to be collected for the test.

Definition at line 109 of file TestData.cpp.

110{
111 return m_metrics.size();
112}

References m_metrics.

Referenced by main().

◆ GetNumRuns()

unsigned int Nektar::TestData::GetNumRuns ( ) const

Returns the number of runs to be performed for the test.

Definition at line 144 of file TestData.cpp.

145{
146 return m_runs;
147}
unsigned int m_runs
The number of times to run the test.
Definition: TestData.h:100

References m_runs.

Referenced by main().

◆ Parse()

void Nektar::TestData::Parse ( TiXmlDocument *  pDoc)
private

Parse the test file and populate member variables for the test.

Definition at line 198 of file TestData.cpp.

199{
200 TiXmlHandle handle(pDoc);
201 TiXmlElement *testElement, *tmp, *metrics, *files;
202 testElement = handle.FirstChildElement("test").Element();
203 ASSERTL0(testElement, "Cannot find 'test' root element.");
204
205 // Find the desired number of test runs
206 unsigned int runs = 1;
207 testElement->QueryUnsignedAttribute("runs", &runs);
208 ASSERTL0(runs > 0, "Number of runs must be greater than zero.");
209 m_runs = runs;
210
211 // Find description tag.
212 tmp = testElement->FirstChildElement("description");
213 ASSERTL0(tmp, "Cannot find 'description' for test.");
214 m_description = string(tmp->GetText());
215
216 // Find command(s) to run.
217 if (m_cmdoptions.count("executable"))
218 {
219 m_commands.push_back(ParseCommand(testElement));
220 m_commands.back().m_executable =
221 fs::path(m_cmdoptions["executable"].as<std::string>());
222 }
223 else if (testElement->FirstChildElement("executable"))
224 {
225 m_commands.push_back(ParseCommand(testElement));
226 }
227 else if ((tmp = testElement->FirstChildElement("segment")))
228 {
229 ASSERTL0(m_cmdoptions.count("executable") == 0,
230 "Test files defining more than one command in segment "
231 "blocks cannot use --executable.");
232
233 while (tmp)
234 {
235 m_commands.push_back(ParseCommand(tmp));
236 tmp = tmp->NextSiblingElement("segment");
237 }
238 }
239
240 ASSERTL0(m_commands.size() > 0,
241 "No executable / command segments specified for test.");
242
243 // Extract metric tags
244 metrics = testElement->FirstChildElement("metrics");
245 ASSERTL0(metrics, "No metrics defined for test.");
246
247 tmp = metrics->FirstChildElement("metric");
248 while (tmp)
249 {
250 m_metrics.push_back(tmp);
251 tmp = tmp->NextSiblingElement("metric");
252 }
253
254 // Extract list of dependent files
255 files = testElement->FirstChildElement("files");
256 if (files)
257 {
258 tmp = files->FirstChildElement("file");
259 while (tmp)
260 {
261 DependentFile f;
262 f.m_filename = string(tmp->GetText());
263 if (tmp->Attribute("description"))
264 {
265 f.m_description = string(tmp->Attribute("description"));
266 }
267 m_files.push_back(f);
268 tmp = tmp->NextSiblingElement("file");
269 }
270 }
271}
Command ParseCommand(TiXmlElement *pElmt) const
Definition: TestData.cpp:149

References ASSERTL0, m_cmdoptions, m_commands, Nektar::DependentFile::m_description, m_description, Nektar::DependentFile::m_filename, m_files, m_metrics, m_runs, and ParseCommand().

Referenced by TestData().

◆ ParseCommand()

Command Nektar::TestData::ParseCommand ( TiXmlElement *  pElmt) const
private

Definition at line 149 of file TestData.cpp.

150{
151 Command cmd;
152 TiXmlElement *tmp;
153
154 cmd.m_pythonTest = false;
155
156 // Parse executable tag. Do not enforce a check because this might be
157 // overridden on the command line.
158 if (elmt->FirstChildElement("executable"))
159 {
160 tmp = elmt->FirstChildElement("executable");
161 cmd.m_executable = fs::path(tmp->GetText());
162
163 // Test to see if this test requires Python
164 std::string needsPython;
165 tmp->QueryStringAttribute("python", &needsPython);
166 cmd.m_pythonTest = needsPython == "true";
167
168#if defined(RELWITHDEBINFO)
169 cmd.m_executable += cmd.m_pythonTest ? "" : "-rg";
170#elif !defined(NDEBUG)
171 cmd.m_executable += cmd.m_pythonTest ? "" : "-g";
172#endif
173 }
174
175 // Find associated parameters.
176 tmp = elmt->FirstChildElement("parameters");
177 ASSERTL0(tmp, "Cannot find 'parameters' for test.");
178 if (tmp->GetText())
179 {
180 cmd.m_parameters = string(tmp->GetText());
181 }
182
183 // Find parallel processes tah.
184 tmp = elmt->FirstChildElement("processes");
185 if (tmp)
186 {
187 cmd.m_processes = atoi(tmp->GetText());
188 }
189 else
190 {
191 cmd.m_processes = 1;
192 }
193
194 return cmd;
195}

References ASSERTL0, Nektar::Command::m_executable, Nektar::Command::m_parameters, Nektar::Command::m_processes, and Nektar::Command::m_pythonTest.

Referenced by Parse().

◆ SaveFile()

void Nektar::TestData::SaveFile ( )

Definition at line 273 of file TestData.cpp.

274{
275 m_doc->SaveFile();
276}

References m_doc.

Referenced by main().

Member Data Documentation

◆ m_cmdoptions

po::variables_map Nektar::TestData::m_cmdoptions
private

Definition at line 93 of file TestData.h.

Referenced by Parse().

◆ m_commands

std::vector<Command> Nektar::TestData::m_commands
private

Definition at line 95 of file TestData.h.

Referenced by GetCommand(), GetNumCommands(), and Parse().

◆ m_description

std::string Nektar::TestData::m_description
private

Definition at line 94 of file TestData.h.

Referenced by GetDescription(), and Parse().

◆ m_doc

TiXmlDocument* Nektar::TestData::m_doc
private

Definition at line 96 of file TestData.h.

Referenced by SaveFile(), and TestData().

◆ m_files

std::vector<DependentFile> Nektar::TestData::m_files
private

Definition at line 98 of file TestData.h.

Referenced by GetDependentFile(), GetNumDependentFiles(), and Parse().

◆ m_metrics

std::vector<TiXmlElement *> Nektar::TestData::m_metrics
private

Definition at line 97 of file TestData.h.

Referenced by GetMetric(), GetMetricId(), GetMetricType(), GetNumMetrics(), and Parse().

◆ m_runs

unsigned int Nektar::TestData::m_runs
private

The number of times to run the test.

Definition at line 100 of file TestData.h.

Referenced by GetNumRuns(), and Parse().