1 #include "elog_entry.hpp"
2 #include "extensions.hpp"
3 
4 #include <sdbusplus/test/sdbus_mock.hpp>
5 
6 #include <gtest/gtest.h>
7 
8 using namespace phosphor::logging;
9 
startup1(internal::Manager &)10 void startup1(internal::Manager& /*manager*/) {}
11 
startup2(internal::Manager &)12 void startup2(internal::Manager& /*manager*/) {}
13 
create1(const std::string &,uint32_t,uint64_t,Entry::Level,const AdditionalDataArg &,const AssociationEndpointsArg &,const FFDCArg &)14 void create1(const std::string& /*message*/, uint32_t /*id*/,
15              uint64_t /*timestamp*/, Entry::Level /*severity*/,
16              const AdditionalDataArg& /*additionalData*/,
17              const AssociationEndpointsArg& /*assocs*/, const FFDCArg& /*ffdc*/)
18 {}
19 
create2(const std::string &,uint32_t,uint64_t,Entry::Level,const AdditionalDataArg &,const AssociationEndpointsArg &,const FFDCArg &)20 void create2(const std::string& /*message*/, uint32_t /*id*/,
21              uint64_t /*timestamp*/, Entry::Level /*severity*/,
22              const AdditionalDataArg& /*additionalData*/,
23              const AssociationEndpointsArg& /*assocs*/, const FFDCArg& /*ffdc*/)
24 {}
25 
deleteLog1(uint32_t)26 void deleteLog1(uint32_t /*id*/) {}
27 
deleteLog2(uint32_t)28 void deleteLog2(uint32_t /*id*/) {}
29 
deleteProhibited1(uint32_t,bool & prohibited)30 void deleteProhibited1(uint32_t /*id*/, bool& prohibited)
31 {
32     prohibited = true;
33 }
34 
deleteProhibited2(uint32_t,bool & prohibited)35 void deleteProhibited2(uint32_t /*id*/, bool& prohibited)
36 {
37     prohibited = true;
38 }
39 
logIDWithHwIsolation1(std::vector<uint32_t> & logIDs)40 void logIDWithHwIsolation1(std::vector<uint32_t>& logIDs)
41 {
42     logIDs.push_back(1);
43 }
44 
logIDWithHwIsolation2(std::vector<uint32_t> & logIDs)45 void logIDWithHwIsolation2(std::vector<uint32_t>& logIDs)
46 {
47     logIDs.push_back(2);
48 }
49 
50 DISABLE_LOG_ENTRY_CAPS()
REGISTER_EXTENSION_FUNCTION(startup1)51 REGISTER_EXTENSION_FUNCTION(startup1)
52 REGISTER_EXTENSION_FUNCTION(startup2)
53 REGISTER_EXTENSION_FUNCTION(create1)
54 REGISTER_EXTENSION_FUNCTION(create2)
55 REGISTER_EXTENSION_FUNCTION(deleteProhibited1)
56 REGISTER_EXTENSION_FUNCTION(deleteProhibited2)
57 REGISTER_EXTENSION_FUNCTION(logIDWithHwIsolation1)
58 REGISTER_EXTENSION_FUNCTION(logIDWithHwIsolation2)
59 REGISTER_EXTENSION_FUNCTION(deleteLog1)
60 REGISTER_EXTENSION_FUNCTION(deleteLog2)
61 
62 TEST(ExtensionsTest, FunctionCallTest)
63 {
64     sdbusplus::SdBusMock sdbusMock;
65     sdbusplus::bus_t bus = sdbusplus::get_mocked_new(&sdbusMock);
66     internal::Manager manager(bus, "testpath");
67 
68     EXPECT_EQ(Extensions::getStartupFunctions().size(), 2);
69     for (auto& s : Extensions::getStartupFunctions())
70     {
71         s(manager);
72     }
73 
74     AdditionalDataArg ad;
75     AssociationEndpointsArg assocs;
76     FFDCArg ffdc;
77     EXPECT_EQ(Extensions::getCreateFunctions().size(), 2);
78     for (auto& c : Extensions::getCreateFunctions())
79     {
80         c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc);
81     }
82 
83     EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2);
84     for (auto& d : Extensions::getDeleteFunctions())
85     {
86         d(5);
87     }
88 
89     EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2);
90     for (auto& p : Extensions::getDeleteProhibitedFunctions())
91     {
92         bool prohibited = false;
93         p(5, prohibited);
94         EXPECT_TRUE(prohibited);
95     }
96 
97     EXPECT_EQ(Extensions::getLogIDWithHwIsolationFunctions().size(), 2);
98     std::vector<uint32_t> ids;
99     for (size_t i = 0; i < 2; ++i)
100     {
101         auto getLogIDWithHwIsolation =
102             Extensions::getLogIDWithHwIsolationFunctions()[i];
103         getLogIDWithHwIsolation(ids);
104         if (i == 0)
105         {
106             EXPECT_EQ(ids.size(), 1);
107             EXPECT_EQ(ids[0], 1);
108         }
109         if (i == 1)
110         {
111             EXPECT_EQ(ids.size(), 2);
112             EXPECT_EQ(ids[1], 2);
113         }
114     }
115 
116     EXPECT_TRUE(Extensions::disableDefaultLogCaps());
117 }
118