xref: /openbmc/phosphor-logging/test/extensions_test.cpp (revision d763db35ef85da1cabae911d704a219175347621)
199c2b405SMatt Spinler #include "elog_entry.hpp"
299c2b405SMatt Spinler #include "extensions.hpp"
399c2b405SMatt Spinler 
4b181d9d1SMatt Spinler #include <sdbusplus/test/sdbus_mock.hpp>
5b181d9d1SMatt Spinler 
699c2b405SMatt Spinler #include <gtest/gtest.h>
799c2b405SMatt Spinler 
899c2b405SMatt Spinler using namespace phosphor::logging;
999c2b405SMatt Spinler 
startup1(internal::Manager &)102544b419SPatrick Williams void startup1(internal::Manager& /*manager*/) {}
1199c2b405SMatt Spinler 
startup2(internal::Manager &)122544b419SPatrick Williams void startup2(internal::Manager& /*manager*/) {}
1399c2b405SMatt Spinler 
create1(const std::string &,uint32_t,uint64_t,Entry::Level,const AdditionalDataArg &,const AssociationEndpointsArg &,const FFDCArg &)14ce0bdf1dSPatrick Williams void create1(const std::string& /*message*/, uint32_t /*id*/,
15ce0bdf1dSPatrick Williams              uint64_t /*timestamp*/, Entry::Level /*severity*/,
16ce0bdf1dSPatrick Williams              const AdditionalDataArg& /*additionalData*/,
17ce0bdf1dSPatrick Williams              const AssociationEndpointsArg& /*assocs*/, const FFDCArg& /*ffdc*/)
182544b419SPatrick Williams {}
1999c2b405SMatt Spinler 
create2(const std::string &,uint32_t,uint64_t,Entry::Level,const AdditionalDataArg &,const AssociationEndpointsArg &,const FFDCArg &)20ce0bdf1dSPatrick Williams void create2(const std::string& /*message*/, uint32_t /*id*/,
21ce0bdf1dSPatrick Williams              uint64_t /*timestamp*/, Entry::Level /*severity*/,
22ce0bdf1dSPatrick Williams              const AdditionalDataArg& /*additionalData*/,
23ce0bdf1dSPatrick Williams              const AssociationEndpointsArg& /*assocs*/, const FFDCArg& /*ffdc*/)
242544b419SPatrick Williams {}
2599c2b405SMatt Spinler 
deleteLog1(uint32_t)262544b419SPatrick Williams void deleteLog1(uint32_t /*id*/) {}
2799c2b405SMatt Spinler 
deleteLog2(uint32_t)282544b419SPatrick Williams void deleteLog2(uint32_t /*id*/) {}
2999c2b405SMatt Spinler 
deleteProhibited1(uint32_t,bool & prohibited)30ce0bdf1dSPatrick Williams void deleteProhibited1(uint32_t /*id*/, bool& prohibited)
3199c2b405SMatt Spinler {
3299c2b405SMatt Spinler     prohibited = true;
3399c2b405SMatt Spinler }
3499c2b405SMatt Spinler 
deleteProhibited2(uint32_t,bool & prohibited)35ce0bdf1dSPatrick Williams void deleteProhibited2(uint32_t /*id*/, bool& prohibited)
3699c2b405SMatt Spinler {
3799c2b405SMatt Spinler     prohibited = true;
3899c2b405SMatt Spinler }
3999c2b405SMatt Spinler 
logIDWithHwIsolation1(std::vector<uint32_t> & logIDs)40*d763db35Sharsh-agarwal1 void logIDWithHwIsolation1(std::vector<uint32_t>& logIDs)
41*d763db35Sharsh-agarwal1 {
42*d763db35Sharsh-agarwal1     logIDs.push_back(1);
43*d763db35Sharsh-agarwal1 }
44*d763db35Sharsh-agarwal1 
logIDWithHwIsolation2(std::vector<uint32_t> & logIDs)45*d763db35Sharsh-agarwal1 void logIDWithHwIsolation2(std::vector<uint32_t>& logIDs)
46*d763db35Sharsh-agarwal1 {
47*d763db35Sharsh-agarwal1     logIDs.push_back(2);
48*d763db35Sharsh-agarwal1 }
49*d763db35Sharsh-agarwal1 
50ce0bdf1dSPatrick Williams DISABLE_LOG_ENTRY_CAPS()
REGISTER_EXTENSION_FUNCTION(startup1)51ce0bdf1dSPatrick Williams REGISTER_EXTENSION_FUNCTION(startup1)
52ce0bdf1dSPatrick Williams REGISTER_EXTENSION_FUNCTION(startup2)
53ce0bdf1dSPatrick Williams REGISTER_EXTENSION_FUNCTION(create1)
54ce0bdf1dSPatrick Williams REGISTER_EXTENSION_FUNCTION(create2)
55ce0bdf1dSPatrick Williams REGISTER_EXTENSION_FUNCTION(deleteProhibited1)
56ce0bdf1dSPatrick Williams REGISTER_EXTENSION_FUNCTION(deleteProhibited2)
57*d763db35Sharsh-agarwal1 REGISTER_EXTENSION_FUNCTION(logIDWithHwIsolation1)
58*d763db35Sharsh-agarwal1 REGISTER_EXTENSION_FUNCTION(logIDWithHwIsolation2)
59ce0bdf1dSPatrick Williams REGISTER_EXTENSION_FUNCTION(deleteLog1)
60ce0bdf1dSPatrick Williams REGISTER_EXTENSION_FUNCTION(deleteLog2)
6199c2b405SMatt Spinler 
6299c2b405SMatt Spinler TEST(ExtensionsTest, FunctionCallTest)
6399c2b405SMatt Spinler {
64b181d9d1SMatt Spinler     sdbusplus::SdBusMock sdbusMock;
6545e83521SPatrick Williams     sdbusplus::bus_t bus = sdbusplus::get_mocked_new(&sdbusMock);
6699c2b405SMatt Spinler     internal::Manager manager(bus, "testpath");
6799c2b405SMatt Spinler 
6899c2b405SMatt Spinler     EXPECT_EQ(Extensions::getStartupFunctions().size(), 2);
6999c2b405SMatt Spinler     for (auto& s : Extensions::getStartupFunctions())
7099c2b405SMatt Spinler     {
7199c2b405SMatt Spinler         s(manager);
7299c2b405SMatt Spinler     }
7399c2b405SMatt Spinler 
7499c2b405SMatt Spinler     AdditionalDataArg ad;
7599c2b405SMatt Spinler     AssociationEndpointsArg assocs;
76c64b7122SMatt Spinler     FFDCArg ffdc;
7799c2b405SMatt Spinler     EXPECT_EQ(Extensions::getCreateFunctions().size(), 2);
7899c2b405SMatt Spinler     for (auto& c : Extensions::getCreateFunctions())
7999c2b405SMatt Spinler     {
80c64b7122SMatt Spinler         c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc);
8199c2b405SMatt Spinler     }
8299c2b405SMatt Spinler 
8399c2b405SMatt Spinler     EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2);
8499c2b405SMatt Spinler     for (auto& d : Extensions::getDeleteFunctions())
8599c2b405SMatt Spinler     {
8699c2b405SMatt Spinler         d(5);
8799c2b405SMatt Spinler     }
8899c2b405SMatt Spinler 
8999c2b405SMatt Spinler     EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2);
9099c2b405SMatt Spinler     for (auto& p : Extensions::getDeleteProhibitedFunctions())
9199c2b405SMatt Spinler     {
9299c2b405SMatt Spinler         bool prohibited = false;
9399c2b405SMatt Spinler         p(5, prohibited);
9499c2b405SMatt Spinler         EXPECT_TRUE(prohibited);
9599c2b405SMatt Spinler     }
9699c2b405SMatt Spinler 
97*d763db35Sharsh-agarwal1     EXPECT_EQ(Extensions::getLogIDWithHwIsolationFunctions().size(), 2);
98*d763db35Sharsh-agarwal1     std::vector<uint32_t> ids;
99*d763db35Sharsh-agarwal1     for (size_t i = 0; i < 2; ++i)
100*d763db35Sharsh-agarwal1     {
101*d763db35Sharsh-agarwal1         auto getLogIDWithHwIsolation =
102*d763db35Sharsh-agarwal1             Extensions::getLogIDWithHwIsolationFunctions()[i];
103*d763db35Sharsh-agarwal1         getLogIDWithHwIsolation(ids);
104*d763db35Sharsh-agarwal1         if (i == 0)
105*d763db35Sharsh-agarwal1         {
106*d763db35Sharsh-agarwal1             EXPECT_EQ(ids.size(), 1);
107*d763db35Sharsh-agarwal1             EXPECT_EQ(ids[0], 1);
108*d763db35Sharsh-agarwal1         }
109*d763db35Sharsh-agarwal1         if (i == 1)
110*d763db35Sharsh-agarwal1         {
111*d763db35Sharsh-agarwal1             EXPECT_EQ(ids.size(), 2);
112*d763db35Sharsh-agarwal1             EXPECT_EQ(ids[1], 2);
113*d763db35Sharsh-agarwal1         }
114*d763db35Sharsh-agarwal1     }
115*d763db35Sharsh-agarwal1 
11699c2b405SMatt Spinler     EXPECT_TRUE(Extensions::disableDefaultLogCaps());
11799c2b405SMatt Spinler }
118