Merge pull request #1 from atgeirr/qilicun-messages-limits

Revised message limits work
This commit is contained in:
Liu Ming
2016-10-20 09:02:53 +08:00
committed by GitHub
15 changed files with 291 additions and 156 deletions

View File

@@ -33,41 +33,57 @@ include(CheckIncludeFileCXX)
# macro to only add option once
include(AddOptions)
if(NOT MSVC)
# try to use compiler flag -std=c++11
CHECK_CXX_ACCEPTS_FLAG("-std=c++11" CXX_FLAG_CXX11)
if(CXX_FLAG_CXX11)
add_options (CXX ALL_BUILDS "-std=c++11")
set(CXX_STD0X_FLAGS "-std=c++11")
if(CMAKE_VERSION VERSION_LESS 3.1)
if(NOT MSVC)
# try to use compiler flag -std=c++11
CHECK_CXX_ACCEPTS_FLAG("-std=c++11" CXX_FLAG_CXX11)
if(CXX_FLAG_CXX11)
add_options (CXX ALL_BUILDS "-std=c++11")
set(CXX_STD0X_FLAGS "-std=c++11")
else()
# try to use compiler flag -std=c++0x for older compilers
CHECK_CXX_ACCEPTS_FLAG("-std=c++0x" CXX_FLAG_CXX0X)
if(CXX_FLAG_CXX0X)
add_options (CXX ALL_BUILDS "-std=c++0x")
set(CXX_STD0X_FLAGS "-std=c++0x")
endif(CXX_FLAG_CXX0X)
endif(CXX_FLAG_CXX11)
endif(NOT MSVC)
# if we are building with an Apple toolchain in MacOS X,
# we cannot use the old GCC 4.2 fork, but must use the
# new runtime library
set (CXX_STDLIB_FLAGS)
string (TOUPPER "${CMAKE_CXX_COMPILER_ID}" _comp_id)
if (APPLE AND (_comp_id MATCHES "CLANG"))
CHECK_CXX_ACCEPTS_FLAG ("-stdlib=libc++" CXX_FLAG_STDLIB_LIBCXX)
if (CXX_FLAG_STDLIB_LIBCXX)
add_options (CXX ALL_BUILDS "-stdlib=libc++")
set (CXX_STDLIB_FLAGS "-stdlib=libc++")
endif (CXX_FLAG_STDLIB_LIBCXX)
endif (APPLE AND (_comp_id MATCHES "CLANG"))
# to format the command-line options pretty, we have an optional space
if (CXX_STD0X_FLAGS AND CXX_STDLIB_FLAGS)
set (CXX_SPACE " ")
else (CXX_STD0X_FLAGS AND CXX_STDLIB_FLAGS)
set (CXX_SPACE)
endif (CXX_STD0X_FLAGS AND CXX_STDLIB_FLAGS)
else()
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Workaround bug in cmake:
# cxx standard flags are not applied in CheckCXXSourceCompiles
if (CMAKE_CXX_STANDARD EQUAL 14)
add_options(CXX ALL_BUILDS ${CMAKE_CXX14_STANDARD_COMPILE_OPTION})
else()
# try to use compiler flag -std=c++0x for older compilers
CHECK_CXX_ACCEPTS_FLAG("-std=c++0x" CXX_FLAG_CXX0X)
if(CXX_FLAG_CXX0X)
add_options (CXX ALL_BUILDS "-std=c++0x")
set(CXX_STD0X_FLAGS "-std=c++0x")
endif(CXX_FLAG_CXX0X)
endif(CXX_FLAG_CXX11)
endif(NOT MSVC)
# if we are building with an Apple toolchain in MacOS X,
# we cannot use the old GCC 4.2 fork, but must use the
# new runtime library
set (CXX_STDLIB_FLAGS)
string (TOUPPER "${CMAKE_CXX_COMPILER_ID}" _comp_id)
if (APPLE AND (_comp_id MATCHES "CLANG"))
CHECK_CXX_ACCEPTS_FLAG ("-stdlib=libc++" CXX_FLAG_STDLIB_LIBCXX)
if (CXX_FLAG_STDLIB_LIBCXX)
add_options (CXX ALL_BUILDS "-stdlib=libc++")
set (CXX_STDLIB_FLAGS "-stdlib=libc++")
endif (CXX_FLAG_STDLIB_LIBCXX)
endif (APPLE AND (_comp_id MATCHES "CLANG"))
# to format the command-line options pretty, we have an optional space
if (CXX_STD0X_FLAGS AND CXX_STDLIB_FLAGS)
set (CXX_SPACE " ")
else (CXX_STD0X_FLAGS AND CXX_STDLIB_FLAGS)
set (CXX_SPACE)
endif (CXX_STD0X_FLAGS AND CXX_STDLIB_FLAGS)
add_options(CXX ALL_BUILDS ${CMAKE_CXX11_STANDARD_COMPILE_OPTION})
endif()
endif()
# perform tests
include(CheckCXXSourceCompiles)
@@ -161,7 +177,7 @@ CHECK_CXX_SOURCE_COMPILES("
# array and fill
CHECK_CXX_SOURCE_COMPILES("
#include <array>
int main(void)
{
std::array<int,2> a;
@@ -216,24 +232,24 @@ CHECK_CXX_SOURCE_COMPILES("
{
bar() DEP;
};
class peng { } DEP;
template <class T>
class t_bar
{
t_bar() DEP;
};
template <class T>
class t_peng {
t_peng() {};
} DEP;
void foo() DEP;
void foo() {};
int main(void)
{
return 0;
@@ -247,25 +263,25 @@ CHECK_CXX_SOURCE_COMPILES("
class bar {
bar() DEP;
};
class peng { } DEP;
template <class T>
class t_bar
{
t_bar() DEP;
};
template <class T>
class t_peng
{
t_peng() {};
t_peng() {};
} DEP;
void foo() DEP;
void foo() {};
int main(void)
{
return 0;
@@ -433,7 +449,7 @@ endif()
if(CXX_FEATURES_MISSING)
set (CXX11FEATURES_FOUND FALSE)
if (CXX11Features_FIND_REQUIRED)
message(FATAL_ERROR
message(FATAL_ERROR
"Your C++ compiler does not support the minimum set of C++-2011 features required. "
"Make sure to use a compiler which implements all C++-2011 features provided by GCC 4.4. "
"Your compiler does not seem to implement the following features:\n"

View File

@@ -57,6 +57,16 @@
throw Exception(oss__.str()); \
} while (false)
// Same as OPM_THROW, except for not making an OpmLog::error() call.
//
// Usage: OPM_THROW_NOLOG(ExceptionClass, "Error message " << value);
#define OPM_THROW_NOLOG(Exception, message) \
do { \
std::ostringstream oss__; \
oss__ << "[" << __FILE__ << ":" << __LINE__ << "] " << message; \
throw Exception(oss__.str()); \
} while (false)
// throw an exception if a condition is true
#define OPM_ERROR_IF(condition, message) do {if(condition){ OPM_THROW(std::logic_error, message);}} while(false)

View File

@@ -48,9 +48,8 @@ size_t CounterLog::numMessages(int64_t messageType) const {
void CounterLog::addTaggedMessage(int64_t messageType, const std::string& messageTag, const std::string& ) {
if (includeMessage( messageType, messageTag ))
m_count[messageType]++;
void CounterLog::addMessageUnconditionally(int64_t messageType, const std::string& ) {
m_count[messageType]++;
}

View File

@@ -30,28 +30,23 @@ namespace Opm {
* \brief Provides a simple sytem for log message which are found by the
* Parser/Deck/EclipseState classes during processing the deck.
*/
class CounterLog : public LogBackend {
public:
class CounterLog : public LogBackend
{
public:
CounterLog(int64_t messageMask);
CounterLog();
CounterLog(int64_t messageMask);
CounterLog();
size_t numMessages(int64_t messageType) const;
size_t numMessages(int64_t messageType) const;
void clear();
protected:
void addMessageUnconditionally(int64_t messageFlag,
const std::string& message) override;
private:
std::map<int64_t , size_t> m_count;
};
void addTaggedMessage(int64_t messageFlag,
const std::string& messageTag,
const std::string& message);
void clear();
~CounterLog() {};
private:
std::map<int64_t , size_t> m_count;
};
typedef std::shared_ptr<CounterLog> CounterLogPtr;
typedef std::shared_ptr<const CounterLog> CounterLogConstPtr;
} // namespace Opm
#endif

View File

@@ -23,9 +23,9 @@
namespace Opm {
void EclipsePRTLog::addTaggedMessage(int64_t messageType, const std::string& messageTag, const std::string& message)
void EclipsePRTLog::addMessageUnconditionally(int64_t messageType, const std::string& message)
{
StreamLog::addTaggedMessage(messageType, messageTag, message);
StreamLog::addMessageUnconditionally(messageType, message);
m_count[messageType]++;
}

View File

@@ -31,8 +31,6 @@ class EclipsePRTLog : public StreamLog {
public:
using StreamLog::StreamLog;
void addTaggedMessage(int64_t messageType, const std::string& messageTag, const std::string& message);
size_t numMessages(int64_t messageType) const;
~EclipsePRTLog();
@@ -54,6 +52,10 @@ public:
/// \param print_summary If true print a summary to the PRT file.
EclipsePRTLog(std::ostream& os , int64_t messageMask,
bool print_summary);
protected:
void addMessageUnconditionally(int64_t messageType, const std::string& message) override;
private:
std::map<int64_t, size_t> m_count;
/// \brief Whether to print a summary to the log file.

View File

@@ -47,6 +47,12 @@ namespace Opm {
addTaggedMessage(messageFlag, "", message);
}
void LogBackend::addTaggedMessage(int64_t messageType, const std::string& messageTag, const std::string& message) {
if (includeMessage( messageType, messageTag )) {
addMessageUnconditionally(messageType, message);
}
}
int64_t LogBackend::getMask() const
{
return m_mask;
@@ -67,12 +73,13 @@ namespace Opm {
if (res == MessageLimiter::Response::JustOverTagLimit) {
// Special case: add a message to this backend about limit being reached.
std::string msg = "Message limit reached for message tag: " + messageTag;
addTaggedMessage(messageFlag, "", msg);
addMessageUnconditionally(messageFlag, msg);
}
if (res == MessageLimiter::Response::JustOverCategoryLimit) {
// Special case: add a message to this backend about limit being reached.
std::string msg = "Message limit reached for message : " + Log::prefixMessage(messageFlag, "");
addTaggedMessage(messageFlag, "", msg);
std::string prefix = Log::prefixMessage(messageFlag, "");
std::string msg = "Message limit reached for message category: " + prefix.substr(0, prefix.size()-2);
addMessageUnconditionally(messageFlag, msg);
}
return res == MessageLimiter::Response::PrintMessage;

View File

@@ -1,5 +1,6 @@
/*
Copyright 2015 Statoil ASA.
Copyright 2015, 2016 Statoil ASA.
Copyright 2016 SINTEF ICT, Applied Mathematics.
This file is part of the Open Porous Media project (OPM).
@@ -46,32 +47,34 @@ namespace Opm
/// Configure how message tags will be used to limit messages.
void setMessageLimiter(std::shared_ptr<MessageLimiter> limiter);
/// Add a message to the backend.
///
/// Typically a subclass may filter, change, and output
/// messages based on configuration and the messageFlag.
/// Add a message to the backend if accepted by the message limiter.
void addMessage(int64_t messageFlag, const std::string& message);
/// Add a tagged message to the backend.
///
/// Typically a subclass may filter, change, and output
/// messages based on configuration and the messageFlag.
virtual void addTaggedMessage(int64_t messageFlag,
const std::string& messageTag,
const std::string& message) = 0;
/// Add a tagged message to the backend if accepted by the message limiter.
void addTaggedMessage(int64_t messageFlag,
const std::string& messageTag,
const std::string& message);
/// The message mask types are specified in the
/// Opm::Log::MessageType namespace, in file LogUtils.hpp.
int64_t getMask() const;
protected:
/// Return true if all bits of messageFlag are also set in our mask.
bool includeMessage(int64_t messageFlag, const std::string& messageTag);
/// This is the method subclasses should override.
///
/// Typically a subclass may filter, change, and output
/// messages based on configuration and the messageFlag.
virtual void addMessageUnconditionally(int64_t messageFlag,
const std::string& message) = 0;
/// Return decorated version of message depending on configureDecoration() arguments.
std::string formatMessage(int64_t messageFlag, const std::string& message);
private:
/// Return true if all bits of messageFlag are also set in our mask,
/// and the message limiter returns a PrintMessage response.
bool includeMessage(int64_t messageFlag, const std::string& messageTag);
int64_t m_mask;
std::shared_ptr<MessageFormatterInterface> m_formatter;
std::shared_ptr<MessageLimiter> m_limiter;

View File

@@ -20,11 +20,14 @@
#ifndef OPM_MESSAGELIMITER_HEADER_INCLUDED
#define OPM_MESSAGELIMITER_HEADER_INCLUDED
#include <opm/common/OpmLog/LogUtil.hpp>
#include <cassert>
#include <map>
#include <string>
#include <unordered_map>
#include <map>
#include <vector>
#include <opm/common/OpmLog/LogUtil.hpp>
namespace Opm
{
@@ -38,13 +41,7 @@ namespace Opm
/// Default constructor, no limit to the number of messages.
MessageLimiter()
: tag_limit_(NoLimit),
category_limits_({{Log::MessageType::Note, NoLimit},
{Log::MessageType::Info, NoLimit},
{Log::MessageType::Warning, NoLimit},
{Log::MessageType::Error, NoLimit},
{Log::MessageType::Problem, NoLimit},
{Log::MessageType::Bug, NoLimit}})
: MessageLimiter(NoLimit)
{
}
@@ -69,14 +66,38 @@ namespace Opm
: tag_limit_(tag_limit < 0 ? NoLimit : tag_limit),
category_limits_(category_limits)
{
// Must ensure NoLimit for categories that are not
// explicitly specified in the input.
for (auto category : { Log::MessageType::Note,
Log::MessageType::Info,
Log::MessageType::Warning,
Log::MessageType::Error,
Log::MessageType::Problem,
Log::MessageType::Bug }) {
if (category_limits_.find(category) == category_limits_.end()) {
category_limits_[category] = NoLimit;
}
}
}
/// The message limit (same for all tags).
int messageLimit() const
/// The tag message limit (same for all tags).
int tagMessageLimit() const
{
return tag_limit_;
}
/// The category message limits.
const std::map<int64_t, int>& categoryMessageLimits() const
{
return category_limits_;
}
/// The category message counts.
const std::map<int64_t, int>& categoryMessageCounts() const
{
return category_counts_;
}
/// Used for handleMessageLimits() return type (see that
/// function).
enum class Response
@@ -84,52 +105,51 @@ namespace Opm
PrintMessage, JustOverTagLimit, JustOverCategoryLimit, OverTagLimit, OverCategoryLimit
};
/// If a tag is empty, there is no message limit or for that
/// (count <= limit), respond PrintMessage.
/// If (count == limit + 1), respond JustOverLimit.
/// If (count > limit + 1), respond OverLimit.
/// If (tag count == tag limit + 1) for the passed tag, respond JustOverTagLimit.
/// If (tag count > tag limit + 1), respond OverTagLimit.
/// If a tag is empty, there is no tag message limit or for that tag
/// (tag count <= tag limit), consider the category limits:
/// If (category count == category limit + 1) for the passed messageMask, respond JustOverCategoryLimit.
/// If (category count > category limit + 1), respond OverCategoryLimit.
/// If (category count <= category limit), or there is no limit for that category, respond PrintMessage.
Response handleMessageLimits(const std::string& tag, const int64_t messageMask)
{
Response res = Response::PrintMessage;
// Deal with tag limits.
if (tag.empty() || tag_limit_ == NoLimit) {
category_counts_[messageMask]++;
res = Response::PrintMessage;
} else {
if (!tag.empty() && tag_limit_ != NoLimit) {
// See if tag already encountered.
auto it = tag_counts_.find(tag);
if (it != tag_counts_.end()) {
// Already encountered this tag. Increment its count.
const int count = ++it->second;
res = countBasedResponse(count, messageMask);
res = countBasedResponseTag(count);
} else {
// First encounter of this tag. Insert 1.
tag_counts_.insert({tag, 1});
res = countBasedResponse(1, messageMask);
res = countBasedResponseTag(1);
}
}
// If tag count reached the limit, ignore all the same tagged messages.
if (res == Response::JustOverTagLimit || res == Response::OverTagLimit) {
return res;
} else {
if (category_limits_[messageMask] == NoLimit) {
category_counts_[messageMask]++;
res = Response::PrintMessage;
} else {
res = countBasedResponse(messageMask);
// If tag count reached the limit, the message is not counted
// towards the category limits.
if (res == Response::PrintMessage) {
// We are *not* above the tag limit, consider category limit.
const int count = ++category_counts_[messageMask];
if (category_limits_[messageMask] != NoLimit) {
res = countBasedResponseCategory(count, messageMask);
}
}
return res;
}
private:
Response countBasedResponse(const int count, const int64_t messageMask)
Response countBasedResponseTag(const int count) const
{
if (count <= tag_limit_) {
category_counts_[messageMask]++;
return Response::PrintMessage;
} else if (count == tag_limit_ + 1) {
category_counts_[messageMask]++;
return Response::JustOverTagLimit;
} else {
return Response::OverTagLimit;
@@ -137,13 +157,12 @@ namespace Opm
}
Response countBasedResponse(const int64_t messageMask)
Response countBasedResponseCategory(const int count, const int64_t messageMask) const
{
if (category_counts_[messageMask] < category_limits_[messageMask]) {
category_counts_[messageMask]++;
const int limit = category_limits_.at(messageMask);
if (count <= limit) {
return Response::PrintMessage;
} else if (category_counts_[messageMask] == category_limits_[messageMask] + 1) {
category_counts_[messageMask]++;
} else if (count == limit + 1) {
return Response::JustOverCategoryLimit;
} else {
return Response::OverCategoryLimit;
@@ -152,10 +171,13 @@ namespace Opm
int tag_limit_;
std::unordered_map<std::string, int> tag_counts_;
std::map<int64_t, int> category_counts_;
// info, note, warning, problem, error, bug.
std::map<int64_t, int> category_limits_;
bool reachTagLimit_;
std::map<int64_t, int> category_counts_ = {{Log::MessageType::Note, 0},
{Log::MessageType::Info, 0},
{Log::MessageType::Warning, 0},
{Log::MessageType::Error, 0},
{Log::MessageType::Problem, 0},
{Log::MessageType::Bug, 0}};
};

View File

@@ -48,12 +48,11 @@ void StreamLog::close() {
}
}
void StreamLog::addTaggedMessage(int64_t messageType, const std::string& messageTag, const std::string& message) {
if (includeMessage( messageType, messageTag )) {
(*m_ostream) << formatMessage(messageType, message) << std::endl;
if (m_ofstream.is_open()) {
m_ofstream.flush();
}
void StreamLog::addMessageUnconditionally(int64_t messageType, const std::string& message)
{
(*m_ostream) << formatMessage(messageType, message) << std::endl;
if (m_ofstream.is_open()) {
m_ofstream.flush();
}
}
@@ -62,4 +61,4 @@ StreamLog::~StreamLog() {
close();
}
}
} // namespace Opm

View File

@@ -33,9 +33,11 @@ class StreamLog : public LogBackend {
public:
StreamLog(const std::string& logFile , int64_t messageMask, bool append = false);
StreamLog(std::ostream& os , int64_t messageMask);
virtual void addTaggedMessage(int64_t messageType, const std::string& messageTag, const std::string& message) override;
~StreamLog();
protected:
virtual void addMessageUnconditionally(int64_t messageType, const std::string& message) override;
private:
void close();

View File

@@ -41,14 +41,14 @@ TimerLog::TimerLog(std::ostream& os) : StreamLog( os , StopTimer | StartTimer )
void TimerLog::addTaggedMessage(int64_t messageType, const std::string& messageTag, const std::string& msg ) {
void TimerLog::addMessageUnconditionally(int64_t messageType, const std::string& msg ) {
if (messageType == StopTimer) {
clock_t stop = clock();
double secondsElapsed = 1.0 * (m_start - stop) / CLOCKS_PER_SEC ;
m_work.str("");
m_work << std::fixed << msg << ": " << secondsElapsed << " seconds ";
StreamLog::addTaggedMessage( messageType, messageTag, m_work.str());
StreamLog::addMessageUnconditionally( messageType, m_work.str());
} else {
if (messageType == StartTimer)
m_start = clock();

View File

@@ -42,12 +42,12 @@ public:
TimerLog(const std::string& logFile);
TimerLog(std::ostream& os);
void addTaggedMessage(int64_t messageFlag,
const std::string& messageTag,
const std::string& message) override;
void clear();
~TimerLog() {};
protected:
void addMessageUnconditionally(int64_t messageFlag,
const std::string& message) override;
private:
clock_t m_start;
std::ostringstream m_work;

View File

@@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(DoLogging) {
BOOST_AUTO_TEST_CASE(Test_Format) {
BOOST_CHECK_EQUAL( "There is a mild fuckup here?\nIn file /path/to/file, line 100\n" , Log::fileMessage("/path/to/file" , 100 , "There is a mild fuckup here?"));
BOOST_CHECK_EQUAL( "There is an error here?\nIn file /path/to/file, line 100\n" , Log::fileMessage("/path/to/file" , 100 , "There is an error here?"));
BOOST_CHECK_EQUAL( "Error: This is the error" , Log::prefixMessage(Log::MessageType::Error , "This is the error"));
BOOST_CHECK_EQUAL( "Warning: This is the warning" , Log::prefixMessage(Log::MessageType::Warning , "This is the warning"));
@@ -118,7 +118,8 @@ public:
m_specialMessages = 0;
}
void addTaggedMessage(int64_t messageType , const std::string& /* messageTag */, const std::string& /* message */) {
void addMessageUnconditionally(int64_t messageType , const std::string& /* message */) override
{
if (messageType & Log::DefaultMessageTypes)
m_defaultMessages +=1;
else
@@ -328,7 +329,8 @@ BOOST_AUTO_TEST_CASE(TestOpmLogWithLimits)
streamLog1->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(false, true));
streamLog1->setMessageLimiter(std::make_shared<MessageLimiter>(2));
streamLog2->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(false, true));
streamLog2->setMessageLimiter(std::make_shared<MessageLimiter>()); // no limit
std::shared_ptr<MessageLimiter> lim(new MessageLimiter(MessageLimiter::NoLimit, {{ Log::MessageType::Warning, 2 }}));
streamLog2->setMessageLimiter(lim); // no tag limit, but a warning category limit
}
const std::string tag = "ExampleTag";
@@ -354,8 +356,7 @@ BOOST_AUTO_TEST_CASE(TestOpmLogWithLimits)
+ Log::colorCodeMessage(Log::MessageType::Info, "Info") + "\n"
+ Log::colorCodeMessage(Log::MessageType::Bug, "Bug") + "\n"
+ Log::colorCodeMessage(Log::MessageType::Warning, "Warning") + "\n"
+ Log::colorCodeMessage(Log::MessageType::Warning, "Warning") + "\n"
+ Log::colorCodeMessage(Log::MessageType::Warning, "Warning") + "\n";
+ Log::colorCodeMessage(Log::MessageType::Warning, "Message limit reached for message category: Warning") + "\n";
BOOST_CHECK_EQUAL(log_stream2.str(), expected2);

View File

@@ -33,16 +33,16 @@ using namespace Opm;
BOOST_AUTO_TEST_CASE(ConstructionAndLimits)
{
MessageLimiter m1;
BOOST_CHECK_EQUAL(m1.messageLimit(), MessageLimiter::NoLimit);
BOOST_CHECK_EQUAL(m1.tagMessageLimit(), MessageLimiter::NoLimit);
MessageLimiter m2(0);
BOOST_CHECK_EQUAL(m2.messageLimit(), 0);
BOOST_CHECK_EQUAL(m2.tagMessageLimit(), 0);
MessageLimiter m3(1);
BOOST_CHECK_EQUAL(m3.messageLimit(), 1);
BOOST_CHECK_EQUAL(m3.tagMessageLimit(), 1);
MessageLimiter m4(-4);
BOOST_CHECK_EQUAL(m4.messageLimit(), MessageLimiter::NoLimit);
BOOST_CHECK_EQUAL(m4.tagMessageLimit(), MessageLimiter::NoLimit);
}
BOOST_AUTO_TEST_CASE(Response)
BOOST_AUTO_TEST_CASE(TagResponse)
{
using namespace Opm;
{
@@ -54,6 +54,7 @@ BOOST_AUTO_TEST_CASE(Response)
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.handleMessageLimits("tag1", Log::MessageType::Info) == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.categoryMessageCounts().at(Log::MessageType::Info) == 6);
}
{
@@ -65,6 +66,7 @@ BOOST_AUTO_TEST_CASE(Response)
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag1", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.categoryMessageCounts().at(Log::MessageType::Info) == 0);
}
{
@@ -76,5 +78,82 @@ BOOST_AUTO_TEST_CASE(Response)
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::JustOverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag1", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.categoryMessageCounts().at(Log::MessageType::Info) == 2);
}
}
BOOST_AUTO_TEST_CASE(CategoryResponse)
{
using namespace Opm;
{
// No limits.
MessageLimiter m;
BOOST_CHECK(m.handleMessageLimits("", Log::MessageType::Info) == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.handleMessageLimits("", Log::MessageType::Info) == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.handleMessageLimits("", Log::MessageType::Info) == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.categoryMessageCounts().at(Log::MessageType::Info) == 3);
}
{
// Limit == 0.
MessageLimiter m(MessageLimiter::NoLimit,
{{ Log::MessageType::Info, 0 }});
BOOST_CHECK(m.handleMessageLimits("", Log::MessageType::Info) == MessageLimiter::Response::JustOverCategoryLimit);
BOOST_CHECK(m.handleMessageLimits("", Log::MessageType::Info) == MessageLimiter::Response::OverCategoryLimit);
BOOST_CHECK(m.handleMessageLimits("", Log::MessageType::Info) == MessageLimiter::Response::OverCategoryLimit);
BOOST_CHECK(m.categoryMessageCounts().at(Log::MessageType::Info) == 3);
}
{
// Limit == 1.
MessageLimiter m(MessageLimiter::NoLimit,
{{ Log::MessageType::Info, 1 }});
BOOST_CHECK(m.handleMessageLimits("", Log::MessageType::Info) == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.handleMessageLimits("", Log::MessageType::Info) == MessageLimiter::Response::JustOverCategoryLimit);
BOOST_CHECK(m.handleMessageLimits("", Log::MessageType::Info) == MessageLimiter::Response::OverCategoryLimit);
BOOST_CHECK(m.categoryMessageCounts().at(Log::MessageType::Info) == 3);
}
}
BOOST_AUTO_TEST_CASE(MixedResponse)
{
using namespace Opm;
{
// Tag Limit == 1. Category limit = 0.
MessageLimiter m(1, {{ Log::MessageType::Info, 0 }});
BOOST_CHECK(m.handleMessageLimits("tag1", Log::MessageType::Info) == MessageLimiter::Response::JustOverCategoryLimit);
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::OverCategoryLimit);
BOOST_CHECK(m.handleMessageLimits("tag1", Log::MessageType::Info) == MessageLimiter::Response::JustOverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::JustOverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag1", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.categoryMessageCounts().at(Log::MessageType::Info) == 2);
}
{
// Tag Limit == 0. Category limit = 1.
MessageLimiter m(0, {{ Log::MessageType::Info, 1 }});
BOOST_CHECK(m.handleMessageLimits("tag1", Log::MessageType::Info) == MessageLimiter::Response::JustOverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::JustOverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag1", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag1", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.categoryMessageCounts().at(Log::MessageType::Info) == 0);
}
{
// Tag Limit == 1. Category limit = 1.
MessageLimiter m(1, {{ Log::MessageType::Info, 1 }});
BOOST_CHECK(m.handleMessageLimits("tag1", Log::MessageType::Info) == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::JustOverCategoryLimit);
BOOST_CHECK(m.handleMessageLimits("tag1", Log::MessageType::Info) == MessageLimiter::Response::JustOverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::JustOverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag1", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.handleMessageLimits("tag2", Log::MessageType::Info) == MessageLimiter::Response::OverTagLimit);
BOOST_CHECK(m.categoryMessageCounts().at(Log::MessageType::Info) == 2);
}
}