gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
34namespace gem5
35{
36
37namespace {
38
39class 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 {
49 SUCCEED() << s;
50 }
51};
52
53class 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 {
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
77Logger&
79 static GTestExitLogger* panic_logger = new GTestExitLogger("panic: ");
80 return *panic_logger;
81}
82
83Logger&
85 static GTestExitLogger* fatal_logger = new GTestExitLogger("fatal: ");
86 return *fatal_logger;
87}
88
89Logger&
91 static GTestLogger* warn_logger = new GTestLogger("warn: ");
92 return *warn_logger;
93}
94
95Logger&
97 static GTestLogger* info_logger = new GTestLogger("info: ");
98 return *info_logger;
99}
100
101Logger&
103 static GTestLogger* hack_logger = new GTestLogger("hack: ");
104 return *hack_logger;
105}
106
107} // namespace gem5
static Logger & getWarn()
Logger(const char *prefix)
Definition logging.hh:90
static Logger & getInfo()
static Logger & getHack()
static Logger & getPanic()
Get a Logger for the specified type of message.
static Logger & getFatal()
Bitfield< 4 > s
Bitfield< 3 > exit
Definition misc.hh:883
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
thread_local GTestLogOutput gtestLogOutput
Definition logging.cc:33

Generated on Tue Jun 18 2024 16:24:00 for gem5 by doxygen 1.11.0