gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
logging_mock.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "base/gtest/logging.hh"
29 
30 #include <string>
31 
32 #include "base/logging.hh"
33 
34 namespace gem5
35 {
36 
37 namespace {
38 
39 class GTestLogger : public Logger
40 {
41  public:
42  using Logger::Logger;
43 
44  protected:
45  void
46  log(const Loc &loc, std::string s) override
47  {
48  gtestLogOutput << s;
49  SUCCEED() << s;
50  }
51 };
52 
53 class GTestExitLogger : public Logger
54 {
55  public:
56  using Logger::Logger;
57 
58  protected:
59  void
60  log(const Loc &loc, std::string s) override
61  {
62  gtestLogOutput << s;
63  std::cerr << loc.file << ":" << loc.line << ": " << s;
64  }
65  // Throw an exception to escape down to the gtest framework.
66  void exit() override { throw GTestException(); }
67 };
68 
69 } // anonymous namespace
70 
71 // We intentionally put all the loggers on the heap to prevent them from being
72 // destructed at the end of the program. This make them safe to be used inside
73 // destructor of other global objects. Also, we make them function static
74 // veriables to ensure they are initialized ondemand, so it is also safe to use
75 // them inside constructor of other global objects.
76 
77 Logger&
79  static GTestExitLogger* panic_logger = new GTestExitLogger("panic: ");
80  return *panic_logger;
81 }
82 
83 Logger&
85  static GTestExitLogger* fatal_logger = new GTestExitLogger("fatal: ");
86  return *fatal_logger;
87 }
88 
89 Logger&
91  static GTestLogger* warn_logger = new GTestLogger("warn: ");
92  return *warn_logger;
93 }
94 
95 Logger&
97  static GTestLogger* info_logger = new GTestLogger("info: ");
98  return *info_logger;
99 }
100 
101 Logger&
103  static GTestLogger* hack_logger = new GTestLogger("hack: ");
104  return *hack_logger;
105 }
106 
107 } // namespace gem5
gem5::VegaISA::s
Bitfield< 1 > s
Definition: pagetable.hh:64
gem5::Logger
Definition: logging.hh:54
gem5::Logger::getPanic
static Logger & getPanic()
Get a Logger for the specified type of message.
Definition: logging_mock.cc:78
logging.hh
gem5::Logger::getHack
static Logger & getHack()
Definition: logging_mock.cc:102
gem5::Logger::getInfo
static Logger & getInfo()
Definition: logging_mock.cc:96
gem5::Logger::getFatal
static Logger & getFatal()
Definition: logging_mock.cc:84
gem5::Logger::getWarn
static Logger & getWarn()
Definition: logging_mock.cc:90
gem5::X86ISA::exit
Bitfield< 3 > exit
Definition: misc.hh:855
logging.hh
gem5::Logger::Logger
Logger(const char *prefix)
Definition: logging.hh:90
gem5::gtestLogOutput
thread_local GTestLogOutput gtestLogOutput
Definition: logging.cc:33
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37

Generated on Sun Jul 30 2023 01:56:51 for gem5 by doxygen 1.8.17