blob: cf532a76fda55a25b29965423684ac93d348d20d [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Jim Flynnbbfe6032020-07-20 16:57:44 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
Sadik Armagan1625efc2021-06-10 18:24:34 +01005
6#ifndef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
7#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
8#endif
9#include <doctest/doctest.h>
telsoa014fcda012018-03-09 14:13:49 +000010
11#include "UnitTests.hpp"
Derek Lamberti08446972019-11-26 16:38:31 +000012
telsoa014fcda012018-03-09 14:13:49 +000013struct ConfigureLoggingFixture
14{
15 ConfigureLoggingFixture()
16 {
17 ConfigureLoggingTest();
18 }
19};
20
telsoa014fcda012018-03-09 14:13:49 +000021
Derek Lamberti08446972019-11-26 16:38:31 +000022
Sadik Armagan1625efc2021-06-10 18:24:34 +010023TEST_SUITE("LoggerSuite")
24{
25TEST_CASE_FIXTURE(ConfigureLoggingFixture, "LoggerTest")
Derek Lamberti08446972019-11-26 16:38:31 +000026{
27 std::stringstream ss;
Derek Lamberti08446972019-11-26 16:38:31 +000028 {
29 struct StreamRedirector
30 {
31 public:
32 StreamRedirector(std::ostream& stream, std::streambuf* newStreamBuffer)
Sadik Armagan1625efc2021-06-10 18:24:34 +010033 : m_Stream(stream)
34 , m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
Derek Lamberti08446972019-11-26 16:38:31 +000035 {}
36 ~StreamRedirector() { m_Stream.rdbuf(m_BackupBuffer); }
37
38 private:
39 std::ostream& m_Stream;
40 std::streambuf* m_BackupBuffer;
41 };
42
Derek Lamberti08446972019-11-26 16:38:31 +000043 StreamRedirector redirect(std::cout, ss.rdbuf());
44
45 using namespace armnn;
46 SetLogFilter(LogSeverity::Trace);
47 SetAllLoggingSinks(true, false, false);
48
Derek Lamberti08446972019-11-26 16:38:31 +000049 ARMNN_LOG(trace) << "My trace message; " << -2;
50 ARMNN_LOG(debug) << "My debug message; " << -1;
51 ARMNN_LOG(info) << "My info message; " << 0;
52 ARMNN_LOG(warning) << "My warning message; " << 1;
53 ARMNN_LOG(error) << "My error message; " << 2;
54 ARMNN_LOG(fatal) << "My fatal message; " << 3;
55
56 SetLogFilter(LogSeverity::Fatal);
Derek Lamberti08446972019-11-26 16:38:31 +000057 }
58
Sadik Armagan1625efc2021-06-10 18:24:34 +010059 CHECK(ss.str().find("Trace: My trace message; -2") != std::string::npos);
60 CHECK(ss.str().find("Debug: My debug message; -1") != std::string::npos);
61 CHECK(ss.str().find("Info: My info message; 0") != std::string::npos);
62 CHECK(ss.str().find("Warning: My warning message; 1") != std::string::npos);
63 CHECK(ss.str().find("Error: My error message; 2") != std::string::npos);
64 CHECK(ss.str().find("Fatal: My fatal message; 3") != std::string::npos);
Derek Lamberti08446972019-11-26 16:38:31 +000065}
66
Sadik Armagan1625efc2021-06-10 18:24:34 +010067}