blob: 6dfe9be161212fbfd3aff85d2b5b1628f7db7371 [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
18void startup1(internal::Manager& manager)
19{
20}
21
22void startup2(internal::Manager& manager)
23{
24}
25
26void create1(const std::string& message, uint32_t id, uint64_t timestamp,
27 Entry::Level severity, const AdditionalDataArg& additionalData,
Matt Spinlerc64b7122020-03-26 10:55:01 -050028 const AssociationEndpointsArg& assocs, const FFDCArg& ffdc)
Matt Spinler99c2b402019-05-23 14:29:16 -050029{
30}
31
32void create2(const std::string& message, uint32_t id, uint64_t timestamp,
33 Entry::Level severity, const AdditionalDataArg& additionalData,
Matt Spinlerc64b7122020-03-26 10:55:01 -050034 const AssociationEndpointsArg& assocs, const FFDCArg& ffdc)
Matt Spinler99c2b402019-05-23 14:29:16 -050035{
36}
37
38void deleteLog1(uint32_t id)
39{
40}
41
42void deleteLog2(uint32_t id)
43{
44}
45
46void deleteProhibited1(uint32_t id, bool& prohibited)
47{
48 prohibited = true;
49}
50
51void deleteProhibited2(uint32_t id, bool& prohibited)
52{
53 prohibited = true;
54}
55
56DISABLE_LOG_ENTRY_CAPS();
57REGISTER_EXTENSION_FUNCTION(startup1);
58REGISTER_EXTENSION_FUNCTION(startup2);
59REGISTER_EXTENSION_FUNCTION(create1);
60REGISTER_EXTENSION_FUNCTION(create2);
61REGISTER_EXTENSION_FUNCTION(deleteProhibited1);
62REGISTER_EXTENSION_FUNCTION(deleteProhibited2);
63REGISTER_EXTENSION_FUNCTION(deleteLog1);
64REGISTER_EXTENSION_FUNCTION(deleteLog2);
65
66TEST(ExtensionsTest, FunctionCallTest)
67{
Matt Spinlerb181d9d2020-06-05 14:49:59 -050068 sdbusplus::SdBusMock sdbusMock;
69 sdbusplus::bus::bus bus = sdbusplus::get_mocked_new(&sdbusMock);
Matt Spinler99c2b402019-05-23 14:29:16 -050070 internal::Manager manager(bus, "testpath");
71
72 EXPECT_EQ(Extensions::getStartupFunctions().size(), 2);
73 for (auto& s : Extensions::getStartupFunctions())
74 {
75 s(manager);
76 }
77
78 AdditionalDataArg ad;
79 AssociationEndpointsArg assocs;
Matt Spinlerc64b7122020-03-26 10:55:01 -050080 FFDCArg ffdc;
Matt Spinler99c2b402019-05-23 14:29:16 -050081 EXPECT_EQ(Extensions::getCreateFunctions().size(), 2);
82 for (auto& c : Extensions::getCreateFunctions())
83 {
Matt Spinlerc64b7122020-03-26 10:55:01 -050084 c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -050085 }
86
87 EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2);
88 for (auto& d : Extensions::getDeleteFunctions())
89 {
90 d(5);
91 }
92
93 EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2);
94 for (auto& p : Extensions::getDeleteProhibitedFunctions())
95 {
96 bool prohibited = false;
97 p(5, prohibited);
98 EXPECT_TRUE(prohibited);
99 }
100
101 EXPECT_TRUE(Extensions::disableDefaultLogCaps());
102}