ArmNN
 20.08
UnitTests.cpp File Reference
#include <boost/test/unit_test.hpp>
#include "UnitTests.hpp"
#include <armnn/Logging.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 66 of file UnitTests.cpp.

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

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

◆ BOOST_GLOBAL_FIXTURE()

BOOST_GLOBAL_FIXTURE ( ConfigureLoggingFixture  )

Referenced by BOOST_AUTO_TEST_CASE().