xref: /openbmc/phosphor-logging/test/elog_quiesce_test.cpp (revision e4960ee73e64066fd32d60355c8847a64c47906a)
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 } // namespace test
82 } // namespace logging
83 } // namespace phosphor
84