blob: d5f29eb1038f4529c8f3411367065cce0e20b8b0 [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
harsh-agarwal1d763db32024-09-03 09:18:50 -050040void logIDWithHwIsolation1(std::vector<uint32_t>& logIDs)
41{
42 logIDs.push_back(1);
43}
44
45void logIDWithHwIsolation2(std::vector<uint32_t>& logIDs)
46{
47 logIDs.push_back(2);
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)
harsh-agarwal1d763db32024-09-03 09:18:50 -050057REGISTER_EXTENSION_FUNCTION(logIDWithHwIsolation1)
58REGISTER_EXTENSION_FUNCTION(logIDWithHwIsolation2)
Patrick Williamsce0bdf12021-04-16 20:09:22 -050059REGISTER_EXTENSION_FUNCTION(deleteLog1)
60REGISTER_EXTENSION_FUNCTION(deleteLog2)
Matt Spinler99c2b402019-05-23 14:29:16 -050061
62TEST(ExtensionsTest, FunctionCallTest)
63{
Matt Spinlerb181d9d2020-06-05 14:49:59 -050064 sdbusplus::SdBusMock sdbusMock;
Patrick Williams45e83522022-07-22 19:26:52 -050065 sdbusplus::bus_t bus = sdbusplus::get_mocked_new(&sdbusMock);
Matt Spinler99c2b402019-05-23 14:29:16 -050066 internal::Manager manager(bus, "testpath");
67
68 EXPECT_EQ(Extensions::getStartupFunctions().size(), 2);
69 for (auto& s : Extensions::getStartupFunctions())
70 {
71 s(manager);
72 }
73
74 AdditionalDataArg ad;
75 AssociationEndpointsArg assocs;
Matt Spinlerc64b7122020-03-26 10:55:01 -050076 FFDCArg ffdc;
Matt Spinler99c2b402019-05-23 14:29:16 -050077 EXPECT_EQ(Extensions::getCreateFunctions().size(), 2);
78 for (auto& c : Extensions::getCreateFunctions())
79 {
Matt Spinlerc64b7122020-03-26 10:55:01 -050080 c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -050081 }
82
83 EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2);
84 for (auto& d : Extensions::getDeleteFunctions())
85 {
86 d(5);
87 }
88
89 EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2);
90 for (auto& p : Extensions::getDeleteProhibitedFunctions())
91 {
92 bool prohibited = false;
93 p(5, prohibited);
94 EXPECT_TRUE(prohibited);
95 }
96
harsh-agarwal1d763db32024-09-03 09:18:50 -050097 EXPECT_EQ(Extensions::getLogIDWithHwIsolationFunctions().size(), 2);
98 std::vector<uint32_t> ids;
99 for (size_t i = 0; i < 2; ++i)
100 {
101 auto getLogIDWithHwIsolation =
102 Extensions::getLogIDWithHwIsolationFunctions()[i];
103 getLogIDWithHwIsolation(ids);
104 if (i == 0)
105 {
106 EXPECT_EQ(ids.size(), 1);
107 EXPECT_EQ(ids[0], 1);
108 }
109 if (i == 1)
110 {
111 EXPECT_EQ(ids.size(), 2);
112 EXPECT_EQ(ids[1], 2);
113 }
114 }
115
Matt Spinler99c2b402019-05-23 14:29:16 -0500116 EXPECT_TRUE(Extensions::disableDefaultLogCaps());
117}