Commit 975c301d authored by Marco Amagliani's avatar Marco Amagliani

submission of test system improvements in the main branch. Now it is able to...

submission of test system improvements in the main branch. Now it is able to create a baseline for test execution.

[git-p4: depot-paths = "//ReForm/ReForm/main/Base/": change = 13990]
parent bbf13645
......@@ -38,28 +38,26 @@
namespace Debug {
typedef unsigned int uint;
const int INVALID_LEVEL = -1;
const char* const ERROR = "ERROR";
const char* const WARNING = "WARNING";
class Stream;
class Command
struct Command
{
public:
enum CommandType
enum Type
{
END = 0x01,
END_LF = 0x03,
END_ERR = 0x07
};
CommandType com_;
Type cmd;
CommandType com() const
{
return com_;
}
Command(CommandType _com) : com_(_com) {}
Command(Type _cmd) : cmd(_cmd) {}
};
......@@ -84,19 +82,20 @@ public:
//! pass the output on the level or not?
bool pass(const int _lvl) const { return _lvl <= lvl_; }
Stream& stream(const int _warn = 0, const bool _print = true);
Stream& stream();
Command end() const { return Command(Command::CommandType::END); }
Command end_lf() const { return Command(Command::CommandType::END_LF); }
Command end_err() const { return Command(Command::CommandType::END_ERR); }
Command end() const { return Command::END; }
Command end_lf() const { return Command::END_LF; }
Command end_err() const { return Command::END_ERR; }
};
//! This is a private implementation for Stream
class File;
class Stream
{
public:
enum StreamType
enum Flags
{
APPEND = 0x01,
HTML = 0x02,
......@@ -104,21 +103,16 @@ public:
KEEP_OPEN = 0x08
};
private:
File* dfile_;
public:
File* dfile() const
{
return dfile_;
}
//! Constructor.
Stream(
const char* _file_name = nullptr, //!< [in] File name if file based.
const StreamType _type = APPEND //!< [in] bitsfield enum type identifier
) ;
const char* _flnm = nullptr, //!< [in] Filename if file based.
const uint _flags = APPEND //!< [in] bit-field type identifier
);
~Stream();
const char* string_out() const;
const std::string& string() const;
const char* c_str() const { return string().c_str(); }
Stream& print(const int);
Stream& print(const double);
......@@ -126,13 +120,18 @@ public:
Stream& print(const char);
Stream& print(const Command&);
//! Get the currently active Stream
static Stream& get_global(int _warn = 0);
private:
File* dfile_;
private:
// inhibit copy
Stream(const Stream&);
Stream& operator=(const Stream&);
File* dfile() const { return dfile_; }
friend class Enter;
friend class Controller;
};
Stream& operator<<(Stream& _ds, const int i);
......@@ -147,6 +146,10 @@ Stream& operator<<(Stream& _ds, const char* const s);
Stream& operator<<(Stream& _ds, const std::string& s);
Stream& operator<<(Stream& _ds, const Command& co);
inline Stream& operator<<(Stream& _ds, const Command::Type _cmd_type)
{
return _ds << Command(_cmd_type);
}
// Stream operator for std::vector<>
template< typename ElementT>
......@@ -189,6 +192,13 @@ Stream& operator<<(Stream& _ds, const std::pair<T0, T1>& _pair)
return _ds;
}
extern void warning(const std::string& _wrng, const char* const _fnct,
const char* const _file, const int _line);
extern void error(const std::string& _err, const char* const _fnct,
const char* const _file, const int _line);
}//namespace Debug
#define DEB_module(MODULE)
//TODO: This should use an atomic thread-safe static int(s)
......@@ -211,9 +221,11 @@ Stream& operator<<(Stream& _ds, const std::pair<T0, T1>& _pair)
#define DEB_warning(LL, AA) DEB_warning_if(true, LL, AA)
#define DEB_warning_if(CC, LL, AA) { if (deb.pass(LL) && (CC)) \
{ deb.stream(1) << "WARNING: " << AA << deb.end_lf(); } }
{ Debug::Stream strm; strm << AA; \
Debug::warning(strm.string(), __FUNCTION__, __FILE__, __LINE__); } }
#define DEB_error(AA) { deb.stream(2) << "ERROR: " << AA << deb.end_err(); }
#define DEB_error(AA) { Debug::Stream strm; strm << AA; \
Debug::error(strm.string(), __FUNCTION__, __FILE__, __LINE__); }
#define DEB_error_if(CC, AA) { if (CC) DEB_error(AA); }
// Stream does not fulfill ostream. If you want to exploit an existing
......@@ -223,8 +235,6 @@ Stream& operator<<(Stream& _ds, const std::pair<T0, T1>& _pair)
#define DEB_os_str(AA) \
dynamic_cast<std::ostringstream &&>((std::ostringstream() << AA )).str()
}//namespace Debug
#endif // DEB_ON
#endif // BASE_DEBOUT_HH_INCLUDED
This diff is collapsed.
set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/IChecksum.hh
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumCount.hh
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumFile.hh
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumLogValueT.hh
${CMAKE_CURRENT_SOURCE_DIR}/IChecksum.hh
${CMAKE_CURRENT_SOURCE_DIR}/types.hh
${CMAKE_CURRENT_SOURCE_DIR}/TestResult.hh
${CMAKE_CURRENT_SOURCE_DIR}/ReadValuesT.hh
${CMAKE_CURRENT_SOURCE_DIR}/StreamContainerT.hh
${CMAKE_CURRENT_SOURCE_DIR}/TestDefault.hh
${CMAKE_CURRENT_SOURCE_DIR}/TestStream.hh
PARENT_SCOPE
)
......@@ -14,7 +17,10 @@ SET(my_t_impls
)
set(my_sources
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumCount.cc
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumFile.cc
${CMAKE_CURRENT_SOURCE_DIR}/ChecksumLogValue.cc
${CMAKE_CURRENT_SOURCE_DIR}/IChecksum.cc
${CMAKE_CURRENT_SOURCE_DIR}/TestStream.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.
#if defined(TEST_ON) && defined(DEB_ON)
#include "ChecksumCount.hh"
#include "ChecksumLogValueT.hh"
#include "TestResult.hh"
#include "TestStream.hh"
#include "Base/Debug/DebOut.hh"
namespace Test {
namespace Checksum {
namespace {
// Counts the number of occurrences of some event and records the
// result in the text log file when the object is destroyed.
struct Count : public LogValueT<size_t>
{
size_t nmbr_; // Number of errors.
Result bad_res_; // Error to record if nmbr_ is bigger than 0.
Count(const char* _name, const Result _res)
: LogValueT<size_t>(_name), nmbr_(0), bad_res_(_res) {}
~Count()
{
if (nmbr_ > 0)
record(bad_res_, nmbr_);
}
};
// This function is intended to count the occurrences of error and warnings with
// the goal to log them at the end of the test.
void checksum_count_add(const bool _err)
{
stream_out(); // Ensure that the static stream output object has been created.
// This force the destructor of cnt_err and cnt_warn to be called
// stream destructor.
static Count cnt_err(Debug::ERROR, Result::ERROR);
static Count cnt_warn(Debug::WARNING, Result::WARNING);
if (_err)
++cnt_err.nmbr_;
else
++cnt_warn.nmbr_;
}
}//namespace
void checksum_count_add_warning()
{
checksum_count_add(false);
}
void checksum_count_add_error()
{
checksum_count_add(true);
}
}//Checksum
}//namespace Test
#endif//defined(TEST_ON) && defined(DEB_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.
#ifndef BASE_CHECKSUMCOUNT_HH_INCLUDE
#define BASE_CHECKSUMCOUNT_HH_INCLUDE
#if defined(TEST_ON) && defined(DEB_ON)
// The functions in this file are used to count the number of errors and warnings
// and makes sense only if both the debug and test macro are on.
namespace Test {
namespace Checksum {
/*!Tells to the test system that there has been a debug warning*/
void checksum_count_add_warning();
/*!Tells to the test system that there has been a debug error*/
void checksum_count_add_error();
}//namespace Checksum
}//namespace Test
#endif//defined(TEST_ON) && defined(DEB_ON)
#endif//BASE_CHECKSUMCOUNT_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.
#ifdef TEST_ON
#include "ChecksumFile.hh"
#include <boost/functional/hash.hpp>
#include <fstream>
namespace Test {
namespace Checksum {
File::File(const char* _name) : LogValueT<std::string>(_name) {}
void File::record(const char* _flnm)
{
// Reads the file, makes a has number form its data and finally record
// hash_number and filename.
std::ifstream fstr(_flnm);
std::array<char, 1000> buf;
size_t file_hash = 0;
size_t file_size = 0;
while(fstr)
{
fstr.read(buf.data(), buf.size());
auto buf_hash = boost::hash_range(buf.data(), buf.data() + fstr.gcount());
file_size += fstr.gcount();
boost::hash_combine(file_hash, buf_hash);
}
std::string log_val = std::string("\"") + _flnm + '\"' +
" (Size: " + std::to_string(file_size) + ")" +
" (Hash: " + std::to_string(file_hash) + ")";
LogValueT<std::string>::record(Result::OK, log_val);
}
}//namespace Checksum
}//namespace Test
#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.
#ifndef BASE_CHECKSUMFILE_HH_INCLUDE
#define BASE_CHECKSUMFILE_HH_INCLUDE
#ifdef TEST_ON
#include "ChecksumLogValueT.hh"
namespace Test {
namespace Checksum {
/*!
checksum for output files. It has a method record that add a file hash.
*/
class File : public LogValueT<std::string>
{
public:
File(const char* _name); //!<[in] Checksum name.
void record(const char* _flnm);
};
}//namespace Checksum
}//namespace Test
#endif//TEST_ON
#endif//BASE_CHECKSUMFILE_HH_INCLUDE
......@@ -16,38 +16,10 @@ namespace Test {
namespace Checksum {
// Template instantiations.
template LogValueT<int>;
template LogValueT<unsigned>;
template LogValueT<double, DoubleCompare>;
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: ");
struct TimeCompare : public DoubleCompare
{
TimeCompare(double _sec) : DoubleCompare(_sec) {}
ReportOutcome check(const std::vector<double>& _times) const
{
if (_times.size() != 1)
return RO_ERRORS; // Error: time not found.
if (_times[0] < 180)
return RO_OK;
if (_times[0] < 600)
return RO_WARNINGS;
return RO_ERRORS; // Time too long.
}
};
// Check the time.
LogValueT<double, TimeCompare>
chk_time(2, "Time", "Test time =", TimeCompare(2), Test::Default::LOG_FILENAME);
template LogValueT<size_t, Test::Checksum::RequiredCompareT<size_t>>;
}//namespace Checksum
}//namespace Test
......
......@@ -13,6 +13,9 @@
#include "ChecksumLogValueT.hh"
#include "ReadValuesT.hh"
#include "StreamContainerT.hh"
#include "TestStream.hh"
#include "Base/Debug/DebOut.hh"
#include <boost/filesystem.hpp>
......@@ -31,32 +34,21 @@ std::ostream& operator<<(std::ostream& _out_str, const std::vector<ValueT>& _val
return write_container(_out_str, _vals);
}
std::ostream& operator<<(std::ostream& _out_str, const std::vector<Count>& _vals)
{
_out_str << '#' << _vals.size();
return _out_str;
}
}//namespace
// 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)
LogValueT<ValueT, CompareT>::LogValueT(const char* _name, const CompareT& _comp)
: IChecksum(_name), comp_(_comp)
{}
template <typename ValueT, class CompareT>
Severity LogValueT<ValueT, CompareT>::compare(const Path& _dir0,
const Path& _dir1, std::stringstream& _os) const
const Path& _dir1, OStream& _os) const
{
auto list0 = read_values<ValueT>(key_, flnm_, _dir0);
auto list1 = read_values<ValueT>(key_, flnm_, _dir1);
auto list0 = read_values<ValueT>("", "", _dir0);
auto list1 = read_values<ValueT>("", "", _dir1);
if (list0.size() != list1.size())
{
_os << '#' << list0.size() << " #" << list1.size();
......@@ -76,17 +68,13 @@ Severity LogValueT<ValueT, CompareT>::compare(const Path& _dir0,
return 0.5;
}
// Reads and check the values using the compare object.
template <typename ValueT, class CompareT>
ReportOutcome LogValueT<ValueT, CompareT>::report(const Path& _dir,
std::stringstream& _os) const
void LogValueT<ValueT, CompareT>::record(const Result& _rep_res, const ValueT& _val)
{
auto vals = read_values<ValueT>(key_, flnm_, _dir);
_os << vals;
return comp_.check(vals);
stream_out() << _rep_res << " " << name() << ": " << _val << std::endl;
}
}//namespace Test
}//namespace Checksum
}//namespace Test
#endif//TEST_ON
\ No newline at end of file
......@@ -13,7 +13,6 @@
#ifdef TEST_ON
#include "IChecksum.hh"
#include "TestDefault.hh"
#include <vector>
......@@ -26,22 +25,6 @@ template <typename ValueT>
struct DefaultCompareT
{
bool same(const ValueT& _a, const ValueT& _b) const { return _a == _b; }
ReportOutcome check(const std::vector<ValueT>& _vals) const
{
return _vals.empty() ? RO_OK : RO_ERRORS;
}
};
/*! Comparison class for LogValueT for checksums that MUST be present in the log.
*/
template <typename ValueT>
struct RequiredCompareT : public DefaultCompareT<ValueT>
{
ReportOutcome check(const std::vector<ValueT>& _vals) const
{
return _vals.empty() ? RO_ERRORS : RO_OK;
}
};
/*! Comparison class for checksums that MUST only be logged.
......@@ -50,7 +33,6 @@ template <typename ValueT>
struct NoCompareT
{
bool same(const ValueT& _a, const ValueT& _b) const { return true; }
ReportOutcome check(const std::vector<ValueT>& _vals) const { return RO_OK; }
};
......@@ -58,7 +40,7 @@ struct NoCompareT
Utility class to compare double with a tolerance. Can be used to redefine the
default compare class in class LogValueT.
*/
struct DoubleCompare : public DefaultCompareT<double>
struct DoubleCompare
{
DoubleCompare(double _tol = 1e-12) : tol_(_tol) {}
bool same(const double& _a, const double& _b) const
......@@ -70,53 +52,24 @@ private:
};
/*!
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 Test::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.
Generic checksum class to record and compare a value of a certain type.
*/
template <typename ValueT, class CompareT = DefaultCompareT<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 = Test::Default::LOG_FILENAME
//*!<[in] File to parse to get the information.
const CompareT& _comp = CompareT() //!<[in] Comparison function.
);
virtual ReportOutcome report(const Path& _dir, std::stringstream& _os) const;
virtual Severity compare(const Path& _dir0, const Path& _dir1,
std::stringstream& _os) const;
void record(const Result& _rep_res, const ValueT& _val);
virtual Severity compare(const Path& _dir0, const Path& _dir1, OStream& _os) const;
private:
CompareT comp_; // Compare class.
// LogValueT<ValueT, CompareT>& operator=(const LogValueT<ValueT, CompareT>&) { return *this;}
};
}//namespace Checksum
}//namespace Test
......
#ifdef TEST_ON
#include "IChecksum.hh"
#include <boost/filesystem.hpp>
#include <array>
#include <functional>
#include <iostream>
#include <tuple>
#include <vector>
......@@ -16,8 +17,8 @@ namespace {
Registry& registry_modify()
{
static Registry chksum_reg;
return chksum_reg;
static Registry chksm_reg;
return chksm_reg;
}
}//namespace
......@@ -30,16 +31,17 @@ const Registry& registry()
///////////////////////////////////////////////////////////////////////////////
// class Checksum implementation
IChecksum::IChecksum(unsigned _order, const char * _name) : name_(_name)
IChecksum::IChecksum(const char * _name) : name_(_name)
{
auto pos = registry_modify().emplace(Key(_order, _name), this);
auto pos = registry_modify().emplace(_name, this);
if (!pos.second)
{
std::cout << "Duplicate checksum definition: "
<< _name << "with order " << _order << std::endl;;
std::cout << "Duplicate checksum definition: " << _name << std::endl;
throw;
}
}
}//Checksum
}//namespace Test
#endif//TEST_ON
......@@ -12,14 +12,18 @@
#define BASE_ICHECKSUM_HH_INCLUDE
#ifndef TEST_ON
# define TEST_only(CC)
#define TEST_only(CC)
#else
#include "types.hh"
#include <Base/Test/TestResult.hh>
#include <map>
#include <sstream>
namespace Test {