Commit 1247a3cd authored by Marco Amagliani's avatar Marco Amagliani

tool to analyse and verify tests results.

[git-p4: depot-paths = "//ReForm/ReForm/main/Base/": change = 13830]
parent 3e9f7763
......@@ -6,8 +6,10 @@ my_add_subdir(Code)
my_add_subdir(Debug)
my_add_subdir(Utils)
my_add_subdir(Security)
my_add_subdir(Test)
include_directories(${PROJECT_SOURCE_DIR}/..)
include_directories(${3P_DIR}/Boost/${INC_DIR})
add_library(Base ${SOURCES} ${HEADERS})
# target_link_libraries(Base)
......
// (C) Copyright 2016 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk, Inc., and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of this information by anyone other than authorized
// employees of Autodesk, Inc. is granted only under a written
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
#ifndef BASE_DEBDEFAULT_HH_INCLUDED
#define BASE_DEBDEFAULT_HH_INCLUDED
namespace Debug {
namespace Default {
const char* const LOG_FILENAME = "reform_deb_out.txt";
}//Default
}//Debug
#endif//BASE_DEBDEFAULT_HH_INCLUDED
......@@ -9,6 +9,7 @@
// and manner of such use.
#include "DebUtils.hh"
#include "DebDefault.hh"
#include "Base/Utils/ThrowError.hh"
#include "Base/Utils/Environment.hh"
......@@ -1004,7 +1005,7 @@ Stream& Stream::get_global(int _warn)
{
_warn;
// TODO: Replace with a Singleton?? ThreadArray??
static Stream g_ds__("reform_deb_out.txt");
static Stream g_ds__(Debug::Default::LOG_FILENAME);
return g_ds__;
}
......
set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/IChecksum.hh
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumLogValueT.hh
${CMAKE_CURRENT_SOURCE_DIR}/types.hh
${CMAKE_CURRENT_SOURCE_DIR}/StreamContainerT.hh
PARENT_SCOPE
)
SET(my_t_impls
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumLogValueT.cc
PARENT_SCOPE
)
set(my_sources
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumLogValue.cc
${CMAKE_CURRENT_SOURCE_DIR}/IChecksum.cc
PARENT_SCOPE
)
// (C) Copyright 2016 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk, Inc., and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of this information by anyone other than authorized
// employees of Autodesk, Inc. is granted only under a written
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
#ifdef TEST_ON
#include "ChecksumLogValueT.cc"
namespace Test {
namespace Checksum {
#if 0
// Returns a compare class for double.
const CompareT<double>* compare_double(double _tol)
{
struct CompareDouble : public CompareT<double>
{
CompareDouble(double _tol) : tol_(_tol) {}
virtual bool same(const double& _a, const double& _b) const
{
return std::fabs(_a - _b) <= tol_;
}
bool operator<(const CompareDouble& _oth) const { return tol_ < _oth.tol_; }
double tol_;
};
static std::set<CompareDouble> comp_dbl__;
return &(*comp_dbl__.emplace(_tol).first);
}
#endif
// Template instantiations.
template LogValueT<unsigned>;
template LogValueT<double>;
template LogValueT<size_t>;
template LogValueT<std::string>;
// Checksums that uses LogValueT
// Check on the debug errors.
LogValueT<Count> chk_error(2, "Debug_errors", "ERROR: ");
// Check the time. No time means that the test has failed.
LogValueT<double, DoubleEqual>
chk_time(2, "Time", "Test time =", DoubleEqual(2), "out.log");
// Check the time. No time means that the test has failed.
LogValueT<Count>
chk_fail(0, "Success", "Test time =", std::equal_to<Count>(), "out.log");
}//namespace Test
}//namespace Checksum
#endif//TEST_ON
// (C) Copyright 2016 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk, Inc., and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of this information by anyone other than authorized
// employees of Autodesk, Inc. is granted only under a written
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
#ifdef TEST_ON
#include "ChecksumLogValueT.hh"
#include "StreamContainerT.hh"
#include <boost/filesystem.hpp>
#include <vector>
namespace Test {
namespace Checksum {
// class ChecksumLog implementation
namespace { // ChecksumLog locals
template <typename ValueT>
std::ostream& operator<<(std::ostream& _out_str, const std::vector<ValueT>& _vals)
{
return write_container(_out_str, _vals);
}
template <typename ValueT> std::vector<ValueT>
get_values(const std::string& _key, const char* const _flnm,
const boost::filesystem::path& _dir)
{
std::ifstream istr((_dir / _flnm).string());
std::string line;
std::vector<ValueT> defcts;
while (std::getline(istr, line))
{
auto pos = line.find(_key);
if (pos == std::string::npos)
continue;
pos += _key.length();
std::stringstream str_dat(line.substr(pos));
defcts.push_back(ValueT());
str_dat >> defcts.back();
}
return defcts;
}
}
// Class LogValueT
template <typename ValueT, class CompareT>
LogValueT<ValueT, CompareT>::LogValueT
(
unsigned _order, const char* _name,
const char* _key,
const CompareT& _comp,
const char* _flnm
)
: IChecksum(_order, _name), comp_(_comp), key_(_key), flnm_(_flnm)
{}
template <typename ValueT, class CompareT>
Severity LogValueT<ValueT, CompareT>::compare(
const boost::filesystem::path& _dir0,
const boost::filesystem::path& _dir1,
std::stringstream& _os) const
{
auto list0 = get_values<ValueT>(key_, flnm_, _dir0);
auto list1 = get_values<ValueT>(key_, flnm_, _dir1);
if (list0.size() != list1.size())
{
_os << '#' << list0.size() << " #" << list1.size();
return 1;
}
for (auto i = list0.size(); i-- > 0; )
{
if (comp_(list0[i], list1[i]))
{
list0.erase(list0.begin() + i);
list1.erase(list1.begin() + i);
}
}
if (list0.empty() && list1.empty())
return 0;
_os << list0 << " " << list1;
return 0.5;
}
template <typename ValueT, class CompareT>
Severity LogValueT<ValueT, CompareT>::report(
const boost::filesystem::path& _dir,
std::stringstream& _os) const
{
auto list = get_values<ValueT>(name(), flnm_, _dir);
if (list.empty())
return 0;
_os << list;
return 1;
}
}//namespace Test
}//namespace Checksum
#endif//TEST_ON
\ No newline at end of file
// (C) Copyright 2016 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk, Inc., and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of this information by anyone other than authorized
// employees of Autodesk, Inc. is granted only under a written
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
#ifndef BASE_CHECKSUMLOGVALUET_HH_INCLUDE
#define BASE_CHECKSUMLOGVALUET_HH_INCLUDE
#ifdef TEST_ON
#include "IChecksum.hh"
#include "Base/Debug/DebDefault.hh"
#include <functional>
namespace Test {
namespace Checksum {
/*!
Utility class to compare double with a tolerance. Can be used to redefine the
default compare class in class LogValueT.
*/
struct DoubleEqual
{
DoubleEqual(double _tol = 1e-12) : tol_(_tol) {}
bool operator()(const double& _a, const double& _b) const
{
return std::fabs(_a - _b) <= tol_;
}
private:
double tol_;
};
/*!
Class that can be used to specialize the behavior of LogValueT in such a way
that it only checks the number of occurrences.
*/
struct Count
{
bool operator==(const Count&) const { return true; }
friend std::istream& operator >> (std::istream& _is, Count&) { return _is; }
friend std::ostream& operator << (std::ostream& _os, const Count&) { return _os; }
};
/*!
Generic Checksum class to compare data that can be read from a output file
(default Debug::Default::LOG_FILENAME). It searches all occurrences of a string
in the file and reads the next field to get the checksum value.
If ValueT == Count it simply counts the number of occurrences of the search string.
*/
template <typename ValueT, class CompareT = std::equal_to<ValueT>>
class LogValueT : public IChecksum
{
public:
const char* flnm_; // File to parse
const char* key_; // String to search as information key.
LogValueT(
unsigned _order, //!<[in] Execution order. Low order means high priority.
const char* _name, //!<[in] Checksum name.
const char* _key, //!<[in] String to search in the output file.
const CompareT& _comp = CompareT(), //!<[in] Comparison function.
const char* _flnm = Debug::Default::LOG_FILENAME
//*!<[in] File to parse to get the information.
);
virtual Severity compare(
const boost::filesystem::path& _dir0, const boost::filesystem::path& _dir1,
std::stringstream& _os) const;
virtual Severity report(
const boost::filesystem::path& _dir, std::stringstream& _os) const;
private:
CompareT comp_; // Compare class.
LogValueT<ValueT>& operator=(const LogValueT<ValueT>&);
};
}//namespace Checksum
}//namespace Test
#endif//TEST_ON
#endif//BASE_CHECKSUMLOGVALUET_HH_INCLUDE
#include "IChecksum.hh"
#include <boost/filesystem.hpp>
#include <array>
#include <functional>
#include <iostream>
#include <tuple>
#include <vector>
namespace Test {
namespace Checksum {
namespace {
Registry& registry_modify()
{
static Registry chksum_reg;
return chksum_reg;
}
}//namespace
const Registry& registry()
{
return registry_modify();
}
///////////////////////////////////////////////////////////////////////////////
// class Checksum implementation
IChecksum::IChecksum(unsigned _order, const char * _name) : name_(_name)
{
auto pos = registry_modify().emplace(Key(_order, _name), this);
if (!pos.second)
{
std::cout << "Duplicate checksum definition: "
<< _name << "with order " << _order << std::endl;;
throw;
}
}
}//Checksum
}//namespace Test
\ No newline at end of file
// (C) Copyright 2016 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk, Inc., and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of this information by anyone other than authorized
// employees of Autodesk, Inc. is granted only under a written
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
#ifndef BASE_ICHECKSUM_HH_INCLUDE
#define BASE_ICHECKSUM_HH_INCLUDE
#ifndef TEST_ON
# define TEST_only(CC)
#else
#include "types.hh"
#include <functional>
#include <list>
#include <map>
#include <set>
#include <sstream>
namespace Test {
namespace Checksum {
/*!
Base class for test checksum. Whatever check we want to add in the test system,
it must be an instance of a class derived from Checksum. All derived classes
must be instantiated as global variable in such a way that they are always available.
*/
class IChecksum
{
protected:
/*!Performs an automatic registration of the new checksum in a
global list, and verifies that the name is unique.
*/
IChecksum(unsigned _order, const char* _name);
public:
/*!Checksum name.
*/
const char* name() const { return name_; }
/*!Override compare to perform a comparison of the results stored in
directories _dir0 and _dir1.
Returns an estimation of the difference between the two test run.
*/
virtual Severity compare(
const Test::Path& _dir0, //!< [in] Directory with the reference result
const Test::Path& _dir1, //!< [in] Directory with the new result
std::stringstream& _os //!< [out] Description of the difference.
) const = 0;
/*!Override report to log any "interesting value" that the check has in
directory _dir. For example a number of face defects greater that 0.
Return an estimation of the severity.
*/
virtual Severity report(
const Test::Path& _dir, //!< [in] Directory with the date to report.
std::stringstream& _os //!< [out] Description of the retrieved information.
) const = 0;
private:
const char * name_;
};
/*!
Definition of the checksums registry. It is a map with a key made of an order
(inverse of a priority) and a name.
This allows to have a unique order for checksum execution and output.
The idea is to have high priority checksums executed first.
*/
typedef std::tuple<unsigned, std::string> Key; // Order and test name.
typedef std::map<Key, IChecksum*> Registry;
/*!
Function to get a static map with all the registered checksums.
*/
const Registry& registry();
}//namespace Checksum
}//namespace Test
#define TEST_only(CC) CC
#endif//TEST_ON
#endif//BASE_ICHECKSUM_HH_INCLUDE
// (C) Copyright 2016 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk, Inc., and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of this information by anyone other than authorized
// employees of Autodesk, Inc. is granted only under a written
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
#ifndef REFORM_STREAMCONTAINERT_HH_INCLUDE
#define REFORM_STREAMCONTAINERT_HH_INCLUDE
/*!
Generic function to fill a std container from a std stream.
*/
template <typename ContainerT>
std::istream& read_container(std::istream& _in_str, ContainerT& _vals)
{
for (auto& val : _vals)
_in_str >> val;
return _in_str;
}
/*!
Generic function to write a std container in a std stream.
*/
template <typename ContainerT>
std::ostream& write_container(std::ostream& _out_str, ContainerT& _cont)
{
_out_str << '(';
if (_cont.size() > 0)
{
auto it = _cont.cbegin();
_out_str << *it;
while (++it != _cont.cend())
_out_str << ',' << *it;
}
_out_str << ')';
return _out_str;
}
#endif//REFORM_STREAMCONTAINERT_HH_INCLUDE
// (C) Copyright 2016 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk, Inc., and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of this information by anyone other than authorized
// employees of Autodesk, Inc. is granted only under a written
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
#ifndef BASE_TYPES_HH_INCLUDE
#define BASE_TYPES_HH_INCLUDE
namespace boost {
namespace filesystem {
class path;
}//namespace boost
}//namespace filesystem
namespace Test {
typedef boost::filesystem::path Path;
typedef double Severity;
}//namespace Test
#endif//BASE_TYPES_HH_INCLUDE
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