xref: /openbmc/phosphor-logging/test/elog_quiesce_test.cpp (revision 6a0ef6f500b5194b4d212a62a8066882b8c819c5)
1 #include "config.h"
2 
3 #include "elog_entry.hpp"
4 #include "log_manager.hpp"
5 
6 #include <sdbusplus/bus.hpp>
7 #include <sdbusplus/test/sdbus_mock.hpp>
8 
9 #include <gmock/gmock.h>
10 #include <gtest/gtest.h>
11 
12 namespace phosphor
13 {
14 namespace logging
15 {
16 namespace test
17 {
18 
19 class TestQuiesceOnError : public testing::Test
20 {
21   public:
22     sdbusplus::SdBusMock sdbusMock;
23     sdbusplus::bus::bus mockedBus = sdbusplus::get_mocked_new(&sdbusMock);
24     phosphor::logging::internal::Manager manager;
25 
26     TestQuiesceOnError() : manager(mockedBus, OBJ_INTERNAL)
27     {
28     }
29 };
30 
31 // Test that false is returned when no callout is present in the log
32 TEST_F(TestQuiesceOnError, testNoCallout)
33 {
34     uint32_t id = 99;
35     uint64_t timestamp{100};
36     std::string message{"test error"};
37     std::string fwLevel{"level42"};
38     std::vector<std::string> testData{"no", "callout"};
39     phosphor::logging::AssociationList associations{};
40 
41     Entry elog{mockedBus,
42                std::string(OBJ_ENTRY) + '/' + std::to_string(id),
43                id,
44                timestamp,
45                Entry::Level::Informational,
46                std::move(message),
47                std::move(testData),
48                std::move(associations),
49                fwLevel,
50                manager};
51 
52     EXPECT_EQ(manager.isCalloutPresent(elog), false);
53 }
54 
55 // Test that trues is returned when a callout is present in the log
56 TEST_F(TestQuiesceOnError, testCallout)
57 {
58     uint32_t id = 99;
59     uint64_t timestamp{100};
60     std::string message{"test error"};
61     std::string fwLevel{"level42"};
62     std::vector<std::string> testData{
63         "CALLOUT_INVENTORY_PATH=/xyz/openbmc_project/inventory/system/chassis/"
64         "motherboard/powersupply0/"};
65     phosphor::logging::AssociationList associations{};
66 
67     Entry elog{mockedBus,
68                std::string(OBJ_ENTRY) + '/' + std::to_string(id),
69                id,
70                timestamp,
71                Entry::Level::Informational,
72                std::move(message),
73                std::move(testData),
74                std::move(associations),
75                fwLevel,
76                manager};
77 
78     EXPECT_EQ(manager.isCalloutPresent(elog), true);
79 }
80 
81 // Test that no blocking errors are created when no callout
82 TEST_F(TestQuiesceOnError, testNoBlockingErrorsCreated)
83 {
84     uint32_t id = 99;
85     uint64_t timestamp{100};
86     std::string message{"test error"};
87     std::string fwLevel{"level42"};
88     std::vector<std::string> testData{"no", "callout"};
89     phosphor::logging::AssociationList associations{};
90 
91     Entry elog{mockedBus,
92                std::string(OBJ_ENTRY) + '/' + std::to_string(id),
93                id,
94                timestamp,
95                Entry::Level::Informational,
96                std::move(message),
97                std::move(testData),
98                std::move(associations),
99                fwLevel,
100                manager};
101 
102     manager.checkQuiesceOnError(elog);
103     EXPECT_EQ(manager.getBlockingErrSize(), 0);
104 }
105 
106 // Test that a blocking error is created on entry with callout
107 TEST_F(TestQuiesceOnError, testBlockingErrorsCreated)
108 {
109     uint32_t id = 100;
110     uint64_t timestamp{100};
111     std::string message{"test error"};
112     std::string fwLevel{"level42"};
113     std::vector<std::string> testData{
114         "CALLOUT_INVENTORY_PATH=/xyz/openbmc_project/inventory/system/chassis/"
115         "motherboard/powersupply0/"};
116     phosphor::logging::AssociationList associations{};
117 
118     // Ensure D-Bus object created for this blocking error
119     // First allow any number of sd_bus_emit_object_added calls
120     EXPECT_CALL(sdbusMock, sd_bus_emit_object_added(testing::_, testing::_))
121         .Times(testing::AnyNumber());
122     // Second verify the new block100 object is created once
123     EXPECT_CALL(sdbusMock,
124                 sd_bus_emit_object_added(
125                     testing::_, testing::HasSubstr(
126                                     "/xyz/openbmc_project/logging/block100")))
127         .Times(1);
128 
129     Entry elog{mockedBus,
130                std::string(OBJ_ENTRY) + '/' + std::to_string(id),
131                id,
132                timestamp,
133                Entry::Level::Informational,
134                std::move(message),
135                std::move(testData),
136                std::move(associations),
137                fwLevel,
138                manager};
139 
140     manager.checkQuiesceOnError(elog);
141     // Created error with callout so expect a blocking error now
142     EXPECT_EQ(manager.getBlockingErrSize(), 1);
143 }
144 
145 } // namespace test
146 } // namespace logging
147 } // namespace phosphor
148