blob: d210115982d28f16ee4b71715df873e1d5593e2f [file] [log] [blame]
Matt Spinler99c2b402019-05-23 14:29:16 -05001#include "elog_entry.hpp"
2#include "extensions.hpp"
3
4#include <gtest/gtest.h>
5
6using namespace phosphor::logging;
7
8// gtest doesn't like this happening in another file, so do it here.
9StartupFunctions Extensions::startupFunctions{};
10CreateFunctions Extensions::createFunctions{};
11DeleteFunctions Extensions::deleteFunctions{};
12DeleteProhibitedFunctions Extensions::deleteProhibitedFunctions{};
13Extensions::DefaultErrorCaps Extensions::defaultErrorCaps =
14 Extensions::DefaultErrorCaps::enable;
15
16void startup1(internal::Manager& manager)
17{
18}
19
20void startup2(internal::Manager& manager)
21{
22}
23
24void create1(const std::string& message, uint32_t id, uint64_t timestamp,
25 Entry::Level severity, const AdditionalDataArg& additionalData,
Matt Spinlerc64b7122020-03-26 10:55:01 -050026 const AssociationEndpointsArg& assocs, const FFDCArg& ffdc)
Matt Spinler99c2b402019-05-23 14:29:16 -050027{
28}
29
30void create2(const std::string& message, uint32_t id, uint64_t timestamp,
31 Entry::Level severity, const AdditionalDataArg& additionalData,
Matt Spinlerc64b7122020-03-26 10:55:01 -050032 const AssociationEndpointsArg& assocs, const FFDCArg& ffdc)
Matt Spinler99c2b402019-05-23 14:29:16 -050033{
34}
35
36void deleteLog1(uint32_t id)
37{
38}
39
40void deleteLog2(uint32_t id)
41{
42}
43
44void deleteProhibited1(uint32_t id, bool& prohibited)
45{
46 prohibited = true;
47}
48
49void deleteProhibited2(uint32_t id, bool& prohibited)
50{
51 prohibited = true;
52}
53
54DISABLE_LOG_ENTRY_CAPS();
55REGISTER_EXTENSION_FUNCTION(startup1);
56REGISTER_EXTENSION_FUNCTION(startup2);
57REGISTER_EXTENSION_FUNCTION(create1);
58REGISTER_EXTENSION_FUNCTION(create2);
59REGISTER_EXTENSION_FUNCTION(deleteProhibited1);
60REGISTER_EXTENSION_FUNCTION(deleteProhibited2);
61REGISTER_EXTENSION_FUNCTION(deleteLog1);
62REGISTER_EXTENSION_FUNCTION(deleteLog2);
63
64TEST(ExtensionsTest, FunctionCallTest)
65{
66 auto bus = sdbusplus::bus::new_default();
67 internal::Manager manager(bus, "testpath");
68
69 EXPECT_EQ(Extensions::getStartupFunctions().size(), 2);
70 for (auto& s : Extensions::getStartupFunctions())
71 {
72 s(manager);
73 }
74
75 AdditionalDataArg ad;
76 AssociationEndpointsArg assocs;
Matt Spinlerc64b7122020-03-26 10:55:01 -050077 FFDCArg ffdc;
Matt Spinler99c2b402019-05-23 14:29:16 -050078 EXPECT_EQ(Extensions::getCreateFunctions().size(), 2);
79 for (auto& c : Extensions::getCreateFunctions())
80 {
Matt Spinlerc64b7122020-03-26 10:55:01 -050081 c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -050082 }
83
84 EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2);
85 for (auto& d : Extensions::getDeleteFunctions())
86 {
87 d(5);
88 }
89
90 EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2);
91 for (auto& p : Extensions::getDeleteProhibitedFunctions())
92 {
93 bool prohibited = false;
94 p(5, prohibited);
95 EXPECT_TRUE(prohibited);
96 }
97
98 EXPECT_TRUE(Extensions::disableDefaultLogCaps());
99}