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 78 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:216
TiXmlDocument * m_doc
Definition: TestData.h:104
po::variables_map m_cmdoptions
Definition: TestData.h:101

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:103

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:106

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:102

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:105

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:108

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 216 of file TestData.cpp.

217{
218 TiXmlHandle handle(pDoc);
219 TiXmlElement *testElement, *tmp, *metrics, *files;
220 testElement = handle.FirstChildElement("test").Element();
221 ASSERTL0(testElement, "Cannot find 'test' root element.");
222
223 // Find the desired number of test runs
224 unsigned int runs = 1;
225 testElement->QueryUnsignedAttribute("runs", &runs);
226 ASSERTL0(runs > 0, "Number of runs must be greater than zero.");
227 m_runs = runs;
228
229 // Find description tag.
230 tmp = testElement->FirstChildElement("description");
231 ASSERTL0(tmp, "Cannot find 'description' for test.");
232 m_description = string(tmp->GetText());
233
234 // Find command(s) to run.
235 if (m_cmdoptions.count("executable"))
236 {
237 m_commands.push_back(ParseCommand(testElement));
238 m_commands.back().m_executable =
239 fs::path(m_cmdoptions["executable"].as<std::string>());
240 }
241 else if (testElement->FirstChildElement("executable"))
242 {
243 m_commands.push_back(ParseCommand(testElement));
244 }
245 else if ((tmp = testElement->FirstChildElement("segment")))
246 {
247 ASSERTL0(m_cmdoptions.count("executable") == 0,
248 "Test files defining more than one command in segment "
249 "blocks cannot use --executable.");
250
251 while (tmp)
252 {
253 m_commands.push_back(ParseCommand(tmp));
254 tmp = tmp->NextSiblingElement("segment");
255 }
256
257 for (int i = 1; i < m_commands.size(); ++i)
258 {
259 ASSERTL0(m_commands[i].m_commandType == m_commands[0].m_commandType,
260 "All segment commands should be of the same type.");
261 }
262 }
263
264 ASSERTL0(m_commands.size() > 0,
265 "No executable / command segments specified for test.");
266
267 // Extract metric tags
268 metrics = testElement->FirstChildElement("metrics");
269 ASSERTL0(metrics, "No metrics defined for test.");
270
271 tmp = metrics->FirstChildElement("metric");
272 while (tmp)
273 {
274 m_metrics.push_back(tmp);
275 tmp = tmp->NextSiblingElement("metric");
276 }
277
278 // Extract list of dependent files
279 files = testElement->FirstChildElement("files");
280 if (files)
281 {
282 tmp = files->FirstChildElement("file");
283 while (tmp)
284 {
285 DependentFile f;
286 f.m_filename = string(tmp->GetText());
287 if (tmp->Attribute("description"))
288 {
289 f.m_description = string(tmp->Attribute("description"));
290 }
291 m_files.push_back(f);
292 tmp = tmp->NextSiblingElement("file");
293 }
294 }
295}
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 std::string commandType = "none";
157 if (elmt->Attribute("type"))
158 {
159 commandType = elmt->Attribute("type");
160
161 if (commandType == "none")
162 {
163 cmd.m_commandType = eNone;
164 }
165 else if (commandType == "parallel")
166 {
167 cmd.m_commandType = eParallel;
168 }
169 else if (commandType == "sequential")
170 {
171 cmd.m_commandType = eSequential;
172 }
173 }
174
175 // Parse executable tag. Do not enforce a check because this might be
176 // overridden on the command line.
177 if (elmt->FirstChildElement("executable"))
178 {
179 tmp = elmt->FirstChildElement("executable");
180 cmd.m_executable = fs::path(tmp->GetText());
181 // Test to see if this test requires Python
182 std::string needsPython;
183 tmp->QueryStringAttribute("python", &needsPython);
184 cmd.m_pythonTest = needsPython == "true";
185
186#if defined(RELWITHDEBINFO)
187 cmd.m_executable += cmd.m_pythonTest ? "" : "-rg";
188#elif !defined(NDEBUG)
189 cmd.m_executable += cmd.m_pythonTest ? "" : "-g";
190#endif
191 }
192
193 // Find associated parameters.
194 tmp = elmt->FirstChildElement("parameters");
195 ASSERTL0(tmp, "Cannot find 'parameters' for test.");
196 if (tmp->GetText())
197 {
198 cmd.m_parameters = string(tmp->GetText());
199 }
200
201 // Find parallel processes tah.
202 tmp = elmt->FirstChildElement("processes");
203 if (tmp)
204 {
205 cmd.m_processes = atoi(tmp->GetText());
206 }
207 else
208 {
209 cmd.m_processes = 1;
210 }
211
212 return cmd;
213}
@ eSequential
Definition: TestData.h:60
@ eParallel
Definition: TestData.h:61
@ eNone
Definition: TestData.h:59

References ASSERTL0, Nektar::eNone, Nektar::eParallel, Nektar::eSequential, Nektar::Command::m_commandType, 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 297 of file TestData.cpp.

298{
299 m_doc->SaveFile();
300}

References m_doc.

Referenced by main().

Member Data Documentation

◆ m_cmdoptions

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

Definition at line 101 of file TestData.h.

Referenced by Parse().

◆ m_commands

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

Definition at line 103 of file TestData.h.

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

◆ m_description

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

Definition at line 102 of file TestData.h.

Referenced by GetDescription(), and Parse().

◆ m_doc

TiXmlDocument* Nektar::TestData::m_doc
private

Definition at line 104 of file TestData.h.

Referenced by SaveFile(), and TestData().

◆ m_files

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

Definition at line 106 of file TestData.h.

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

◆ m_metrics

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

Definition at line 105 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 108 of file TestData.h.

Referenced by GetNumRuns(), and Parse().