ArmNN
 20.02
UnitTests.cpp File Reference
#include <boost/test/unit_test.hpp>
#include "UnitTests.hpp"
#include <armnn/Logging.hpp>
#include <boost/algorithm/string.hpp>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   UnitTests
 

Functions

 BOOST_GLOBAL_FIXTURE (ConfigureLoggingFixture)
 
 BOOST_AUTO_TEST_CASE (LoggerTest)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   UnitTests

Definition at line 5 of file UnitTests.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( LoggerTest  )

Definition at line 68 of file UnitTests.cpp.

References ARMNN_LOG, BOOST_AUTO_TEST_SUITE_END(), BOOST_CHECK(), armnn::debug, armnn::error, armnn::fatal, armnn::info, armnn::SetAllLoggingSinks(), armnn::SetLogFilter(), armnn::trace, and armnn::warning.

69 {
70  std::stringstream ss;
71 
72  {
73  struct StreamRedirector
74  {
75  public:
76  StreamRedirector(std::ostream& stream, std::streambuf* newStreamBuffer)
77  : m_Stream(stream)
78  , m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
79  {}
80  ~StreamRedirector() { m_Stream.rdbuf(m_BackupBuffer); }
81 
82  private:
83  std::ostream& m_Stream;
84  std::streambuf* m_BackupBuffer;
85  };
86 
87 
88  StreamRedirector redirect(std::cout, ss.rdbuf());
89 
90  using namespace armnn;
91  SetLogFilter(LogSeverity::Trace);
92  SetAllLoggingSinks(true, false, false);
93 
94 
95  ARMNN_LOG(trace) << "My trace message; " << -2;
96  ARMNN_LOG(debug) << "My debug message; " << -1;
97  ARMNN_LOG(info) << "My info message; " << 0;
98  ARMNN_LOG(warning) << "My warning message; " << 1;
99  ARMNN_LOG(error) << "My error message; " << 2;
100  ARMNN_LOG(fatal) << "My fatal message; " << 3;
101 
102  SetLogFilter(LogSeverity::Fatal);
103 
104  }
105 
106  BOOST_CHECK(boost::contains(ss.str(), "Trace: My trace message; -2"));
107  BOOST_CHECK(boost::contains(ss.str(), "Debug: My debug message; -1"));
108  BOOST_CHECK(boost::contains(ss.str(), "Info: My info message; 0"));
109  BOOST_CHECK(boost::contains(ss.str(), "Warning: My warning message; 1"));
110  BOOST_CHECK(boost::contains(ss.str(), "Error: My error message; 2"));
111  BOOST_CHECK(boost::contains(ss.str(), "Fatal: My fatal message; 3"));
112 }
void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured)
Definition: Logging.cpp:146
#define ARMNN_LOG(severity)
Definition: Logging.hpp:163
Copyright (c) 2020 ARM Limited.
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void SetLogFilter(LogSeverity level)
Definition: Logging.cpp:28

◆ BOOST_GLOBAL_FIXTURE()

BOOST_GLOBAL_FIXTURE ( ConfigureLoggingFixture  )

Referenced by BOOST_AUTO_TEST_CASE().