Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 1 | #include "elog_entry.hpp" |
| 2 | #include "extensions.hpp" |
| 3 | |
Matt Spinler | b181d9d | 2020-06-05 14:49:59 -0500 | [diff] [blame] | 4 | #include <sdbusplus/test/sdbus_mock.hpp> |
| 5 | |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 6 | #include <gtest/gtest.h> |
| 7 | |
| 8 | using namespace phosphor::logging; |
| 9 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 10 | void startup1(internal::Manager& /*manager*/) {} |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 11 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 12 | void startup2(internal::Manager& /*manager*/) {} |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 13 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 14 | void 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 Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 18 | {} |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 19 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 20 | void 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 Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 24 | {} |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 25 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 26 | void deleteLog1(uint32_t /*id*/) {} |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 27 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 28 | void deleteLog2(uint32_t /*id*/) {} |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 29 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 30 | void deleteProhibited1(uint32_t /*id*/, bool& prohibited) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 31 | { |
| 32 | prohibited = true; |
| 33 | } |
| 34 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 35 | void deleteProhibited2(uint32_t /*id*/, bool& prohibited) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 36 | { |
| 37 | prohibited = true; |
| 38 | } |
| 39 | |
harsh-agarwal1 | d763db3 | 2024-09-03 09:18:50 -0500 | [diff] [blame] | 40 | void logIDWithHwIsolation1(std::vector<uint32_t>& logIDs) |
| 41 | { |
| 42 | logIDs.push_back(1); |
| 43 | } |
| 44 | |
| 45 | void logIDWithHwIsolation2(std::vector<uint32_t>& logIDs) |
| 46 | { |
| 47 | logIDs.push_back(2); |
| 48 | } |
| 49 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 50 | DISABLE_LOG_ENTRY_CAPS() |
| 51 | REGISTER_EXTENSION_FUNCTION(startup1) |
| 52 | REGISTER_EXTENSION_FUNCTION(startup2) |
| 53 | REGISTER_EXTENSION_FUNCTION(create1) |
| 54 | REGISTER_EXTENSION_FUNCTION(create2) |
| 55 | REGISTER_EXTENSION_FUNCTION(deleteProhibited1) |
| 56 | REGISTER_EXTENSION_FUNCTION(deleteProhibited2) |
harsh-agarwal1 | d763db3 | 2024-09-03 09:18:50 -0500 | [diff] [blame] | 57 | REGISTER_EXTENSION_FUNCTION(logIDWithHwIsolation1) |
| 58 | REGISTER_EXTENSION_FUNCTION(logIDWithHwIsolation2) |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 59 | REGISTER_EXTENSION_FUNCTION(deleteLog1) |
| 60 | REGISTER_EXTENSION_FUNCTION(deleteLog2) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 61 | |
| 62 | TEST(ExtensionsTest, FunctionCallTest) |
| 63 | { |
Matt Spinler | b181d9d | 2020-06-05 14:49:59 -0500 | [diff] [blame] | 64 | sdbusplus::SdBusMock sdbusMock; |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 65 | sdbusplus::bus_t bus = sdbusplus::get_mocked_new(&sdbusMock); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 66 | 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 Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 76 | FFDCArg ffdc; |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 77 | EXPECT_EQ(Extensions::getCreateFunctions().size(), 2); |
| 78 | for (auto& c : Extensions::getCreateFunctions()) |
| 79 | { |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 80 | c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 81 | } |
| 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-agarwal1 | d763db3 | 2024-09-03 09:18:50 -0500 | [diff] [blame] | 97 | 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 Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 116 | EXPECT_TRUE(Extensions::disableDefaultLogCaps()); |
| 117 | } |