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 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 40 | DISABLE_LOG_ENTRY_CAPS() |
| 41 | REGISTER_EXTENSION_FUNCTION(startup1) |
| 42 | REGISTER_EXTENSION_FUNCTION(startup2) |
| 43 | REGISTER_EXTENSION_FUNCTION(create1) |
| 44 | REGISTER_EXTENSION_FUNCTION(create2) |
| 45 | REGISTER_EXTENSION_FUNCTION(deleteProhibited1) |
| 46 | REGISTER_EXTENSION_FUNCTION(deleteProhibited2) |
| 47 | REGISTER_EXTENSION_FUNCTION(deleteLog1) |
| 48 | REGISTER_EXTENSION_FUNCTION(deleteLog2) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 49 | |
| 50 | TEST(ExtensionsTest, FunctionCallTest) |
| 51 | { |
Matt Spinler | b181d9d | 2020-06-05 14:49:59 -0500 | [diff] [blame] | 52 | sdbusplus::SdBusMock sdbusMock; |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 53 | sdbusplus::bus_t bus = sdbusplus::get_mocked_new(&sdbusMock); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 54 | internal::Manager manager(bus, "testpath"); |
| 55 | |
| 56 | EXPECT_EQ(Extensions::getStartupFunctions().size(), 2); |
| 57 | for (auto& s : Extensions::getStartupFunctions()) |
| 58 | { |
| 59 | s(manager); |
| 60 | } |
| 61 | |
| 62 | AdditionalDataArg ad; |
| 63 | AssociationEndpointsArg assocs; |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 64 | FFDCArg ffdc; |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 65 | EXPECT_EQ(Extensions::getCreateFunctions().size(), 2); |
| 66 | for (auto& c : Extensions::getCreateFunctions()) |
| 67 | { |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 68 | c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2); |
| 72 | for (auto& d : Extensions::getDeleteFunctions()) |
| 73 | { |
| 74 | d(5); |
| 75 | } |
| 76 | |
| 77 | EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2); |
| 78 | for (auto& p : Extensions::getDeleteProhibitedFunctions()) |
| 79 | { |
| 80 | bool prohibited = false; |
| 81 | p(5, prohibited); |
| 82 | EXPECT_TRUE(prohibited); |
| 83 | } |
| 84 | |
| 85 | EXPECT_TRUE(Extensions::disableDefaultLogCaps()); |
| 86 | } |