blob: 31115af56f6d0609cf031acd0062e54acb9c7ee0 [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
10// gtest doesn't like this happening in another file, so do it here.
11StartupFunctions Extensions::startupFunctions{};
12CreateFunctions Extensions::createFunctions{};
13DeleteFunctions Extensions::deleteFunctions{};
14DeleteProhibitedFunctions Extensions::deleteProhibitedFunctions{};
15Extensions::DefaultErrorCaps Extensions::defaultErrorCaps =
16 Extensions::DefaultErrorCaps::enable;
17
Patrick Williamsce0bdf12021-04-16 20:09:22 -050018void startup1(internal::Manager& /*manager*/)
Matt Spinler99c2b402019-05-23 14:29:16 -050019{
20}
21
Patrick Williamsce0bdf12021-04-16 20:09:22 -050022void startup2(internal::Manager& /*manager*/)
Matt Spinler99c2b402019-05-23 14:29:16 -050023{
24}
25
Patrick Williamsce0bdf12021-04-16 20:09:22 -050026void create1(const std::string& /*message*/, uint32_t /*id*/,
27 uint64_t /*timestamp*/, Entry::Level /*severity*/,
28 const AdditionalDataArg& /*additionalData*/,
29 const AssociationEndpointsArg& /*assocs*/, const FFDCArg& /*ffdc*/)
Matt Spinler99c2b402019-05-23 14:29:16 -050030{
31}
32
Patrick Williamsce0bdf12021-04-16 20:09:22 -050033void create2(const std::string& /*message*/, uint32_t /*id*/,
34 uint64_t /*timestamp*/, Entry::Level /*severity*/,
35 const AdditionalDataArg& /*additionalData*/,
36 const AssociationEndpointsArg& /*assocs*/, const FFDCArg& /*ffdc*/)
Matt Spinler99c2b402019-05-23 14:29:16 -050037{
38}
39
Patrick Williamsce0bdf12021-04-16 20:09:22 -050040void deleteLog1(uint32_t /*id*/)
Matt Spinler99c2b402019-05-23 14:29:16 -050041{
42}
43
Patrick Williamsce0bdf12021-04-16 20:09:22 -050044void deleteLog2(uint32_t /*id*/)
Matt Spinler99c2b402019-05-23 14:29:16 -050045{
46}
47
Patrick Williamsce0bdf12021-04-16 20:09:22 -050048void deleteProhibited1(uint32_t /*id*/, bool& prohibited)
Matt Spinler99c2b402019-05-23 14:29:16 -050049{
50 prohibited = true;
51}
52
Patrick Williamsce0bdf12021-04-16 20:09:22 -050053void deleteProhibited2(uint32_t /*id*/, bool& prohibited)
Matt Spinler99c2b402019-05-23 14:29:16 -050054{
55 prohibited = true;
56}
57
Patrick Williamsce0bdf12021-04-16 20:09:22 -050058DISABLE_LOG_ENTRY_CAPS()
59REGISTER_EXTENSION_FUNCTION(startup1)
60REGISTER_EXTENSION_FUNCTION(startup2)
61REGISTER_EXTENSION_FUNCTION(create1)
62REGISTER_EXTENSION_FUNCTION(create2)
63REGISTER_EXTENSION_FUNCTION(deleteProhibited1)
64REGISTER_EXTENSION_FUNCTION(deleteProhibited2)
65REGISTER_EXTENSION_FUNCTION(deleteLog1)
66REGISTER_EXTENSION_FUNCTION(deleteLog2)
Matt Spinler99c2b402019-05-23 14:29:16 -050067
68TEST(ExtensionsTest, FunctionCallTest)
69{
Matt Spinlerb181d9d2020-06-05 14:49:59 -050070 sdbusplus::SdBusMock sdbusMock;
71 sdbusplus::bus::bus bus = sdbusplus::get_mocked_new(&sdbusMock);
Matt Spinler99c2b402019-05-23 14:29:16 -050072 internal::Manager manager(bus, "testpath");
73
74 EXPECT_EQ(Extensions::getStartupFunctions().size(), 2);
75 for (auto& s : Extensions::getStartupFunctions())
76 {
77 s(manager);
78 }
79
80 AdditionalDataArg ad;
81 AssociationEndpointsArg assocs;
Matt Spinlerc64b7122020-03-26 10:55:01 -050082 FFDCArg ffdc;
Matt Spinler99c2b402019-05-23 14:29:16 -050083 EXPECT_EQ(Extensions::getCreateFunctions().size(), 2);
84 for (auto& c : Extensions::getCreateFunctions())
85 {
Matt Spinlerc64b7122020-03-26 10:55:01 -050086 c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -050087 }
88
89 EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2);
90 for (auto& d : Extensions::getDeleteFunctions())
91 {
92 d(5);
93 }
94
95 EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2);
96 for (auto& p : Extensions::getDeleteProhibitedFunctions())
97 {
98 bool prohibited = false;
99 p(5, prohibited);
100 EXPECT_TRUE(prohibited);
101 }
102
103 EXPECT_TRUE(Extensions::disableDefaultLogCaps());
104}