Nektar++
Loading...
Searching...
No Matches
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 (TiXmlElement *pElmt, po::variables_map &pVm)
 TestData constructor.
 
 TestData (const TestData &pSrc)
 
const std::string & GetDescription () const
 Returns the description of a test.
 
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.
 
unsigned int GetNumMetrics () const
 Returns the number of metrics to be collected for the test.
 
TiXmlElement * GetMetric (unsigned int pId)
 Returns a pointer to the TiXmlElement object representing the metric for a given metric ID.
 
unsigned int GetMetricId (unsigned int pId)
 Returns the ID of the metric for a given metric ID.
 
DependentFile GetDependentFile (unsigned int pId) const
 
unsigned int GetNumDependentFiles () const
 Returns the number of dependent files required for the test.
 
unsigned int GetNumRuns () const
 Returns the number of runs to be performed for the test.
 

Private Member Functions

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

Private Attributes

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

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 ( TiXmlElement *  pElmt,
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 Parse(pElmt);
62}
void Parse(TiXmlElement *pElmt)
Parse the test file and populate member variables for the test.
Definition TestData.cpp:207
po::variables_map m_cmdoptions
Definition TestData.h:99

References Parse().

◆ TestData() [2/2]

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

Definition at line 64 of file TestData.cpp.

65{
66 boost::ignore_unused(pSrc);
67}

Member Function Documentation

◆ GetCommand()

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

Definition at line 75 of file TestData.cpp.

76{
77 ASSERTL0(pId < m_commands.size(),
78 "Command ID '" + std::to_string(pId) + "' not found");
79 return m_commands[pId];
80}
#define ASSERTL0(condition, msg)
std::vector< Command > m_commands
Definition TestData.h:101

References ASSERTL0, and m_commands.

◆ GetDependentFile()

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

Definition at line 122 of file TestData.cpp.

123{
124 ASSERTL0(pId < m_files.size(), "File index out of range.");
125 return m_files[pId];
126}
std::vector< DependentFile > m_files
Definition TestData.h:103

References ASSERTL0, and m_files.

◆ GetDescription()

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

Returns the description of a test.

Definition at line 70 of file TestData.cpp.

71{
72 return m_description;
73}
std::string m_description
Definition TestData.h:100

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

108{
109 ASSERTL0(pId < m_metrics.size(), "Metric index out of range.");
110 return m_metrics[pId];
111}
std::vector< TiXmlElement * > m_metrics
Definition TestData.h:102

References ASSERTL0, and m_metrics.

◆ GetMetricId()

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

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

Definition at line 114 of file TestData.cpp.

115{
116 ASSERTL0(pId < m_metrics.size(), "Metric index out of range.");
117 const char *id = m_metrics[pId]->Attribute("id");
118 ASSERTL0(id, "No ID found for metric!");
119 return boost::lexical_cast<unsigned int>(id);
120}

References ASSERTL0, and m_metrics.

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

89{
90 ASSERTL0(pId < m_metrics.size(), "Metric ID out of range.");
91
92 // read the property name
93 ASSERTL0(m_metrics[pId]->Attribute("type"),
94 "Missing 'type' attribute in metric " +
95 boost::lexical_cast<string>(pId) + ").");
96 return boost::to_upper_copy(string(m_metrics[pId]->Attribute("type")));
97}

References ASSERTL0, and m_metrics.

◆ GetNumCommands()

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

Definition at line 82 of file TestData.cpp.

83{
84 return m_commands.size();
85}

References m_commands.

◆ GetNumDependentFiles()

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

Returns the number of dependent files required for the test.

Definition at line 129 of file TestData.cpp.

130{
131 return m_files.size();
132}

References m_files.

◆ GetNumMetrics()

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

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

Definition at line 100 of file TestData.cpp.

101{
102 return m_metrics.size();
103}

References m_metrics.

◆ GetNumRuns()

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

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

Definition at line 135 of file TestData.cpp.

136{
137 return m_runs;
138}
unsigned int m_runs
The number of times to run the test.
Definition TestData.h:105

References m_runs.

◆ Parse()

void Nektar::TestData::Parse ( TiXmlElement *  pElmt)
private

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

Definition at line 207 of file TestData.cpp.

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

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

141{
142 Command cmd;
143 TiXmlElement *tmp;
144
145 cmd.m_pythonTest = false;
146
147 std::string commandType = "none";
148 if (elmt->Attribute("type"))
149 {
150 commandType = elmt->Attribute("type");
151
152 if (commandType == "none")
153 {
154 cmd.m_commandType = eNone;
155 }
156 else if (commandType == "parallel")
157 {
158 cmd.m_commandType = eParallel;
159 }
160 else if (commandType == "sequential")
161 {
162 cmd.m_commandType = eSequential;
163 }
164 }
165
166 // Parse executable tag. Do not enforce a check because this might be
167 // overridden on the command line.
168 if (elmt->FirstChildElement("executable"))
169 {
170 tmp = elmt->FirstChildElement("executable");
171 cmd.m_executable = fs::path(tmp->GetText());
172 // Test to see if this test requires Python
173 std::string needsPython;
174 tmp->QueryStringAttribute("python", &needsPython);
175 cmd.m_pythonTest = needsPython == "true";
176
177#if defined(RELWITHDEBINFO)
178 cmd.m_executable += cmd.m_pythonTest ? "" : "-rg";
179#elif !defined(NDEBUG)
180 cmd.m_executable += cmd.m_pythonTest ? "" : "-g";
181#endif
182 }
183
184 // Find associated parameters.
185 tmp = elmt->FirstChildElement("parameters");
186 ASSERTL0(tmp, "Cannot find 'parameters' for test.");
187 if (tmp->GetText())
188 {
189 cmd.m_parameters = string(tmp->GetText());
190 }
191
192 // Find parallel processes tah.
193 tmp = elmt->FirstChildElement("processes");
194 if (tmp)
195 {
196 cmd.m_processes = atoi(tmp->GetText());
197 }
198 else
199 {
200 cmd.m_processes = 1;
201 }
202
203 return cmd;
204}
@ 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().

Member Data Documentation

◆ m_cmdoptions

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

Definition at line 99 of file TestData.h.

Referenced by Parse().

◆ m_commands

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

Definition at line 101 of file TestData.h.

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

◆ m_description

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

Definition at line 100 of file TestData.h.

Referenced by GetDescription(), and Parse().

◆ m_files

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

Definition at line 103 of file TestData.h.

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

◆ m_metrics

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

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

Referenced by GetNumRuns(), and Parse().