ArmNN
 21.02
UnitTests.cpp File Reference
#include <boost/test/unit_test.hpp>
#include "UnitTests.hpp"
#include <armnn/Logging.hpp>
#include <armnn/utility/NumericCast.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 67 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.

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

◆ BOOST_GLOBAL_FIXTURE()

BOOST_GLOBAL_FIXTURE ( ConfigureLoggingFixture  )

Referenced by BOOST_AUTO_TEST_CASE().