blob: c54f376a69d9a4d7b532956c1e25cef5ba17b32f [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 Williamsce0bdf12021-04-16 20:09:22 -050010void startup1(internal::Manager& /*manager*/)
Matt Spinler99c2b402019-05-23 14:29:16 -050011{
12}
13
Patrick Williamsce0bdf12021-04-16 20:09:22 -050014void startup2(internal::Manager& /*manager*/)
Matt Spinler99c2b402019-05-23 14:29:16 -050015{
16}
17
Patrick Williamsce0bdf12021-04-16 20:09:22 -050018void create1(const std::string& /*message*/, uint32_t /*id*/,
19 uint64_t /*timestamp*/, Entry::Level /*severity*/,
20 const AdditionalDataArg& /*additionalData*/,
21 const AssociationEndpointsArg& /*assocs*/, const FFDCArg& /*ffdc*/)
Matt Spinler99c2b402019-05-23 14:29:16 -050022{
23}
24
Patrick Williamsce0bdf12021-04-16 20:09:22 -050025void create2(const std::string& /*message*/, uint32_t /*id*/,
26 uint64_t /*timestamp*/, Entry::Level /*severity*/,
27 const AdditionalDataArg& /*additionalData*/,
28 const AssociationEndpointsArg& /*assocs*/, const FFDCArg& /*ffdc*/)
Matt Spinler99c2b402019-05-23 14:29:16 -050029{
30}
31
Patrick Williamsce0bdf12021-04-16 20:09:22 -050032void deleteLog1(uint32_t /*id*/)
Matt Spinler99c2b402019-05-23 14:29:16 -050033{
34}
35
Patrick Williamsce0bdf12021-04-16 20:09:22 -050036void deleteLog2(uint32_t /*id*/)
Matt Spinler99c2b402019-05-23 14:29:16 -050037{
38}
39
Patrick Williamsce0bdf12021-04-16 20:09:22 -050040void deleteProhibited1(uint32_t /*id*/, bool& prohibited)
Matt Spinler99c2b402019-05-23 14:29:16 -050041{
42 prohibited = true;
43}
44
Patrick Williamsce0bdf12021-04-16 20:09:22 -050045void deleteProhibited2(uint32_t /*id*/, bool& prohibited)
Matt Spinler99c2b402019-05-23 14:29:16 -050046{
47 prohibited = true;
48}
49
Patrick Williamsce0bdf12021-04-16 20:09:22 -050050DISABLE_LOG_ENTRY_CAPS()
51REGISTER_EXTENSION_FUNCTION(startup1)
52REGISTER_EXTENSION_FUNCTION(startup2)
53REGISTER_EXTENSION_FUNCTION(create1)
54REGISTER_EXTENSION_FUNCTION(create2)
55REGISTER_EXTENSION_FUNCTION(deleteProhibited1)
56REGISTER_EXTENSION_FUNCTION(deleteProhibited2)
57REGISTER_EXTENSION_FUNCTION(deleteLog1)
58REGISTER_EXTENSION_FUNCTION(deleteLog2)
Matt Spinler99c2b402019-05-23 14:29:16 -050059
60TEST(ExtensionsTest, FunctionCallTest)
61{
Matt Spinlerb181d9d2020-06-05 14:49:59 -050062 sdbusplus::SdBusMock sdbusMock;
Patrick Williams45e83522022-07-22 19:26:52 -050063 sdbusplus::bus_t bus = sdbusplus::get_mocked_new(&sdbusMock);
Matt Spinler99c2b402019-05-23 14:29:16 -050064 internal::Manager manager(bus, "testpath");
65
66 EXPECT_EQ(Extensions::getStartupFunctions().size(), 2);
67 for (auto& s : Extensions::getStartupFunctions())
68 {
69 s(manager);
70 }
71
72 AdditionalDataArg ad;
73 AssociationEndpointsArg assocs;
Matt Spinlerc64b7122020-03-26 10:55:01 -050074 FFDCArg ffdc;
Matt Spinler99c2b402019-05-23 14:29:16 -050075 EXPECT_EQ(Extensions::getCreateFunctions().size(), 2);
76 for (auto& c : Extensions::getCreateFunctions())
77 {
Matt Spinlerc64b7122020-03-26 10:55:01 -050078 c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -050079 }
80
81 EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2);
82 for (auto& d : Extensions::getDeleteFunctions())
83 {
84 d(5);
85 }
86
87 EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2);
88 for (auto& p : Extensions::getDeleteProhibitedFunctions())
89 {
90 bool prohibited = false;
91 p(5, prohibited);
92 EXPECT_TRUE(prohibited);
93 }
94
95 EXPECT_TRUE(Extensions::disableDefaultLogCaps());
96}