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 | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 10 | void startup1(internal::Manager& /*manager*/) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 11 | { |
| 12 | } |
| 13 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 14 | void startup2(internal::Manager& /*manager*/) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 15 | { |
| 16 | } |
| 17 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 18 | void create1(const std::string& /*message*/, uint32_t /*id*/, |
| 19 | uint64_t /*timestamp*/, Entry::Level /*severity*/, |
| 20 | const AdditionalDataArg& /*additionalData*/, |
| 21 | const AssociationEndpointsArg& /*assocs*/, const FFDCArg& /*ffdc*/) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 22 | { |
| 23 | } |
| 24 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 25 | void create2(const std::string& /*message*/, uint32_t /*id*/, |
| 26 | uint64_t /*timestamp*/, Entry::Level /*severity*/, |
| 27 | const AdditionalDataArg& /*additionalData*/, |
| 28 | const AssociationEndpointsArg& /*assocs*/, const FFDCArg& /*ffdc*/) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 32 | void deleteLog1(uint32_t /*id*/) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 33 | { |
| 34 | } |
| 35 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 36 | void deleteLog2(uint32_t /*id*/) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 37 | { |
| 38 | } |
| 39 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 40 | void deleteProhibited1(uint32_t /*id*/, bool& prohibited) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 41 | { |
| 42 | prohibited = true; |
| 43 | } |
| 44 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 45 | void deleteProhibited2(uint32_t /*id*/, bool& prohibited) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 46 | { |
| 47 | prohibited = true; |
| 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) |
| 57 | REGISTER_EXTENSION_FUNCTION(deleteLog1) |
| 58 | REGISTER_EXTENSION_FUNCTION(deleteLog2) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 59 | |
| 60 | TEST(ExtensionsTest, FunctionCallTest) |
| 61 | { |
Matt Spinler | b181d9d | 2020-06-05 14:49:59 -0500 | [diff] [blame] | 62 | sdbusplus::SdBusMock sdbusMock; |
| 63 | sdbusplus::bus::bus bus = sdbusplus::get_mocked_new(&sdbusMock); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 64 | internal::Manager manager(bus, "testpath"); |
| 65 | |
| 66 | EXPECT_EQ(Extensions::getStartupFunctions().size(), 2); |
| 67 | for (auto& s : Extensions::getStartupFunctions()) |
| 68 | { |
| 69 | s(manager); |
| 70 | } |
| 71 | |
| 72 | AdditionalDataArg ad; |
| 73 | AssociationEndpointsArg assocs; |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 74 | FFDCArg ffdc; |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 75 | EXPECT_EQ(Extensions::getCreateFunctions().size(), 2); |
| 76 | for (auto& c : Extensions::getCreateFunctions()) |
| 77 | { |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 78 | c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2); |
| 82 | for (auto& d : Extensions::getDeleteFunctions()) |
| 83 | { |
| 84 | d(5); |
| 85 | } |
| 86 | |
| 87 | EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2); |
| 88 | for (auto& p : Extensions::getDeleteProhibitedFunctions()) |
| 89 | { |
| 90 | bool prohibited = false; |
| 91 | p(5, prohibited); |
| 92 | EXPECT_TRUE(prohibited); |
| 93 | } |
| 94 | |
| 95 | EXPECT_TRUE(Extensions::disableDefaultLogCaps()); |
| 96 | } |