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 10 void startup1(internal::Manager& /*manager*/) {} 11 12 void startup2(internal::Manager& /*manager*/) {} 13 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 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 26 void deleteLog1(uint32_t /*id*/) {} 27 28 void deleteLog2(uint32_t /*id*/) {} 29 30 void deleteProhibited1(uint32_t /*id*/, bool& prohibited) 31 { 32 prohibited = true; 33 } 34 35 void deleteProhibited2(uint32_t /*id*/, bool& prohibited) 36 { 37 prohibited = true; 38 } 39 40 DISABLE_LOG_ENTRY_CAPS() 41 REGISTER_EXTENSION_FUNCTION(startup1) 42 REGISTER_EXTENSION_FUNCTION(startup2) 43 REGISTER_EXTENSION_FUNCTION(create1) 44 REGISTER_EXTENSION_FUNCTION(create2) 45 REGISTER_EXTENSION_FUNCTION(deleteProhibited1) 46 REGISTER_EXTENSION_FUNCTION(deleteProhibited2) 47 REGISTER_EXTENSION_FUNCTION(deleteLog1) 48 REGISTER_EXTENSION_FUNCTION(deleteLog2) 49 50 TEST(ExtensionsTest, FunctionCallTest) 51 { 52 sdbusplus::SdBusMock sdbusMock; 53 sdbusplus::bus_t bus = sdbusplus::get_mocked_new(&sdbusMock); 54 internal::Manager manager(bus, "testpath"); 55 56 EXPECT_EQ(Extensions::getStartupFunctions().size(), 2); 57 for (auto& s : Extensions::getStartupFunctions()) 58 { 59 s(manager); 60 } 61 62 AdditionalDataArg ad; 63 AssociationEndpointsArg assocs; 64 FFDCArg ffdc; 65 EXPECT_EQ(Extensions::getCreateFunctions().size(), 2); 66 for (auto& c : Extensions::getCreateFunctions()) 67 { 68 c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc); 69 } 70 71 EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2); 72 for (auto& d : Extensions::getDeleteFunctions()) 73 { 74 d(5); 75 } 76 77 EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2); 78 for (auto& p : Extensions::getDeleteProhibitedFunctions()) 79 { 80 bool prohibited = false; 81 p(5, prohibited); 82 EXPECT_TRUE(prohibited); 83 } 84 85 EXPECT_TRUE(Extensions::disableDefaultLogCaps()); 86 } 87