blob: bfd22683cdbb5df31546179bbfb4964bc2d03304 [file] [log] [blame]
Matt Spinler99c2b402019-05-23 14:29:16 -05001#include "elog_entry.hpp"
2#include "extensions.hpp"
3
Matt Spinlerb181d9d2020-06-05 14:49:59 -05004#include <sdbusplus/test/sdbus_mock.hpp>
5
Matt Spinler99c2b402019-05-23 14:29:16 -05006#include <gtest/gtest.h>
7
8using namespace phosphor::logging;
9
Patrick Williams2544b412022-10-04 08:41:06 -050010void startup1(internal::Manager& /*manager*/) {}
Matt Spinler99c2b402019-05-23 14:29:16 -050011
Patrick Williams2544b412022-10-04 08:41:06 -050012void startup2(internal::Manager& /*manager*/) {}
Matt Spinler99c2b402019-05-23 14:29:16 -050013
Patrick Williamsce0bdf12021-04-16 20:09:22 -050014void 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*/)
Patrick Williams2544b412022-10-04 08:41:06 -050018{}
Matt Spinler99c2b402019-05-23 14:29:16 -050019
Patrick Williamsce0bdf12021-04-16 20:09:22 -050020void 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*/)
Patrick Williams2544b412022-10-04 08:41:06 -050024{}
Matt Spinler99c2b402019-05-23 14:29:16 -050025
Patrick Williams2544b412022-10-04 08:41:06 -050026void deleteLog1(uint32_t /*id*/) {}
Matt Spinler99c2b402019-05-23 14:29:16 -050027
Patrick Williams2544b412022-10-04 08:41:06 -050028void deleteLog2(uint32_t /*id*/) {}
Matt Spinler99c2b402019-05-23 14:29:16 -050029
Patrick Williamsce0bdf12021-04-16 20:09:22 -050030void deleteProhibited1(uint32_t /*id*/, bool& prohibited)
Matt Spinler99c2b402019-05-23 14:29:16 -050031{
32 prohibited = true;
33}
34
Patrick Williamsce0bdf12021-04-16 20:09:22 -050035void deleteProhibited2(uint32_t /*id*/, bool& prohibited)
Matt Spinler99c2b402019-05-23 14:29:16 -050036{
37 prohibited = true;
38}
39
Patrick Williamsce0bdf12021-04-16 20:09:22 -050040DISABLE_LOG_ENTRY_CAPS()
41REGISTER_EXTENSION_FUNCTION(startup1)
42REGISTER_EXTENSION_FUNCTION(startup2)
43REGISTER_EXTENSION_FUNCTION(create1)
44REGISTER_EXTENSION_FUNCTION(create2)
45REGISTER_EXTENSION_FUNCTION(deleteProhibited1)
46REGISTER_EXTENSION_FUNCTION(deleteProhibited2)
47REGISTER_EXTENSION_FUNCTION(deleteLog1)
48REGISTER_EXTENSION_FUNCTION(deleteLog2)
Matt Spinler99c2b402019-05-23 14:29:16 -050049
50TEST(ExtensionsTest, FunctionCallTest)
51{
Matt Spinlerb181d9d2020-06-05 14:49:59 -050052 sdbusplus::SdBusMock sdbusMock;
Patrick Williams45e83522022-07-22 19:26:52 -050053 sdbusplus::bus_t bus = sdbusplus::get_mocked_new(&sdbusMock);
Matt Spinler99c2b402019-05-23 14:29:16 -050054 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;
Matt Spinlerc64b7122020-03-26 10:55:01 -050064 FFDCArg ffdc;
Matt Spinler99c2b402019-05-23 14:29:16 -050065 EXPECT_EQ(Extensions::getCreateFunctions().size(), 2);
66 for (auto& c : Extensions::getCreateFunctions())
67 {
Matt Spinlerc64b7122020-03-26 10:55:01 -050068 c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -050069 }
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}