Commit 1d2c0333 authored by Chris Cantwell's avatar Chris Cantwell

Completed main test program and implemented L2 test support.

parent fc9a414c
......@@ -59,38 +59,16 @@ namespace Nektar
}
m_id = atoi(metric->Attribute("id"));
}
/**
* @brief Parse the contents of a metric tag. This function is implemented by
* subclasses.
*/
void Metric::Parse(TiXmlElement *metric)
{
v_Parse(metric);
}
/**
* @brief Test a line of output from an executible.
*/
bool Metric::TestLine(std::string line)
{
return v_TestLine(line);
}
/**
* @brief Test which is run after the executible has finished.
*/
bool Metric::FinishTest()
bool Metric::Test(std::istream& pStdout, std::istream& pStderr)
{
return v_FinishTest();
}
bool Metric::v_TestLine(std::string line)
{
return true;
return v_Test(pStdout, pStderr);
}
bool Metric::v_FinishTest()
bool Metric::v_Test(std::istream& pStdout, std::istream& pStderr)
{
return true;
}
......
......@@ -48,19 +48,19 @@ namespace Nektar
public:
Metric(TiXmlElement *metric);
bool TestLine (std::string line);
bool Test (std::istream& pStdout, std::istream& pStderr);
bool FinishTest();
protected:
// Stores the ID of this metric.
int m_id;
virtual void v_Parse (TiXmlElement *metric) = 0;
virtual bool v_TestLine (std::string line);
virtual bool v_FinishTest();
// virtual void v_Parse (TiXmlElement *metric) = 0;
virtual bool v_Test (std::istream& pStdout, std::istream& pStderr);
// virtual bool v_FinishTest();
private:
void Parse (TiXmlElement *metric);
// private:
// void Parse (TiXmlElement *metric);
};
/// A shared pointer to an EquationSystem object
......
......@@ -38,7 +38,7 @@
namespace Nektar
{
std::string MetricL2::type = GetMetricFactory().
RegisterCreatorFunction("l2", MetricL2::create);
RegisterCreatorFunction("L2", MetricL2::create);
MetricL2::MetricL2(TiXmlElement *metric) : MetricRegex(metric)
{
......@@ -46,11 +46,10 @@ namespace Nektar
// name if it exists: first field is variable name, second field is L2
// error.
m_regex =
"^L 2 error\\s*(?:\\(variable (\\w+)\\))?\\s*:\\s*([+-]?\\d.+\\d).*";
"^L 2 error\\s*(?:\\(variable (\\w+)\\))?\\s*:\\s*([+-]?\\d.+\\d|0).*";
// Find the L2 error to match against.
TiXmlElement *value = metric->FirstChildElement("value");
while (value)
{
// Find name of field.
......
......@@ -37,26 +37,23 @@
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
using namespace std;
namespace Nektar
{
std::string MetricRegex::type = GetMetricFactory().
RegisterCreatorFunction("regex", MetricRegex::create);
RegisterCreatorFunction("REGEX", MetricRegex::create);
/**
* @brief Constructor.
*/
MetricRegex::MetricRegex(TiXmlElement *metric) : Metric(metric)
{
}
void MetricRegex::v_Parse(TiXmlElement *metric)
{
// Parse a regex <METRIC> tag. This would populate m_regex, m_matches
// and m_tolerance below.
}
bool MetricRegex::v_TestLine(std::string line)
bool MetricRegex::v_Test(std::istream& pStdout, std::istream& pStderr)
{
// If we have matched everything, nothing to do.
if (m_matches.size() == 0)
......@@ -67,35 +64,50 @@ namespace Nektar
boost::cmatch matches;
std::vector<std::string> &okValues = m_matches[0];
// Test to see if we have a match.
if (boost::regex_match(line.c_str(), matches, m_regex))
// Process output file line by line searching for regex matches
std::string line;
while (getline(pStdout, line))
{
for (int i = 0; i < matches.size(); ++i)
// Test to see if we have a match on this line.
if (boost::regex_match(line.c_str(), matches, m_regex))
{
std::string match(matches[i].first, matches[i].second);
// Error if no fields in regex then throw an error.
if (matches.size() == 1)
{
cout << "No test sections in regex!" << endl;
return false;
}
if (m_tolerance.count(i) > 0)
// Check each field in turn
for (int i = 1; i < matches.size(); ++i)
{
// If the okValues are not within tolerance, failed the
// test.
if (fabs(boost::lexical_cast<int>(okValues[i]) -
boost::lexical_cast<int>(match)) > 1e-6)
std::string match(matches[i].first, matches[i].second);
if (m_tolerance.count(i-1) > 0)
{
return false;
// If the okValues are not within tolerance, failed the
// test.
if (fabs(boost::lexical_cast<double>(okValues[i-1]) -
boost::lexical_cast<double>(match)) > 1e-6)
{
return false;
}
}
}
else
{
// Case insensitive match.
if (!boost::iequals(match, okValues[i]))
else
{
return false;
// Case insensitive match.
if (!boost::iequals(match, okValues[i-1]))
{
return false;
}
}
}
// Remove this match from the list of matches.
m_matches.erase(m_matches.begin());
}
// Remove this match from the list of matches.
m_matches.erase(m_matches.begin());
}
return true;
}
}
......@@ -62,8 +62,7 @@ namespace Nektar
MetricRegex(TiXmlElement *metric);
virtual void v_Parse (TiXmlElement *metric);
virtual bool v_TestLine(std::string line);
virtual bool v_Test(std::istream& pStdout, std::istream& pStderr);
};
}
......
......@@ -6,6 +6,7 @@
*/
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include "TestData.h"
......@@ -55,7 +56,7 @@ std::string TestData::GetMetricType(unsigned int pId) const
ASSERTL0(m_metrics[pId]->Attribute("type"),
"Missing 'type' attribute in metric "
+ boost::lexical_cast<string>(pId) + ").");
return string(m_metrics[pId]->Attribute("type"));
return boost::to_upper_copy(string(m_metrics[pId]->Attribute("type")));
}
unsigned int TestData::GetNumMetrics() const
......
......@@ -35,6 +35,7 @@
#include <cstdio>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sys/stat.h>
......@@ -76,8 +77,13 @@ std::string PortablePath(const boost::filesystem::path& path)
int main(int argc, char *argv[])
{
if (argc != 2)
{
cout << "Error: incorrect number of arguments" << endl;
}
const string specFile = string(argv[1]);
// Parse the test file
Test::TestData file("example.xml");
Test::TestData file(specFile);
// Generate the metric objects
vector<MetricSharedPtr> metrics;
......@@ -123,31 +129,19 @@ int main(int argc, char *argv[])
command += " 1>output.out 2>output.err";
// Run executable and perform tests.
cout << "EXECUTING: " << command << endl;
int status=system(command.c_str());
/*
ifstream file(filename);
while (getline(file, line))
{
for (int i = 0; i < metricList.size(); ++i)
{
if (!metricList[i]->TestLine(line))
{
return 1;
}
}
}
for (int i = 0; i < metricList.size(); ++i)
// Open the output files and test against all metrics
ifstream vStdout("output.out");
ifstream vStderr("output.err");
for (int i = 0; i < metrics.size(); ++i)
{
if (!metricList[i]->FinishTest())
if (!metrics[i]->Test(vStdout, vStderr))
{
cout << "FAILED" << endl;
return 1;
}
}
*/
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment