Commit 615a0992 authored by Dave Moxey's avatar Dave Moxey

Adding initial template for new code.

git-svn-id: https://gforge.sci.utah.edu/svn/nektar/branches/new-tests@4035 305cdda6-5ce1-45b3-a98d-dfc68c8b3305
parent 59ff2eac
......@@ -60,6 +60,8 @@ SET(NEKTAR_BUILD_UTILITIES ON CACHE BOOL
"Build utilities for pre-processing and post-processing Nektar++ files.")
SET(NEKTAR_BUILD_UNIT_TESTS ON CACHE BOOL
"Build unit tests.")
SET(NEKTAR_BUILD_TESTS ON CACHE BOOL
"Build tests for checking the correctness of the code.")
SET(NEKTAR_BUILD_REGRESSION_TESTS ON CACHE BOOL
"Build regression tests for checking the correctness of the code.")
SET(NEKTAR_BUILD_TIMINGS OFF CACHE BOOL
......@@ -250,6 +252,11 @@ IF (NEKTAR_BUILD_UTILITIES)
ADD_SUBDIRECTORY(utilities)
ENDIF (NEKTAR_BUILD_UTILITIES)
IF (NEKTAR_BUILD_TESTS)
INCLUDE_DIRECTORIES(tests)
ADD_SUBDIRECTORY(tests)
ENDIF (NEKTAR_BUILD_TESTS)
IF (NEKTAR_BUILD_REGRESSION_TESTS)
INCLUDE_DIRECTORIES(regressionTests)
ADD_SUBDIRECTORY(regressionTests)
......
SET(TESTER_SOURCES
Metric.cpp
MetricL2.cpp
MetricRegex.cpp
Tester.cpp
)
SET(TESTER_HEADERS
Metric.h
MetricL2.h
MetricRegex.h
Tester.h
)
ADD_EXECUTABLE(Tester ${TESTER_SOURCES} ${ARGN})
TARGET_LINK_LIBRARIES(Tester
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${Boost_REGEX_LIBRARY}
optimized ${TINYXML_LIB} debug ${TINYXML_LIB}
)
ADD_DEPENDENCIES(Tester boost tinyxml)
IF( ${CMAKE_SYSTEM} MATCHES "Linux.*")
TARGET_LINK_LIBRARIES(Tester optimized rt debug rt)
ENDIF()
IF( ${CMAKE_SYSTEM} MATCHES "Darwin-*")
SET_TARGET_PROPERTIES(Tester
PROPERTIES LINK_FLAGS "-Wl,-undefined,dynamic_lookup -Wl,-rpath,${CMAKE_INSTALL_PREFIX}/${LIB_DIR} -Wl,-rpath,${Boost_LIBRARY_DIRS}")
ENDIF( ${CMAKE_SYSTEM} MATCHES "Darwin-*")
INSTALL(TARGETS Tester
RUNTIME DESTINATION ${NEKTAR_BIN_DIR} COMPONENT test OPTIONAL
ARCHIVE DESTINATION ${NEKTAR_LIB_DIR} COMPONENT test OPTIONAL
LIBRARY DESTINATION ${NEKTAR_LIB_DIR} COMPONENT test OPTIONAL)
///////////////////////////////////////////////////////////////////////////////
//
// File: Metric.cpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Implementation of the metric base class.
//
///////////////////////////////////////////////////////////////////////////////
#include <Metric.h>
/**
* @brief Constructor.
*/
Metric::Metric(int id) : m_id(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()
{
return v_FinishTest();
}
bool Metric::v_TestLine(std::string line)
{
return true;
}
bool Metric::v_FinishTest()
{
return true;
}
///////////////////////////////////////////////////////////////////////////////
//
// File: Metric.h
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Definition of the metric base class.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_TESTS_METRIC_H
#define NEKTAR_TESTS_METRIC_H
#include <tinyxml/tinyxml.h>
#include <string>
class Metric
{
public:
Metric(int id);
void Parse (TiXmlElement *metric);
bool TestLine (std::string line);
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();
};
#endif
///////////////////////////////////////////////////////////////////////////////
//
// File: MetricL2.cpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Implementation of the L2 metric.
//
///////////////////////////////////////////////////////////////////////////////
#include <MetricL2.h>
MetricL2::MetricL2(int id) : MetricRegex(id)
{
}
void MetricL2::v_Parse(TiXmlElement *metric)
{
// Set up the regular expression. This (optionally) matches a variable
// 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).*";
// Find the L2 error to match against.
TiXmlElement *value;
while (value = metric->FirstChildElement("value"))
{
// Find name of field.
std::string variable = value->Attribute("variable");
// Set up a match with two fields which correspond with the
// subexpression above. The first is the variable name, second is
// the L2 error.
std::vector<std::string> tmp(2);
tmp[0] = variable;
tmp[1] = value->GetText();
m_matches.push_back(tmp);
// Indicate that the L2 error needs tolerance testing.
m_tolerance.insert(1);
}
}
///////////////////////////////////////////////////////////////////////////////
//
// File: MetricL2.h
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Definition of the L2 metric.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_TESTS_METRICL2_H
#define NEKTAR_TESTS_METRICL2_H
#include <MetricRegex.h>
class MetricL2 : public MetricRegex
{
public:
MetricL2(int id);
protected:
virtual void v_Parse(TiXmlElement *metric);
};
#endif
///////////////////////////////////////////////////////////////////////////////
//
// File: MetricRegex.cpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Implementation of the regular-expression metric.
//
///////////////////////////////////////////////////////////////////////////////
#include <MetricRegex.h>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
/**
* @brief Constructor.
*/
MetricRegex::MetricRegex(int id) : Metric(id)
{
}
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)
{
// If we have matched everything, nothing to do.
if (m_matches.size() == 0)
{
return true;
}
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))
{
for (int i = 0; i < matches.size(); ++i)
{
std::string match(matches[i].first, matches[i].second);
if (m_tolerance.count(i) > 0)
{
// 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)
{
return false;
}
}
else
{
// Case insensitive match.
if (!boost::iequals(match, okValues[i]))
{
return false;
}
}
}
// Remove this match from the list of matches.
m_matches.erase(m_matches.begin());
}
}
///////////////////////////////////////////////////////////////////////////////
//
// File: MetricRegex.h
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Definition of the regular-expression metric.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_TESTS_METRICREGEX_H
#define NEKTAR_TESTS_METRICREGEX_H
#include <Metric.h>
#include <boost/regex.hpp>
#include <vector>
class MetricRegex : public Metric
{
public:
MetricRegex(int id);
protected:
// Storage for the boost regex.
boost::regex m_regex;
// Stores the multiple matches defined in each <MATCH> tag.
std::vector<std::vector<std::string> > m_matches;
// Indicates which fields of a match need to be tested for tolerance.
std::set<int> m_tolerance;
virtual void v_Parse (TiXmlElement *metric);
virtual bool v_TestLine(std::string line);
};
#endif
///////////////////////////////////////////////////////////////////////////////
//
// File: Tester.cpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Tester executible.
//
///////////////////////////////////////////////////////////////////////////////
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <MetricL2.h>
#include <MetricRegex.h>
#include <boost/lexical_cast.hpp>
#include <boost/version.hpp>
using namespace std;
int main(int argc, char *argv[])
{
// Open file.
TiXmlDocument *file = new TiXmlDocument(argv[1]);
bool loadOkay = file->LoadFile();
if (!loadOkay)
{
cout << file->ErrorDesc() << endl;
return 1;
}
TiXmlHandle handle(file);
TiXmlElement *testElement;
testElement = handle.FirstChildElement("test").Element();
// Find description tag.
TiXmlElement *descElement = handle.FirstChildElement("test").
FirstChildElement("description").Element();
string description(descElement->GetText());
cout << description << endl;
// Find solver tag.
TiXmlElement *solverElement = handle.FirstChildElement("test").
FirstChildElement("executable").Element();
string executable(solverElement->GetText());
cout << executable << endl;
// Find input tag.
TiXmlElement *inputElement = handle.FirstChildElement("test").
FirstChildElement("parameters").Element();
string input(inputElement->GetText());
cout << input << endl;
// Iterate through metric tags.
TiXmlElement *metrics = testElement->FirstChildElement("metrics");
if (!metrics)
{
cout << "Couldn't find metrics tag." << endl;
return 1;
}
// Construct vector of metrics.
TiXmlElement *metric = metrics->FirstChildElement("metric");
vector<Metric*> metricList;
while (metric)
{
string metricType = metric->Attribute("type");
int metricId = boost::lexical_cast<int>(metric->Attribute("id"));
Metric *m;
cout << "Metric type: " << metricType << ", id = " << metricId << endl;
if (metricType == "L2")
{
m = new MetricL2(metricId);
}
else if (metricType == "Regex")
{
m = new MetricRegex(metricId);
}
m->Parse(metric);
metric = metric->NextSiblingElement("metric");
}
/*
while (getline(fpstream, line))
{
for (int i = 0; i < metricList.size(); ++i)
{
if (!metricList[i]->TestLine(line))
{
return 1;
}
}
}
for (int i = 0; i < metricList.size(); ++i)
{
if (!metricList[i]->FinishTest())
{
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